From 1700c0e4f88e81ba39bef08e8587e466c8087a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Barreiro?= <52393857+BarreiroT@users.noreply.github.com> Date: Mon, 19 May 2025 22:32:35 +0200 Subject: [PATCH] Run tests against Windows and Ubuntu (#3246) * add a matrix strategy for testing * Handle EOL on Windows * use bash as shell on every os and run the test-ci script * fix tsconfig path resolution using the __dirnname * print test results regardless of status * Limit artifact upload to Linux * update the test-cli * Add windows-specific dependencies as optional dependencies lightningcss-win32-x64-msvc rollup-win32-x64-msvc * Do not collect coverage on Windows * Use UTF-8 on the Python Scripts * force the ubuntu-latest name to be `test` --- .gitattributes | 2 ++ .github/workflows/test.yml | 35 ++++++++++++++++++++----- .prettierrc.json | 3 ++- package-lock.json | 18 ++++++------- package.json | 4 +-- scripts/test-ci.js | 2 +- test-setup.js | 7 +++-- webview-ui/package-lock.json | 50 +++--------------------------------- webview-ui/package.json | 4 ++- 9 files changed, 56 insertions(+), 69 deletions(-) diff --git a/.gitattributes b/.gitattributes index 92a294bfa..9f1ff5fcc 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,4 @@ demo.gif filter=lfs diff=lfs merge=lfs -text assets/docs/demo.gif filter=lfs diff=lfs merge=lfs -text + +* text=auto eol=lf diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 03bf83884..df170e9cd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,15 @@ permissions: jobs: test: - runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} + name: ${{ matrix.os == 'ubuntu-latest' && 'test' || format('test ({0})', matrix.os) }} + defaults: + run: + shell: bash steps: - name: Checkout code uses: actions/checkout@v4 @@ -60,6 +68,11 @@ jobs: if: steps.webview-cache.outputs.cache-hit != 'true' run: cd webview-ui && npm ci + - name: Set up NPM on Windows + if: runner.os == 'Windows' + run: | + npm config set script-shell "C:\\Program Files\\Git\\bin\\bash.exe" + - name: Type Check run: npm run check-types @@ -81,8 +94,9 @@ jobs: id: extension_coverage continue-on-error: true run: | - xvfb-run -a npm run test:coverage > extension_coverage.txt 2>&1 - PYTHONPATH=.github/scripts python -m coverage_check extract-coverage extension_coverage.txt --type=extension --github-output --verbose + node ./scripts/test-ci.js > extension_coverage.txt 2>&1 + # Default the encoding to UTF-8 - It's not the default on Windows + PYTHONUTF8=1 PYTHONPATH=.github/scripts python -m coverage_check extract-coverage extension_coverage.txt --type=extension --github-output --verbose # Run webview tests with coverage - name: Webview Tests with Coverage @@ -94,11 +108,14 @@ jobs: npm install --no-save @vitest/coverage-v8 npm run test:coverage > webview_coverage.txt 2>&1 cd .. - PYTHONPATH=.github/scripts python -m coverage_check extract-coverage webview-ui/webview_coverage.txt --type=webview --github-output --verbose + # Default the encoding to UTF-8 - It's not the default on Windows + PYTHONUTF8=1 PYTHONPATH=.github/scripts python -m coverage_check extract-coverage webview-ui/webview_coverage.txt --type=webview --github-output --verbose # Save coverage reports as artifacts (workflow-scoped) - name: Save Coverage Reports uses: actions/upload-artifact@v4 + # Only upload artifacts on Linux - We only need coverage from one OS + if: runner.os == 'Linux' with: name: pr-coverage-reports path: | @@ -107,14 +124,18 @@ jobs: retention-period: workflow # Artifacts are automatically deleted when the workflow completes # Set the check as failed if any of the tests failed - - name: Check for test failures + - name: Print test results and check for failures run: | + echo "Extension Tests Result: ${{ steps.extension_coverage.outcome }}" + cat extension_coverage.txt + + echo "Webview Tests Result: ${{ steps.webview_coverage.outcome }}" + cat webview-ui/webview_coverage.txt + # Check if any of the test steps failed # https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#steps-context if [ "${{ steps.extension_coverage.outcome }}" != "success" ] || [ "${{ steps.webview_coverage.outcome }}" != "success" ]; then echo "Tests failed." - cat extension_coverage.txt - cat webview-ui/webview_coverage.txt exit 1 fi diff --git a/.prettierrc.json b/.prettierrc.json index f2cbe27cf..98201ba7d 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -3,5 +3,6 @@ "useTabs": true, "printWidth": 130, "semi": false, - "bracketSameLine": true + "bracketSameLine": true, + "endOfLine": "lf" } diff --git a/package-lock.json b/package-lock.json index 8619f093f..9428e81d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -86,8 +86,8 @@ "@types/vscode": "^1.84.0", "@typescript-eslint/eslint-plugin": "^7.14.1", "@typescript-eslint/parser": "^7.11.0", - "@vscode/test-cli": "^0.0.9", - "@vscode/test-electron": "^2.4.0", + "@vscode/test-cli": "^0.0.10", + "@vscode/test-electron": "^2.4.1", "chai": "^4.3.10", "chalk": "^5.3.0", "esbuild": "^0.25.0", @@ -11473,9 +11473,9 @@ "license": "CC-BY-4.0" }, "node_modules/@vscode/test-cli": { - "version": "0.0.9", - "resolved": "https://registry.npmjs.org/@vscode/test-cli/-/test-cli-0.0.9.tgz", - "integrity": "sha512-vsl5/ueE3Jf0f6XzB0ECHHMsd5A0Yu6StElb8a+XsubZW7kHNAOw4Y3TSSuDzKEpLnJ92nbMy1Zl+KLGCE6NaA==", + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/@vscode/test-cli/-/test-cli-0.0.10.tgz", + "integrity": "sha512-B0mMH4ia+MOOtwNiLi79XhA+MLmUItIC8FckEuKrVAVriIuSWjt7vv4+bF8qVFiNFe4QRfzPaIZk39FZGWEwHA==", "dev": true, "license": "MIT", "dependencies": { @@ -34535,9 +34535,9 @@ "integrity": "sha512-wsNOvNMMJ2BY8rC2N2MNBG7yOowV3ov8KlvUE/AiVUlHKTfWsw3OgAOQduX7h0Un6GssKD3aoTVH+TF3DSQwKQ==" }, "@vscode/test-cli": { - "version": "0.0.9", - "resolved": "https://registry.npmjs.org/@vscode/test-cli/-/test-cli-0.0.9.tgz", - "integrity": "sha512-vsl5/ueE3Jf0f6XzB0ECHHMsd5A0Yu6StElb8a+XsubZW7kHNAOw4Y3TSSuDzKEpLnJ92nbMy1Zl+KLGCE6NaA==", + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/@vscode/test-cli/-/test-cli-0.0.10.tgz", + "integrity": "sha512-B0mMH4ia+MOOtwNiLi79XhA+MLmUItIC8FckEuKrVAVriIuSWjt7vv4+bF8qVFiNFe4QRfzPaIZk39FZGWEwHA==", "dev": true, "requires": { "@types/mocha": "^10.0.2", @@ -44188,4 +44188,4 @@ "dev": true } } -} +} \ No newline at end of file diff --git a/package.json b/package.json index 9ce317024..370aa5009 100644 --- a/package.json +++ b/package.json @@ -292,8 +292,8 @@ "@types/vscode": "^1.84.0", "@typescript-eslint/eslint-plugin": "^7.14.1", "@typescript-eslint/parser": "^7.11.0", - "@vscode/test-cli": "^0.0.9", - "@vscode/test-electron": "^2.4.0", + "@vscode/test-cli": "^0.0.10", + "@vscode/test-electron": "^2.4.1", "chai": "^4.3.10", "chalk": "^5.3.0", "esbuild": "^0.25.0", diff --git a/scripts/test-ci.js b/scripts/test-ci.js index 26823a2b5..ff069ad34 100644 --- a/scripts/test-ci.js +++ b/scripts/test-ci.js @@ -9,7 +9,7 @@ try { execSync("which xvfb-run", { stdio: "ignore" }) console.log("xvfb-run is installed. Running tests with xvfb-run...") - execSync("xvfb-run -a npm run test:integration", { stdio: "inherit" }) + execSync("xvfb-run -a npm run test:coverage", { stdio: "inherit" }) } else { console.log("Non-Linux environment detected. Running tests normally.") execSync("npm run test:integration", { stdio: "inherit" }) diff --git a/test-setup.js b/test-setup.js index 58f88d0c9..a096b7374 100644 --- a/test-setup.js +++ b/test-setup.js @@ -1,7 +1,10 @@ const tsConfigPaths = require("tsconfig-paths") const fs = require("fs") +const path = require("path") -const tsConfig = JSON.parse(fs.readFileSync("./tsconfig.json", "utf-8")) +const baseUrl = path.resolve(__dirname) + +const tsConfig = JSON.parse(fs.readFileSync(path.join(baseUrl, "tsconfig.json"), "utf-8")) /** * The aliases point towards the `src` directory. @@ -17,6 +20,6 @@ Object.keys(tsConfig.compilerOptions.paths).forEach((key) => { }) tsConfigPaths.register({ - baseUrl: ".", + baseUrl: baseUrl, paths: outPaths, }) diff --git a/webview-ui/package-lock.json b/webview-ui/package-lock.json index ebf79b3cc..be56de8e2 100644 --- a/webview-ui/package-lock.json +++ b/webview-ui/package-lock.json @@ -71,9 +71,11 @@ "optionalDependencies": { "@rollup/rollup-linux-arm64-gnu": "^4.40.0", "@rollup/rollup-linux-x64-gnu": "^4.40.0", + "@rollup/rollup-win32-x64-msvc": "^4.40.0", "@swc/core-linux-x64-gnu": "^1.11.0", "@tailwindcss/oxide-linux-x64-gnu": "^4.0.1", - "lightningcss-linux-x64-gnu": "^1.29.1" + "lightningcss-linux-x64-gnu": "^1.29.1", + "lightningcss-win32-x64-msvc": "1.29.2" } }, "node_modules/@adobe/css-tools": { @@ -5731,48 +5733,6 @@ "linux" ] }, - "node_modules/@rollup/rollup-linux-x64-musl": { - "version": "4.40.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.40.1.tgz", - "integrity": "sha512-2BRORitq5rQ4Da9blVovzNCMaUlyKrzMSvkVR0D4qPuOy/+pMCrh1d7o01RATwVy+6Fa1WBw+da7QPeLWU/1mQ==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@rollup/rollup-win32-arm64-msvc": { - "version": "4.40.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.40.1.tgz", - "integrity": "sha512-b2bcNm9Kbde03H+q+Jjw9tSfhYkzrDUf2d5MAd1bOJuVplXvFhWz7tRtWvD8/ORZi7qSCy0idW6tf2HgxSXQSg==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ] - }, - "node_modules/@rollup/rollup-win32-ia32-msvc": { - "version": "4.40.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.40.1.tgz", - "integrity": "sha512-DfcogW8N7Zg7llVEfpqWMZcaErKfsj9VvmfSyRjCyo4BI3wPEfrzTtJkZG6gKP/Z92wFm6rz2aDO7/JfiR/whA==", - "cpu": [ - "ia32" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ] - }, "node_modules/@rollup/rollup-win32-x64-msvc": { "version": "4.40.1", "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.40.1.tgz", @@ -5780,7 +5740,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -12208,7 +12167,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MPL-2.0", "optional": true, "os": [ @@ -17616,4 +17574,4 @@ } } } -} +} \ No newline at end of file diff --git a/webview-ui/package.json b/webview-ui/package.json index a9562efd3..ed058aab3 100644 --- a/webview-ui/package.json +++ b/webview-ui/package.json @@ -78,8 +78,10 @@ "optionalDependencies": { "@rollup/rollup-linux-arm64-gnu": "^4.40.0", "@rollup/rollup-linux-x64-gnu": "^4.40.0", + "@rollup/rollup-win32-x64-msvc": "^4.40.0", "@swc/core-linux-x64-gnu": "^1.11.0", "@tailwindcss/oxide-linux-x64-gnu": "^4.0.1", - "lightningcss-linux-x64-gnu": "^1.29.1" + "lightningcss-linux-x64-gnu": "^1.29.1", + "lightningcss-win32-x64-msvc": "1.29.2" } }