Skip to content
This repository was archived by the owner on Nov 19, 2025. It is now read-only.

Commit 6370373

Browse files
Merge pull request #320 from google/jasmine-launcher
Add a helper script to invoke the jasmine test runner
2 parents e3d5862 + e7844d0 commit 6370373

File tree

6 files changed

+103
-4
lines changed

6 files changed

+103
-4
lines changed

build-scripts/jasmine.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
# Run the test commands and fail the script if any of them failed
3+
EXIT_STATUS=0
4+
./packages/google-closure-compiler/test/support/jasmine-launcher.js "$@" || EXIT_STATUS=$?
5+
exit $EXIT_STATUS

build-scripts/test.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env bash
22
# Run the test commands and fail the script if any of them failed
33
EXIT_STATUS=0
4-
yarn workspaces run test "$@" || EXIT_STATUS=$?
5-
jasmine --reporter=jasmine-console-reporter test/*.js "$@" || EXIT_STATUS=$?
4+
./packages/google-closure-compiler/test/support/jasmine-launcher.js "$@" || EXIT_STATUS=$?
65
exit $EXIT_STATUS

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"scripts": {
4949
"build": "./build-scripts/build.sh",
5050
"test": "./build-scripts/test.sh",
51-
"test:root": "jasmine --reporter=jasmine-console-reporter test/*.js",
51+
"test:root": "./build-scripts/jasmine.sh --reporter=jasmine-console-reporter test/*.js",
5252
"clean": "./build-scripts/clean.sh",
5353
"version": "./build-scripts/version-packages.js",
5454
"publish-packages": "./build-scripts/publish.js"

packages/google-closure-compiler/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
},
6565
"scripts": {
6666
"build": "echo \"google-closure-compiler build\"",
67-
"test": "jasmine --reporter=jasmine-console-reporter test/*.js --"
67+
"test": "./test/support/jasmine.sh --reporter=jasmine-console-reporter 'test/*.js'"
6868
},
6969
"engines": {
7070
"node": ">=18"
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env node
2+
/*
3+
* Copyright 2025 The Closure Compiler Authors.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
/**
18+
* @fileoverview
19+
*
20+
* Execute jasmine with the arguments in the correct order.
21+
* Extra arguments passed to test specs must be preceded by an '--' argument.
22+
* We want to keep the arguments in the same order, but arguments for the jasmine runner itself must
23+
* come first followed by a '--' argument and then finally by any extra arguments.
24+
*/
25+
26+
import {spawn} from 'node:child_process';
27+
import parseArgs from 'minimist';
28+
29+
const supportedJasmineFlags = new Set([
30+
'parallel',
31+
'no-color',
32+
'color',
33+
'filter',
34+
'helper',
35+
'require',
36+
'fail-fast',
37+
'config',
38+
'reporter',
39+
'verbose',
40+
]);
41+
42+
const cliFlags = parseArgs(process.argv.slice(2));
43+
const jasmineFlags = [];
44+
const extraFlags = [];
45+
for (const [name, value] of Object.entries(cliFlags)) {
46+
const normalizedValues = Array.isArray(value) ? value : [value];
47+
if (name === '_') {
48+
jasmineFlags.push(...value);
49+
} else if (supportedJasmineFlags.has(name)) {
50+
for (const normalizedValue of normalizedValues) {
51+
jasmineFlags.push(`--${name}${typeof normalizedValue === 'boolean' ? '' : `=${normalizedValue}`}`);
52+
}
53+
} else {
54+
for (const normalizedValue of normalizedValues) {
55+
extraFlags.push(`--${name}${typeof normalizedValue === 'boolean' ? '' : `=${normalizedValue}`}`);
56+
}
57+
}
58+
}
59+
60+
const flagName = (flag) => {
61+
if (flag.startsWith('--')) {
62+
const valStart = flag.indexOf('=', 2);
63+
return flag.slice(0, valStart > 0 ? valStart : flag.length);
64+
}
65+
return flag;
66+
}
67+
const flagSorter = (a, b) => {
68+
const aFlagName = flagName(a);
69+
const bFlagName = flagName(b);
70+
const aIndex = process.argv.findIndex((arg) => arg === aFlagName || arg.startsWith(`${aFlagName}=`));
71+
const bIndex = process.argv.findIndex((arg) => arg === bFlagName || arg.startsWith(`${bFlagName}=`));
72+
return aIndex - bIndex;
73+
};
74+
jasmineFlags.sort(flagSorter);
75+
extraFlags.sort(flagSorter);
76+
if (extraFlags.length > 0) {
77+
jasmineFlags.push('--', ...extraFlags);
78+
}
79+
80+
const jasmineProcess = spawn(
81+
'jasmine',
82+
jasmineFlags,
83+
{
84+
stdio: 'inherit',
85+
},
86+
);
87+
88+
jasmineProcess.on('close', (exitCode) => {
89+
process.exitCode = exitCode;
90+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
# Run the test commands and fail the script if any of them failed
3+
EXIT_STATUS=0
4+
./test/support/jasmine-launcher.js "$@" || EXIT_STATUS=$?
5+
exit $EXIT_STATUS

0 commit comments

Comments
 (0)