-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
--bail
option for cancelling test run
- Loading branch information
1 parent
0eafb17
commit 821b597
Showing
22 changed files
with
223 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { expect, test } from 'vitest' | ||
|
||
test('1 - first.test.ts - this should pass', async () => { | ||
await new Promise(resolve => setTimeout(resolve, 250)) | ||
expect(true).toBeTruthy() | ||
}) | ||
|
||
test('2 - first.test.ts - this should fail', () => { | ||
expect(false).toBeTruthy() | ||
}) | ||
|
||
test('3 - first.test.ts - this should be skipped', () => { | ||
expect(true).toBeTruthy() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { expect, test } from 'vitest' | ||
|
||
// When using multi threads the first test will start before failing.test.ts fails | ||
const isThreads = process.env.THREADS === 'true' | ||
|
||
test(`1 - second.test.ts - this should ${isThreads ? 'pass' : 'be skipped'}`, async () => { | ||
await new Promise(resolve => setTimeout(resolve, 1500)) | ||
expect(true).toBeTruthy() | ||
}) | ||
|
||
test('2 - second.test.ts - this should be skipped', () => { | ||
expect(true).toBeTruthy() | ||
}) | ||
|
||
test('3 - second.test.ts - this should be skipped', () => { | ||
expect(true).toBeTruthy() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { defineConfig } from 'vitest/config' | ||
import type { WorkspaceSpec } from 'vitest/node' | ||
|
||
class TestNameSequencer { | ||
async sort(files: WorkspaceSpec[]): Promise<WorkspaceSpec[]> { | ||
return [...files].sort(([, filenameA], [, filenameB]) => { | ||
if (filenameA > filenameB) | ||
return 1 | ||
|
||
if (filenameA < filenameB) | ||
return -1 | ||
|
||
return 0 | ||
}) | ||
} | ||
|
||
public async shard(files: WorkspaceSpec[]): Promise<WorkspaceSpec[]> { | ||
return files | ||
} | ||
} | ||
|
||
export default defineConfig({ | ||
test: { | ||
reporters: 'verbose', | ||
cache: false, | ||
watch: false, | ||
sequence: { | ||
sequencer: TestNameSequencer, | ||
}, | ||
browser: { | ||
headless: true, | ||
name: 'chrome', | ||
}, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "@vitest/test-bail", | ||
"private": true, | ||
"scripts": { | ||
"test": "vitest" | ||
}, | ||
"devDependencies": { | ||
"@vitest/browser": "workspace:*", | ||
"execa": "^7.0.0", | ||
"vite": "latest", | ||
"vitest": "workspace:*", | ||
"webdriverio": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { expect, test } from 'vitest' | ||
import { execa } from 'execa' | ||
|
||
const configs: string[][] = [] | ||
const pools = [['--threads', 'true'], ['--threads', 'false'], ['--single-thread']] | ||
|
||
if (process.platform !== 'win32') | ||
pools.push(['--browser']) | ||
|
||
for (const isolate of ['true', 'false']) { | ||
for (const pool of pools) { | ||
configs.push([ | ||
'--bail', | ||
'1', | ||
'--isolate', | ||
isolate, | ||
...pool, | ||
]) | ||
} | ||
} | ||
|
||
for (const config of configs) { | ||
test(`should bail with "${config.join(' ')}"`, async () => { | ||
const { exitCode, stdout } = await execa('vitest', [ | ||
'--no-color', | ||
'--root', | ||
'fixtures', | ||
...config, | ||
], { | ||
reject: false, | ||
env: { THREADS: config.join(' ').includes('--threads true') ? 'true' : 'false' }, | ||
}) | ||
|
||
expect(exitCode).toBe(1) | ||
expect(stdout).toMatch('✓ test/first.test.ts > 1 - first.test.ts - this should pass') | ||
expect(stdout).toMatch('× test/first.test.ts > 2 - first.test.ts - this should fail') | ||
|
||
// Cancelled tests should not be run | ||
expect(stdout).not.toMatch('test/first.test.ts > 3 - first.test.ts - this should be skipped') | ||
expect(stdout).not.toMatch('test/second.test.ts > 1 - second.test.ts - this should be skipped') | ||
expect(stdout).not.toMatch('test/second.test.ts > 2 - second.test.ts - this should be skipped') | ||
expect(stdout).not.toMatch('test/second.test.ts > 3 - second.test.ts - this should be skipped') | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({ | ||
test: { | ||
reporters: 'verbose', | ||
include: ['test/**/*.test.*'], | ||
|
||
// For Windows CI mostly | ||
testTimeout: process.env.CI ? 30_000 : 10_000, | ||
chaiConfig: { | ||
truncateThreshold: 999, | ||
}, | ||
}, | ||
}) |