Skip to content

Commit 0e2293e

Browse files
authored
feat: remove Salesforce API version dependency (#370)
1 parent 45b545c commit 0e2293e

File tree

7 files changed

+21
-51
lines changed

7 files changed

+21
-51
lines changed

README.md

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,6 @@ The npm `latest` tag corresponds to the latest version of this repo, not necessa
1515

1616
To see a full list of available versions, and the tag that maps to the corresponding Salesforce release, see [the list of `npm` package versions](https://www.npmjs.com/package/@salesforce/sfdx-lwc-jest?activeTab=versions).
1717

18-
## Invalid sourceApiVersion found in sfdx-project.json
19-
20-
If you see this error while running tests in your Salesforce DX project, it most likely means you are using the incorrect version of this project.
21-
22-
For example, the error message `Invalid sourceApiVersion found in sfdx-project.json. Expected 45.0, found 46.0` means this project is targeted to API version 45.0, which maps to Spring '19, but the Salesforce DX project the tests are run in is using API version 46.0, which maps to Summer '19. The version check is done against the projects `sourceApiVersion` field in the `sfdx-project.json` file at the top level of the project.
23-
24-
To fix this issue, make sure the most recent version of this project is being used, or switch to the `prerelease` version, depending on what release your target org is on.
25-
26-
## Disabling the sourceApiVersion check
27-
28-
The `sourceApiVersion` field check is not a perfect check. Projects may be targeting orgs that are on the current release, but still have an older `sourceApiVersion` value set in their `sfdx-project.json` file. To disable this check, run tests with the `--skipApiVersionCheck` flag set.
29-
30-
**Note that by doing this, you risk running with an old version of the test runner and your tests may be using an out of date version of the LWC framework. To ensure tests are always run with the proper framework version and configuration, make sure to be on the most recent `latest` or `prerelease` tagged version of this package.**
31-
3218
## Installation
3319

3420
Add this project as a devDependency:
@@ -72,13 +58,6 @@ Options:
7258
--debug Run tests in debug mode
7359
(https://jestjs.io/docs/en/troubleshooting)
7460
[boolean] [default: false]
75-
--skipApiVersionCheck Disable the "sourceApiVersion" field check before
76-
running tests. **Warning** By disabling this check
77-
you risk running tests against stale versions of
78-
the framework. See details here:
79-
https://github.com/salesforce/sfdx-lwc-jest#disabli
80-
ng-the-sourceApiVersion-check
81-
[boolean] [default: false]
8261
--help Show help [boolean]
8362
8463
Examples:

src/config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,4 @@ const jestConfig = {
4949
],
5050
};
5151

52-
const expectedApiVersion = '61.0';
53-
54-
module.exports = { jestConfig, expectedApiVersion };
52+
module.exports = { jestConfig };

src/log.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ function blue(message) {
1313
return `\x1B[34m${message}\x1B[39m`;
1414
}
1515

16+
function yellow(message) {
17+
// equivalent to chalk.yellow()
18+
return `\x1B[33m${message}\x1B[39m`;
19+
}
20+
1621
function red(message) {
1722
// equivalent to chalk.red()
1823
return `\x1B[31m${message}\x1B[39m`;
@@ -22,11 +27,16 @@ function info(message) {
2227
console.log(`${blue('info')} ${message}`);
2328
}
2429

30+
function warn(message) {
31+
console.warn(`${yellow('warn')} ${message}`);
32+
}
33+
2534
function error(message) {
2635
console.error(`${red('error')} ${message}`);
2736
}
2837

2938
module.exports = {
3039
info,
40+
warn,
3141
error,
3242
};

src/options/options.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ const testOptions = {
3939
},
4040

4141
skipApiVersionCheck: {
42-
description:
43-
'Disable the "sourceApiVersion" field check before running tests. **Warning** By disabling this check you risk running tests against stale versions of the framework. See details here: https://github.com/salesforce/sfdx-lwc-jest#disabling-the-sourceApiVersion-check',
42+
description: 'Deprecated: this noop flag is kept for backward compatibility',
4443
type: 'boolean',
4544
default: false,
4645
},

src/utils/__mocks__/project.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
*/
77
'use strict';
88

9-
const { expectedApiVersion } = require('../../config');
10-
119
module.exports = {
1210
PROJECT_ROOT: 'projectRoot',
1311
getSfdxProjectJson: () => {
14-
return { mock: true, sourceApiVersion: expectedApiVersion };
12+
return { mock: true };
1513
},
1614
getModulePaths: () => ['force-app/main/unix/lwc', 'force-app\\main\\windows\\lwc'],
1715
};

src/utils/test-runner.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,14 @@ const fs = require('fs');
1010
const path = require('path');
1111
const { spawn } = require('child_process');
1212

13-
const { PROJECT_ROOT, getSfdxProjectJson } = require('./project');
13+
const { PROJECT_ROOT } = require('./project');
1414

15-
const { error, info } = require('../log');
16-
const { jestConfig, expectedApiVersion } = require('../config');
15+
const { info, warn } = require('../log');
16+
const { jestConfig } = require('../config');
1717

1818
// List of CLI options that should be passthrough to jest.
1919
const JEST_PASSTHROUGH_OPTIONS = new Set(['coverage', 'updateSnapshot', 'verbose', 'watch']);
2020

21-
function validSourceApiVersion() {
22-
const sfdxProjectJson = getSfdxProjectJson();
23-
const apiVersion = sfdxProjectJson.sourceApiVersion;
24-
if (apiVersion !== expectedApiVersion) {
25-
error(
26-
`Invalid sourceApiVersion found in sfdx-project.json. Expected ${expectedApiVersion}, found ${apiVersion}`,
27-
);
28-
}
29-
}
30-
3121
function getJestPath() {
3222
const packageJsonPath = require.resolve('jest/package.json');
3323

@@ -72,9 +62,10 @@ function getJestArgs(argv) {
7262

7363
async function testRunner(argv) {
7464
if (!argv.skipApiVersionCheck) {
75-
validSourceApiVersion();
65+
warn(
66+
'The --skipApiVersionCheck flag is deprecated and will be removed in future versions.',
67+
);
7668
}
77-
7869
const spawnCommand = 'node';
7970
const spawnArgs = [getJestPath(), ...getJestArgs(argv)];
8071

tests/__snapshots__/help.test.js.snap

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,8 @@ Options:
1616
--debug Run tests in debug mode
1717
(https://jestjs.io/docs/en/troubleshooting)
1818
[boolean] [default: false]
19-
--skipApiVersionCheck Disable the "sourceApiVersion" field check before
20-
running tests. **Warning** By disabling this check
21-
you risk running tests against stale versions of
22-
the framework. See details here:
23-
https://github.com/salesforce/sfdx-lwc-jest#disabli
24-
ng-the-sourceApiVersion-check
25-
[boolean] [default: false]
19+
--skipApiVersionCheck Deprecated: this noop flag is kept for backward
20+
compatibility [boolean] [default: false]
2621
--help Show help [boolean]
2722
2823
Examples:

0 commit comments

Comments
 (0)