Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for project change
Browse files Browse the repository at this point in the history
sheremet-va committed Jan 22, 2025
1 parent 07331ba commit 4457ad0
Showing 2 changed files with 46 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/test-utils/index.ts
Original file line number Diff line number Diff line change
@@ -294,13 +294,14 @@ export function useFS(root: string, structure: Record<string, string | ViteUserC
export async function runInlineTests(
structure: Record<string, string | ViteUserConfig | WorkspaceProjectConfiguration[]>,
config?: UserConfig,
options?: VitestRunnerCLIOptions,
) {
const root = resolve(process.cwd(), `vitest-test-${crypto.randomUUID()}`)
const fs = useFS(root, structure)
const vitest = await runVitest({
root,
...config,
})
}, [], 'test', {}, options)
return {
fs,
root,
44 changes: 44 additions & 0 deletions test/watch/test/change-project.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { expect, test } from 'vitest'
import { runInlineTests } from '../../test-utils'

test('reruns tests when config changes', async () => {
const { vitest, ctx } = await runInlineTests({
'vitest.config.ts': `
process.stdin.isTTY = true
process.stdin.setRawMode = () => process.stdin
export default {
test: {
workspace: [
'./project-1',
'./project-2',
],
},
}`,
'project-1/vitest.config.ts': { test: { name: 'project-1' } },
'project-1/basic-1.test.ts': /* ts */`
import { test } from 'vitest'
test('basic test 1', () => {})
`,
'project-2/vitest.config.ts': { test: { name: 'project-2' } },
'project-2/basic-2.test.ts': /* ts */`
import { test } from 'vitest'
test('basic test 2', () => {})
`,
}, { watch: true })

await vitest.waitForStdout('Waiting for file changes')

expect(vitest.stdout).toContain('2 passed')
expect(vitest.stdout).toContain('basic-1.test.ts')
expect(vitest.stdout).toContain('basic-2.test.ts')
vitest.resetOutput()

await ctx!.changeProjectName('project-2')

await vitest.waitForStdout('Waiting for file changes')

expect(vitest.stdout).toContain('1 passed')
expect(vitest.stdout).toContain('basic-2.test.ts')
})

0 comments on commit 4457ad0

Please sign in to comment.