Skip to content

add npm-test workflow #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/npm-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@ on:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- os: windows-latest
- os: ubuntu-latest
- os: macos-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'npm'
- run: npm ci
- run: xvfb-run -a npm test
if: runner.os == 'Linux'
- run: npm test
if: runner.os != 'Linux'
21 changes: 1 addition & 20 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "cp-wasm",
"command": "cp node_modules/float-pigment-css/float_pigment_css_bg.wasm dist/",
"problemMatcher": "$ts-webpack-watch",
"isBackground": true,
"presentation": {
"reveal": "never",
"group": "watchers"
},
"group": {
"kind": "build"
},
"options": {
"cwd": "${workspaceFolder}"
}
},
{
"type": "npm",
"script": "watch",
Expand Down Expand Up @@ -55,16 +38,14 @@
"label": "tasks: watch-tests",
"dependsOn": [
"npm: watch",
"cp-wasm",
"npm: watch-tests"
],
"problemMatcher": []
},
{
"label": "tasks: watch",
"dependsOn": [
"npm: watch",
"cp-wasm"
"npm: watch"
],
"problemMatcher": []
}
Expand Down
171 changes: 169 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"@vscode/test-cli": "^0.0.10",
"@vscode/test-electron": "^2.4.1",
"assert": "^2.1.0",
"copy-webpack-plugin": "^12.0.2",
"eslint": "^7.17.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.6.0",
Expand Down
39 changes: 35 additions & 4 deletions src/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,57 @@ import assert from 'assert'

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

const getUri = (rel: string) => {
const absPath = path.resolve(TEST_FIXTURE_DIR, rel)
const uri = vscode.Uri.file(absPath)
return uri
}

const sleep = (ms: number): Promise<void> =>
// const diagChangeCallbacks: ((uris: readonly vscode.Uri[]) => void)[] = []
// vscode.languages.onDidChangeDiagnostics((e) => {
// // eslint-disable-next-line @typescript-eslint/no-floating-promises, promise/catch-or-return
// vscode.window.showInformationMessage('!!!')
// diagChangeCallbacks.forEach((f) => f(e.uris))
// })
const waitDiagnosticsUpdate = (uri: vscode.Uri, source: string): Promise<void> =>
new Promise((resolve) => {
setTimeout(resolve, ms)
const diag = vscode.languages.getDiagnostics(uri).find((diag) => diag.source === source)
if (diag) {
resolve()
return
}
// const cb = (uris: readonly vscode.Uri[]) => {
// if (uris.includes(uri)) {
// const diag = vscode.languages.getDiagnostics(uri).find((diag) => diag.source === source)
// if (diag) {
// const index = diagChangeCallbacks.indexOf(cb)
// diagChangeCallbacks.splice(index, 1)
// resolve()
// }
// }
// }
// diagChangeCallbacks.push(cb)
const cb = () => {
const diag = vscode.languages.getDiagnostics(uri).find((diag) => diag.source === source)
if (diag) {
resolve()
return
}
setTimeout(cb, 100)
}
setTimeout(cb, 100)
})

suite('common', () => {
test('diagnostics for CSS', async () => {
const uri = getUri('components/index.css')
await vscode.window.showTextDocument(uri)
await sleep(1000)
await waitDiagnosticsUpdate(uri, DIAGNOSTIC_SOURCE)
const diagList = vscode.languages
.getDiagnostics(uri)
.filter((diag) => diag.source === 'float-pigment-css-analyzer')
.filter((diag) => diag.source === DIAGNOSTIC_SOURCE)
assert.equal(diagList.length, 1)
})
})
Loading
Loading