Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: editing file in a workspace reruns tests
- Loading branch information
1 parent
bde49db
commit 9a35fd0
Showing
15 changed files
with
150 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { fileURLToPath } from 'node:url' | ||
import { readFileSync, writeFileSync } from 'node:fs' | ||
import { afterAll, it } from 'vitest' | ||
import { dirname, resolve } from 'pathe' | ||
import { startWatchMode } from './utils' | ||
|
||
const file = fileURLToPath(import.meta.url) | ||
const dir = dirname(file) | ||
const root = resolve(dir, '..', '..', 'workspaces') | ||
const config = resolve(root, 'vitest.config.ts') | ||
|
||
const srcMathFile = resolve(root, 'src', 'math.ts') | ||
const specSpace2File = resolve(root, 'space_2', 'test', 'node.spec.ts') | ||
|
||
const srcMathContent = readFileSync(srcMathFile, 'utf-8') | ||
const specSpace2Content = readFileSync(specSpace2File, 'utf-8') | ||
|
||
function startVitest() { | ||
return startWatchMode( | ||
{ cwd: root, env: { TEST_WATCH: 'true' } }, | ||
'--root', | ||
root, | ||
'--config', | ||
config, | ||
'--no-coverage', | ||
) | ||
} | ||
|
||
afterAll(() => { | ||
writeFileSync(srcMathFile, srcMathContent, 'utf8') | ||
writeFileSync(specSpace2File, specSpace2Content, 'utf8') | ||
}) | ||
|
||
it('editing a test file in a suite with workspaces reruns test', async () => { | ||
const vitest = await startVitest() | ||
|
||
writeFileSync(specSpace2File, `${specSpace2Content}\n`, 'utf8') | ||
|
||
await vitest.waitForOutput('RERUN space_2/test/node.spec.ts x1') | ||
await vitest.waitForOutput('|space_2| test/node.spec.ts') | ||
await vitest.waitForOutput('Test Files 1 passed') | ||
}) | ||
|
||
it('editing a file that is imported in different workspaces reruns both files', async () => { | ||
const vitest = await startVitest() | ||
|
||
writeFileSync(srcMathFile, `${srcMathContent}\n`, 'utf8') | ||
|
||
await vitest.waitForOutput('RERUN src/math.ts') | ||
await vitest.waitForOutput('|space_3| math.space-test.ts') | ||
await vitest.waitForOutput('|space_1| test/math.spec.ts') | ||
await vitest.waitForOutput('Test Files 2 passed') | ||
}) | ||
|
||
it('filters by test name inside a workspace', async () => { | ||
const vitest = await startVitest() | ||
|
||
vitest.write('t') | ||
|
||
await vitest.waitForOutput('Input test name pattern') | ||
|
||
vitest.write('2 x 2 = 4\n') | ||
|
||
await vitest.waitForOutput('Test name pattern: /2 x 2 = 4/') | ||
await vitest.waitForOutput('Test Files 1 passed') | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { expect, test } from 'vitest' | ||
import { sum } from '../../src/math' | ||
|
||
test('3 + 3 = 6', () => { | ||
expect(sum(3, 3)).toBe(6) | ||
}) |
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 |
---|---|---|
@@ -1,6 +1,11 @@ | ||
import { expect, test } from 'vitest' | ||
import { sum } from '../src/math' | ||
import { multiple } from './src/multiply' | ||
|
||
test('2 x 2 = 4', () => { | ||
expect(multiple(2, 2)).toBe(4) | ||
}) | ||
|
||
test('2 + 2 = 4', () => { | ||
expect(sum(2, 2)).toBe(4) | ||
}) |
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 @@ | ||
Object.defineProperty(global, 'testValue', { value: 'jsdom' }) |
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 @@ | ||
Object.defineProperty(global, 'testValue', { value: 'node' }) |
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,9 @@ | ||
import { expect, it } from 'vitest' | ||
|
||
declare global { | ||
const testValue: string | ||
} | ||
|
||
it('the same file works with different workspaces', () => { | ||
expect(testValue).toBe(expect.getState().environment === 'node' ? 'node' : 'jsdom') | ||
}) |
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,3 @@ | ||
export function sum(a: number, b: number) { | ||
return a + b | ||
} |
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