Skip to content

Commit f856668

Browse files
committed
feat: add integration testing setup and esbuild for bundling
- Introduced `.vscode-test.mjs` for running integration tests within a VS Code environment. - Added `esbuild.js` for building and bundling the extension, replacing the previous TypeScript compilation method. - Updated `package.json` scripts to include new build and test commands. - Modified `.vscodeignore` to exclude new build artifacts and test files. - Created initial integration tests in `src/integration/extension.itest.ts` to verify extension activation and command registration.
1 parent 8fc1a1f commit f856668

8 files changed

Lines changed: 2436 additions & 389 deletions

File tree

.github/workflows/ci.yml

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ on:
55
branches: [main]
66
pull_request:
77

8+
permissions:
9+
contents: read
10+
811
jobs:
9-
build:
10-
runs-on: ubuntu-latest
12+
test:
13+
name: Test (${{ matrix.os }})
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
os: [ubuntu-latest, windows-latest, macos-latest]
1119

1220
steps:
1321
- uses: actions/checkout@v4
@@ -20,14 +28,45 @@ jobs:
2028
- name: Install dependencies
2129
run: npm ci
2230

23-
- name: Compile
31+
- name: Type-check and bundle
2432
run: npm run compile
2533

2634
- name: Lint
2735
run: npm run lint
2836

29-
- name: Test
37+
- name: Test (unit)
3038
run: npm test
3139

32-
- name: Package (smoke check)
40+
- name: Test (integration, Linux)
41+
if: runner.os == 'Linux'
42+
run: xvfb-run -a npm run test:integration
43+
44+
- name: Test (integration, Windows/macOS)
45+
if: runner.os != 'Linux'
46+
run: npm run test:integration
47+
48+
package:
49+
name: Package (smoke check)
50+
runs-on: ubuntu-latest
51+
needs: test
52+
53+
steps:
54+
- uses: actions/checkout@v4
55+
56+
- uses: actions/setup-node@v4
57+
with:
58+
node-version: 20
59+
cache: 'npm'
60+
61+
- name: Install dependencies
62+
run: npm ci
63+
64+
- name: Package VSIX
3365
run: npx --yes @vscode/vsce package --out angular-code-quality-toolkit.vsix
66+
67+
- name: Upload VSIX artifact
68+
uses: actions/upload-artifact@v4
69+
with:
70+
name: angular-code-quality-toolkit-vsix
71+
path: angular-code-quality-toolkit.vsix
72+
if-no-files-found: error

.vscode-test.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defineConfig } from '@vscode/test-cli';
2+
3+
// Runs the compiled integration tests (src/integration/*.itest.ts -> out/integration)
4+
// inside a real VS Code Extension Development Host. Unit tests live in src/test and
5+
// run separately via `npm test` (node:test); this file drives Mocha for the host tests.
6+
export default defineConfig({
7+
files: 'out/integration/**/*.itest.js',
8+
version: 'stable',
9+
mocha: {
10+
ui: 'tdd',
11+
timeout: 20000,
12+
},
13+
});

.vscodeignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
out/test/**
1+
out/**
22
src/**
33
.vscode/**
4+
.vscode-test/**
45
**/*.map
56
**/*.ts
67
node_modules/**
8+
esbuild.js
9+
.vscode-test.mjs
710
eslint.config.mjs
811
tsconfig.json
912
package-lock.json
1013
.gitignore
1114
.github/**
1215
assets/angular-code-quality-icon.png
13-
!.vscode-test/**

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ To catch unused variables and parameters, add the rule to your ESLint config so
8585
| `angularCodeQuality.stylelint.useJsonFormat` | `true` | Ask stylelint for JSON output. |
8686
| `angularCodeQuality.depcheck.ignoreAngularImplicit` | `true` | Hide false "unused" hits for packages Angular uses implicitly (`@angular/*`, `zone.js`, `rxjs`, `tslib`, `typescript`, karma/jasmine, builders). |
8787
| `angularCodeQuality.depcheck.ignores` | `[]` | Extra packages to hide (`*` wildcard, e.g. `@my-scope/*`). |
88-
| `angularCodeQuality.revealOutputOnRun` | `true` | Auto-open the Output channel on each run. |
88+
| `angularCodeQuality.revealOutputOnRun` | `false` | Auto-open the Output channel on each run. Off by default — findings go to the Problems panel; enable this only to watch raw tool logs. |
8989

9090
---
9191

esbuild.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const esbuild = require('esbuild');
2+
3+
const production = process.argv.includes('--production');
4+
const watch = process.argv.includes('--watch');
5+
6+
/**
7+
* Reports esbuild problems in a format VS Code's task matcher understands and
8+
* fails the build (non-zero exit) when a bundle error occurs outside watch mode.
9+
* @type {import('esbuild').Plugin}
10+
*/
11+
const esbuildProblemMatcherPlugin = {
12+
name: 'esbuild-problem-matcher',
13+
setup(build) {
14+
build.onStart(() => {
15+
console.log('[watch] build started');
16+
});
17+
build.onEnd((result) => {
18+
result.errors.forEach(({ text, location }) => {
19+
console.error(`✘ [ERROR] ${text}`);
20+
if (location) {
21+
console.error(` ${location.file}:${location.line}:${location.column}:`);
22+
}
23+
});
24+
console.log('[watch] build finished');
25+
});
26+
},
27+
};
28+
29+
async function main() {
30+
const ctx = await esbuild.context({
31+
entryPoints: ['src/extension.ts'],
32+
bundle: true,
33+
format: 'cjs',
34+
minify: production,
35+
sourcemap: !production,
36+
sourcesContent: false,
37+
platform: 'node',
38+
target: 'node18',
39+
outfile: 'dist/extension.js',
40+
// The 'vscode' module is provided by the VS Code runtime, never bundled.
41+
external: ['vscode'],
42+
logLevel: 'silent',
43+
plugins: [esbuildProblemMatcherPlugin],
44+
});
45+
46+
if (watch) {
47+
await ctx.watch();
48+
} else {
49+
await ctx.rebuild();
50+
await ctx.dispose();
51+
}
52+
}
53+
54+
main().catch((e) => {
55+
console.error(e);
56+
process.exit(1);
57+
});

0 commit comments

Comments
 (0)