Skip to content

Commit

Permalink
test: correct test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Jun 30, 2024
1 parent 613bd6b commit 2e21f74
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 211 deletions.
4 changes: 0 additions & 4 deletions playground/config-initialIsOpen-error-clean/.eslintrc.json

This file was deleted.

44 changes: 0 additions & 44 deletions playground/config-initialIsOpen-error-clean/__tests__/test.spec.ts

This file was deleted.

13 changes: 0 additions & 13 deletions playground/config-initialIsOpen-error-clean/index.html

This file was deleted.

26 changes: 0 additions & 26 deletions playground/config-initialIsOpen-error-clean/package.json

This file was deleted.

8 changes: 0 additions & 8 deletions playground/config-initialIsOpen-error-clean/src/main.ts

This file was deleted.

1 change: 0 additions & 1 deletion playground/config-initialIsOpen-error-clean/src/text.ts

This file was deleted.

19 changes: 0 additions & 19 deletions playground/config-initialIsOpen-error-clean/tsconfig.json

This file was deleted.

15 changes: 0 additions & 15 deletions playground/config-initialIsOpen-error-clean/vite.config.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`config-initialIsOpen-error-warnings > serve > should not show overlay when only warning exists 1`] = `
" 1 | import { text } from './text'
2 |
> 3 | var rootDom = document.querySelector('#root')! as HTMLElement
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4 | rootDom.innerHTML = text
5 |
6 | export {}"
`;
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
import { describe, expect, it } from 'vitest'

import { editFile, getHmrOverlayText, isServe, sleepForEdit, sleepForServerReady } from '../../testUtils'
import {
editFile,
getHmrOverlay,
getHmrOverlayText,
isServe,
pollingUntil,
sleepForEdit,
sleepForServerReady,
} from '../../testUtils'

describe('config-initialIsOpen-error-warnings', () => {
describe.runIf(isServe)('serve', () => {
it('should not find overlay', async () => {
if (isServe) {
await sleepForServerReady()
try {
await getHmrOverlayText()
} catch (e) {
expect((e as any).toString()).toContain(
'Invariant failed: <vite-plugin-checker-error-overlay> shadow dom is expected to be found, but got null'
)
}

console.log('-- overlay remains closed after introduced error --')
editFile('src/main.ts', (code) => code.replace('! as', '! is'))
await sleepForEdit()
try {
await getHmrOverlayText()
} catch (e) {
expect((e as any).toString()).toContain(
'Invariant failed: <vite-plugin-checker-error-overlay> shadow dom is expected to be found, but got null'
)
}
it('should not show overlay when only warning exists', async () => {
await sleepForServerReady()
try {
await getHmrOverlayText()
} catch (e) {
expect((e as any).toString()).toContain(
'Invariant failed: <vite-plugin-checker-error-overlay> shadow dom is expected to be found, but got null'
)
}

console.log('-- overlay appears after introduce an error --')
editFile('src/main.ts', (code) => code.replace('const rootDom', 'var rootDom'))
await sleepForEdit()
await getHmrOverlayText()
await pollingUntil(getHmrOverlay, (dom) => !!dom)
const [, , frame] = await getHmrOverlayText()
expect(frame).toMatchSnapshot()
})
})
})
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`config-initialIsOpen-error > serve > should find overlay 1`] = `"Unexpected var, use let or const instead. (no-var)"`;
exports[`config-initialIsOpen-error > serve > -- should find overlay with error -- 1`] = `"Unexpected var, use let or const instead. (no-var)"`;

exports[`config-initialIsOpen-error > serve > should find overlay 2`] = `"<PROJECT_ROOT>/playground-temp/config-initialIsOpen-error/src/main.ts:3:1"`;
exports[`config-initialIsOpen-error > serve > -- should find overlay with error -- 2`] = `"<PROJECT_ROOT>/playground-temp/config-initialIsOpen-error/src/main.ts:3:1"`;
exports[`config-initialIsOpen-error > serve > should find overlay 3`] = `
exports[`config-initialIsOpen-error > serve > -- should find overlay with error -- 3`] = `
" 1 | import { text } from './text'
2 |
> 3 | var hello = 'Hello'
Expand All @@ -14,4 +14,4 @@ exports[`config-initialIsOpen-error > serve > should find overlay 3`] = `
6 | rootDom.innerHTML = hello + text"
`;
exports[`config-initialIsOpen-error > serve > should find overlay 4`] = `""`;
exports[`config-initialIsOpen-error > serve > -- should find overlay with error -- 4`] = `""`;
49 changes: 28 additions & 21 deletions playground/config-initialIsOpen-error/__tests__/test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
import { describe, expect, it } from 'vitest'

import { editFile, getHmrOverlay, getHmrOverlayText, isServe, pollingUntil, sleep, sleepForEdit, sleepForServerReady } from '../../testUtils'
import {
editFile,
getHmrOverlay,
getHmrOverlayText,
isServe,
pollingUntil,
sleep,
sleepForEdit,
sleepForServerReady,
} from '../../testUtils'

describe('config-initialIsOpen-error', () => {
describe.runIf(isServe)('serve', () => {
it('should find overlay', async () => {
if (isServe) {
await sleepForServerReady()
const [message1, file1, frame1] = await getHmrOverlayText()
expect(message1).toMatchSnapshot()
expect(file1).toMatchSnapshot()
expect(frame1).toMatchSnapshot()
it('-- should find overlay with error --', async () => {
await sleepForServerReady()
const [message1, file1, frame1] = await getHmrOverlayText()
expect(message1).toMatchSnapshot()
expect(file1).toMatchSnapshot()
expect(frame1).toMatchSnapshot()

console.log('-- overlay remains after fix error --')
editFile('src/main.ts', (code) => code.replace('var hello', `const hello`))
await sleepForEdit()
await pollingUntil(getHmrOverlay, (dom) => !!dom)
const [, , frame2] = await getHmrOverlayText()
expect(frame2).toMatchSnapshot()
console.log('-- overlay remains after fix error --')
editFile('src/main.ts', (code) => code.replace('var hello', `const hello`))
await sleepForEdit()
await pollingUntil(getHmrOverlay, (dom) => !!dom)
const [, , frame2] = await getHmrOverlayText()
expect(frame2).toMatchSnapshot()

console.log('-- overlay dismiss after fix warning --')
editFile('src/main.ts', (code) => code.replace('! as', ` as`))
await sleep(6000)
await expect(getHmrOverlayText()).rejects.toThrow(
'Invariant failed: .message-body is expected in shadow root'
)
}
console.log('-- overlay dismiss after fix warning --')
editFile('src/main.ts', (code) => code.replace('! as', ` as`))
await sleep(6000)
await expect(getHmrOverlayText()).rejects.toThrow(
'Invariant failed: .message-body is expected in shadow root'
)
})
})
})
34 changes: 0 additions & 34 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2e21f74

Please sign in to comment.