diff --git a/.github/workflows/test-pull-request.yml b/.github/workflows/test-pull-request.yml index 9ff20b2..0865f30 100644 --- a/.github/workflows/test-pull-request.yml +++ b/.github/workflows/test-pull-request.yml @@ -35,7 +35,7 @@ jobs: name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: 18.x + node-version: 22.x - &install-dependencies name: Install dependencies run: npm run project-install-clean @@ -254,3 +254,47 @@ jobs: name: screenshots-macos-${{ matrix.version }} path: ${{ github.workspace }}/.s/screenshots if-no-files-found: ignore + + # UNIT TESTS + test-unit-linux: + name: Unit Tests-linux + needs: build-linux + runs-on: ubuntu-latest + steps: + - *checkout + - *verify-head + - *download-linux-build-artifacts + - *setup-node + - *install-dependencies + - &run-unit-tests + name: Run Unit tests + run: npm run test-unit:fast + - &run-wsb-tests + name: Run Workspace Browser tests + run: npm run test-wsb:fast + + test-unit-windows: + name: Unit Tests-windows + needs: build-windows + runs-on: windows-latest + steps: + - *checkout + - *verify-head + - *download-windows-build-artifacts + - *setup-node + - *install-dependencies + - *run-unit-tests + - *run-wsb-tests + + test-unit-macos: + name: Unit Tests-macos + needs: build-macos + runs-on: macos-14 + steps: + - *checkout + - *verify-head + - *download-macos-build-artifacts + - *setup-node + - *install-dependencies + - *run-unit-tests + - *run-wsb-tests diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b9d909f..2a44379 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ jobs: name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: 18.x + node-version: 22.x - &install-dependencies name: Install dependencies run: npm run project-install-clean @@ -228,3 +228,44 @@ jobs: name: screenshots-macos-${{ matrix.version }} path: ${{ github.workspace }}/.s/screenshots if-no-files-found: ignore + + # UNIT TESTS + test-unit-linux: + name: Unit Tests-linux + needs: build-linux + runs-on: ubuntu-latest + steps: + - *checkout + - *download-linux-build-artifacts + - *setup-node + - *install-dependencies + - &run-unit-tests + name: Run Unit tests + run: npm run test-unit:fast + - &run-wsb-tests + name: Run Workspace Browser tests + run: npm run test-wsb:fast + + test-unit-windows: + name: Unit Tests-windows + needs: build-windows + runs-on: windows-latest + steps: + - *checkout + - *download-windows-build-artifacts + - *setup-node + - *install-dependencies + - *run-unit-tests + - *run-wsb-tests + + test-unit-macos: + name: Unit Tests-macos + needs: build-macos + runs-on: macos-14 + steps: + - *checkout + - *download-macos-build-artifacts + - *setup-node + - *install-dependencies + - *run-unit-tests + - *run-wsb-tests diff --git a/package.json b/package.json index f2db70f..efaf98e 100644 --- a/package.json +++ b/package.json @@ -524,10 +524,12 @@ "test-ui": "npm run test-setup && node ./out/test/ui/runTest.js", "test-smoke:fast": "node ./out/test/smoke/runTest.js", "test-ui:fast": "node ./out/test/ui/runTest.js", + "test-unit": "npm run test-setup && node ./out/test/unit/runTest.js", + "test-unit:fast": "node ./out/test/unit/runTest.js", "test-wsb": "npm run test-setup && node out/test/workspacebrowser/runTest.js", "test-wsb:fast": "node out/test/workspacebrowser/runTest.js", "test": "npm run test-setup && npm run test:fast", - "test:fast": "npm run test-smoke:fast && npm run test-ui:fast && npm run test-wsb:fast", + "test:fast": "npm run test-smoke:fast && npm run test-ui:fast && npm run test-unit:fast && npm run test-wsb:fast", "project-install": "node ./build/projectInstall.js", "project-install-clean": "node ./build/projectInstall.js --clean", "package": "vsce package" diff --git a/src/test/unit/runTest.ts b/src/test/unit/runTest.ts new file mode 100644 index 0000000..b1352f3 --- /dev/null +++ b/src/test/unit/runTest.ts @@ -0,0 +1,31 @@ +// Copyright 2026 The MathWorks, Inc. + +import { registerMockVscode } from './mock-vscode' +import * as path from 'path' +import * as Mocha from 'mocha' +import * as glob from 'glob' + +// Register mock before any test imports that depend on vscode +registerMockVscode() + +async function runTests (): Promise { + const mocha = new Mocha({ + ui: 'tdd', + reporter: 'spec' + }) + + const testRoot = path.resolve(__dirname, '**', '*.test.js').split(path.sep).join('/') + const testFiles = glob.sync(testRoot) + testFiles.forEach((file: string) => mocha.addFile(file)) + + return await new Promise((resolve, reject) => { + mocha.run((failures: number) => { + failures > 0 ? reject(new Error(`${failures} tests failed`)) : resolve() + }) + }) +} + +runTests().catch((err: unknown) => { + console.error(err) + process.exit(1) +})