1+ /* eslint-disable no-nested-ternary */
12import path from 'path' ;
23import { expect as chaiExpect } from 'chai' ;
3- import { readFileSync , writeFileSync , unlinkSync } from 'fs' ;
4+ import { existsSync , readFileSync , writeFileSync , unlinkSync } from 'fs' ;
45// $FlowIgnore
56import execa from 'execa' ;
67import { collect } from '../src/collect' ;
@@ -60,7 +61,7 @@ describe('Format', () => {
6061const ESLINT_PATH = path . resolve ( './node_modules/eslint/bin/eslint.js' ) ;
6162
6263async 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 } ) ;
6465 result . stdout = result . stdout && result . stdout . toString ( ) ;
6566 result . stderr = result . stderr && result . stderr . toString ( ) ;
6667 return result ;
@@ -72,6 +73,8 @@ const codebases = [
7273 'coverage-fail2' ,
7374 'coverage-ok' ,
7475 'coverage-ok2' ,
76+ 'coverage-sync-remove' ,
77+ 'coverage-sync-update' ,
7578 'flow-pragma-1' ,
7679 'flow-pragma-2' ,
7780 'html-support' ,
@@ -86,7 +89,7 @@ const codebases = [
8689 'uncovered-example'
8790] ;
8891
89- const eslintConfig = ( enforceMinCoverage , checkUncovered , html ) => `
92+ const eslintConfig = ( enforceMinCoverage , updateCommentThreshold , checkUncovered , html ) => `
9093 const Module = require('module');
9194 const path = require('path');
9295 const original = Module._resolveFilename;
@@ -119,8 +122,15 @@ const eslintConfig = (enforceMinCoverage, checkUncovered, html) => `
119122 }
120123 },
121124 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+ }
124134 ${ checkUncovered ? `'flowtype-errors/uncovered': 2,` : '' }
125135 'flowtype-errors/show-errors': 2,
126136 'flowtype-errors/show-warnings': 1
@@ -144,13 +154,20 @@ describe('Check codebases', () => {
144154 // eslint-disable-next-line no-loop-func
145155 it ( `${ title } - eslint should give expected output` , async ( ) => {
146156 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 )
147160 const configPath = path . resolve ( fullFolder , '.eslintrc.js' ) ;
148161
162+ const contentsBefore = hasFix && readFileSync ( exampleJsFilePath , 'utf8' )
163+ const contentsExpected = hasFix && readFileSync ( exampleJsFixedFilePath , 'utf8' )
164+
149165 // Write config file
150166 writeFileSync (
151167 configPath ,
152168 eslintConfig (
153169 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 ,
154171 ! ! folder . match ( / ^ u n c o v e r e d - / ) ,
155172 / h t m l - s u p p o r t / . test ( folder )
156173 )
@@ -164,6 +181,11 @@ describe('Check codebases', () => {
164181 'gm'
165182 ) ; // Escape regexp
166183
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+
167189 // Strip root from filenames
168190 expect (
169191 stdout . replace ( regexp , match =>
@@ -173,6 +195,10 @@ describe('Check codebases', () => {
173195
174196 expect ( stderr ) . toEqual ( '' ) ;
175197
198+ if ( hasFix ) {
199+ expect ( contentsAfter ) . toEqual ( contentsExpected ) ;
200+ }
201+
176202 // Clean up
177203 unlinkSync ( configPath ) ;
178204 } ) ;
0 commit comments