From 11296d164aa5092973b50098b67a96c7f1fd33bb Mon Sep 17 00:00:00 2001 From: Chad Killingsworth Date: Sat, 17 May 2025 07:40:01 -0500 Subject: [PATCH 1/4] Add a helper script to invoke the jasmine test runner Helper script is needed to ensure command line arguments are correctly passed to jasmine --- build-scripts/test.sh | 2 +- package.json | 2 +- packages/google-closure-compiler/package.json | 2 +- .../test/support/jasmine-launcher.js | 90 +++++++++++++++++++ 4 files changed, 93 insertions(+), 3 deletions(-) create mode 100755 packages/google-closure-compiler/test/support/jasmine-launcher.js diff --git a/build-scripts/test.sh b/build-scripts/test.sh index bcb74ebe..4ddce5a9 100755 --- a/build-scripts/test.sh +++ b/build-scripts/test.sh @@ -2,5 +2,5 @@ # Run the test commands and fail the script if any of them failed EXIT_STATUS=0 yarn workspaces run test "$@" || EXIT_STATUS=$? -jasmine --reporter=jasmine-console-reporter test/*.js "$@" || EXIT_STATUS=$? +yarn test:root "$@" || EXIT_STATUS=$? exit $EXIT_STATUS diff --git a/package.json b/package.json index a081923a..47074605 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "scripts": { "build": "./build-scripts/build.sh", "test": "./build-scripts/test.sh", - "test:root": "jasmine --reporter=jasmine-console-reporter test/*.js", + "test:root": "./packages/google-closure-compiler/test/support/jasmine-launcher.js --reporter=jasmine-console-reporter test/*.js", "clean": "./build-scripts/clean.sh", "version": "./build-scripts/version-packages.js", "publish-packages": "./build-scripts/publish.js" diff --git a/packages/google-closure-compiler/package.json b/packages/google-closure-compiler/package.json index 9a451d84..791389c8 100644 --- a/packages/google-closure-compiler/package.json +++ b/packages/google-closure-compiler/package.json @@ -64,7 +64,7 @@ }, "scripts": { "build": "echo \"google-closure-compiler build\"", - "test": "jasmine --reporter=jasmine-console-reporter test/*.js --" + "test": "./test/support/jasmine-launcher.js --reporter=jasmine-console-reporter 'test/*.js'" }, "engines": { "node": ">=18" diff --git a/packages/google-closure-compiler/test/support/jasmine-launcher.js b/packages/google-closure-compiler/test/support/jasmine-launcher.js new file mode 100755 index 00000000..a220ac72 --- /dev/null +++ b/packages/google-closure-compiler/test/support/jasmine-launcher.js @@ -0,0 +1,90 @@ +#!/usr/bin/env node +/* + * Copyright 2025 The Closure Compiler Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @fileoverview + * + * Execute jasmine with the arguments in the correct order. + * Extra arguments passed to test specs must be preceded by an '--' argument. + * We want to keep the arguments in the same order, but arguments for the jasmine runner itself must + * come first followed by a '--' argument and then finally by any extra arguments. + */ + +import {spawn} from 'node:child_process'; +import parseArgs from 'minimist'; + +const supportedJasmineFlags = new Set([ + 'parallel', + 'no-color', + 'color', + 'filter', + 'helper', + 'require', + 'fail-fast', + 'config', + 'reporter', + 'verbose', +]); + +const cliFlags = parseArgs(process.argv.slice(2)); +const jasmineFlags = []; +const extraFlags = []; +for (const [name, value] of Object.entries(cliFlags)) { + const normalizedValues = Array.isArray(value) ? value : [value]; + if (name === '_') { + jasmineFlags.push(...value); + } else if (supportedJasmineFlags.has(name)) { + for (const normalizedValue of normalizedValues) { + jasmineFlags.push(`--${name}${typeof normalizedValue === 'boolean' ? '' : `=${normalizedValue}`}`); + } + } else { + for (const normalizedValue of normalizedValues) { + extraFlags.push(`--${name}${typeof normalizedValue === 'boolean' ? '' : `=${normalizedValue}`}`); + } + } +} + +const flagName = (flag) => { + if (flag.startsWith('--')) { + const valStart = flag.indexOf('=', 2); + return flag.slice(0, valStart > 0 ? valStart : flag.length); + } + return flag; +} +const flagSorter = (a, b) => { + const aFlagName = flagName(a); + const bFlagName = flagName(b); + const aIndex = process.argv.findIndex((arg) => arg === aFlagName || arg.startsWith(`${aFlagName}=`)); + const bIndex = process.argv.findIndex((arg) => arg === bFlagName || arg.startsWith(`${bFlagName}=`)); + return aIndex - bIndex; +}; +jasmineFlags.sort(flagSorter); +extraFlags.sort(flagSorter); +if (extraFlags.length > 0) { + jasmineFlags.push('--', ...extraFlags); +} + +const jasmineProcess = spawn( + 'jasmine', + jasmineFlags, + { + stdio: 'inherit', + }, +); + +jasmineProcess.on('close', (exitCode) => { + process.exitCode = exitCode; +}); From 06ddad932381775a51de9d74b7c3b77ba03e8a05 Mon Sep 17 00:00:00 2001 From: Chad Killingsworth Date: Sat, 17 May 2025 10:06:10 -0500 Subject: [PATCH 2/4] Fix test execution on windows --- package.json | 2 +- packages/google-closure-compiler/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 47074605..dc50f049 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "scripts": { "build": "./build-scripts/build.sh", "test": "./build-scripts/test.sh", - "test:root": "./packages/google-closure-compiler/test/support/jasmine-launcher.js --reporter=jasmine-console-reporter test/*.js", + "test:root": "node ./packages/google-closure-compiler/test/support/jasmine-launcher.js --reporter=jasmine-console-reporter test/*.js", "clean": "./build-scripts/clean.sh", "version": "./build-scripts/version-packages.js", "publish-packages": "./build-scripts/publish.js" diff --git a/packages/google-closure-compiler/package.json b/packages/google-closure-compiler/package.json index 791389c8..875993d7 100644 --- a/packages/google-closure-compiler/package.json +++ b/packages/google-closure-compiler/package.json @@ -64,7 +64,7 @@ }, "scripts": { "build": "echo \"google-closure-compiler build\"", - "test": "./test/support/jasmine-launcher.js --reporter=jasmine-console-reporter 'test/*.js'" + "test": "node ./test/support/jasmine-launcher.js --reporter=jasmine-console-reporter 'test/*.js'" }, "engines": { "node": ">=18" From 69fc904dc1c71bd2906856ab779a364c6bde80c4 Mon Sep 17 00:00:00 2001 From: Chad Killingsworth Date: Sat, 17 May 2025 10:23:46 -0500 Subject: [PATCH 3/4] Use a bash script to run the jasmine launcher Required for windows builds --- build-scripts/jasmine.sh | 5 +++++ build-scripts/test.sh | 3 +-- package.json | 2 +- packages/google-closure-compiler/package.json | 2 +- packages/google-closure-compiler/test/support/jasmine.sh | 5 +++++ 5 files changed, 13 insertions(+), 4 deletions(-) create mode 100755 build-scripts/jasmine.sh create mode 100755 packages/google-closure-compiler/test/support/jasmine.sh diff --git a/build-scripts/jasmine.sh b/build-scripts/jasmine.sh new file mode 100755 index 00000000..733bf727 --- /dev/null +++ b/build-scripts/jasmine.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +# Run the test commands and fail the script if any of them failed +EXIT_STATUS=0 +./packages/google-closure-compiler/test/support/jasmine-launcher.js "$@" || EXIT_STATUS=$? +exit $EXIT_STATUS diff --git a/build-scripts/test.sh b/build-scripts/test.sh index 4ddce5a9..733bf727 100755 --- a/build-scripts/test.sh +++ b/build-scripts/test.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash # Run the test commands and fail the script if any of them failed EXIT_STATUS=0 -yarn workspaces run test "$@" || EXIT_STATUS=$? -yarn test:root "$@" || EXIT_STATUS=$? +./packages/google-closure-compiler/test/support/jasmine-launcher.js "$@" || EXIT_STATUS=$? exit $EXIT_STATUS diff --git a/package.json b/package.json index dc50f049..d2c78be7 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "scripts": { "build": "./build-scripts/build.sh", "test": "./build-scripts/test.sh", - "test:root": "node ./packages/google-closure-compiler/test/support/jasmine-launcher.js --reporter=jasmine-console-reporter test/*.js", + "test:root": "./build-scripts/jasmine.sh --reporter=jasmine-console-reporter test/*.js", "clean": "./build-scripts/clean.sh", "version": "./build-scripts/version-packages.js", "publish-packages": "./build-scripts/publish.js" diff --git a/packages/google-closure-compiler/package.json b/packages/google-closure-compiler/package.json index 875993d7..8698d8e2 100644 --- a/packages/google-closure-compiler/package.json +++ b/packages/google-closure-compiler/package.json @@ -64,7 +64,7 @@ }, "scripts": { "build": "echo \"google-closure-compiler build\"", - "test": "node ./test/support/jasmine-launcher.js --reporter=jasmine-console-reporter 'test/*.js'" + "test": "./test/support/jasmine-launcher.sh --reporter=jasmine-console-reporter 'test/*.js'" }, "engines": { "node": ">=18" diff --git a/packages/google-closure-compiler/test/support/jasmine.sh b/packages/google-closure-compiler/test/support/jasmine.sh new file mode 100755 index 00000000..8fec70db --- /dev/null +++ b/packages/google-closure-compiler/test/support/jasmine.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +# Run the test commands and fail the script if any of them failed +EXIT_STATUS=0 +./test/support/jasmine-launcher.js "$@" || EXIT_STATUS=$? +exit $EXIT_STATUS From e7844d0dee9a459376244257d6e5e8a9cadc1117 Mon Sep 17 00:00:00 2001 From: Chad Killingsworth Date: Sat, 17 May 2025 10:51:22 -0500 Subject: [PATCH 4/4] Fix test path --- packages/google-closure-compiler/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/google-closure-compiler/package.json b/packages/google-closure-compiler/package.json index 8698d8e2..2b5a0c11 100644 --- a/packages/google-closure-compiler/package.json +++ b/packages/google-closure-compiler/package.json @@ -64,7 +64,7 @@ }, "scripts": { "build": "echo \"google-closure-compiler build\"", - "test": "./test/support/jasmine-launcher.sh --reporter=jasmine-console-reporter 'test/*.js'" + "test": "./test/support/jasmine.sh --reporter=jasmine-console-reporter 'test/*.js'" }, "engines": { "node": ">=18"