Skip to content

Commit 95bf61e

Browse files
committed
Factor website's run-tests.mjs into reusable module
I want to use Jasmine and website/run-tests.mjs for testing code in wasm/. Make run-tests.mjs reusable by moving it into its own package. This commit should not change behavior.
1 parent 7c05d81 commit 95bf61e

File tree

8 files changed

+242
-108
lines changed

8 files changed

+242
-108
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules/
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This directory contains a Node.js support package for
2+
running Jasmine-based tests.
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Copyright (C) 2020 Matthew "strager" Glazar
2+
// See end of file for extended copyright information.
3+
4+
import Jasmine from "jasmine";
5+
import colors from "colors";
6+
import fs from "fs";
7+
import path from "path";
8+
import url from "url";
9+
10+
export function main(projectDirectory) {
11+
let jasmine = new Jasmine();
12+
jasmine.loadConfig({
13+
spec_dir: path.relative("", projectDirectory),
14+
spec_files: ["!node_modules/**", "**/test-*.mjs"],
15+
stopSpecOnExpectationFailure: true,
16+
random: false,
17+
});
18+
jasmine.clearReporters();
19+
jasmine.addReporter(new BasicReporter());
20+
let { fileNames, testNames } = parseCommandLineOptions();
21+
jasmine.execute(fileNames, testNames);
22+
}
23+
24+
function parseCommandLineOptions() {
25+
let options = process.argv.slice(2);
26+
27+
let fileNames = [];
28+
let testNames = [];
29+
for (let option of options) {
30+
if (fs.existsSync(option)) {
31+
fileNames.push(option);
32+
} else {
33+
testNames.push(option);
34+
}
35+
}
36+
if (testNames.length > 1) {
37+
console.error(
38+
`${colors.red("ERROR")} only one test name filter is allowed`
39+
);
40+
process.exit(1);
41+
}
42+
return { fileNames, testNames };
43+
}
44+
45+
class BasicReporter {
46+
constructor() {
47+
this._executedTests = 0;
48+
}
49+
50+
jasmineStarted(_summary) {}
51+
52+
jasmineDone(summary) {
53+
switch (summary.overallStatus) {
54+
case "passed":
55+
if (this._executedTests === 0) {
56+
console.error(`${colors.red("ERROR")} no tests executed`);
57+
process.exit(1);
58+
}
59+
break;
60+
61+
case "incomplete":
62+
console.error(`${colors.red("ERROR")} ${summary.incompleteReason}`);
63+
process.exit(1);
64+
break;
65+
66+
case "failed":
67+
// specDone should have killed the process already. But just in case...
68+
console.error(`${colors.red("ERROR")} tests failed`);
69+
process.exit(1);
70+
break;
71+
72+
default:
73+
console.error(
74+
`${colors.red("ERROR")} unknown status: ${summary.overallStatus}`
75+
);
76+
process.exit(1);
77+
break;
78+
}
79+
}
80+
81+
suiteStarted(_suite) {}
82+
83+
suiteDone(_suite) {}
84+
85+
specStarted(spec) {
86+
console.error(`Running ${spec.fullName} ...`);
87+
}
88+
89+
specDone(spec) {
90+
switch (spec.status) {
91+
case "passed":
92+
console.error(`${colors.green("OK")} ${spec.fullName}`);
93+
this._executedTests += 1;
94+
break;
95+
96+
case "excluded":
97+
console.error(`${colors.yellow("SKIP")} ${spec.fullName}`);
98+
break;
99+
100+
default:
101+
case "failed":
102+
for (let failure of spec.failedExpectations) {
103+
console.error(failure.stack);
104+
}
105+
console.error(`${colors.red("FAIL")} ${spec.fullName}`);
106+
process.exit(1);
107+
break;
108+
}
109+
}
110+
}
111+
112+
// quick-lint-js finds bugs in JavaScript programs.
113+
// Copyright (C) 2020 Matthew "strager" Glazar
114+
//
115+
// This file is part of quick-lint-js.
116+
//
117+
// quick-lint-js is free software: you can redistribute it and/or modify
118+
// it under the terms of the GNU General Public License as published by
119+
// the Free Software Foundation, either version 3 of the License, or
120+
// (at your option) any later version.
121+
//
122+
// quick-lint-js is distributed in the hope that it will be useful,
123+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
124+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
125+
// GNU General Public License for more details.
126+
//
127+
// You should have received a copy of the GNU General Public License
128+
// along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "quick-lint-js-node-test-runner",
3+
"version": "0.1.0",
4+
"main": "index.mjs",
5+
"dependencies": {
6+
"colors": "^1.4.0",
7+
"jasmine": "^3.7.0"
8+
}
9+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
balanced-match@^1.0.0:
6+
version "1.0.2"
7+
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
8+
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==
9+
10+
brace-expansion@^1.1.7:
11+
version "1.1.11"
12+
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
13+
integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==
14+
dependencies:
15+
balanced-match "^1.0.0"
16+
concat-map "0.0.1"
17+
18+
colors@^1.4.0:
19+
version "1.4.0"
20+
resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
21+
integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==
22+
23+
24+
version "0.0.1"
25+
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
26+
integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=
27+
28+
fs.realpath@^1.0.0:
29+
version "1.0.0"
30+
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
31+
integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8=
32+
33+
glob@^7.1.6:
34+
version "7.1.7"
35+
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.7.tgz#3b193e9233f01d42d0b3f78294bbeeb418f94a90"
36+
integrity sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==
37+
dependencies:
38+
fs.realpath "^1.0.0"
39+
inflight "^1.0.4"
40+
inherits "2"
41+
minimatch "^3.0.4"
42+
once "^1.3.0"
43+
path-is-absolute "^1.0.0"
44+
45+
inflight@^1.0.4:
46+
version "1.0.6"
47+
resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
48+
integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=
49+
dependencies:
50+
once "^1.3.0"
51+
wrappy "1"
52+
53+
inherits@2:
54+
version "2.0.4"
55+
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
56+
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
57+
58+
jasmine-core@~3.8.0:
59+
version "3.8.0"
60+
resolved "https://registry.yarnpkg.com/jasmine-core/-/jasmine-core-3.8.0.tgz#815399aae5aa5d9beeb1262805f981b99ffc9bf0"
61+
integrity sha512-zl0nZWDrmbCiKns0NcjkFGYkVTGCPUgoHypTaj+G2AzaWus7QGoXARSlYsSle2VRpSdfJmM+hzmFKzQNhF2kHg==
62+
63+
jasmine@^3.7.0:
64+
version "3.8.0"
65+
resolved "https://registry.yarnpkg.com/jasmine/-/jasmine-3.8.0.tgz#4497bc797eede7ca9de18179aedd4cf50245d8dc"
66+
integrity sha512-kdQ3SfcNpMbbMdgJPLyFe9IksixdnrgYaCJapP9sS0aLgdWdIZADNXEr+11Zafxm1VDfRSC5ZL4fzXT0bexzXw==
67+
dependencies:
68+
glob "^7.1.6"
69+
jasmine-core "~3.8.0"
70+
71+
minimatch@^3.0.4:
72+
version "3.0.4"
73+
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
74+
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==
75+
dependencies:
76+
brace-expansion "^1.1.7"
77+
78+
once@^1.3.0:
79+
version "1.4.0"
80+
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
81+
integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E=
82+
dependencies:
83+
wrappy "1"
84+
85+
path-is-absolute@^1.0.0:
86+
version "1.0.1"
87+
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
88+
integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18=
89+
90+
wrappy@1:
91+
version "1.0.2"
92+
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
93+
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=

