Skip to content

Commit edabb2a

Browse files
committed
Try re-running tasks when they fail in testing
1 parent 2ec8f52 commit edabb2a

File tree

1 file changed

+34
-0
lines changed
  • integration/vscode/ada/test/suite

1 file changed

+34
-0
lines changed

integration/vscode/ada/test/suite/utils.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import assert from 'assert';
2+
import { spawnSync } from 'child_process';
23
import { existsSync, readFileSync, writeFileSync } from 'fs';
34
import * as vscode from 'vscode';
45
import {
56
SimpleTaskProvider,
67
findTaskByName,
78
getConventionalTaskLabel,
89
} from '../../src/taskProviders';
10+
import { setTerminalEnvironment } from '../../src/helpers';
911

1012
/**
1113
* This function compares some actual output to an expected referenced stored in
@@ -155,7 +157,39 @@ export async function testTask(
155157
let msg = `Got status ${execStatus ?? "'undefined'"} for task '${taskName}'`;
156158
if (task.execution instanceof vscode.ShellExecution) {
157159
msg += ` with command line: ${getCmdLine(task.execution)}`;
160+
161+
try {
162+
/**
163+
* Let's try re-running the command line explicitlely to obtain its output.
164+
*/
165+
const cwd = vscode.workspace.workspaceFolders[0].uri.fsPath;
166+
msg += `\nTrying to re-run the command explicitly in: ${cwd}`;
167+
const env = { ...process.env };
168+
setTerminalEnvironment(env);
169+
const cp = spawnSync(
170+
typeof task.execution.command == 'string'
171+
? task.execution.command
172+
: task.execution.command.value,
173+
task.execution.args.map((arg) => {
174+
if (typeof arg == 'string') {
175+
return arg;
176+
} else {
177+
return arg.value;
178+
}
179+
}),
180+
{ cwd: cwd, env: env }
181+
);
182+
183+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
184+
msg += `\nProcess ended with exit code ${cp.status} and output:\n`;
185+
// msg += cp.stdout.toString() + cp.stderr.toString();
186+
msg += cp.output.map((b) => (b != null ? b.toString() : '')).join('');
187+
} catch (error) {
188+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
189+
msg += `\nEncountered an error: ${error}`;
190+
}
158191
}
192+
159193
assert.fail(msg);
160194
}
161195
}

0 commit comments

Comments
 (0)