Skip to content

Commit

Permalink
fix: cannot get test result correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n committed Mar 21, 2022
1 parent 89daff4 commit 3847bd4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion samples/basic/test/add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe("addition", () => {
});

it("failed", () => {
expect(1 + 1).toBe(2);
expect(1 + 2).toBe(2);
});

it.skip("skipped", () => {
Expand Down
5 changes: 2 additions & 3 deletions src/discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export function discoverTestFromFileContent(
item: vscode.TestItem,
data: TestFile
) {
data.testCases.length = 0;
if (testItemIdMap.get(controller) == null) {
testItemIdMap.set(controller, new Map());
}
Expand Down Expand Up @@ -99,9 +98,10 @@ export function discoverTestFromFileContent(
const arr: NamedBlock[] = [...result.describeBlocks, ...result.itBlocks];
arr.sort((a, b) => (a.start?.line || 0) - (b.start?.line || 0));
let testCaseIndex = 0;
let index = 0;
for (const block of arr) {
const parent = getParent(block);
const id = `${item.uri}/${block.name}`;
const id = `${item.uri}/${block.name}@${index++}`;
const caseItem = controller.createTestItem(id, block.name!, item.uri);
idMap.set(id, caseItem);
caseItem.range = new vscode.Range(
Expand All @@ -121,7 +121,6 @@ export function discoverTestFromFileContent(
testCaseIndex++
);
WEAKMAP_TEST_DATA.set(caseItem, testCase);
data.testCases.push(caseItem);
} else {
throw new Error();
}
Expand Down
4 changes: 2 additions & 2 deletions src/pure/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export class TestRunner {
}

try {
console.log(args);
if (this.vitePath) {
await execa(this.vitePath, args, {
windowsHide: false,
Expand All @@ -99,7 +98,8 @@ export class TestRunner {
}

const file = await readFile(path, "utf-8");
return JSON.parse(file) as AggregatedResult;
const out = JSON.parse(file) as AggregatedResult;
return out;
} finally {
release();
}
Expand Down
17 changes: 8 additions & 9 deletions src/run_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,32 @@ export async function runTest(
throw new Error("file item not found");
}

let file: TestFile;
let file: vscode.TestItem;
if (testingData instanceof TestFile) {
file = testingData;
file = item;
} else {
file = WEAKMAP_TEST_DATA.get(testingData.fileItem) as TestFile;
file = testingData.fileItem;
if (!file) {
throw new Error("file item not found");
}
}

const fileTestCases = getAllTestCases(file);
const testCaseSet = new Set(getAllTestCases(item));
const idMap = new Map<string, vscode.TestItem>();
testCaseSet.forEach((testCase) => {
run.started(testCase);
idMap.set(testCase.id, testCase);
});

const data = WEAKMAP_TEST_DATA.get(item)!;
const out = await runner.scheduleRun(item.uri!.fsPath, data.getFullPattern());
out.testResults.forEach((result, index) => {
let child: undefined | vscode.TestItem = file.testCases[index];
let child: undefined | vscode.TestItem = fileTestCases[index];
const id = getTestCaseId(item, result.displayName!) || "";
if (!child || child.id !== id) {
child = idMap.get(id);
if (!child || !child.id.startsWith(id)) {
console.error("not match");
console.dir(out.testResults);
console.dir(file.testCases);
console.dir(fileTestCases);
throw new Error();
}

if (!child || !testCaseSet.has(child)) {
Expand Down
1 change: 0 additions & 1 deletion src/test_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export class TestCase {
export class TestFile {
resolved = false;
pattern = "";
testCases: vscode.TestItem[] = [];
public async updateFromDisk(
controller: vscode.TestController,
item: vscode.TestItem
Expand Down

0 comments on commit 3847bd4

Please sign in to comment.