Skip to content

Commit

Permalink
test: pass overlay test
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Feb 6, 2022
1 parent 458e4cc commit 4285d54
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 24 deletions.
9 changes: 3 additions & 6 deletions packages/vite-plugin-checker/src/checkers/eslint/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ import { translateOptions } from './cli'

import type { CreateDiagnostic } from '../../types'
const createDiagnostic: CreateDiagnostic<'eslint'> = (pluginConfig) => {
let overlay = true // Vite defaults to true
let overlay = true

return {
config: async ({ hmr }) => {
const viteOverlay = !(typeof hmr === 'object' && hmr.overlay === false)
if (pluginConfig.overlay === false || !viteOverlay) {
overlay = false
}
config: async ({ enableOverlay }) => {
overlay = enableOverlay
},
async configureServer({ root }) {
if (!pluginConfig.eslint) return
Expand Down
10 changes: 3 additions & 7 deletions packages/vite-plugin-checker/src/checkers/typescript/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ import { ACTION_TYPES, CreateDiagnostic } from '../../types'
import type { ErrorPayload } from 'vite'

const createDiagnostic: CreateDiagnostic<'typescript'> = (pluginConfig) => {
let overlay = true // Vite defaults to true
let overlay = true
// let currErr: ErrorPayload['err'] | null = null
let currErrs: ErrorPayload['err'][] = []

return {
config: ({ hmr }) => {
const viteOverlay = !(typeof hmr === 'object' && hmr.overlay === false)

if (pluginConfig.overlay === false || !viteOverlay) {
overlay = false
}
config: async ({ enableOverlay }) => {
overlay = enableOverlay
},
configureServer({ root }) {
invariant(pluginConfig.typescript, 'config.typescript should be `false`')
Expand Down
10 changes: 3 additions & 7 deletions packages/vite-plugin-checker/src/checkers/vls/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ import { toViteCustomPayload } from '../../logger'

import type { CreateDiagnostic } from '../../types'
export const createDiagnostic: CreateDiagnostic<'vls'> = (pluginConfig) => {
let overlay = true // Vite defaults to true
let overlay = true

return {
config: ({ hmr }) => {
const viteOverlay = !(typeof hmr === 'object' && hmr.overlay === false)

if (pluginConfig.overlay === false || !viteOverlay) {
overlay = false
}
config: ({ enableOverlay }) => {
overlay = enableOverlay
},
async configureServer({ root }) {
const workDir: string = root
Expand Down
6 changes: 4 additions & 2 deletions packages/vite-plugin-checker/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function createCheckers(userConfig: UserPluginConfig, env: ConfigEnv): ServeAndB

export default function Plugin(userConfig: UserPluginConfig): Plugin {
const enableBuild = userConfig?.enableBuild ?? true
const enableOverlay = userConfig?.overlay ?? true
let checkers: ServeAndBuildChecker[] = []
let viteMode: ConfigEnv['command'] | undefined

Expand All @@ -54,11 +55,12 @@ export default function Plugin(userConfig: UserPluginConfig): Plugin {
checkers = createCheckers(userConfig || {}, env)
if (viteMode !== 'serve') return

const hmr = config.server?.hmr
// const hmr = config.server?.hmr
checkers.forEach((checker) => {
const workerConfig = checker.serve.config
workerConfig({
hmr: typeof hmr === 'object' ? { overlay: hmr.overlay } : hmr,
// hmr: typeof hmr === 'object' ? { overlay: hmr.overlay } : hmr,
enableOverlay,
env,
})
})
Expand Down
3 changes: 2 additions & 1 deletion packages/vite-plugin-checker/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ export interface OverlayErrorAction extends Action {
}

interface ConfigActionPayload {
hmr?: { overlay?: boolean } | boolean
// hmr?: { overlay?: boolean } | boolean
enableOverlay: boolean
env: ConfigEnv
}

Expand Down
2 changes: 1 addition & 1 deletion playground/react-ts/__tests__/overlay-false.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('overlay', () => {
await viteServe({ cwd: testDir, launchPage: true })
await sleep(6000)
await expect(getHmrOverlayText()).rejects.toThrow(
'<vite-error-overlay> shadow dom is expected to be found, but got null'
'Invariant failed: <vite-plugin-checker-error-overlay> shadow dom is expected to be found, but got null'
)
})
})

0 comments on commit 4285d54

Please sign in to comment.