Skip to content

Commit 14c4f84

Browse files
committed
wasm: add a basic test
Begin porting tests from plugin/vscode/test/other-tests.js to Jasmine by porting a single, simple test.
1 parent 95bf61e commit 14c4f84

File tree

7 files changed

+264
-10
lines changed

7 files changed

+264
-10
lines changed

.github/workflows/build-wasm.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright (C) 2020 Matthew Glazar
2+
# See end of file for extended copyright information.
3+
4+
name: build wasm
5+
on:
6+
push:
7+
pull_request:
8+
types: [opened, synchronize]
9+
10+
jobs:
11+
build:
12+
name: wasm
13+
runs-on: ubuntu-latest
14+
container: ghcr.io/quick-lint/quick-lint-js-github-builder:v3
15+
env:
16+
QLJS_COLLECT_COPYRIGHT_NO_WARNINGS: 1
17+
steps:
18+
- uses: mymindstorm/setup-emsdk@v7
19+
with:
20+
version: 2.0.4
21+
- name: checkout
22+
uses: actions/checkout@v2
23+
24+
- name: C++ configure
25+
run: emcmake cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug
26+
- name: C++ build
27+
run: emmake cmake --build build --target quick-lint-js-vscode quick-lint-js-vscode-licenses
28+
- name: C++ install
29+
run: emmake cmake --install build --component vscode --prefix wasm
30+
31+
- name: JS configure
32+
run: cd wasm && yarn install
33+
- name: JS test
34+
run: cd wasm && yarn test
35+
36+
# quick-lint-js finds bugs in JavaScript programs.
37+
# Copyright (C) 2020 Matthew Glazar
38+
#
39+
# This file is part of quick-lint-js.
40+
#
41+
# quick-lint-js is free software: you can redistribute it and/or modify
42+
# it under the terms of the GNU General Public License as published by
43+
# the Free Software Foundation, either version 3 of the License, or
44+
# (at your option) any later version.
45+
#
46+
# quick-lint-js is distributed in the hope that it will be useful,
47+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
48+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49+
# GNU General Public License for more details.
50+
#
51+
# You should have received a copy of the GNU General Public License
52+
# along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>.

tools/quick-lint-js-node-test-runner/index.mjs renamed to tools/quick-lint-js-node-test-runner/index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
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";
7-
import path from "path";
8-
import url from "url";
4+
let Jasmine = require("jasmine");
5+
let colors = require("colors");
6+
let fs = require("fs");
7+
let path = require("path");
8+
let url = require("url");
99

