Skip to content
46 changes: 45 additions & 1 deletion .github/workflows/test-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
43 changes: 42 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 31 additions & 0 deletions src/test/unit/runTest.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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<void>((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)
})