Skip to content
This repository was archived by the owner on Aug 1, 2024. It is now read-only.

Commit ba58647

Browse files
committed
Generate alltests.js on npm run serve_tests.
RELNOTES: n/a PiperOrigin-RevId: 358844337
1 parent b923bd4 commit ba58647

File tree

10 files changed

+191
-742
lines changed

10 files changed

+191
-742
lines changed

.gitignore

+7-5
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@
1010

1111
# python
1212
*.pyc
13-
14-
# Generated deps.js
15-
closure/goog/deps.js
16-
1713
node_modules/
1814
closure-deps/node_modules/
1915
package-lock.json
2016

21-
# Closure Generated Unit Test
17+
# Closure Generated Unit Tests
2218
*_test.html
2319

20+
# Generated alltests.js
21+
alltests.js
22+
23+
# Generated deps.js
24+
closure/goog/deps.js
25+
File renamed without changes.

alltests.js

-634
This file was deleted.

closure/bin/generate_closure_unit_tests/package.json

-19
This file was deleted.

package.json

+8-6
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,21 @@
2020
},
2121
"homepage": "https://developers.google.com/closure/library/",
2222
"devDependencies": {
23-
"generate_closure_unit_tests": "file:./closure/bin/generate_closure_unit_tests/",
2423
"google-closure-deps": "file:./closure-deps/",
2524
"http-server": "^0.12.1",
25+
"parse5": "^6.0.1",
2626
"promise": "^7.0.4",
2727
"promises-aplus-tests": "^2.1.2",
2828
"protractor": "^7.0.0"
2929
},
3030
"scripts": {
31-
"gen_deps_js": "node scripts/gen_deps_js > ./closure/goog/deps.js",
32-
"gen_all_tests": "npx generate_closure_unit_tests --base=closure/goog/base.js --recursive ./closure/goog/ --overwrite",
31+
"gen_deps_js": "node scripts/generate_deps_js > ./closure/goog/deps.js",
32+
"gen_deps_js_with_tests": "node scripts/generate_deps_js --with_tests > ./closure/goog/deps.js",
33+
"gen_alltests_js": "node scripts/generate_alltests_js > ./alltests.js",
34+
"gen_test_htmls": "node scripts/generate_closure_unit_tests --base=closure/goog/base.js --recursive ./closure/goog/ ./third_party/closure/goog/ --overwrite",
3335
"prepare": "npm run gen_deps_js",
34-
"preserve_tests": "npm run gen_all_tests",
35-
"serve_tests": "npx http-server -o allTests.html",
36-
"serve_demos": "npx http-server -o closure/goog/demos/index.html"
36+
"preserve_tests": "npm run gen_deps_js_with_tests && npm run gen_test_htmls && npm run gen_alltests_js",
37+
"serve_tests": "http-server -o alltests.html",
38+
"serve_demos": "http-server -o closure/goog/demos/index.html"
3739
}
3840
}

scripts/ci/compile_closure.sh

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ java -Xmx1G -jar ../closure-compiler-1.0-SNAPSHOT.jar \
4545
--js='!**protractor_spec.js' \
4646
--js='!**protractor.conf.js' \
4747
--js='!**browser_capabilities.js' \
48-
--js='!**generate_closure_unit_tests.js' \
4948
--js='!./doc/**.js' \
5049
--js='!**debug_loader_integration_tests/testdata/**' \
5150
--js_output_file="$(mktemp)"

scripts/gen_deps_js.js

-77
This file was deleted.

