|
1 |
| -import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs' |
| 1 | +import { existsSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs' |
2 | 2 | import { afterEach, describe, expect, test } from 'vitest'
|
3 | 3 |
|
4 | 4 | import * as testUtils from '../../test-utils'
|
@@ -120,6 +120,42 @@ test("dynamic test case", () => {
|
120 | 120 | await vitest.waitForStdout('1 passed')
|
121 | 121 | })
|
122 | 122 |
|
| 123 | +test('renaming an existing test file', async () => { |
| 124 | + cleanups.push(() => rmSync('fixtures/after.test.ts')) |
| 125 | + const beforeFile = 'fixtures/before.test.ts' |
| 126 | + const afterFile = 'fixtures/after.test.ts' |
| 127 | + const textContent = ` |
| 128 | +import { expect, test } from "vitest"; |
| 129 | +
|
| 130 | +test("test case", () => { |
| 131 | + console.log("Running existing test") |
| 132 | + expect(true).toBeTruthy() |
| 133 | +}) |
| 134 | +` |
| 135 | + writeFileSync(beforeFile, textContent, 'utf-8') |
| 136 | + const { vitest } = await testUtils.runVitest({ root: 'fixtures', watch: true }) |
| 137 | + await vitest.waitForStdout('Running existing test') |
| 138 | + |
| 139 | + renameSync(beforeFile, afterFile) |
| 140 | + await vitest.waitForStdout('Test removed') |
| 141 | + await vitest.waitForStdout('Waiting for file changes...') |
| 142 | + |
| 143 | + vitest.write('p') |
| 144 | + await vitest.waitForStdout('Input filename pattern') |
| 145 | + vitest.write('before') |
| 146 | + await vitest.waitForStdout('Pattern matches no results') |
| 147 | + vitest.write('\n') |
| 148 | + await vitest.waitForStdout('No test files found') |
| 149 | + await vitest.waitForStdout('Waiting for file changes...') |
| 150 | + vitest.write('p') |
| 151 | + await vitest.waitForStdout('Input filename pattern') |
| 152 | + vitest.write('after') |
| 153 | + await vitest.waitForStdout('Pattern matches 1 result') |
| 154 | + vitest.write('\n') |
| 155 | + await vitest.waitForStdout('Filename pattern: after') |
| 156 | + await vitest.waitForStdout('1 passed') |
| 157 | +}) |
| 158 | + |
123 | 159 | test('editing source file generates new test report to file system', async () => {
|
124 | 160 | const report = 'fixtures/test-results/junit.xml'
|
125 | 161 | if (existsSync(report)) {
|
|
0 commit comments