From 446b520a261aa970f893d5649d5652088c68d8e1 Mon Sep 17 00:00:00 2001 From: Evan Siroky Date: Sun, 8 Sep 2019 14:30:23 -0700 Subject: [PATCH] feat(jest): allow specifying custom config to jest --- README.md | 24 ++++++++++++++---------- bin/mastarm-test | 4 ++++ lib/jest.js | 10 ++++++++++ 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 71dc242..96796f3 100644 --- a/README.md +++ b/README.md @@ -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 Extra paths to collect code coverage from - --jest-cli-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 Setup files to run before each test - --test-environment Jest test environment to use (Jest default is jsdom) - --test-path-ignore-patterns File patterns to ignore when scanning for test files +-c, --config Path to configuration files. (default: path.join(process.cwd() + '/configurations/default')) +-e, --env Environment to use. +-u, --update-snapshots Force update of snapshots. USE WITH CAUTION. +--coverage Run Jest with coverage reporting +--coverage-paths Extra paths to collect code coverage from +--customConfigFile 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 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 Setup files to run before each test +--test-environment Jest test environment to use (Jest default is jsdom) +--test-path-ignore-patterns File patterns to ignore when scanning for test files +-h, --help output usage information ``` diff --git a/bin/mastarm-test b/bin/mastarm-test index 5d09ba4..5d134fb 100755 --- a/bin/mastarm-test +++ b/bin/mastarm-test @@ -25,6 +25,10 @@ commander '--coverage-paths ', 'Extra paths to collect code coverage from' ) + .option( + '--custom-config-file ', + '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 ', diff --git a/lib/jest.js b/lib/jest.js index 73184be..ed4436a 100644 --- a/lib/jest.js +++ b/lib/jest.js @@ -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 = []