10-
export function main(projectDirectory) {
10+
function main(projectDirectory) {
1111
let jasmine = new Jasmine();
1212
jasmine.loadConfig({
1313
spec_dir: path.relative("", projectDirectory),
14-
spec_files: ["!node_modules/**", "**/test-*.mjs"],
14+
spec_files: ["!node_modules/**", "**/test-*.js", "**/test-*.mjs"],
1515
stopSpecOnExpectationFailure: true,
1616
random: false,
1717
});
@@ -20,6 +20,7 @@ export function main(projectDirectory) {
2020
let { fileNames, testNames } = parseCommandLineOptions();
2121
jasmine.execute(fileNames, testNames);
2222
}
23+
exports.main = main;
2324

2425
function parseCommandLineOptions() {
2526
let options = process.argv.slice(2);

tools/quick-lint-js-node-test-runner/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "quick-lint-js-node-test-runner",
33
"version": "0.1.0",
4-
"main": "index.mjs",
4+
"main": "index.js",
55
"dependencies": {
66
"colors": "^1.4.0",
77
"jasmine": "^3.7.0"

wasm/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
"name": "quick-lint-js-wasm",
33
"version": "0.0.0",
44
"scripts": {
5-
"fmt": "prettier --write '*.js' '*.json'"
5+
"fmt": "prettier --write '*.js' '*.json'",
6+
"test": "node run-tests.js"
67
},
78
"devDependencies": {
8-
"prettier": "^2.3.0"
9+
"prettier": "^2.3.0",
10+
"quick-lint-js-node-test-runner": "../tools/quick-lint-js-node-test-runner/"
911
}
1012
}

wasm/run-tests.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (C) 2020 Matthew "strager" Glazar
2+
// See end of file for extended copyright information.
3+
4+
let { main } = require("quick-lint-js-node-test-runner");
5+
6+
main(__dirname);
7+
8+
// quick-lint-js finds bugs in JavaScript programs.
9+
// Copyright (C) 2020 Matthew "strager" Glazar
10+
//
11+
// This file is part of quick-lint-js.
12+
//
13+
// quick-lint-js is free software: you can redistribute it and/or modify
14+
// it under the terms of the GNU General Public License as published by
15+
// the Free Software Foundation, either version 3 of the License, or
16+
// (at your option) any later version.
17+
//
18+
// quick-lint-js is distributed in the hope that it will be useful,
19+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
// GNU General Public License for more details.
22+
//
23+
// You should have received a copy of the GNU General Public License
24+
// along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>.

wasm/test-document.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright (C) 2020 Matthew "strager" Glazar
2+
// See end of file for extended copyright information.
3+
4+
"use strict";
5+
6+
let assert = require("assert");
7+
let {
8+
DocumentLinter,
9+
createProcessFactoryAsync,
10+
} = require("./quick-lint-js.js");
11+
12+
let processFactoryPromise = createProcessFactoryAsync();
13+
14+
describe("DocumentLinter", () => {
15+
let toDisposeAfterTest = [];
16+
function disposeAfterTest(disposable) {
17+
toDisposeAfterTest.push(disposable);
18+
return disposable;
19+
}
20+
afterEach(async () => {
21+
for (let toDispose of toDisposeAfterTest) {
22+
await toDispose.disposeAsync();
23+
}
24+
});
25+
26+
it("opening editor lints", async () => {
27+
let document = new MockDocument("let x;let x;");
28+
let linter = disposeAfterTest(
29+
new DocumentLinter(document, processFactoryPromise)
30+
);
31+
32+
await linter.editorChangedVisibilityAsync();
33+
34+
assert.deepStrictEqual(document.getDiagnosticMessages(), [
35+
"redeclaration of variable: x",
36+
]);
37+
});
38+
});
39+
40+
class MockDocument {
41+
constructor(text) {
42+
this.text = text;
43+
this.diagnostics = [];
44+
}
45+
46+
getText() {
47+
return this.text;
48+
}
49+
50+
setDiagnostics(diagnostics) {
51+
this.diagnostics = diagnostics;
52+
}
53+
54+
removeDiagnostics() {
55+
this.diagnostics = [];
56+
}
57+
58+
getDiagnosticMessages() {
59+
return this.diagnostics.map((diag) => diag.message);
60+
}
61+
}
62+
63+
// quick-lint-js finds bugs in JavaScript programs.
64+
// Copyright (C) 2020 Matthew "strager" Glazar
65+
//
66+
// This file is part of quick-lint-js.
67+
//
68+
// quick-lint-js is free software: you can redistribute it and/or modify
69+
// it under the terms of the GNU General Public License as published by
70+
// the Free Software Foundation, either version 3 of the License, or
71+
// (at your option) any later version.
72+
//
73+
// quick-lint-js is distributed in the hope that it will be useful,
74+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
75+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
76+
// GNU General Public License for more details.
77+
//
78+
// You should have received a copy of the GNU General Public License
79+
// along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>.

wasm/yarn.lock

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,103 @@
22
# yarn lockfile v1
33

44

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+
590
prettier@^2.3.0:
691
version "2.3.0"
792
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.3.0.tgz#b6a5bf1284026ae640f17f7ff5658a7567fc0d18"
893
integrity sha512-kXtO4s0Lz/DW/IJ9QdWhAf7/NmPWQXkFr/r/WkR3vyI+0v8amTDxiaQSLzs8NBlytfLWX/7uQUMIW677yLKl4w==
94+
95+
quick-lint-js-node-test-runner@../tools/quick-lint-js-node-test-runner/:
96+
version "0.1.0"
97+
dependencies:
98+
colors "^1.4.0"
99+
jasmine "^3.7.0"
100+
101+
wrappy@1:
102+
version "1.0.2"
103+
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
104+
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=

0 commit comments

Comments
 (0)