Skip to content

Commit

Permalink
test: pass ut
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Jul 26, 2023
1 parent 42f1121 commit 8b37c30
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 323 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`eslint logger > normalizeEslintDiagnostic > get multiple diagnostics 1`] = `
[
{
"checker": "ESLint",
"codeFrame": "   1 | import { text } from './text'
  2 |
> 3 | var hello = 'Hello'
  | ^^^^^^^^^^^^^^^^^^^
  4 | var hello1 = 'Hello1'
  5 |
  6 | const rootDom = document.querySelector('#root')!",
"conclusion": "",
"id": "/Users/vite-plugin-checker/playground/eslint/src/main.ts",
"level": 1,
"loc": {
"end": {
"column": 20,
"line": 3,
},
"start": {
"column": 1,
"line": 3,
},
},
"message": "Unexpected var, use let or const instead. (no-var)",
"stripedCodeFrame": " 1 | import { text } from './text'
2 |
> 3 | var hello = 'Hello'
| ^^^^^^^^^^^^^^^^^^^
4 | var hello1 = 'Hello1'
5 |
6 | const rootDom = document.querySelector('#root')!",
},
{
"checker": "ESLint",
"codeFrame": "   2 |
  3 | var hello = 'Hello'
> 4 | var hello1 = 'Hello1'
  | ^^^^^^^^^^^^^^^^^^^^^
  5 |
  6 | const rootDom = document.querySelector('#root')!
  7 | rootDom.innerHTML = hello + text",
"conclusion": "",
"id": "/Users/vite-plugin-checker/playground/eslint/src/main.ts",
"level": 1,
"loc": {
"end": {
"column": 22,
"line": 4,
},
"start": {
"column": 1,
"line": 4,
},
},
"message": "Unexpected var, use let or const instead. (no-var)",
"stripedCodeFrame": " 2 |
3 | var hello = 'Hello'
> 4 | var hello1 = 'Hello1'
| ^^^^^^^^^^^^^^^^^^^^^
5 |
6 | const rootDom = document.querySelector('#root')!
7 | rootDom.innerHTML = hello + text",
},
]
`;
55 changes: 55 additions & 0 deletions packages/checker-eslint/__tests__/fixtures/eslintDiagnostic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import type { NormalizedDiagnostic } from './../../src/logger'
import type { ESLint } from 'eslint'

export const error1: NormalizedDiagnostic = {
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/eslint/src/main.ts',
checker: 'ESLint',
loc: { start: { line: 3, column: 1 }, end: { line: 3, column: 20 } },
level: 1,
}

export const warning1: NormalizedDiagnostic = { ...error1, level: 0 }

export const eslintResult1: ESLint.LintResult = {
filePath: '/Users/vite-plugin-checker/playground/eslint/src/main.ts',
messages: [
{
ruleId: 'no-var',
severity: 2,
message: 'Unexpected var, use let or const instead.',
line: 3,
column: 1,
nodeType: 'VariableDeclaration',
messageId: 'unexpectedVar',
endLine: 3,
endColumn: 20,
fix: { range: [31, 34], text: 'let' },
},
{
ruleId: 'no-var',
severity: 2,
message: 'Unexpected var, use let or const instead.',
line: 4,
column: 1,
nodeType: 'VariableDeclaration',
messageId: 'unexpectedVar',
endLine: 4,
endColumn: 22,
fix: { range: [51, 54], text: 'let' },
},
],
errorCount: 2,
fatalErrorCount: 2,
warningCount: 0,
fixableErrorCount: 2,
fixableWarningCount: 0,
source:
"import { text } from './text'\n\nvar hello = 'Hello'\nvar hello1 = 'Hello1'\n\nconst rootDom = document.querySelector('#root')!\nrootDom.innerHTML = hello + text\n\nexport {}\n",
usedDeprecatedRules: [],
}
13 changes: 13 additions & 0 deletions packages/checker-eslint/__tests__/logger.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, expect, it } from 'vitest'

import { normalizeEslintDiagnostic } from '../src/logger.js'
import { eslintResult1 } from './fixtures/eslintDiagnostic.js'

