Skip to content

Commit 120aad7

Browse files
committed
Add auto-detection of connected boards for run tests
1 parent 15ea7b4 commit 120aad7

File tree

7 files changed

+174
-69
lines changed

7 files changed

+174
-69
lines changed

.github/workflows/test.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Test extension
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v5
16+
- name: Setup node v22
17+
uses: actions/setup-node@v5
18+
with:
19+
node-version: '22'
20+
cache: 'npm'
21+
- name: Install Dependencies
22+
run: |
23+
npm i -g @vscode/vsce ovsx
24+
npm ci
25+
- name: Test Extension
26+
run: npm run test

.vscode-test.js

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
// .vscode-test.js
22
const { defineConfig } = require('@vscode/test-cli');
33
const fs = require('fs');
4+
const { findByIds } = require('usb');
45

5-
const testNames = [
6-
{
6+
const testNames = {
7+
'blink': {
78
'name': 'blink',
8-
'boards': ['pico2'],
9+
'boards': ['pico', 'pico_w', 'pico2', 'pico2_w'],
10+
'runBoards': [],
911
},
10-
{
12+
'hello_serial': {
1113
'name': 'hello_serial',
12-
'boards': ['pico2'],
14+
'boards': ['pico', 'pico_w', 'pico2', 'pico2_w'],
15+
'runBoards': [],
1316
},
14-
];
15-
16-
fs.writeFileSync('out/projectCreation/testNames.json', JSON.stringify(testNames));
17+
};
1718

1819
function getProjectTestConfigs(name, boards, compileTimeout=10000) {
1920
const ret = [];
@@ -43,9 +44,52 @@ const configs = [
4344
},
4445
];
4546

46-
for (const testName of testNames) {
47-
const { name, boards } = testName;
47+
const debugProbe = findByIds(0x2E8A, 0x000C);
48+
const rp2040 = findByIds(0x2E8A, 0x0003);
49+
const rp2350 = findByIds(0x2E8A, 0x000f);
50+
if (debugProbe) {
51+
console.log("Debugprobe found");
52+
console.log(debugProbe);
53+
54+
if (rp2040) {
55+
console.log("RP2040 found");
56+
console.log(rp2040);
57+
Object.values(testNames).forEach(testName => {
58+
if (testName.boards.includes('pico')) {
59+
testName.runBoards.push('pico');
60+
}
61+
if (testName.boards.includes('pico_w')) {
62+
testName.runBoards.push('pico_w');
63+
}
64+
});
65+
} else {
66+
console.log("RP2040 not found");
67+
}
68+
69+
if (rp2350) {
70+
console.log("RP2350 found");
71+
console.log(rp2350);
72+
Object.values(testNames).forEach(testName => {
73+
if (testName.boards.includes('pico2')) {
74+
testName.runBoards.push('pico2');
75+
}
76+
if (testName.boards.includes('pico2_w')) {
77+
testName.runBoards.push('pico2_w');
78+
}
79+
});
80+
} else {
81+
console.log("RP2350 not found");
82+
}
83+
} else {
84+
console.log("Debugprobe not found - not running run tests");
85+
}
86+
87+
for (const testName of Object.values(testNames)) {
88+
const { name, boards, runBoards } = testName;
4889
configs.push(...getProjectTestConfigs(name, boards));
4990
}
5091

92+
fs.writeFileSync('out/projectCreation/testNames.json', JSON.stringify(testNames));
93+
fs.writeFileSync('out/projectCompilation/testNames.json', JSON.stringify(testNames));
94+
5195
module.exports = defineConfig(configs);

package-lock.json

Lines changed: 61 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@
375375
"@eslint/js": "^9.36.0",
376376
"@types/adm-zip": "^0.5.7",
377377
"@types/ini": "^4.1.1",
378-
"@types/node": "^22.18",
378+
"@types/node": "^22.18.8",
379+
"@types/usb": "^2.0.4",
379380
"@types/vscode": "^1.104.0",
380381
"@types/which": "^3.0.4",
381382
"@vscode/test-cli": "^0.0.11",
@@ -387,6 +388,7 @@
387388
"tslib": "^2.8.1",
388389
"typescript": "^5.9.3",
389390
"typescript-eslint": "^8.45.0",
391+
"usb": "^2.16.0",
390392
"webpack": "^5.102.0",
391393
"webpack-cli": "^6.0.1"
392394
},

test/projectCompilation/projectCompilation.test.ts

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,43 @@ import * as assert from 'assert';
33
// You can import and use all API from the 'vscode' module
44
// as well as import your extension to test it
55
import * as vscode from 'vscode';
6+
import * as path from 'path';
7+
import * as fs from 'fs';
68
// import * as myExtension from '../../extension';
79

8-
import { EventEmitter } from 'events';
10+
const projectPath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath.split(path.sep);
11+
const testName = projectPath?.pop();
12+
const board = projectPath?.pop();
913

10-
const testName = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath.split('/').pop();
14+
const testNamesFilePath = path.join(__dirname, 'testNames.json');
15+
const testNames = JSON.parse(fs.readFileSync(testNamesFilePath, 'utf8'));
1116

1217
suite(`${testName} Project Test Suite`, () => {
1318

14-
test(`${testName} Erase Start`, async () => {
15-
// // Get the task with the specified name
16-
// const task = (await vscode.tasks.fetchTasks()).find(
17-
// task =>
18-
// task.name === "Erase Start"
19-
// );
19+
if (!testName) {
20+
throw new Error(`testName not found`);
21+
}
2022

21-
// assert.notStrictEqual(task, undefined);
23+
if (!testNames[testName]) {
24+
throw new Error(`${testName} not found in testNames.json`);
25+
}
2226

23-
// // Execute the task
24-
// const emitter = new EventEmitter();
25-
26-
// // add callbacks for task completion
27-
// const end = vscode.tasks.onDidEndTaskProcess(e => {
28-
// if (e.execution.task === task) {
29-
// emitter.emit(
30-
// "terminated",
31-
// e.exitCode === undefined ? -1 : e.exitCode
32-
// );
33-
// }
34-
// });
35-
// const end2 = vscode.tasks.onDidEndTask(e => {
36-
// if (e.execution.task === task) {
37-
// emitter.emit("terminated", -1);
38-
// }
39-
// });
40-
41-
// await vscode.tasks.executeTask(task!);
42-
// // eslint-disable-next-line @typescript-eslint/no-unused-vars
43-
// const code = await new Promise<number>((resolve, reject) => {
44-
// emitter.on("terminated", code => {
45-
// if (typeof code === "number") {
46-
// resolve(code);
47-
// } else {
48-
// resolve(-1);
49-
// }
50-
// });
51-
// });
52-
53-
// // dispose of callbacks
54-
// end.dispose();
55-
// end2.dispose();
56-
57-
const result = await vscode.commands.executeCommand("raspberry-pi-pico.testRunTask", "Erase Start") as string;
58-
assert.strictEqual(result, "Task completed");
59-
});
27+
if (testNames[testName].runBoards.includes(board)) {
28+
test(`${testName} Erase Start`, async () => {
29+
const result = await vscode.commands.executeCommand("raspberry-pi-pico.testRunTask", "Erase Start") as string;
30+
assert.strictEqual(result, "Task completed");
31+
});
32+
}
6033

6134
test(`${testName} Compile Project`, async () => {
6235
const result = await vscode.commands.executeCommand("raspberry-pi-pico.compileProject") as boolean;
6336
assert.strictEqual(result, true);
6437
});
6538

66-
test(`${testName} Run Project`, async () => {
67-
const result = await vscode.commands.executeCommand('raspberry-pi-pico.runProject') as boolean;
68-
assert.strictEqual(result, true);
69-
});
39+
if (testNames[testName].runBoards.includes(board)) {
40+
test(`${testName} Run Project`, async () => {
41+
const result = await vscode.commands.executeCommand('raspberry-pi-pico.runProject') as boolean;
42+
assert.strictEqual(result, true);
43+
});
44+
}
7045
});

test/projectCreation/projectCreation.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import * as fs from 'fs';
88
// import * as myExtension from '../../extension';
99

1010
const testNamesFilePath = path.join(__dirname, 'testNames.json');
11-
const testNames = JSON.parse(fs.readFileSync(testNamesFilePath, 'utf8'));
11+
const testNames: Record<string, { name: string, boards: string[], runBoards: string[] }> = JSON.parse(fs.readFileSync(testNamesFilePath, 'utf8'));
1212

1313
suite(`Project Creation Test Suite`, function() {
1414

15-
for (const testName of testNames) {
16-
const { name, boards } = testName;
15+
for (const testName of Object.values(testNames)) {
16+
const { name, boards, runBoards } = testName;
1717
for (const board of boards) {
1818
test(`New Project ${name} ${board}`, async () => {
1919
if (vscode.workspace.workspaceFolders?.[0]?.uri.fsPath.endsWith(name)) {

tests.tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"outDir": "out",
99
"sourceMap": true,
1010
"strict": true,
11-
"rootDir": "test"
11+
"rootDir": "test",
12+
"types": ["node", "mocha"]
1213
},
1314
"include": [
1415
"test/**/*.ts",

0 commit comments

Comments
 (0)