Skip to content

Commit

Permalink
feat: Add new --skipApiVersionCheck flag (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmdartus committed Jan 13, 2021
1 parent 1013774 commit 6f7052b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 27 deletions.
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,28 @@ Alternatively, you can globally install the package and run directly from the co
## Usage

```
`sfdx-lwc-jest [options]` runs Jest unit tests
`sfdx-lwc-jest [options]` runs Jest unit tests in SFDX workspace
Options:
--version Show version number [boolean]
--coverage Collect coverage and display in output
--version Show version number [boolean]
--coverage Collect coverage and display in output
[boolean] [default: false]
--updateSnapshot, -u Re-record every snapshot that fails during a test run
-u, --updateSnapshot Re-record every snapshot that fails during a test
run [boolean] [default: false]
--verbose Display individual test results with the test suite
hierarchy [boolean] [default: false]
--watch Watch files for changes and rerun tests related to
changed files [boolean] [default: false]
--debug Run tests in debug mode
(https://jestjs.io/docs/en/troubleshooting)
[boolean] [default: false]
--verbose Display individual test results with the test suite
hierarchy [boolean] [default: false]
--watch Watch files for changes and rerun tests related to
changed files [boolean] [default: false]
--debug Run tests in debug mode
(https://jestjs.io/docs/en/troubleshooting)
[boolean] [default: false]
--help Show help [boolean]
--skipApiVersionCheck Disable the "sourceApiVersion" field check before
running tests. [boolean] [default: false]
--help Show help [boolean]
Examples:
sfdx-lwc-jest --coverage Collect coverage and display in output
sfdx-lwc-jest -- --json All params after `--` will be directly passed to Jest
sfdx-lwc-jest -- --json All params after `--` are directly passed to Jest
```

## Passing Additional Jest CLI Options
Expand Down
6 changes: 6 additions & 0 deletions src/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ const testOptions = {
type: 'boolean',
default: false,
},

skipApiVersionCheck: {
description: 'Disable the "sourceApiVersion" field check before running tests',
type: 'boolean',
default: false,
},
};

module.exports = testOptions;
18 changes: 15 additions & 3 deletions src/utils/test-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,39 @@ const { PROJECT_ROOT, getSfdxProjectJson } = require('./project');
const { jestConfig, expectedApiVersion, jestPath } = require('../config');

// CLI options we do not want to pass along to Jest
const OPTIONS_BLACKLIST = ['_', '$0', 'debug', 'd'];
// prettier-ignore
const OPTIONS_DISALLOW_LIST = [
'_',
'$0',
'debug', 'd',
'skipApiVersionCheck', 'skip-api-version-check'
];

function getOptions(argv) {
let options = [];

Object.keys(argv).forEach((arg) => {
if (argv[arg] && !OPTIONS_BLACKLIST.includes(arg)) {
if (argv[arg] && !OPTIONS_DISALLOW_LIST.includes(arg)) {
options.push(`--${arg}`);
}
});
return options.concat(argv._);
}

async function testRunner(argv) {
function validSourceApiVersion() {
const sfdxProjectJson = getSfdxProjectJson();
const apiVersion = sfdxProjectJson.sourceApiVersion;
if (apiVersion !== expectedApiVersion) {
error(
`Invalid sourceApiVersion found in sfdx-project.json. Expected ${expectedApiVersion}, found ${apiVersion}`,
);
}
}

async function testRunner(argv) {
if (!argv.skipApiVersionCheck) {
validSourceApiVersion();
}

const hasCustomConfig = fs.existsSync(path.resolve(PROJECT_ROOT, 'jest.config.js'));
const config = hasCustomConfig ? [] : ['--config', JSON.stringify(jestConfig)];
Expand Down
24 changes: 13 additions & 11 deletions tests/__snapshots__/help.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ exports[`--help attribute shows help 1`] = `
"\`sfdx-lwc-jest [options]\` runs Jest unit tests in SFDX workspace
Options:
--version Show version number [boolean]
--coverage Collect coverage and display in output
--version Show version number [boolean]
--coverage Collect coverage and display in output
[boolean] [default: false]
-u, --updateSnapshot Re-record every snapshot that fails during a test run
-u, --updateSnapshot Re-record every snapshot that fails during a test
run [boolean] [default: false]
--verbose Display individual test results with the test suite
hierarchy [boolean] [default: false]
--watch Watch files for changes and rerun tests related to
changed files [boolean] [default: false]
--debug Run tests in debug mode
(https://jestjs.io/docs/en/troubleshooting)
[boolean] [default: false]
--verbose Display individual test results with the test suite
hierarchy [boolean] [default: false]
--watch Watch files for changes and rerun tests related to
changed files [boolean] [default: false]
--debug Run tests in debug mode
(https://jestjs.io/docs/en/troubleshooting)
[boolean] [default: false]
--help Show help [boolean]
--skipApiVersionCheck Disable the \\"sourceApiVersion\\" field check before
running tests [boolean] [default: false]
--help Show help [boolean]
Examples:
sfdx-lwc-jest --coverage Collect coverage and display in output
Expand Down

0 comments on commit 6f7052b

Please sign in to comment.