-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: exclude
cwd
from test name filter (#3353)
- Loading branch information
1 parent
a5b3d78
commit 324a9b5
Showing
8 changed files
with
110 additions
and
8 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
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,5 @@ | ||
import { expect, test } from 'vitest' | ||
|
||
test('this will fail', () => { | ||
expect('This test should not be run').toBeFalsy() | ||
}) |
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,5 @@ | ||
import { expect, test } from 'vitest' | ||
|
||
test('this will pass', () => { | ||
expect(1 + 1).toBe(2) | ||
}) |
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,5 @@ | ||
import { expect, test } from 'vitest' | ||
|
||
test('this will pass', () => { | ||
expect('This test should be run').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,11 @@ | ||
{ | ||
"name": "@vitest/test-filters", | ||
"private": true, | ||
"scripts": { | ||
"test": "vitest run" | ||
}, | ||
"devDependencies": { | ||
"vite": "latest", | ||
"vitest": "workspace:*" | ||
} | ||
} |
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,50 @@ | ||
import { resolve } from 'pathe' | ||
import { expect, test } from 'vitest' | ||
import type { File } from 'vitest' | ||
import { startVitest } from 'vitest/node' | ||
|
||
test('match by partial pattern', async () => { | ||
const output = await runVitest('example') | ||
|
||
expect(output).toMatchInlineSnapshot('"pass: test/example.test.ts"') | ||
}) | ||
|
||
test('match by full test file name', async () => { | ||
const filename = resolve('./fixtures/test/example.test.ts') | ||
const output = await runVitest(filename) | ||
|
||
expect(output).toMatchInlineSnapshot('"pass: test/example.test.ts"') | ||
}) | ||
|
||
test('match by pattern that also matches current working directory', async () => { | ||
const filter = 'filters' | ||
expect(process.cwd()).toMatch(filter) | ||
|
||
const output = await runVitest(filter) | ||
expect(output).toMatchInlineSnapshot('"pass: test/filters.test.ts"') | ||
}) | ||
|
||
async function runVitest(...cliArgs: string[]) { | ||
let resolve: (value: string) => void | ||
const promise = new Promise<string>((_resolve) => { | ||
resolve = _resolve | ||
}) | ||
|
||
await startVitest('test', cliArgs, { | ||
root: './fixtures', | ||
watch: false, | ||
reporters: [{ | ||
onFinished(files?: File[], errors?: unknown[]) { | ||
if (errors?.length) | ||
resolve(`Error: ${JSON.stringify(errors, null, 2)}`) | ||
|
||
if (files) | ||
resolve(files.map(file => `${file.result?.state}: ${file.name}`).join('\n')) | ||
else | ||
resolve('No files') | ||
}, | ||
}], | ||
}) | ||
|
||
return promise | ||
} |
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,8 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({ | ||
test: { | ||
reporters: 'verbose', | ||
include: ['test/**/*.test.*'], | ||
}, | ||
}) |