scripts/generate_alltests_js.js

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* @license
3+
* Copyright The Closure Library Authors.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @fileoverview A utility to write alltests.js for Closure Library.
9+
*/
10+
11+
const {promises: fs} = require('fs');
12+
13+
const CLOSURE_PATH = 'closure/goog';
14+
const THIRD_PARTY_PATH = 'third_party/closure/goog';
15+
16+
const HEADER = `
17+
/**
18+
* @license
19+
* Copyright The Closure Library Authors.
20+
* SPDX-License-Identifier: Apache-2.0
21+
*/
22+
23+
// This file has been auto-generated, please do not edit.
24+
// To regenerate, run \`npm run gen_alltests_js\` in the root directory of the
25+
// Closure Library git repository.
26+
`.trim();
27+
28+
const FOOTER = `
29+
// If we're running in a nodejs context, export tests. Used when running tests
30+
// externally on Travis.
31+
if (typeof module !== 'undefined' && module.exports) {
32+
module.exports = _allTests;
33+
}
34+
`.trim();
35+
36+
/**
37+
* Calls fs.readdir recursively on the given path and subdirectories.
38+
* Returns only the list of files.
39+
* @param {string} path The path to read.
40+
* @return {!Array<string>} A list of files.
41+
*/
42+
async function readdirRecursive(path) {
43+
const filesAndDirectories =
44+
(await fs.readdir(path))
45+
.map(fileOrDirectory => `${path}/${fileOrDirectory}`)
46+
.sort();
47+
const files = [];
48+
for (const fileOrDirectory of filesAndDirectories) {
49+
const fileStat = await fs.stat(fileOrDirectory);
50+
if (fileStat.isDirectory()) {
51+
files.push(...await readdirRecursive(fileOrDirectory));
52+
} else {
53+
files.push(fileOrDirectory);
54+
}
55+
}
56+
return files;
57+
}
58+
59+
/**
60+
* Prints the generated alltests.js contents.
61+
* @return {!Promise<number>} The exit code.
62+
*/
63+
async function main() {
64+
try {
65+
// Get a list of all *_test.html files.
66+
const allTestHtmls = [
67+
...await readdirRecursive(CLOSURE_PATH),
68+
...await readdirRecursive(THIRD_PARTY_PATH),
69+
].filter(f => f.endsWith('_test.html'));
70+
if (allTestHtmls.length === 0) {
71+
throw new Error(
72+
'No *_test.html files found. Did you run `npm run gen_test_htmls`?');
73+
}
74+
75+
const output = [
76+
HEADER, '', 'var _allTests = [', ...allTestHtmls.map(f => ` '${f}',`),
77+
'];', '', FOOTER
78+
];
79+
console.log(output.join('\n'));
80+
return 0;
81+
} catch (e) {
82+
console.error(e);
83+
return 1;
84+
}
85+
}
86+
87+
main().then(code => process.exit(code));
+2
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ function createHtml(
251251
// Use parse5 to parse and reserialize the test dom. This generates any
252252
// optional tags (html, body, head) if missing. Meaning test doms can specify
253253
// these tags, if needed.
254+
// TODO(user): Remove parse5 as a dependency, as this code can be
255+
// written without it.
254256
return parse5.serialize(parse5.parse(`<!DOCTYPE html>
255257
<!-- DO NOT EDIT. This file auto-generated by generate_closure_unit_tests.js -->
256258
<!--

scripts/generate_deps_js.js

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* @license
3+
* Copyright The Closure Library Authors.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @fileoverview A utility to write deps.js for Closure Library.
9+
*/
10+
11+
const {closureMakeDeps} = require('google-closure-deps');
12+
13+
const CLOSURE_PATH = 'closure/goog';
14+
const THIRD_PARTY_PATH = 'third_party/closure/goog';
15+
16+
const HEADER = `
17+
// Copyright The Closure Library Authors.
18+
// SPDX-License-Identifier: Apache-2.0
19+
20+
// This file has been auto-generated, please do not edit.
21+
// To regenerate, run \`npm run gen_deps_js\` in the root directory of the
22+
// Closure Library git repository.
23+
24+
// Disable Clang formatter for this file.
25+
// See http://goo.gl/SdiwZH
26+
// clang-format off
27+
`.trim();
28+
29+
/**
30+
* Flags to add to closureMakeDeps in order to exclude tests.
31+
*/
32+
const TEST_EXCLUSION_FLAGS = [
33+
'--exclude',
34+
'**/*_test.js',
35+
'--exclude',
36+
'**/tester.js',
37+
'--exclude',
38+
'**/*_test_vectors.js',
39+
'--exclude',
40+
'**/*_test_suite.js',
41+
'--exclude',
42+
'**/*_test_cases.js',
43+
'--exclude',
44+
'**/testdata/**/*.js',
45+
];
46+
47+
/**
48+
* Prints the generated deps.js contents.
49+
* @param {!Array<string>} args Command-line arguments.
50+
* @return {!Promise<number>} The exit code.
51+
*/
52+
async function main(args) {
53+
try {
54+
const genDepsWithTests = args.indexOf('--with_tests') != -1;
55+
const {text, errors} = await closureMakeDeps.execute([
56+
'--root',
57+
CLOSURE_PATH,
58+
'--root',
59+
THIRD_PARTY_PATH,
60+
...genDepsWithTests ? [] : TEST_EXCLUSION_FLAGS,
61+
'--exclude',
62+
`${CLOSURE_PATH}/css`,
63+
'--exclude',
64+
`${CLOSURE_PATH}/demos`,
65+
'--exclude',
66+
`${CLOSURE_PATH}/deps.js`,
67+
'--exclude',
68+
`${CLOSURE_PATH}/transpile.js`,
69+
]);
70+
// Print all encountered errors. Errors are not necessarily fatal.
71+
for (const error of errors) {
72+
console.error(error.toString());
73+
}
74+
if (text) {
75+
console.log(`${HEADER}\n\n${text.trim()}`);
76+
return 0;
77+
} else {
78+
// No text indicates that the errors were fatal.
79+
return 1;
80+
}
81+
} catch (e) {
82+
console.error(e);
83+
return 1;
84+
}
85+
}
86+
87+
main(process.argv.slice(2)).then(code => process.exit(code));

0 commit comments

Comments
 (0)