Skip to content

Commit

Permalink
Add support for addFiles config parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
hswolff committed Dec 20, 2017
1 parent 690a95f commit 2385d88
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
16 changes: 14 additions & 2 deletions README.md
Expand Up @@ -61,7 +61,10 @@ In `package.json`
"jest-runner-mocha": {
"cliOptions": {
// Options here
}
},
"addFiles": [
// Absolute file paths
],
}
}
```
Expand All @@ -71,7 +74,10 @@ or in `jest-runner-mocha.config.js`
module.exports = {
cliOptions: {
// Options here
}
},
addFiles: [
// Absolute file paths
],
}
```

Expand All @@ -86,6 +92,12 @@ jest-runner-mocha maps some mocha CLI arguments to config options. For example `
|timeout|`"timeout": 10000`
|compiler|`"compiler": "./path/to/babel-register"`

### addFiles

If you want to include additional files (for example additional Mocha setup code), you can list the files that you want added.

This value can be a string or an array of absolute file paths.

### Coverage

Coverage works outside of the box, simply `yarn jest -- --coverage`
Expand Down
3 changes: 2 additions & 1 deletion src/runMocha.js
Expand Up @@ -4,7 +4,7 @@ const setupCollectCoverage = require('./utils/setupCollectCoverage');
const getMochaOptions = require('./utils/getMochaOptions');

const runMocha = ({ config, testPath, globalConfig }, workerCallback) => {
const { cliOptions: mochaOptions } = getMochaOptions(config);
const { cliOptions: mochaOptions, addFiles } = getMochaOptions(config);

class Reporter extends Mocha.reporters.Base {
constructor(runner) {
Expand Down Expand Up @@ -56,6 +56,7 @@ const runMocha = ({ config, testPath, globalConfig }, workerCallback) => {
coveragePathIgnorePatterns: config.coveragePathIgnorePatterns,
});

addFiles.forEach(file => mocha.addFile(file));
mocha.addFile(testPath);

const onEnd = () => {
Expand Down
9 changes: 7 additions & 2 deletions src/utils/getMochaOptions.js
Expand Up @@ -3,14 +3,19 @@ const cosmiconfig = require('cosmiconfig');

const explorer = cosmiconfig('jest-runner-mocha', { sync: true });

const normalize = (jestConfig, { cliOptions: rawCliOptions = {} }) => {
const normalize = (
jestConfig,
{ cliOptions: rawCliOptions = {}, addFiles: rawAddFiles = [] },
) => {
const cliOptions = Object.assign({}, rawCliOptions);

if (cliOptions.compiler && !path.isAbsolute(cliOptions.compiler)) {
cliOptions.compiler = path.resolve(jestConfig.rootDir, cliOptions.compiler);
}

return { cliOptions };
const addFiles = [].concat(rawAddFiles);

return { cliOptions, addFiles };
};

const getMochaOptions = jestConfig => {
Expand Down

0 comments on commit 2385d88

Please sign in to comment.