describe('eslint logger', () => {
describe('normalizeEslintDiagnostic', () => {
it('get multiple diagnostics', () => {
const received = normalizeEslintDiagnostic(eslintResult1)
expect(received).toMatchSnapshot()
})
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`VLS config > customized config 1`] = `
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import path from 'path'
import { describe, expect, it } from 'vitest'
import { ShutdownRequest } from 'vscode-languageserver/node'
import { ShutdownRequest } from 'vscode-languageserver/node.js'
import { URI } from 'vscode-uri'
import { fileURLToPath } from 'node:url'
import { dirname } from 'node:path'

import { prepareClientConnection, logLevel2Severity } from '../../checker-vls/src/diagnostics'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
import { prepareClientConnection, logLevel2Severity } from '../src/diagnostics.js'

async function testVslConfig(overrideConfig?: any) {
const workspaceUri = URI.file(path.join(__dirname, 'fixtures'))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`logger > diagnosticToTerminalLog > get error 1`] = `
" ERROR(ESLint) Unexpected var, use let or const instead.
Expand Down Expand Up @@ -27,70 +27,3 @@ exports[`logger > diagnosticToTerminalLog > get warning 1`] = `
6 | rootDom.innerHTML = hello + text
"
`;

exports[`logger > normalizeEslintDiagnostic > get multiple diagnostics 1`] = `
[
{
"checker": "ESLint",
"codeFrame": "   1 | import { text } from './text'
  2 |
> 3 | var hello = 'Hello'
  | ^^^^^^^^^^^^^^^^^^^
  4 | var hello1 = 'Hello1'
  5 |
  6 | const rootDom = document.querySelector('#root')!",
"conclusion": "",
"id": "/Users/vite-plugin-checker/playground/eslint/src/main.ts",
"level": 1,
"loc": {
"end": {
"column": 20,
"line": 3,
},
"start": {
"column": 1,
"line": 3,
},
},
"message": "Unexpected var, use let or const instead. (no-var)",
"stripedCodeFrame": " 1 | import { text } from './text'
2 |
> 3 | var hello = 'Hello'
| ^^^^^^^^^^^^^^^^^^^
4 | var hello1 = 'Hello1'
5 |
6 | const rootDom = document.querySelector('#root')!",
},
{
"checker": "ESLint",
"codeFrame": "   2 |
  3 | var hello = 'Hello'
> 4 | var hello1 = 'Hello1'
  | ^^^^^^^^^^^^^^^^^^^^^
  5 |
  6 | const rootDom = document.querySelector('#root')!
  7 | rootDom.innerHTML = hello + text",
"conclusion": "",
"id": "/Users/vite-plugin-checker/playground/eslint/src/main.ts",
"level": 1,
"loc": {
"end": {
"column": 22,
"line": 4,
},
"start": {
"column": 1,
"line": 4,
},
},
"message": "Unexpected var, use let or const instead. (no-var)",
"stripedCodeFrame": " 2 |
3 | var hello = 'Hello'
> 4 | var hello1 = 'Hello1'
| ^^^^^^^^^^^^^^^^^^^^^
5 |
6 | const rootDom = document.querySelector('#root')!
7 | rootDom.innerHTML = hello + text",
},
]
`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { NormalizedDiagnostic } from './../../src/logger'
import type { ESLint } from 'eslint'

export const error1: NormalizedDiagnostic = {
message: 'Unexpected var, use let or const instead.',
Expand All @@ -15,41 +14,3 @@ export const error1: NormalizedDiagnostic = {
}

export const warning1: NormalizedDiagnostic = { ...error1, level: 0 }

export const eslintResult1: ESLint.LintResult = {
filePath: '/Users/vite-plugin-checker/playground/eslint/src/main.ts',
messages: [
{
ruleId: 'no-var',
severity: 2,
message: 'Unexpected var, use let or const instead.',
line: 3,
column: 1,
nodeType: 'VariableDeclaration',
messageId: 'unexpectedVar',
endLine: 3,
endColumn: 20,
fix: { range: [31, 34], text: 'let' },
},
{
ruleId: 'no-var',
severity: 2,
message: 'Unexpected var, use let or const instead.',
line: 4,
column: 1,
nodeType: 'VariableDeclaration',
messageId: 'unexpectedVar',
endLine: 4,
endColumn: 22,
fix: { range: [51, 54], text: 'let' },
},
],
errorCount: 2,
fatalErrorCount: 2,
warningCount: 0,
fixableErrorCount: 2,
fixableWarningCount: 0,
source:
"import { text } from './text'\n\nvar hello = 'Hello'\nvar hello1 = 'Hello1'\n\nconst rootDom = document.querySelector('#root')!\nrootDom.innerHTML = hello + text\n\nexport {}\n",
usedDeprecatedRules: [],
}
Loading

0 comments on commit 8b37c30

Please sign in to comment.