Skip to content

Commit 64bc52b

Browse files
authored
add npm-test workflow (#1)
* Update npm-test.yml * fix: test cases * fix: build system * build: update actions
1 parent c93351e commit 64bc52b

File tree

6 files changed

+236
-41
lines changed

6 files changed

+236
-41
lines changed

.github/workflows/npm-test.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@ on:
99

1010
jobs:
1111
test:
12-
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
include:
15+
- os: windows-latest
16+
- os: ubuntu-latest
17+
- os: macos-latest
18+
runs-on: ${{ matrix.os }}
1319
steps:
1420
- uses: actions/checkout@v4
1521
- uses: actions/setup-node@v4
1622
with:
1723
node-version: 20.x
1824
cache: 'npm'
1925
- run: npm ci
26+
- run: xvfb-run -a npm test
27+
if: runner.os == 'Linux'
2028
- run: npm test
29+
if: runner.os != 'Linux'

.vscode/tasks.json

+1-20
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,6 @@
33
{
44
"version": "2.0.0",
55
"tasks": [
6-
{
7-
"type": "shell",
8-
"label": "cp-wasm",
9-
"command": "cp node_modules/float-pigment-css/float_pigment_css_bg.wasm dist/",
10-
"problemMatcher": "$ts-webpack-watch",
11-
"isBackground": true,
12-
"presentation": {
13-
"reveal": "never",
14-
"group": "watchers"
15-
},
16-
"group": {
17-
"kind": "build"
18-
},
19-
"options": {
20-
"cwd": "${workspaceFolder}"
21-
}
22-
},
236
{
247
"type": "npm",
258
"script": "watch",
@@ -55,16 +38,14 @@
5538
"label": "tasks: watch-tests",
5639
"dependsOn": [
5740
"npm: watch",
58-
"cp-wasm",
5941
"npm: watch-tests"
6042
],
6143
"problemMatcher": []
6244
},
6345
{
6446
"label": "tasks: watch",
6547
"dependsOn": [
66-
"npm: watch",
67-
"cp-wasm"
48+
"npm: watch"
6849
],
6950
"problemMatcher": []
7051
}

package-lock.json

+169-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"@vscode/test-cli": "^0.0.10",
8888
"@vscode/test-electron": "^2.4.1",
8989
"assert": "^2.1.0",
90+
"copy-webpack-plugin": "^12.0.2",
9091
"eslint": "^7.17.0",
9192
"eslint-config-airbnb-base": "^14.2.1",
9293
"eslint-config-prettier": "^8.6.0",

src/test/index.test.ts

+35-4
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,57 @@ import assert from 'assert'
44

55
const EXTENSION_DIR = path.resolve(__dirname, '..', '..')
66
const TEST_FIXTURE_DIR = path.resolve(EXTENSION_DIR, 'test-fixture')
7+
const DIAGNOSTIC_SOURCE = 'float-pigment-css-analyzer'
78

89
const getUri = (rel: string) => {
910
const absPath = path.resolve(TEST_FIXTURE_DIR, rel)
1011
const uri = vscode.Uri.file(absPath)
1112
return uri
1213
}
1314

14-
const sleep = (ms: number): Promise<void> =>
15+
// const diagChangeCallbacks: ((uris: readonly vscode.Uri[]) => void)[] = []
16+
// vscode.languages.onDidChangeDiagnostics((e) => {
17+
// // eslint-disable-next-line @typescript-eslint/no-floating-promises, promise/catch-or-return
18+
// vscode.window.showInformationMessage('!!!')
19+
// diagChangeCallbacks.forEach((f) => f(e.uris))
20+
// })
21+
const waitDiagnosticsUpdate = (uri: vscode.Uri, source: string): Promise<void> =>
1522
new Promise((resolve) => {
16-
setTimeout(resolve, ms)
23+
const diag = vscode.languages.getDiagnostics(uri).find((diag) => diag.source === source)
24+
if (diag) {
25+
resolve()
26+
return
27+
}
28+
// const cb = (uris: readonly vscode.Uri[]) => {
29+
// if (uris.includes(uri)) {
30+
// const diag = vscode.languages.getDiagnostics(uri).find((diag) => diag.source === source)
31+
// if (diag) {
32+
// const index = diagChangeCallbacks.indexOf(cb)
33+
// diagChangeCallbacks.splice(index, 1)
34+
// resolve()
35+
// }
36+
// }
37+
// }
38+
// diagChangeCallbacks.push(cb)
39+
const cb = () => {
40+
const diag = vscode.languages.getDiagnostics(uri).find((diag) => diag.source === source)
41+
if (diag) {
42+
resolve()
43+
return
44+
}
45+
setTimeout(cb, 100)
46+
}
47+
setTimeout(cb, 100)
1748
})
1849

1950
suite('common', () => {
2051
test('diagnostics for CSS', async () => {
2152
const uri = getUri('components/index.css')
2253
await vscode.window.showTextDocument(uri)
23-
await sleep(1000)
54+
await waitDiagnosticsUpdate(uri, DIAGNOSTIC_SOURCE)
2455
const diagList = vscode.languages
2556
.getDiagnostics(uri)
26-
.filter((diag) => diag.source === 'float-pigment-css-analyzer')
57+
.filter((diag) => diag.source === DIAGNOSTIC_SOURCE)
2758
assert.equal(diagList.length, 1)
2859
})
2960
})

0 commit comments

Comments
 (0)