Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/discoverer/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ export class EvaluationTestDiscoverer implements ITestDiscoverer {
sourceMap?: TraceMap | undefined,
directive?: string,
) {
const fn = (name: string, callback: () => void) => {
if (typeof name !== 'string' || typeof callback !== 'function') {
const fn = (name: string, callback: (() => void) | undefined) => {
if (typeof name !== 'string') {
return placeholder();
}

Expand All @@ -114,7 +114,7 @@ export class EvaluationTestDiscoverer implements ITestDiscoverer {
let startColumn = frame.columnNumber || 1;

// approximate the length of the test case:
const functionLines = String(callback).split('\n');
const functionLines = String(callback ?? '').split('\n');
let endLine = startLine + functionLines.length - 1;
let endColumn = functionLines[functionLines.length - 1].length + 1;

Expand Down Expand Up @@ -167,7 +167,7 @@ export class EvaluationTestDiscoverer implements ITestDiscoverer {
if (kind === NodeKind.Suite) {
stack.push(node);
try {
return callback.call(placeholder());
return typeof callback === 'function' ? callback.call(placeholder()) : placeholder();
} catch (e) {
node.error = e instanceof Error ? e.message : String(e);
} finally {
Expand Down
2 changes: 1 addition & 1 deletion src/discoverer/syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class SyntaxTestDiscoverer implements ITestDiscoverer {

traverse(ast, {
enter(node) {
if (node.type !== C.CallExpression || node.arguments.length < 2) {
if (node.type !== C.CallExpression || node.arguments.length === 0) {
return;
}

Expand Down
14 changes: 2 additions & 12 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,8 @@ export class TestRunner {
}

if (!spawnCts.token.isCancellationRequested) {
if (ranAnyTest) {
for (const t of leafTests) {
run.skipped(t);
}
} else {
const md = new vscode.MarkdownString(
'Test process exited unexpectedly, [view output](command:testing.showMostRecentOutput)',
);
md.isTrusted = true;
for (const t of leafTests) {
run.errored(t, new vscode.TestMessage(md));
}
for (const t of leafTests) {
run.skipped(t);
}
}

Expand Down
33 changes: 33 additions & 0 deletions src/test/unit/extract/evaluate-typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,37 @@ describe('evaluate typescript', () => {
},
]);
});

it('works with pending test', async () => {
const src = await extractWithEvaluation(
'function topLevel(a: number): string {', //
' return a.toString() as string;',
'}',
'',
"suite('hello', () => {", //
" it('works');",
'})',
);
expect(src).to.deep.equal([
{
name: 'hello',
kind: NodeKind.Suite,
startLine: 4,
startColumn: 0,
endColumn: 1,
endLine: 6,
children: [
{
name: 'works',
kind: NodeKind.Test,
startLine: 5,
startColumn: 2,
endColumn: Number.MAX_SAFE_INTEGER,
endLine: 5,
children: [],
},
],
},
]);
});
});
44 changes: 44 additions & 0 deletions src/test/unit/extract/evaluate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,50 @@ describe('evaluate', () => {
]);
});

it('works with pending test', async () => {
const src = await extractWithEvaluation(
"suite('hello', () => {", //
" it('works');",
'})',
);
expect(src).to.deep.equal([
{
name: 'hello',
startLine: 0,
kind: NodeKind.Suite,
startColumn: 0,
endColumn: 1,
endLine: 2,
children: [
{
name: 'works',
kind: NodeKind.Test,
startLine: 1,
startColumn: 2,
endColumn: Number.MAX_SAFE_INTEGER,
endLine: 1,
children: [],
},
],
},
]);
});

it('works with pending suite', async () => {
const src = await extractWithEvaluation("suite('hello')");
expect(src).to.deep.equal([
{
name: 'hello',
startLine: 0,
kind: NodeKind.Suite,
startColumn: 0,
endColumn: Number.MAX_SAFE_INTEGER,
endLine: 0,
children: [],
},
]);
});

it('stubs out requires and placeholds correctly', async () => {
const src = await extractWithEvaluation(
'require("some invalid module").doing().other.things()',
Expand Down
44 changes: 44 additions & 0 deletions src/test/unit/extract/syntax.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,50 @@ describe('syntax', () => {
]);
});

it('works with pending test', async () => {
const src = await extractWithAst(
"suite('hello', () => {", //
" it('works');",
'})',
);
expect(src).to.deep.equal([
{
name: 'hello',
startLine: 0,
kind: NodeKind.Suite,
startColumn: 0,
endColumn: 2,
endLine: 2,
children: [
{
name: 'works',
kind: NodeKind.Test,
startLine: 1,
startColumn: 2,
endColumn: 13,
endLine: 1,
children: [],
},
],
},
]);
});

it('works with pending suite', async () => {
const src = await extractWithAst("suite('hello')");
expect(src).to.deep.equal([
{
name: 'hello',
startLine: 0,
kind: NodeKind.Suite,
startColumn: 0,
endColumn: 14,
endLine: 0,
children: [],
},
]);
});

it('can detect suite but not dynamic tests', async () => {
const src = await extractWithAst(
"suite('hello', () => {", //
Expand Down
Loading