-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support initially opened overlay for errors (#259)
- Loading branch information
Showing
35 changed files
with
511 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'vite-plugin-checker': patch | ||
--- | ||
|
||
feat: support initially open overlay for errors |
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
2 changes: 1 addition & 1 deletion
2
packages/vite-plugin-checker/__tests__/__snapshots__/logger.spec.ts.snap
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
2 changes: 1 addition & 1 deletion
2
packages/vite-plugin-checker/__tests__/__snapshots__/vlsConfig.spec.ts.snap
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,4 @@ | ||
{ | ||
"root": true, | ||
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"] | ||
} |
44 changes: 44 additions & 0 deletions
44
playground/config-initialIsOpen-error-clean/__tests__/test.spec.ts
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,44 @@ | ||
import { describe, expect, it } from 'vitest' | ||
|
||
import { | ||
editFile, | ||
getHmrOverlayText, | ||
isServe, | ||
sleepForEdit, | ||
sleepForServerReady, | ||
} from '../../testUtils' | ||
|
||
describe('config-initialIsOpen-error-clean', () => { | ||
describe.runIf(isServe)('serve', () => { | ||
it('should not find overlay', async () => { | ||
if (isServe) { | ||
await sleepForServerReady() | ||
await expect(getHmrOverlayText()).rejects.toThrow( | ||
'Invariant failed: .message-body is expected in shadow root' | ||
) | ||
|
||
console.log('-- badge appears, but overlay remains collapsed after error introduced --') | ||
editFile('src/main.ts', (code) => code.replace('const hello', 'var hello')) | ||
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' | ||
) | ||
} | ||
|
||
console.log('-- badge remains, overlay remains collapsed after warning introduced --') | ||
editFile('src/main.ts', (code) => code.replace(' as', '! as')) | ||
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' | ||
) | ||
} | ||
} | ||
}) | ||
}) | ||
}) |
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,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="src/favicon.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite App</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.ts"></script> | ||
</body> | ||
</html> |
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,26 @@ | ||
{ | ||
"private": true, | ||
"name": "@playground/config-initial-is-open-error-clean", | ||
"type": "module", | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"serve": "vite preview", | ||
"lint": "eslint --ext .js,.ts ./src/**" | ||
}, | ||
"dependencies": { | ||
"react": "^17.0.0", | ||
"react-dom": "^17.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^17.0.0", | ||
"@types/react-dom": "^17.0.0", | ||
"@typescript-eslint/eslint-plugin": "^5.59.0", | ||
"@typescript-eslint/parser": "^5.59.0", | ||
"eslint": "^8.11.0", | ||
"typescript": "^5.0.4", | ||
"vite": "^4.3.0", | ||
"vite-plugin-checker": "workspace:*" | ||
} | ||
} |
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,8 @@ | ||
import { text } from './text' | ||
|
||
const hello = 'Hello' | ||
|
||
const rootDom = document.querySelector('#root') as HTMLElement | ||
rootDom.innerHTML = hello + text | ||
|
||
export {} |
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 @@ | ||
export const text = 'Vanilla JS/TS' |
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,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"lib": ["DOM", "DOM.Iterable", "ESNext"], | ||
"types": ["vite/client"], | ||
"allowJs": false, | ||
"skipLibCheck": false, | ||
"esModuleInterop": false, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"module": "ESNext", | ||
"moduleResolution": "Node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true | ||
}, | ||
"include": ["./src"] | ||
} |
15 changes: 15 additions & 0 deletions
15
playground/config-initialIsOpen-error-clean/vite.config.js
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,15 @@ | ||
import { defineConfig } from 'vite' | ||
import checker from 'vite-plugin-checker' | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
checker({ | ||
overlay: { | ||
initialIsOpen: 'error', | ||
}, | ||
eslint: { | ||
lintCommand: 'eslint ./src --ext .ts', | ||
}, | ||
}), | ||
], | ||
}) |
4 changes: 4 additions & 0 deletions
4
playground/config-initialIsOpen-error-warnings/.eslintrc.json
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,4 @@ | ||
{ | ||
"root": true, | ||
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"] | ||
} |
31 changes: 31 additions & 0 deletions
31
playground/config-initialIsOpen-error-warnings/__tests__/test.spec.ts
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,31 @@ | ||
import { describe, expect, it } from 'vitest' | ||
|
||
import { editFile, getHmrOverlayText, isServe, 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' | ||
) | ||
} | ||
} | ||
}) | ||
}) | ||
}) |
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,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="src/favicon.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite App</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.ts"></script> | ||
</body> | ||
</html> |
26 changes: 26 additions & 0 deletions
26
playground/config-initialIsOpen-error-warnings/package.json
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,26 @@ | ||
{ | ||
"private": true, | ||
"name": "@playground/config-initial-is-open-error-warnings", | ||
"type": "module", | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"serve": "vite preview", | ||
"lint": "eslint --ext .js,.ts ./src/**" | ||
}, | ||
"dependencies": { | ||
"react": "^17.0.0", | ||
"react-dom": "^17.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^17.0.0", | ||
"@types/react-dom": "^17.0.0", | ||
"@typescript-eslint/eslint-plugin": "^5.59.0", | ||
"@typescript-eslint/parser": "^5.59.0", | ||
"eslint": "^8.11.0", | ||
"typescript": "^5.0.4", | ||
"vite": "^4.3.0", | ||
"vite-plugin-checker": "workspace:*" | ||
} | ||
} |
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 { text } from './text' | ||
|
||
const rootDom = document.querySelector('#root')! as HTMLElement | ||
rootDom.innerHTML = text | ||
|
||
export {} |
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 @@ | ||
export const text = 'Vanilla JS/TS' |
19 changes: 19 additions & 0 deletions
19
playground/config-initialIsOpen-error-warnings/tsconfig.json
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,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"lib": ["DOM", "DOM.Iterable", "ESNext"], | ||
"types": ["vite/client"], | ||
"allowJs": false, | ||
"skipLibCheck": false, | ||
"esModuleInterop": false, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"module": "ESNext", | ||
"moduleResolution": "Node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true | ||
}, | ||
"include": ["./src"] | ||
} |
15 changes: 15 additions & 0 deletions
15
playground/config-initialIsOpen-error-warnings/vite.config.js
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,15 @@ | ||
import { defineConfig } from 'vite' | ||
import checker from 'vite-plugin-checker' | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
checker({ | ||
overlay: { | ||
initialIsOpen: 'error', | ||
}, | ||
eslint: { | ||
lintCommand: 'eslint ./src --ext .ts', | ||
}, | ||
}), | ||
], | ||
}) |
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,4 @@ | ||
{ | ||
"root": true, | ||
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"] | ||
} |
Oops, something went wrong.