website/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
"markdown-it": "^12.0.6",
1818
"mime": "^2.5.2",
1919
"morgan": "^1.10.0",
20+
"quick-lint-js-node-test-runner": "../tools/quick-lint-js-node-test-runner/",
2021
"quick-lint-js-wasm": "../wasm"
2122
},
2223
"devDependencies": {
2324
"axios": "^0.21.1",
24-
"colors": "^1.4.0",
25-
"jasmine": "^3.7.0",
2625
"prettier": "^2.3.0"
2726
}
2827
}

website/run-tests.mjs

Lines changed: 2 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,14 @@
11
// Copyright (C) 2020 Matthew "strager" Glazar
22
// See end of file for extended copyright information.
33

4-
import Jasmine from "jasmine";
5-
import colors from "colors";
6-
import fs from "fs";
4+
import { main } from "quick-lint-js-node-test-runner";
75
import path from "path";
86
import url from "url";
97

108
let __filename = url.fileURLToPath(import.meta.url);
119
let __dirname = path.dirname(__filename);
1210

13-
function main() {
14-
let jasmine = new Jasmine();
15-
jasmine.loadConfig({
16-
spec_dir: path.relative("", __dirname),
17-
spec_files: ["!node_modules/**", "**/test-*.mjs"],
18-
stopSpecOnExpectationFailure: true,
19-
random: false,
20-
});
21-
jasmine.clearReporters();
22-
jasmine.addReporter(new BasicReporter());
23-
let { fileNames, testNames } = parseCommandLineOptions();
24-
jasmine.execute(fileNames, testNames);
25-
}
26-
27-
function parseCommandLineOptions() {
28-
let options = process.argv.slice(2);
29-
30-
let fileNames = [];
31-
let testNames = [];
32-
for (let option of options) {
33-
if (fs.existsSync(option)) {
34-
fileNames.push(option);
35-
} else {
36-
testNames.push(option);
37-
}
38-
}
39-
if (testNames.length > 1) {
40-
console.error(
41-
`${colors.red("ERROR")} only one test name filter is allowed`
42-
);
43-
process.exit(1);
44-
}
45-
return { fileNames, testNames };
46-
}
47-
48-
class BasicReporter {
49-
constructor() {
50-
this._executedTests = 0;
51-
}
52-
53-
jasmineStarted(_summary) {}
54-
55-
jasmineDone(summary) {
56-
switch (summary.overallStatus) {
57-
case "passed":
58-
if (this._executedTests === 0) {
59-
console.error(`${colors.red("ERROR")} no tests executed`);
60-
process.exit(1);
61-
}
62-
break;
63-
64-
case "incomplete":
65-
console.error(`${colors.red("ERROR")} ${summary.incompleteReason}`);
66-
process.exit(1);
67-
break;
68-
69-
case "failed":
70-
// specDone should have killed the process already. But just in case...
71-
console.error(`${colors.red("ERROR")} tests failed`);
72-
process.exit(1);
73-
break;
74-
75-
default:
76-
console.error(
77-
`${colors.red("ERROR")} unknown status: ${summary.overallStatus}`
78-
);
79-
process.exit(1);
80-
break;
81-
}
82-
}
83-
84-
suiteStarted(_suite) {}
85-
86-
suiteDone(_suite) {}
87-
88-
specStarted(spec) {
89-
console.error(`Running ${spec.fullName} ...`);
90-
}
91-
92-
specDone(spec) {
93-
switch (spec.status) {
94-
case "passed":
95-
console.error(`${colors.green("OK")} ${spec.fullName}`);
96-
this._executedTests += 1;
97-
break;
98-
99-
case "excluded":
100-
console.error(`${colors.yellow("SKIP")} ${spec.fullName}`);
101-
break;
102-
103-
default:
104-
case "failed":
105-
for (let failure of spec.failedExpectations) {
106-
console.error(failure.stack);
107-
}
108-
console.error(`${colors.red("FAIL")} ${spec.fullName}`);
109-
process.exit(1);
110-
break;
111-
}
112-
}
113-
}
114-
115-
main();
11+
main(__dirname);
11612

11713
// quick-lint-js finds bugs in JavaScript programs.
11814
// Copyright (C) 2020 Matthew "strager" Glazar

website/yarn.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,12 @@ [email protected]:
920920
resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc"
921921
integrity sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==
922922

923+
quick-lint-js-node-test-runner@../tools/quick-lint-js-node-test-runner/:
924+
version "0.1.0"
925+
dependencies:
926+
colors "^1.4.0"
927+
jasmine "^3.7.0"
928+
923929
quick-lint-js-wasm@../wasm:
924930
version "0.0.0"
925931

0 commit comments

Comments
 (0)