Skip to content

Commit 7df4278

Browse files
fix: fixes broken tests (#840)
Fixes HTML test generation to support `goog.module()` and take into account newlines and spaces. Updates python print statements to work in Python3+.
1 parent 389aa98 commit 7df4278

File tree

5 files changed

+15404
-305
lines changed

5 files changed

+15404
-305
lines changed

buildtools/gen_all_tests_js.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525

2626
def main():
2727
common.cd_to_firebaseui_root()
28-
print "var allTests = ["
28+
print("var allTests = [")
2929
_print_test_files_under_root(common.TESTS_BASE_PATH)
30-
print "];"
30+
print("];")
3131
# The following is required in the context of protractor.
32-
print "if (typeof module !== 'undefined' && module.exports) {"
33-
print " module.exports = allTests;"
34-
print "}"
32+
print("if (typeof module !== 'undefined' && module.exports) {")
33+
print(" module.exports = allTests;")
34+
print("}")
3535

3636

3737
def _print_test_files_under_root(root):
@@ -41,7 +41,7 @@ def _print_test_files_under_root(root):
4141
root: The path to the directory.
4242
"""
4343
for file_name in common.get_files_with_suffix(root, "_test.html"):
44-
print " '%s'," % file_name[2:] # Ignore the beginning './'.
44+
print(" '%s'," % file_name[2:]) # Ignore the beginning './'.
4545

4646

4747
if __name__ == "__main__":

buildtools/gen_test_html.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ def _gen_html(js_path, template):
6363

6464
_write_file(related_paths.html, generated_html)
6565

66-
except: # pylint: disable=bare-except
67-
print "HTML generation failed for: %s" % js_path
66+
except Exception as e: # pylint: disable=bare-except
67+
print("HTML generation failed for: %s" % js_path)
68+
print(e)
6869

6970

7071
def _get_related_paths_from_js_path(js_path):
@@ -86,21 +87,22 @@ def _get_related_paths_from_js_path(js_path):
8687

8788

8889
def _extract_closure_package(js_data):
89-
"""Extracts the package name that is goog.provide()d in the JS file.
90+
"""Extracts the package name that is goog.provide() or goog.module()
91+
in the JS file.
9092
9193
Args:
9294
js_data: The contents of a JS test (*_test.js) file.
9395
9496
Returns:
95-
The closure package goog.provide()d by the file.
97+
The closure package goog.provide() or good.module() by the file.
9698
9799
Raises:
98-
ValueError: The JS does not contain a goog.provide().
100+
ValueError: The JS does not contain a goog.provide() or goog.module().
99101
"""
100-
matches = re.search(r"goog\.provide\('(.+)'\);", js_data)
102+
matches = re.search(r"goog\.(provide|module)\([\n\s]*'(.+)'\);", js_data)
101103
if matches is None:
102-
raise ValueError("goog.provide() not found in file")
103-
return matches.group(1)
104+
raise ValueError("goog.provide() or goog.module() not found in file")
105+
return matches.group(2)
104106

105107

106108
def _read_file(path):

javascript/ui/page/selecttenant_test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
goog.module('firebaseui.auth.ui.page.SelectTenantTest');
2020
goog.setTestOnly();
2121

22-
22+
const InfoBarTestHelper =
23+
goog.require('firebaseui.auth.ui.element.InfoBarTestHelper');
2324
const KeyCodes = goog.require('goog.events.KeyCodes');
2425
const MockClock = goog.require('goog.testing.MockClock');
2526
const PageTestHelper = goog.require('firebaseui.auth.ui.page.PageTestHelper');
@@ -34,6 +35,8 @@ const testSuite = goog.require('goog.testing.testSuite');
3435
let mockClock;
3536
let root;
3637
let component;
38+
const infoBarTestHelper =
39+
new InfoBarTestHelper().registerTests();
3740
const tosPpTestHelper = new TosPpTestHelper().registerTests();
3841
const pageTestHelper = new PageTestHelper().registerTests();
3942

@@ -75,6 +78,7 @@ testSuite({
7578
TosPpTestHelper.prototype.onPpLinkClick,
7679
tosPpTestHelper));
7780
component.render(root);
81+
infoBarTestHelper.setComponent(component);
7882
tosPpTestHelper.setComponent(component);
7983
// Reset previous state of tosPp helper.
8084
tosPpTestHelper.resetState();

0 commit comments

Comments
 (0)