Skip to content

Commit

Permalink
feat: add setupFilesAfterEnv support (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayank1791989 committed Sep 22, 2021
1 parent 5b654a9 commit 0f51688
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/runner/__tests__/runESLint.test.js
Expand Up @@ -58,6 +58,40 @@ it('Requires the config setupTestFrameworkScriptFile when specified', async () =
expect(setupFileWasLoaded).toBeTruthy();
});

it('Requires the config setupFilesAfterEnv when specified', async () => {
const setupFiles = [
path.join(__dirname, './path/to/setupFileFoo.js'),
path.join(__dirname, './path/to/setupFileBar.js'),
];

const setupFilesWereLoaded = setupFiles.map(() => false);

setupFiles.forEach((setupFile, index) => {
jest.doMock(
setupFile,
() => {
setupFilesWereLoaded[index] = true;
},
{ virtual: true },
);
});

await runESLintRunnerWithMockedEngine({
cliEngine: {
ignoredFiles: ['/path/to/file.test.js'],
errorCount: 0,
},
runESLint: {
testPath: 'path/to/file.test.js',
config: {
setupFilesAfterEnv: setupFiles,
},
},
});

expect(setupFilesWereLoaded).toEqual([true, true]);
});

it('Returns "skipped" when the test path is ignored', async () => {
const result = await runESLintRunnerWithMockedEngine({
cliEngine: {
Expand Down
5 changes: 5 additions & 0 deletions src/runner/runESLint.js
Expand Up @@ -69,6 +69,11 @@ const runESLint = async ({ testPath, config, extraOptions }) => {
require(config.setupTestFrameworkScriptFile);
}

if (config.setupFilesAfterEnv) {
// eslint-disable-next-line import/no-dynamic-require,global-require
config.setupFilesAfterEnv.forEach(require);
}

const { isPathIgnored, lintFiles, formatter, cliOptions } = getCachedValues(
config,
extraOptions,
Expand Down

0 comments on commit 0f51688

Please sign in to comment.