-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix warning level logging * test: add unit test to logger Co-authored-by: fi3ework <fi3ework@gmail.com>
- Loading branch information
1 parent
1403f6f
commit 5b0ac3a
Showing
4 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
packages/vite-plugin-checker/__tests__/unit/__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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`logger diagnosticToTerminalLog get error 1`] = ` | ||
" ERROR(ESLint) Unexpected var, use let or const instead. | ||
FILE /Users/vite-plugin-checker/playground/vanilla-ts/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 | ||
" | ||
`; | ||
|
||
exports[`logger diagnosticToTerminalLog get warning 1`] = ` | ||
" WARNING(ESLint) Unexpected var, use let or const instead. | ||
FILE /Users/vite-plugin-checker/playground/vanilla-ts/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 | ||
" | ||
`; |
14 changes: 14 additions & 0 deletions
14
packages/vite-plugin-checker/__tests__/unit/fixtures/eslintDiagnostic.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,14 @@ | ||
export const error1 = { | ||
message: 'Unexpected var, use let or const instead.', | ||
conclusion: '', | ||
codeFrame: | ||
" \u001b[0m \u001b[90m 1 |\u001b[39m \u001b[36mimport\u001b[39m { text } \u001b[36mfrom\u001b[39m \u001b[32m'./text'\u001b[39m\u001b[0m\n \u001b[0m \u001b[90m 2 |\u001b[39m\u001b[0m\n \u001b[0m\u001b[31m\u001b[1m>\u001b[22m\u001b[39m\u001b[90m 3 |\u001b[39m \u001b[36mvar\u001b[39m hello \u001b[33m=\u001b[39m \u001b[32m'Hello'\u001b[39m\u001b[0m\n \u001b[0m \u001b[90m |\u001b[39m \u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[0m\n \u001b[0m \u001b[90m 4 |\u001b[39m\u001b[0m\n \u001b[0m \u001b[90m 5 |\u001b[39m \u001b[36mconst\u001b[39m rootDom \u001b[33m=\u001b[39m document\u001b[33m.\u001b[39mquerySelector(\u001b[32m'#root'\u001b[39m)\u001b[33m!\u001b[39m\u001b[0m\n \u001b[0m \u001b[90m 6 |\u001b[39m rootDom\u001b[33m.\u001b[39minnerHTML \u001b[33m=\u001b[39m hello \u001b[33m+\u001b[39m text\u001b[0m", | ||
stripedCodeFrame: | ||
" 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: '/Users/vite-plugin-checker/playground/vanilla-ts/src/main.ts', | ||
checker: 'ESLint', | ||
loc: { start: { line: 3, column: 1 }, end: { line: 3, column: 20 } }, | ||
level: 1, | ||
} as const | ||
|
||
export const warning1 = { ...error1, level: 0 } |
17 changes: 17 additions & 0 deletions
17
packages/vite-plugin-checker/__tests__/unit/logger.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,17 @@ | ||
import { diagnosticToTerminalLog } from '../../src/logger' | ||
import { error1 as eslintError1, warning1 as eslintWarning1 } from './fixtures/eslintDiagnostic' | ||
import strip from 'strip-ansi' | ||
|
||
describe('logger', () => { | ||
describe('diagnosticToTerminalLog', () => { | ||
it('get error', () => { | ||
const receive = strip(diagnosticToTerminalLog(eslintError1, 'ESLint')) | ||
expect(receive).toMatchSnapshot() | ||
}) | ||
|
||
it('get warning', () => { | ||
const receive = strip(diagnosticToTerminalLog(eslintWarning1, 'ESLint')) | ||
expect(receive).toMatchSnapshot() | ||
}) | ||
}) | ||
}) |
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