-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Small clean up in runESLint and improve test setup (#51)
* Add tests for normalizing maxWarnings * Add jest-watch-typeahead and split use multi project in jest config * Remove extra checks for existance of cliOptions * WIP * Add jest-runner-eslint as a runner * Fix eslint issues * Add jest-watch-select-projects * Small refactor to runESLint * Extract computed fix value
- Loading branch information
Showing
7 changed files
with
221 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* eslint-disable class-methods-use-this, global-require */ | ||
const path = require('path'); | ||
|
||
const runESLintRunnerWithMockedEngine = options => { | ||
jest.resetModules(); | ||
jest.doMock('../utils/getLocalESLint', () => () => { | ||
return { | ||
CLIEngine: class { | ||
isPathIgnored(file) { | ||
return options.cliEngine.ignoredFiles.includes(file); | ||
} | ||
|
||
executeOnFiles() { | ||
return { | ||
errorCount: options.cliEngine.errorCount, | ||
}; | ||
} | ||
|
||
getFormatter() { | ||
return () => {}; | ||
} | ||
}, | ||
}; | ||
}); | ||
const runESLint = require('../runESLint'); | ||
|
||
return runESLint(options.runESLint); | ||
}; | ||
|
||
it('Requires the config setupTestFrameworkScriptFile when specified', () => { | ||
const setupFile = path.join(__dirname, './path/to/setupFile.js'); | ||
|
||
let setupFileWasLoaded = false; | ||
jest.doMock( | ||
setupFile, | ||
() => { | ||
setupFileWasLoaded = true; | ||
}, | ||
{ virtual: true }, | ||
); | ||
|
||
runESLintRunnerWithMockedEngine({ | ||
cliEngine: { | ||
ignoredFiles: ['/path/to/file.test.js'], | ||
errorCount: 0, | ||
}, | ||
runESLint: { | ||
testPath: 'path/to/file.test.js', | ||
config: { | ||
setupTestFrameworkScriptFile: setupFile, | ||
}, | ||
}, | ||
}); | ||
|
||
expect(setupFileWasLoaded).toBeTruthy(); | ||
}); | ||
|
||
it('Returns "skipped" when the test path is ignored', () => { | ||
const result = runESLintRunnerWithMockedEngine({ | ||
cliEngine: { | ||
ignoredFiles: ['/path/to/file.test.js'], | ||
errorCount: 0, | ||
}, | ||
runESLint: { | ||
testPath: '/path/to/file.test.js', | ||
config: {}, | ||
}, | ||
}); | ||
|
||
expect(result).toMatchObject({ | ||
numFailingTests: 0, | ||
numPassingTests: 0, | ||
numPendingTests: 1, | ||
skipped: true, | ||
}); | ||
}); | ||
|
||
it('Returns "passed" when the test passed', () => { | ||
const result = runESLintRunnerWithMockedEngine({ | ||
cliEngine: { | ||
ignoredFiles: [], | ||
errorCount: 0, | ||
}, | ||
runESLint: { | ||
testPath: '/path/to/file.test.js', | ||
config: {}, | ||
}, | ||
}); | ||
|
||
expect(result).toMatchObject({ | ||
numFailingTests: 0, | ||
numPassingTests: 1, | ||
numPendingTests: 0, | ||
}); | ||
}); | ||
|
||
it('Returns "fail" when the test failed', () => { | ||
const result = runESLintRunnerWithMockedEngine({ | ||
cliEngine: { | ||
ignoredFiles: [], | ||
errorCount: 1, | ||
}, | ||
runESLint: { | ||
testPath: '/path/to/file.test.js', | ||
config: {}, | ||
}, | ||
}); | ||
|
||
expect(result).toMatchObject({ | ||
numFailingTests: 1, | ||
numPassingTests: 0, | ||
numPendingTests: 0, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters