Skip to content

Commit

Permalink
test: junit in watch mode
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Jun 2, 2023
1 parent 2deb70a commit ab7f2ff
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/test-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export async function runVitestCli(_options?: Options | string, ...args: string[
return resolve()

const timeout = setTimeout(() => {
reject(new Error(`Timeout when waiting for output "${expected}".\nReceived:\n${this.stdout}`))
reject(new Error(`Timeout when waiting for output "${expected}".\nReceived:\n${this.stdout}. \nStderr:\n${this.stderr}`))
}, process.env.CI ? 20_000 : 4_000)

const listener = () => {
Expand Down
1 change: 1 addition & 0 deletions test/watch/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fixtures/test-results
34 changes: 32 additions & 2 deletions test/watch/test/file-watching.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFileSync, rmSync, writeFileSync } from 'node:fs'
import { afterEach, describe, test } from 'vitest'
import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { afterEach, describe, expect, test } from 'vitest'

import { runVitestCli } from '../../test-utils'

Expand Down Expand Up @@ -88,6 +88,36 @@ test("dynamic test case", () => {
await vitest.waitForStdout('1 passed')
})

test('editing source file generates new test report to file system', async () => {
const report = 'fixtures/test-results/junit.xml'
if (existsSync(report))
rmSync(report)

// Test report should not be present before test run
expect(existsSync(report)).toBe(false)

const vitest = await runVitestCli(
...cliArgs,
'--reporter', 'verbose',
'--reporter', 'junit',
'--output-file', 'test-results/junit.xml',
)

// Test report should be generated on initial test run
expect(existsSync(report)).toBe(true)

// Test report should be re-generated on second test run
rmSync(report)
expect(existsSync(report)).toBe(false)

vitest.resetOutput()
writeFileSync(sourceFile, editFile(sourceFileContent), 'utf8')

await vitest.waitForStdout('JUNIT report written')
await vitest.waitForStdout(report)
expect(existsSync(report)).toBe(true)
})

describe('browser', () => {
test.runIf((process.platform !== 'win32'))('editing source file triggers re-run', async () => {
const vitest = await runVitestCli(...cliArgs, '--browser.enabled', '--browser.headless', '--browser.name=chrome')
Expand Down

0 comments on commit ab7f2ff

Please sign in to comment.