Skip to content

Commit

Permalink
fix: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
HerringtonDarkholme committed Oct 9, 2024
1 parent 2220328 commit 1a08025
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 40 deletions.
45 changes: 25 additions & 20 deletions src/test/diagnostics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,33 @@ import * as vscode from 'vscode'

import { getDocUri, testDiagnostics, toRange, testAndRetry } from './utils'

export const EXPECTED_NON_EMPTY_DIAGNOSTICS = [
{
message: 'No console.log\n\nno console.log',
range: toRange(2, 4, 2, 32),
severity: vscode.DiagnosticSeverity.Warning,
source: 'ast-grep',
code: 'no-console-log',
},
{
message: 'Test rule for vscode extension\n\nTest Rule\n',
range: toRange(0, 0, 4, 1),
severity: vscode.DiagnosticSeverity.Error,
source: 'ast-grep',
code: 'test-sg-rule',
},
{
message: 'Test rule for vscode extension\n\nTest Rule\n',
range: toRange(6, 0, 10, 1),
severity: vscode.DiagnosticSeverity.Error,
source: 'ast-grep',
code: 'test-sg-rule',
},
]

suite('Should get diagnostics', () => {
const docUri = getDocUri('test.ts')
testAndRetry('Get ast-grep issues', async () => {
await testDiagnostics(docUri, [
{
message: 'No console.log',
range: toRange(2, 4, 2, 32),
severity: vscode.DiagnosticSeverity.Warning,
source: 'ex',
},
{
message: 'Test rule for vscode extension',
range: toRange(0, 0, 4, 1),
severity: vscode.DiagnosticSeverity.Error,
source: 'ex',
},
{
message: 'Test rule for vscode extension',
range: toRange(6, 0, 10, 1),
severity: vscode.DiagnosticSeverity.Error,
source: 'ex',
},
])
await testDiagnostics(docUri, [])
})
})
22 changes: 2 additions & 20 deletions src/test/restart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
toRange,
testAndRetry,
} from './utils'
import { EXPECTED_NON_EMPTY_DIAGNOSTICS } from './diagnostics.test'

suite('ast-grep.restartLanguageServer should work', () => {
const docUri = getDocUri('test.ts')
Expand All @@ -24,25 +25,6 @@ suite('ast-grep.restartLanguageServer should work', () => {
await vscode.workspace.fs.rename(tempSgConfigYml, sgConfigYml)
await vscode.commands.executeCommand('ast-grep.restartLanguageServer')
await sleep(1000)
await testDiagnostics(docUri, [
{
message: 'No console.log',
range: toRange(2, 4, 2, 32),
severity: vscode.DiagnosticSeverity.Warning,
source: 'ex',
},
{
message: 'Test rule for vscode extension',
range: toRange(0, 0, 4, 1),
severity: vscode.DiagnosticSeverity.Error,
source: 'ex',
},
{
message: 'Test rule for vscode extension',
range: toRange(6, 0, 10, 1),
severity: vscode.DiagnosticSeverity.Error,
source: 'ex',
},
])
await testDiagnostics(docUri, EXPECTED_NON_EMPTY_DIAGNOSTICS)
})
})
2 changes: 2 additions & 0 deletions src/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ export function testAndRetry(name: string, fn: () => Promise<void>) {
if (++retries < MAX_RETRIES) {
await sleep(1000)
console.log(`Retrying test at t = ${Date.now() - startTime}ms`)
} else {
break
}
}
}
Expand Down

0 comments on commit 1a08025

Please sign in to comment.