Skip to content

Commit

Permalink
auto-refresh test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sezna committed Dec 12, 2024
1 parent d9f288d commit 9ec9f41
Showing 1 changed file with 40 additions and 43 deletions.
83 changes: 40 additions & 43 deletions vscode/src/testExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export async function initTestExplorer(context: vscode.ExtensionContext) {

ctrl.resolveHandler = async item => {
if (!item) {
context.subscriptions.push(...startWatchingWorkspace(ctrl, fileChangedEmitter));
context.subscriptions.push(...startWatchingWorkspace(ctrl, fileChangedEmitter, context));
return;
}

Expand Down Expand Up @@ -229,23 +229,20 @@ function getWorkspaceTestPatterns() {
}


function startWatchingWorkspace(controller: vscode.TestController, fileChangedEmitter: vscode.EventEmitter<vscode.Uri>) {
function startWatchingWorkspace(controller: vscode.TestController, fileChangedEmitter: vscode.EventEmitter<vscode.Uri>, context: vscode.ExtensionContext) {
return getWorkspaceTestPatterns().map(({ pattern }) => {
const refresher = mkRefreshHandler(controller, context, true)
const watcher = vscode.workspace.createFileSystemWatcher(pattern);
/*
watcher.onDidCreate(uri => {
getOrCreateFile(controller, uri);
fileChangedEmitter.fire(uri);
});
watcher.onDidChange(async uri => {
const { file, data } = getOrCreateFile(controller, uri);
if (data.didResolve) {
await data.updateFromDisk(controller, file);
}
fileChangedEmitter.fire(uri);
});
*/
watcher.onDidDelete(uri => controller.items.delete(uri.toString()));
watcher.onDidCreate(async uri => {

Check failure on line 236 in vscode/src/testExplorer.ts

View workflow job for this annotation

GitHub Actions / Check web files

'uri' is defined but never used
await refresher();
});
watcher.onDidChange(async uri => {

Check failure on line 239 in vscode/src/testExplorer.ts

View workflow job for this annotation

GitHub Actions / Check web files

'uri' is defined but never used
await refresher();
});

watcher.onDidDelete(async uri => {

Check failure on line 243 in vscode/src/testExplorer.ts

View workflow job for this annotation

GitHub Actions / Check web files

'uri' is defined but never used
await refresher();
});

// findInitialFiles(controller, pattern);

Expand All @@ -255,34 +252,34 @@ function startWatchingWorkspace(controller: vscode.TestController, fileChangedEm

async function runTestCase(ctrl: vscode.TestController, testCase: vscode.TestItem, request: vscode.TestRunRequest, worker: ICompilerWorker, program: ProgramConfig): Promise<void> {
const run = ctrl.createTestRun(request);
const evtTarget = new QscEventTarget(false);
evtTarget.addEventListener('Message', (msg) => {
run.appendOutput(`Test ${testCase.id}: ${msg.detail}\r\n`);

})

evtTarget.addEventListener('Result', (msg) => {
if (msg.detail.success) {
run.passed(testCase);
} else {
let message: vscode.TestMessage = {
message: msg.detail.value.message,
location: {
range: toVsCodeRange(msg.detail.value.range),
uri: vscode.Uri.parse(msg.detail.value.uri || "")
}
const evtTarget = new QscEventTarget(false);
evtTarget.addEventListener('Message', (msg) => {
run.appendOutput(`Test ${testCase.id}: ${msg.detail}\r\n`);

})

evtTarget.addEventListener('Result', (msg) => {
if (msg.detail.success) {
run.passed(testCase);
} else {
let message: vscode.TestMessage = {

Check failure on line 265 in vscode/src/testExplorer.ts

View workflow job for this annotation

GitHub Actions / Check web files

'message' is never reassigned. Use 'const' instead
message: msg.detail.value.message,
location: {
range: toVsCodeRange(msg.detail.value.range),
uri: vscode.Uri.parse(msg.detail.value.uri || "")
}
run.failed(testCase, message);
}
run.end();
})

const callableExpr = `${testCase.id}()`;
try {
await worker.run(program, callableExpr, 1, evtTarget);
} catch (error) {
log.error(`Error running test ${testCase.id}:`, error);
run.appendOutput(`Error running test ${testCase.id}: ${error}\r\n`);
run.failed(testCase, message);
}
log.info("ran test", testCase.id);
run.end();
})

const callableExpr = `${testCase.id}()`;
try {
await worker.run(program, callableExpr, 1, evtTarget);
} catch (error) {
log.error(`Error running test ${testCase.id}:`, error);
run.appendOutput(`Error running test ${testCase.id}: ${error}\r\n`);
}
log.info("ran test", testCase.id);
}

0 comments on commit 9ec9f41

Please sign in to comment.