@@ -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 
55import  *  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
1217suite ( `${ testName }  ,  ( )  =>  { 
1318
14- 	test ( `${ testName }  ,  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 }  ) ; 
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 }  ,  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 }  ,  async  ( )  =>  { 
6235		const  result  =  await  vscode . commands . executeCommand ( "raspberry-pi-pico.compileProject" )  as  boolean ; 
6336		assert . strictEqual ( result ,  true ) ; 
6437	} ) ; 
6538
66- 	test ( `${ testName }  ,  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 }  ,  async  ( )  =>  { 
41+ 			const  result  =  await  vscode . commands . executeCommand ( 'raspberry-pi-pico.runProject' )  as  boolean ; 
42+ 			assert . strictEqual ( result ,  true ) ; 
43+ 		} ) ; 
44+ 	} 
7045} ) ; 
0 commit comments