@@ -2,31 +2,36 @@ import * as path from 'path'
2
2
import * as LSP from 'vscode-languageserver'
3
3
4
4
import { FIXTURE_DOCUMENT , FIXTURE_FOLDER } from '../../../testing/fixtures'
5
+ import { getMockConnection } from '../../../testing/mocks'
5
6
import { assertShellcheckResult , Linter } from '../linter'
6
7
8
+ const mockConsole = getMockConnection ( ) . console
9
+
7
10
function textToDoc ( txt : string ) {
8
11
return LSP . TextDocument . create ( 'foo' , 'bar' , 0 , txt )
9
12
}
10
13
11
14
describe ( 'linter' , ( ) => {
12
15
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 )
14
17
} )
15
18
16
19
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 )
18
21
} )
19
22
20
23
it ( 'should set canLint to false when linting fails' , async ( ) => {
21
- jest . spyOn ( console , 'error' ) . mockImplementation ( )
22
24
const executablePath = '77b4d3f6-c87a-11ec-9b62-a3c90f66d29f'
23
25
const linter = new Linter ( {
26
+ console : mockConsole ,
24
27
executablePath,
25
28
} )
26
29
expect ( await linter . lint ( textToDoc ( '' ) , [ ] ) ) . toEqual ( [ ] )
27
30
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
+ ) ,
30
35
)
31
36
} )
32
37
@@ -54,21 +59,26 @@ describe('linter', () => {
54
59
} ,
55
60
]
56
61
57
- const linter = new Linter ( { executablePath : 'shellcheck' } )
62
+ const linter = new Linter ( { console : mockConsole , executablePath : 'shellcheck' } )
58
63
const result = await linter . lint ( textToDoc ( shell ) , [ ] )
59
64
expect ( result ) . toEqual ( expected )
60
65
} )
61
66
62
67
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
+ } )
64
73
const result = await linter . lint ( FIXTURE_DOCUMENT . SHELLCHECK_SOURCE , [ ] )
65
74
expect ( result ) . toEqual ( [ ] )
66
75
} )
67
76
68
77
it ( 'should fail to follow sources with incorrect cwd' , async ( ) => {
69
78
const linter = new Linter ( {
70
- executablePath : 'shellcheck' ,
79
+ console : mockConsole ,
71
80
cwd : path . resolve ( path . join ( FIXTURE_FOLDER , '../' ) ) ,
81
+ executablePath : 'shellcheck' ,
72
82
} )
73
83
// prettier-ignore
74
84
const expected = [
@@ -81,8 +91,9 @@ describe('linter', () => {
81
91
82
92
it ( 'should follow sources with incorrect cwd if correct path is passed as a workspace path' , async ( ) => {
83
93
const linter = new Linter ( {
84
- executablePath : 'shellcheck' ,
94
+ console : mockConsole ,
85
95
cwd : path . resolve ( path . join ( FIXTURE_FOLDER , '../' ) ) ,
96
+ executablePath : 'shellcheck' ,
86
97
} )
87
98
const result = await linter . lint ( FIXTURE_DOCUMENT . SHELLCHECK_SOURCE , [
88
99
{ uri : `file://${ path . resolve ( FIXTURE_FOLDER ) } ` , name : 'fixtures' } ,
0 commit comments