Skip to content

Commit

Permalink
test: assert test item tree order
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed May 22, 2024
1 parent 96430ed commit bdd2301
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 30 deletions.
8 changes: 4 additions & 4 deletions tests/debug-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ test('should debug all tests', async ({ activate }) => {

const testRun = await vscode.testControllers[0].debug();
expect(testRun.renderLog()).toBe(`
tests > test-2.spec.ts > should fail [2:0]
enqueued
started
failed
tests > test-1.spec.ts > should pass [2:0]
enqueued
started
passed
tests > test-2.spec.ts > should fail [2:0]
enqueued
started
failed
`);

await expect(vscode).toHaveExecLog(`
Expand Down
2 changes: 1 addition & 1 deletion tests/list-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,8 @@ test('should list parametrized tests', async ({ activate }) => {
- tests
- test.spec.ts
- one [3:0]
- three [3:0]
- two [3:0]
- three [3:0]
`);
});

Expand Down
11 changes: 0 additions & 11 deletions tests/mock/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ class TestItem {
innerToString(indent: string, result: string[]) {
result.push(`${indent}- ${this.statusIcon()} ${this.treeTitle()}`);
const items = [...this.children.map.values()];
items.sort((i1, i2) => itemOrder(i1).localeCompare(itemOrder(i2)));
for (const item of items)
item.innerToString(indent + ' ', result);
}
Expand Down Expand Up @@ -266,14 +265,6 @@ class TestItem {
}
}

function itemOrder(item: TestItem) {
let result = '';
if (item.range)
result += item.range.start.line.toString().padStart(5, '0');
result += item.label;
return result;
}

class TestRunProfile {
private _isDefault = true;
readonly didChangeDefault = new EventEmitter<boolean>();
Expand Down Expand Up @@ -426,7 +417,6 @@ export class TestRun {
const indent = ' ';
const result: string[] = [''];
const tests = [...this.entries.keys()];
tests.sort((i1, i2) => itemOrder(i1).localeCompare(itemOrder(i2)));
for (const test of tests) {
const entries = this.entries.get(test)!;
result.push(` ${test.flatTitle()}`);
Expand Down Expand Up @@ -499,7 +489,6 @@ export class TestController {
renderTestTree() {
const result: string[] = [''];
const items = [...this.items.map.values()];
items.sort((i1, i2) => itemOrder(i1).localeCompare(itemOrder(i2)));
for (const item of items)
item.innerToString(' ', result);
result.push(' ');
Expand Down
14 changes: 7 additions & 7 deletions tests/project-setup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ test.describe(() => {
await expect(testController).toHaveTestTree(`
- setup.ts
- ✅ setup [2:0]
- teardown.ts
- ✅ teardown [2:0]
- test.ts
- ✅ test [2:0]
- teardown.ts
- ✅ teardown [2:0]
`);

const output = testRun.renderLog({ output: true });
Expand All @@ -82,10 +82,10 @@ test.describe(() => {
const testRun = await testController.run();

await expect(testController).toHaveTestTree(`
- teardown.ts
- ✅ teardown [2:0]
- test.ts
- ✅ test [2:0]
- teardown.ts
- ✅ teardown [2:0]
`);

const output = testRun.renderLog({ output: true });
Expand Down Expand Up @@ -121,9 +121,9 @@ test.describe(() => {
await expect(testController).toHaveTestTree(`
- setup.ts
- ✅ setup [2:0]
- test.ts
- teardown.ts
- ✅ teardown [2:0]
- test.ts
`);
});
});
Expand All @@ -139,9 +139,9 @@ test('should run setup and teardown for test', async ({ activate }) => {
await expect(testController).toHaveTestTree(`
- setup.ts
- ✅ setup [2:0]
- teardown.ts
- ✅ teardown [2:0]
- test.ts
- ✅ test [2:0]
- teardown.ts
- ✅ teardown [2:0]
`);
});
12 changes: 6 additions & 6 deletions tests/run-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ test('should run all tests', async ({ activate }) => {
`);

expect(testRun.renderLog()).toBe(`
tests > test-2.spec.ts > should fail [2:0]
enqueued
started
failed
tests > test-1.spec.ts > should pass [2:0]
enqueued
started
passed
tests > test-2.spec.ts > should fail [2:0]
enqueued
started
failed
`);

await expect(vscode).toHaveExecLog(`
Expand Down Expand Up @@ -682,12 +682,12 @@ test('should run all parametrized tests', async ({ activate }) => {
enqueued
started
passed
tests > test.spec.ts > test-three [3:0]
tests > test.spec.ts > test-two [3:0]
enqueued
enqueued
started
passed
tests > test.spec.ts > test-two [3:0]
tests > test.spec.ts > test-three [3:0]
enqueued
enqueued
started
Expand Down
2 changes: 1 addition & 1 deletion tests/source-map.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ test('should discover new tests', async ({ activate }) => {
await expect(testController).toHaveTestTree(`
- tests
- test.spec.ts
- new [2:0]
- one [3:0]
- two [4:0]
- new [2:0]
`);

await expect(vscode).toHaveExecLog(`
Expand Down

0 comments on commit bdd2301

Please sign in to comment.