1
- import { describe , it , expect , afterEach } from 'bun:test' ;
1
+ import { describe , it , expect , afterEach , spyOn } from 'bun:test' ;
2
2
import { existsSync , unlinkSync , readFileSync } from 'node:fs' ;
3
3
import { execSync } from 'node:child_process' ;
4
+ import { prettierFormatterGitLab } from '../src/index.js' ;
4
5
5
6
const CODE_QUALITY_FILENAME = 'gl-prettier-codequality.json' ;
6
7
@@ -24,4 +25,28 @@ describe('prettier-formatter-gitlab cli', () => {
24
25
const content = readFileSync ( CODE_QUALITY_FILENAME ) ;
25
26
expect ( content . toString ( ) ) . toMatchSnapshot ( ) ;
26
27
} ) ;
28
+
29
+ it ( 'should work with the `-c` or `-l` flag' , async ( ) => {
30
+ const consoleSpy = spyOn ( console , 'log' ) ;
31
+ consoleSpy . mockImplementation ( ( ) => null ) ;
32
+ process . env . PRETTIER_CODE_QUALITY_REPORT = CODE_QUALITY_FILENAME ;
33
+
34
+ // prettier -c path/to/folder/
35
+ const outputCheck = `Checking formatting...
36
+ [warn] test/dirty-2.js
37
+ [warn] test/dirty.js
38
+ [warn] Code style issues found in 3 files. Run Prettier to fix.
39
+ ` ;
40
+
41
+ // prettier -l path/to/folder/
42
+ const outputList = `test/dirty-2.js
43
+ test/dirty.js
44
+ ` ;
45
+
46
+ await prettierFormatterGitLab ( outputCheck ) ;
47
+ await prettierFormatterGitLab ( outputList ) ;
48
+ expect ( consoleSpy ) . toHaveBeenCalledTimes ( 12 ) ;
49
+ expect ( consoleSpy . mock . calls . slice ( 0 , 6 ) ) . toEqual ( consoleSpy . mock . calls . slice ( 6 , 12 ) ) ;
50
+ consoleSpy . mockRestore ( ) ;
51
+ } ) ;
27
52
} ) ;
0 commit comments