Skip to content

Commit 11a39c9

Browse files
committed
Update test
1 parent 0b582a5 commit 11a39c9

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

server/src/__tests__/linter.test.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,36 @@ import * as path from 'path'
22
import * as LSP from 'vscode-languageserver'
33

44
import { FIXTURE_DOCUMENT, FIXTURE_FOLDER } from '../../../testing/fixtures'
5+
import { getMockConnection } from '../../../testing/mocks'
56
import { assertShellcheckResult, Linter } from '../linter'
67

8+
const mockConsole = getMockConnection().console
9+
710
function textToDoc(txt: string) {
811
return LSP.TextDocument.create('foo', 'bar', 0, txt)
912
}
1013

1114
describe('linter', () => {
1215
it('should set canLint to false if executable empty', () => {
13-
expect(new Linter({ executablePath: null }).canLint).toBe(false)
16+
expect(new Linter({ console: mockConsole, executablePath: null }).canLint).toBe(false)
1417
})
1518

1619
it('should set canLint to true if executable not empty', () => {
17-
expect(new Linter({ executablePath: 'foo' }).canLint).toBe(true)
20+
expect(new Linter({ console: mockConsole, executablePath: 'foo' }).canLint).toBe(true)
1821
})
1922

2023
it('should set canLint to false when linting fails', async () => {
21-
jest.spyOn(console, 'error').mockImplementation()
2224
const executablePath = '77b4d3f6-c87a-11ec-9b62-a3c90f66d29f'
2325
const linter = new Linter({
26+
console: mockConsole,
2427
executablePath,
2528
})
2629
expect(await linter.lint(textToDoc(''), [])).toEqual([])
2730
expect(linter.canLint).toBe(false)
28-
expect(console.error).toBeCalledWith(
29-
expect.stringContaining('shellcheck not available at path'),
31+
expect(mockConsole.warn).toBeCalledWith(
32+
expect.stringContaining(
33+
'ShellCheck: disabling linting as no executable was found at path',
34+
),
3035
)
3136
})
3237

@@ -54,21 +59,26 @@ describe('linter', () => {
5459
},
5560
]
5661

57-
const linter = new Linter({ executablePath: 'shellcheck' })
62+
const linter = new Linter({ console: mockConsole, executablePath: 'shellcheck' })
5863
const result = await linter.lint(textToDoc(shell), [])
5964
expect(result).toEqual(expected)
6065
})
6166

6267
it('should correctly follow sources with correct cwd', async () => {
63-
const linter = new Linter({ executablePath: 'shellcheck', cwd: FIXTURE_FOLDER })
68+
const linter = new Linter({
69+
console: mockConsole,
70+
executablePath: 'shellcheck',
71+
cwd: FIXTURE_FOLDER,
72+
})
6473
const result = await linter.lint(FIXTURE_DOCUMENT.SHELLCHECK_SOURCE, [])
6574
expect(result).toEqual([])
6675
})
6776

6877
it('should fail to follow sources with incorrect cwd', async () => {
6978
const linter = new Linter({
70-
executablePath: 'shellcheck',
79+
console: mockConsole,
7180
cwd: path.resolve(path.join(FIXTURE_FOLDER, '../')),
81+
executablePath: 'shellcheck',
7282
})
7383
// prettier-ignore
7484
const expected = [
@@ -81,8 +91,9 @@ describe('linter', () => {
8191

8292
it('should follow sources with incorrect cwd if correct path is passed as a workspace path', async () => {
8393
const linter = new Linter({
84-
executablePath: 'shellcheck',
94+
console: mockConsole,
8595
cwd: path.resolve(path.join(FIXTURE_FOLDER, '../')),
96+
executablePath: 'shellcheck',
8697
})
8798
const result = await linter.lint(FIXTURE_DOCUMENT.SHELLCHECK_SOURCE, [
8899
{ uri: `file://${path.resolve(FIXTURE_FOLDER)}`, name: 'fixtures' },

server/src/linter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class Linter {
103103
if ((e as any).code === 'ENOENT') {
104104
// shellcheck path wasn't found, don't try to lint any more:
105105
this.console.warn(
106-
`ShellCheck: disabling linting as no executable '${this.executablePath}'`,
106+
`ShellCheck: disabling linting as no executable was found at path '${this.executablePath}'`,
107107
)
108108
this._canLint = false
109109
return { comments: [] }

0 commit comments

Comments
 (0)