Skip to content

Commit c7168a9

Browse files
authored
Merge pull request #333 from mathworks/rdancy/add-unit-tests
Adding unit tests to test.yml and test-pull-request.yml
2 parents f9aa48a + e15089a commit c7168a9

4 files changed

Lines changed: 121 additions & 3 deletions

File tree

‎.github/workflows/test-pull-request.yml‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
name: Setup Node.js
3636
uses: actions/setup-node@v4
3737
with:
38-
node-version: 18.x
38+
node-version: 22.x
3939
- &install-dependencies
4040
name: Install dependencies
4141
run: npm run project-install-clean
@@ -254,3 +254,47 @@ jobs:
254254
name: screenshots-macos-${{ matrix.version }}
255255
path: ${{ github.workspace }}/.s/screenshots
256256
if-no-files-found: ignore
257+
258+
# UNIT TESTS
259+
test-unit-linux:
260+
name: Unit Tests-linux
261+
needs: build-linux
262+
runs-on: ubuntu-latest
263+
steps:
264+
- *checkout
265+
- *verify-head
266+
- *download-linux-build-artifacts
267+
- *setup-node
268+
- *install-dependencies
269+
- &run-unit-tests
270+
name: Run Unit tests
271+
run: npm run test-unit:fast
272+
- &run-wsb-tests
273+
name: Run Workspace Browser tests
274+
run: npm run test-wsb:fast
275+
276+
test-unit-windows:
277+
name: Unit Tests-windows
278+
needs: build-windows
279+
runs-on: windows-latest
280+
steps:
281+
- *checkout
282+
- *verify-head
283+
- *download-windows-build-artifacts
284+
- *setup-node
285+
- *install-dependencies
286+
- *run-unit-tests
287+
- *run-wsb-tests
288+
289+
test-unit-macos:
290+
name: Unit Tests-macos
291+
needs: build-macos
292+
runs-on: macos-14
293+
steps:
294+
- *checkout
295+
- *verify-head
296+
- *download-macos-build-artifacts
297+
- *setup-node
298+
- *install-dependencies
299+
- *run-unit-tests
300+
- *run-wsb-tests

‎.github/workflows/test.yml‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
name: Setup Node.js
2020
uses: actions/setup-node@v4
2121
with:
22-
node-version: 18.x
22+
node-version: 22.x
2323
- &install-dependencies
2424
name: Install dependencies
2525
run: npm run project-install-clean
@@ -228,3 +228,44 @@ jobs:
228228
name: screenshots-macos-${{ matrix.version }}
229229
path: ${{ github.workspace }}/.s/screenshots
230230
if-no-files-found: ignore
231+
232+
# UNIT TESTS
233+
test-unit-linux:
234+
name: Unit Tests-linux
235+
needs: build-linux
236+
runs-on: ubuntu-latest
237+
steps:
238+
- *checkout
239+
- *download-linux-build-artifacts
240+
- *setup-node
241+
- *install-dependencies
242+
- &run-unit-tests
243+
name: Run Unit tests
244+
run: npm run test-unit:fast
245+
- &run-wsb-tests
246+
name: Run Workspace Browser tests
247+
run: npm run test-wsb:fast
248+
249+
test-unit-windows:
250+
name: Unit Tests-windows
251+
needs: build-windows
252+
runs-on: windows-latest
253+
steps:
254+
- *checkout
255+
- *download-windows-build-artifacts
256+
- *setup-node
257+
- *install-dependencies
258+
- *run-unit-tests
259+
- *run-wsb-tests
260+
261+
test-unit-macos:
262+
name: Unit Tests-macos
263+
needs: build-macos
264+
runs-on: macos-14
265+
steps:
266+
- *checkout
267+
- *download-macos-build-artifacts
268+
- *setup-node
269+
- *install-dependencies
270+
- *run-unit-tests
271+
- *run-wsb-tests

‎package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,12 @@
524524
"test-ui": "npm run test-setup && node ./out/test/ui/runTest.js",
525525
"test-smoke:fast": "node ./out/test/smoke/runTest.js",
526526
"test-ui:fast": "node ./out/test/ui/runTest.js",
527+
"test-unit": "npm run test-setup && node ./out/test/unit/runTest.js",
528+
"test-unit:fast": "node ./out/test/unit/runTest.js",
527529
"test-wsb": "npm run test-setup && node out/test/workspacebrowser/runTest.js",
528530
"test-wsb:fast": "node out/test/workspacebrowser/runTest.js",
529531
"test": "npm run test-setup && npm run test:fast",
530-
"test:fast": "npm run test-smoke:fast && npm run test-ui:fast && npm run test-wsb:fast",
532+
"test:fast": "npm run test-smoke:fast && npm run test-ui:fast && npm run test-unit:fast && npm run test-wsb:fast",
531533
"project-install": "node ./build/projectInstall.js",
532534
"project-install-clean": "node ./build/projectInstall.js --clean",
533535
"package": "vsce package"

‎src/test/unit/runTest.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2026 The MathWorks, Inc.
2+
3+
import { registerMockVscode } from './mock-vscode'
4+
import * as path from 'path'
5+
import * as Mocha from 'mocha'
6+
import * as glob from 'glob'
7+
8+
// Register mock before any test imports that depend on vscode
9+
registerMockVscode()
10+
11+
async function runTests (): Promise<void> {
12+
const mocha = new Mocha({
13+
ui: 'tdd',
14+
reporter: 'spec'
15+
})
16+
17+
const testRoot = path.resolve(__dirname, '**', '*.test.js').split(path.sep).join('/')
18+
const testFiles = glob.sync(testRoot)
19+
testFiles.forEach((file: string) => mocha.addFile(file))
20+
21+
return await new Promise<void>((resolve, reject) => {
22+
mocha.run((failures: number) => {
23+
failures > 0 ? reject(new Error(`${failures} tests failed`)) : resolve()
24+
})
25+
})
26+
}
27+
28+
runTests().catch((err: unknown) => {
29+
console.error(err)
30+
process.exit(1)
31+
})

0 commit comments

Comments
 (0)