Skip to content

Commit

Permalink
test: update snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Feb 12, 2022
1 parent 904d49d commit d1b6c0f
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 54 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ A Vite plugin that can run TypeScript, VLS, vue-tsc, ESLint in worker thread.

3. Open localhost page and start development 🚀.

_It's recommended to open browser for a better terminal display, see [#27](https://github.com/fi3ework/vite-plugin-checker/pull/27)._
💡 **Caveats**:

1. It's recommended to open browser for a better terminal flush, see [#27](https://github.com/fi3ework/vite-plugin-checker/pull/27).

## Available checkers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let binPath: string
export let log = ''
export let stripedLog = ''

export function proxyConsoleInTest(accumulate = false) {
export function proxyConsoleInTest(accumulate = true) {
Checker.logger = [
(...args: any[]) => {
if (accumulate) {
Expand Down
9 changes: 6 additions & 3 deletions packages/vite-plugin-checker/src/checkers/typescript/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
ensureCall,
normalizeTsDiagnostic,
toViteCustomPayload,
composeCheckerSummary,
wrapCheckerSummary,
} from '../../logger'
import { ACTION_TYPES, CreateDiagnostic, DiagnosticLevel, DiagnosticToRuntime } from '../../types'

Expand Down Expand Up @@ -93,8 +93,11 @@ const createDiagnostic: CreateDiagnostic<'typescript'> = (pluginConfig) => {
}

if (terminal) {
consoleLog(logChunk)
consoleLog(composeCheckerSummary('TypeScript', 1, 2))
consoleLog(
logChunk +
os.EOL +
wrapCheckerSummary('TypeScript', diagnostic.messageText.toString())
)
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions packages/vite-plugin-checker/src/checkers/vls/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export async function diagnostics(
logLevel: LogLevel,
options: DiagnosticOptions = { watch: false, verbose: false, config: null }
) {
const { watch, onDispatchDiagnostics: onDispatch } = options
if (options.verbose) {
console.log('====================================')
console.log('Getting Vetur diagnostics')
Expand Down Expand Up @@ -161,9 +160,10 @@ export async function prepareClientConnection(
const errorCount = normalized.filter((d) => d.level === DiagnosticSeverity.Error).length
const warningCount = normalized.filter((d) => d.level === DiagnosticSeverity.Warning).length
initialVueFilesTick++
options.onDispatchDiagnostics?.(normalized)
// only starts to log summary when all .vue files are loaded
// only starts to log when all .vue files are loaded
// onDispatchDiagnostics will dispatch diagnostics of all watched files
if (initialVueFilesTick >= initialVueFilesCount) {
options.onDispatchDiagnostics?.(normalized)
options.onDispatchDiagnosticsSummary?.(errorCount, warningCount)
}
}
Expand Down
9 changes: 0 additions & 9 deletions packages/vite-plugin-checker/src/checkers/vls/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import chalk from 'chalk'
import os from 'os'
import { parentPort } from 'worker_threads'

Expand Down Expand Up @@ -37,14 +36,6 @@ export const createDiagnostic: CreateDiagnostic<'vls'> = (pluginConfig) => {
if (!terminal) return

consoleLog(composeCheckerSummary('VLS', errorCount, warningCount))

// if (!errorCount) {
// consoleLog(chalk.green(`[VLS checker] No error found`))
// } else {
// consoleLog(
// chalk.red(`[VLS checker] Found ${errorCount} ${errorCount === 1 ? 'error' : 'errors'}`)
// )
// }
}

const onDispatchDiagnostics: DiagnosticOptions['onDispatchDiagnostics'] = (normalized) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ exports[`config-default serve get initial error and subsequent error 2`] = `
6 | rootDom.innerHTML = hello + text
7 |
8 | export {}
"
[ESLint] Found 1 error and 1 warning"
`;
2 changes: 0 additions & 2 deletions playground/basic/__tests__/default.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import stringify from 'fast-json-stable-stringify'
import {
killServer,
preTest,
proxyConsoleInTest,
resetReceivedLog,
sleepForEdit,
sleepForServerReady,
Expand Down Expand Up @@ -45,7 +44,6 @@ describe('config-default', () => {
let diagnostics: any
await viteServe({
cwd: testDir,
proxyConsole: () => proxyConsoleInTest(true),
wsSend: (_payload) => {
if (_payload.type === 'custom' && _payload.event === WS_CHECKER_ERROR_EVENT) {
diagnostics = _payload.data.diagnostics
Expand Down
4 changes: 2 additions & 2 deletions playground/basic/__tests__/no-runtime-code-in-build.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs/promises'
import fs from 'fs'
import klaw from 'klaw'
import path from 'path'
import { preTest, viteBuild } from 'vite-plugin-checker/__tests__/e2e/Sandbox/Sandbox'
Expand Down Expand Up @@ -35,7 +35,7 @@ describe('no-runtime-code-in-build', () => {

for await (const file of klaw(path.resolve(testDir, 'dist'))) {
if (file.stats.isFile()) {
const content = await fs.readFile(file.path, 'utf-8')
const content = await fs.promises.readFile(file.path, 'utf-8')
expect(content).not.toContain('vite-plugin-checker')
}
}
Expand Down
2 changes: 0 additions & 2 deletions playground/basic/__tests__/overlay-terminal-false.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import stringify from 'fast-json-stable-stringify'
import {
killServer,
preTest,
proxyConsoleInTest,
sleepForServerReady,
stripedLog,
viteServe,
Expand Down Expand Up @@ -44,7 +43,6 @@ describe('overlay-terminal-false', () => {
editFile('vite.config.ts', (code) => code.replace(`// edit-slot`, `terminal: false,`))
await viteServe({
cwd: testDir,
proxyConsole: () => proxyConsoleInTest(true),
wsSend: (_payload) => {
if (_payload.type === 'custom' && _payload.event === WS_CHECKER_ERROR_EVENT) {
diagnostics = _payload.data.diagnostics
Expand Down
4 changes: 2 additions & 2 deletions playground/eslint/__tests__/__snapshots__/config.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports[`eslint-config serve get initial error and subsequent error 2`] = `
6 | rootDom.innerHTML = hello + text
7 |
8 | export {}
"
[ESLint] Found 0 error and 1 warning"
`;
exports[`eslint-config serve get initial error and subsequent error 3`] = `"[{\\"checkerId\\":\\"ESLint\\",\\"frame\\":\\" 3 | var hello = 'Hello~'/n 4 |/n > 5 | const rootDom = document.querySelector('#root')!/n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^/n 6 | rootDom.innerHTML = hello + text/n 7 |/n 8 | export {}\\",\\"id\\":\\"<PROJECT_ROOT>/temp/eslint/src/main.ts\\",\\"level\\":0,\\"loc\\":{\\"column\\":17,\\"file\\":\\"<PROJECT_ROOT>/temp/eslint/src/main.ts\\",\\"line\\":5},\\"message\\":\\"Forbidden non-null assertion.\\",\\"stack\\":\\"\\"}]"`;
Expand All @@ -29,5 +29,5 @@ exports[`eslint-config serve get initial error and subsequent error 4`] = `
6 | rootDom.innerHTML = hello + text
7 |
8 | export {}
"
[ESLint] Found 0 error and 1 warning"
`;
42 changes: 36 additions & 6 deletions playground/eslint/__tests__/__snapshots__/test.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
exports[`eslint serve get initial error and subsequent error 1`] = `"[{\\"checkerId\\":\\"ESLint\\",\\"frame\\":\\" 1 | import { text } from './text'/n 2 |/n > 3 | var hello = 'Hello'/n | ^^^^^^^^^^^^^^^^^^^/n 4 |/n 5 | const rootDom = document.querySelector('#root')!/n 6 | rootDom.innerHTML = hello + text\\",\\"id\\":\\"<PROJECT_ROOT>/temp/eslint/src/main.ts\\",\\"level\\":1,\\"loc\\":{\\"column\\":1,\\"file\\":\\"<PROJECT_ROOT>/temp/eslint/src/main.ts\\",\\"line\\":3},\\"message\\":\\"Unexpected var, use let or const instead.\\",\\"stack\\":\\"\\"},{\\"checkerId\\":\\"ESLint\\",\\"frame\\":\\" 3 | var hello = 'Hello'/n 4 |/n > 5 | const rootDom = document.querySelector('#root')!/n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^/n 6 | rootDom.innerHTML = hello + text/n 7 |/n 8 | export {}\\",\\"id\\":\\"<PROJECT_ROOT>/temp/eslint/src/main.ts\\",\\"level\\":0,\\"loc\\":{\\"column\\":17,\\"file\\":\\"<PROJECT_ROOT>/temp/eslint/src/main.ts\\",\\"line\\":5},\\"message\\":\\"Forbidden non-null assertion.\\",\\"stack\\":\\"\\"}]"`;

exports[`eslint serve get initial error and subsequent error 2`] = `
" WARNING(ESLint) Forbidden non-null assertion.
" ERROR(ESLint) Unexpected var, use let or const instead.
FILE <PROJECT_ROOT>/temp/eslint/src/main.ts:3:1
1 | import { text } from './text'
2 |
> 3 | var hello = 'Hello'
| ^^^^^^^^^^^^^^^^^^^
4 |
5 | const rootDom = document.querySelector('#root')!
6 | rootDom.innerHTML = hello + text
WARNING(ESLint) Forbidden non-null assertion.
FILE <PROJECT_ROOT>/temp/eslint/src/main.ts:5:17
3 | var hello = 'Hello'
Expand All @@ -13,13 +23,23 @@ exports[`eslint serve get initial error and subsequent error 2`] = `
6 | rootDom.innerHTML = hello + text
7 |
8 | export {}
"
[ESLint] Found 1 error and 1 warning"
`;
exports[`eslint serve get initial error and subsequent error 3`] = `"[{\\"checkerId\\":\\"ESLint\\",\\"frame\\":\\" 1 | import { text } from './text'/n 2 |/n > 3 | var hello = 'Hello~'/n | ^^^^^^^^^^^^^^^^^^^^/n 4 |/n 5 | const rootDom = document.querySelector('#root')!/n 6 | rootDom.innerHTML = hello + text\\",\\"id\\":\\"<PROJECT_ROOT>/temp/eslint/src/main.ts\\",\\"level\\":1,\\"loc\\":{\\"column\\":1,\\"file\\":\\"<PROJECT_ROOT>/temp/eslint/src/main.ts\\",\\"line\\":3},\\"message\\":\\"Unexpected var, use let or const instead.\\",\\"stack\\":\\"\\"},{\\"checkerId\\":\\"ESLint\\",\\"frame\\":\\" 3 | var hello = 'Hello~'/n 4 |/n > 5 | const rootDom = document.querySelector('#root')!/n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^/n 6 | rootDom.innerHTML = hello + text/n 7 |/n 8 | export {}\\",\\"id\\":\\"<PROJECT_ROOT>/temp/eslint/src/main.ts\\",\\"level\\":0,\\"loc\\":{\\"column\\":17,\\"file\\":\\"<PROJECT_ROOT>/temp/eslint/src/main.ts\\",\\"line\\":5},\\"message\\":\\"Forbidden non-null assertion.\\",\\"stack\\":\\"\\"}]"`;
exports[`eslint serve get initial error and subsequent error 4`] = `
" WARNING(ESLint) Forbidden non-null assertion.
" ERROR(ESLint) Unexpected var, use let or const instead.
FILE <PROJECT_ROOT>/temp/eslint/src/main.ts:3:1
1 | import { text } from './text'
2 |
> 3 | var hello = 'Hello~'
| ^^^^^^^^^^^^^^^^^^^^
4 |
5 | const rootDom = document.querySelector('#root')!
6 | rootDom.innerHTML = hello + text
WARNING(ESLint) Forbidden non-null assertion.
FILE <PROJECT_ROOT>/temp/eslint/src/main.ts:5:17
3 | var hello = 'Hello~'
Expand All @@ -29,13 +49,23 @@ exports[`eslint serve get initial error and subsequent error 4`] = `
6 | rootDom.innerHTML = hello + text
7 |
8 | export {}
"
[ESLint] Found 1 error and 1 warning"
`;
exports[`eslint serve get initial error and subsequent error 5`] = `"[{\\"checkerId\\":\\"ESLint\\",\\"frame\\":\\" 1 | import { text } from './text'/n 2 |/n > 3 | var hello = 'Hello~'/n | ^^^^^^^^^^^^^^^^^^^^/n 4 |/n 5 | const rootDom = document.querySelector('#root')!/n 6 | rootDom.innerHTML = hello + text\\",\\"id\\":\\"<PROJECT_ROOT>/temp/eslint/src/main.ts\\",\\"level\\":1,\\"loc\\":{\\"column\\":1,\\"file\\":\\"<PROJECT_ROOT>/temp/eslint/src/main.ts\\",\\"line\\":3},\\"message\\":\\"Unexpected var, use let or const instead.\\",\\"stack\\":\\"\\"},{\\"checkerId\\":\\"ESLint\\",\\"frame\\":\\" 3 | var hello = 'Hello~'/n 4 |/n > 5 | const rootDom = document.querySelector('#root')!/n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^/n 6 | rootDom.innerHTML = hello + text/n 7 |/n 8 | export {}\\",\\"id\\":\\"<PROJECT_ROOT>/temp/eslint/src/main.ts\\",\\"level\\":0,\\"loc\\":{\\"column\\":17,\\"file\\":\\"<PROJECT_ROOT>/temp/eslint/src/main.ts\\",\\"line\\":5},\\"message\\":\\"Forbidden non-null assertion.\\",\\"stack\\":\\"\\"}]"`;
exports[`eslint serve get initial error and subsequent error 6`] = `
" WARNING(ESLint) Forbidden non-null assertion.
" ERROR(ESLint) Unexpected var, use let or const instead.
FILE <PROJECT_ROOT>/temp/eslint/src/main.ts:3:1
1 | import { text } from './text'
2 |
> 3 | var hello = 'Hello~'
| ^^^^^^^^^^^^^^^^^^^^
4 |
5 | const rootDom = document.querySelector('#root')!
6 | rootDom.innerHTML = hello + text
WARNING(ESLint) Forbidden non-null assertion.
FILE <PROJECT_ROOT>/temp/eslint/src/main.ts:5:17
3 | var hello = 'Hello~'
Expand All @@ -45,5 +75,5 @@ exports[`eslint serve get initial error and subsequent error 6`] = `
6 | rootDom.innerHTML = hello + text
7 |
8 | export {}
"
[ESLint] Found 1 error and 1 warning"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports[`multiple-hmr serve get initial error and subsequent error 2`] = `
7 | return (
8 | <div className=\\"App\\">
9 | <header className=\\"App-header\\">
[ESLint] Found 1 error and 0 warning
ERROR(TypeScript) Argument of type 'number' is not assignable to parameter of type 'string | (() => string)'.
FILE <PROJECT_ROOT>/temp/multiple-hmr/src/App.tsx:6:44
Expand All @@ -25,7 +25,7 @@ exports[`multiple-hmr serve get initial error and subsequent error 2`] = `
8 | <div className=\\"App\\">
9 | <header className=\\"App-header\\">
Found 1 error. Watching for file changes."
[TypeScript] Found 1 error. Watching for file changes."
`;
exports[`multiple-hmr serve get initial error and subsequent error 3`] = `"[{\\"checkerId\\":\\"ESLint\\",\\"frame\\":\\" 4 |/n 5 | function App() {/n > 6 | var [count, setCount] = useState<string>(2)/n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^/n 7 | return (/n 8 | <div className=/\\"App/\\">/n 9 | <header className=/\\"App-header/\\">\\",\\"id\\":\\"<PROJECT_ROOT>/temp/multiple-hmr/src/App.tsx\\",\\"level\\":1,\\"loc\\":{\\"column\\":3,\\"file\\":\\"<PROJECT_ROOT>/temp/multiple-hmr/src/App.tsx\\",\\"line\\":6},\\"message\\":\\"Unexpected var, use let or const instead.\\",\\"stack\\":\\"\\"},{\\"checkerId\\":\\"TypeScript\\",\\"frame\\":\\" 4 |/n 5 | function App() {/n > 6 | var [count, setCount] = useState<string>(2)/n | ^/n 7 | return (/n 8 | <div className=/\\"App/\\">/n 9 | <header className=/\\"App-header/\\">\\",\\"id\\":\\"<PROJECT_ROOT>/temp/multiple-hmr/src/App.tsx\\",\\"level\\":1,\\"loc\\":{\\"column\\":44,\\"file\\":\\"<PROJECT_ROOT>/temp/multiple-hmr/src/App.tsx\\",\\"line\\":6},\\"message\\":\\"Argument of type 'number' is not assignable to parameter of type 'string | (() => string)'.\\",\\"stack\\":\\"\\"}]"`;
Expand All @@ -41,7 +41,7 @@ exports[`multiple-hmr serve get initial error and subsequent error 4`] = `
7 | return (
8 | <div className=\\"App\\">
9 | <header className=\\"App-header\\">
[ESLint] Found 1 error and 0 warning
ERROR(TypeScript) Argument of type 'number' is not assignable to parameter of type 'string | (() => string)'.
FILE <PROJECT_ROOT>/temp/multiple-hmr/src/App.tsx:6:44
Expand All @@ -53,7 +53,7 @@ exports[`multiple-hmr serve get initial error and subsequent error 4`] = `
8 | <div className=\\"App\\">
9 | <header className=\\"App-header\\">
Found 1 error. Watching for file changes."
[TypeScript] Found 1 error. Watching for file changes."
`;
exports[`multiple-hmr serve get initial error and subsequent error 5`] = `"[{\\"checkerId\\":\\"ESLint\\",\\"frame\\":\\" 4 |/n 5 | function App() {/n > 6 | var [count, setCount] = useState<string>('x')/n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^/n 7 | return (/n 8 | <div className=/\\"App/\\">/n 9 | <header className=/\\"App-header/\\">\\",\\"id\\":\\"<PROJECT_ROOT>/temp/multiple-hmr/src/App.tsx\\",\\"level\\":1,\\"loc\\":{\\"column\\":3,\\"file\\":\\"<PROJECT_ROOT>/temp/multiple-hmr/src/App.tsx\\",\\"line\\":6},\\"message\\":\\"Unexpected var, use let or const instead.\\",\\"stack\\":\\"\\"}]"`;
Expand All @@ -69,13 +69,13 @@ exports[`multiple-hmr serve get initial error and subsequent error 6`] = `
7 | return (
8 | <div className=\\"App\\">
9 | <header className=\\"App-header\\">
Found 0 errors. Watching for file changes."
[ESLint] Found 1 error and 0 warning
[TypeScript] Found 0 errors. Watching for file changes."
`;
exports[`multiple-hmr serve get initial error and subsequent error 7`] = `"[]"`;
exports[`multiple-hmr serve get initial error and subsequent error 8`] = `
"
Found 0 errors. Watching for file changes."
"[ESLint] Found 0 error and 0 warning
[TypeScript] Found 0 errors. Watching for file changes."
`;
2 changes: 0 additions & 2 deletions playground/multiple-hmr/__tests__/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import stable from 'sort-deep-object-arrays'
import {
killServer,
preTest,
proxyConsoleInTest,
resetReceivedLog,
sleepForEdit,
sleepForServerReady,
Expand Down Expand Up @@ -51,7 +50,6 @@ describe('multiple-hmr', () => {
diagnostics = diagnostics.concat(_payload.data.diagnostics)
}
},
proxyConsole: () => proxyConsoleInTest(true),
})
await sleepForServerReady()
expect(stringify(stable(diagnostics))).toMatchSnapshot()
Expand Down
Loading

0 comments on commit d1b6c0f

Please sign in to comment.