Skip to content

Commit

Permalink
feat(jest): allow specifying custom config to jest
Browse files Browse the repository at this point in the history
  • Loading branch information
evansiroky committed Sep 8, 2019
1 parent 022ec63 commit 446b520
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,20 @@ Run tests using Jest

Options:

-h, --help output usage information
-u, --update-snapshots Force update of snapshots. USE WITH CAUTION.
--coverage Run Jest with coverage reporting
--coverage-paths <paths> Extra paths to collect code coverage from
--jest-cli-args <args> Extra arguments to pass directly to the Jest Cli. Make sure to encapsulate all extra arguments in quote
--no-cache Run Jest without cache (defaults to using cache)
--run-in-band Run all tests serially in the current process
--setup-files <paths> Setup files to run before each test
--test-environment <env> Jest test environment to use (Jest default is jsdom)
--test-path-ignore-patterns <patterns> File patterns to ignore when scanning for test files
-c, --config <path> Path to configuration files. (default: path.join(process.cwd() + '/configurations/default'))
-e, --env <environment> Environment to use.
-u, --update-snapshots Force update of snapshots. USE WITH CAUTION.
--coverage Run Jest with coverage reporting
--coverage-paths <paths> Extra paths to collect code coverage from
--customConfigFile <path> Override the Jest config with the values found in a file path relative to the current working directory
--force-exit Force Jest to exit after all tests have completed running.
--jest-cli-args <args> Extra arguments to pass directly to the Jest Cli. Make sure to encapsulate all extra arguments in quotes
--no-cache Run Jest without cache (defaults to using cache)
--run-in-band Run all tests serially in the current process
--setup-files <paths> Setup files to run before each test
--test-environment <env> Jest test environment to use (Jest default is jsdom)
--test-path-ignore-patterns <patterns> File patterns to ignore when scanning for test files
-h, --help output usage information

```
Expand Down
4 changes: 4 additions & 0 deletions bin/mastarm-test
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ commander
'--coverage-paths <paths>',
'Extra paths to collect code coverage from'
)
.option(
'--custom-config-file <path>',
'Override the Jest config with the values found in a file path relative to the current working directory'
)
.option('--force-exit', 'Force Jest to exit after all tests have completed running.')
.option(
'--jest-cli-args <args>',
Expand Down
10 changes: 10 additions & 0 deletions lib/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ module.exports.generateTestConfig = (patterns, options) => {
})
}

// override config with the values found in a specified file
if (options.customConfigFile) {
const customConfig = require(
path.resolve(process.cwd(), options.customConfigFile)
)
Object.keys(customConfig).forEach(key => {
jestConfig[key] = customConfig[key]
})
}

// jest cli params
let jestArguments = []

Expand Down

0 comments on commit 446b520

Please sign in to comment.