1
+ /* eslint-disable no-nested-ternary */
1
2
import path from 'path' ;
2
3
import { expect as chaiExpect } from 'chai' ;
3
- import { readFileSync , writeFileSync , unlinkSync } from 'fs' ;
4
+ import { existsSync , readFileSync , writeFileSync , unlinkSync } from 'fs' ;
4
5
// $FlowIgnore
5
6
import execa from 'execa' ;
6
7
import { collect } from '../src/collect' ;
@@ -60,7 +61,7 @@ describe('Format', () => {
60
61
const ESLINT_PATH = path . resolve ( './node_modules/eslint/bin/eslint.js' ) ;
61
62
62
63
async function runEslint ( cwd ) {
63
- const result = await execa ( ESLINT_PATH , [ '**/*.{js,vue}' ] , { cwd, stripEof : false } ) ;
64
+ const result = await execa ( ESLINT_PATH , [ '**/*.{js,vue}' , '--fix' ] , { cwd, stripEof : false } ) ;
64
65
result . stdout = result . stdout && result . stdout . toString ( ) ;
65
66
result . stderr = result . stderr && result . stderr . toString ( ) ;
66
67
return result ;
@@ -72,6 +73,8 @@ const codebases = [
72
73
'coverage-fail2' ,
73
74
'coverage-ok' ,
74
75
'coverage-ok2' ,
76
+ 'coverage-sync-remove' ,
77
+ 'coverage-sync-update' ,
75
78
'flow-pragma-1' ,
76
79
'flow-pragma-2' ,
77
80
'html-support' ,
@@ -86,7 +89,7 @@ const codebases = [
86
89
'uncovered-example'
87
90
] ;
88
91
89
- const eslintConfig = ( enforceMinCoverage , checkUncovered , html ) => `
92
+ const eslintConfig = ( enforceMinCoverage , updateCommentThreshold , checkUncovered , html ) => `
90
93
const Module = require('module');
91
94
const path = require('path');
92
95
const original = Module._resolveFilename;
@@ -119,8 +122,15 @@ const eslintConfig = (enforceMinCoverage, checkUncovered, html) => `
119
122
}
120
123
},
121
124
rules: {
122
- ${ enforceMinCoverage
123
- ? `'flowtype-errors/enforce-min-coverage': [2, ${ enforceMinCoverage } ],` : `` }
125
+ ${ updateCommentThreshold
126
+ ? [
127
+ `'flowtype-errors/enforce-min-coverage': [2, ${ enforceMinCoverage } ],` ,
128
+ `'flowtype-errors/enforce-min-coverage-comments-sync': [2, ${ enforceMinCoverage } , ${ updateCommentThreshold } ],` ,
129
+ ] . join ( '\n' )
130
+ : enforceMinCoverage
131
+ ? `'flowtype-errors/enforce-min-coverage': [2, ${ enforceMinCoverage } ],`
132
+ : ``
133
+ }
124
134
${ checkUncovered ? `'flowtype-errors/uncovered': 2,` : '' }
125
135
'flowtype-errors/show-errors': 2,
126
136
'flowtype-errors/show-warnings': 1
@@ -144,13 +154,20 @@ describe('Check codebases', () => {
144
154
// eslint-disable-next-line no-loop-func
145
155
it ( `${ title } - eslint should give expected output` , async ( ) => {
146
156
const fullFolder = path . resolve ( `./test/codebases/${ folder } ` ) ;
157
+ const exampleJsFilePath = path . resolve ( `./test/codebases/${ folder } /example.js` ) ;
158
+ const exampleJsFixedFilePath = path . resolve ( `./test/codebases/${ folder } /example.fixed` ) ;
159
+ const hasFix = existsSync ( exampleJsFixedFilePath )
147
160
const configPath = path . resolve ( fullFolder , '.eslintrc.js' ) ;
148
161
162
+ const contentsBefore = hasFix && readFileSync ( exampleJsFilePath , 'utf8' )
163
+ const contentsExpected = hasFix && readFileSync ( exampleJsFixedFilePath , 'utf8' )
164
+
149
165
// Write config file
150
166
writeFileSync (
151
167
configPath ,
152
168
eslintConfig (
153
169
folder . match ( / ^ c o v e r a g e - / ) ? 50 : 0 ,
170
+ folder . match ( / ^ c o v e r a g e - s y n c / ) ? 10 : 0 ,
154
171
! ! folder . match ( / ^ u n c o v e r e d - / ) ,
155
172
/ h t m l - s u p p o r t / . test ( folder )
156
173
)
@@ -164,6 +181,11 @@ describe('Check codebases', () => {
164
181
'gm'
165
182
) ; // Escape regexp
166
183
184
+ const contentsAfter = hasFix && readFileSync ( exampleJsFilePath , 'utf8' )
185
+
186
+ // Revert the file to before it was fixed, since this file is checked into git.
187
+ if ( hasFix && contentsBefore !== contentsAfter ) writeFileSync ( exampleJsFilePath , contentsBefore )
188
+
167
189
// Strip root from filenames
168
190
expect (
169
191
stdout . replace ( regexp , match =>
@@ -173,6 +195,10 @@ describe('Check codebases', () => {
173
195
174
196
expect ( stderr ) . toEqual ( '' ) ;
175
197
198
+ if ( hasFix ) {
199
+ expect ( contentsAfter ) . toEqual ( contentsExpected ) ;
200
+ }
201
+
176
202
// Clean up
177
203
unlinkSync ( configPath ) ;
178
204
} ) ;
0 commit comments