Skip to content

Commit

Permalink
Support automatic enzyme configuration for Jest above version 24. (#1763
Browse files Browse the repository at this point in the history
)

* Support configuring Jest for versions > 24.

* Fix magic number.
  • Loading branch information
AndrewSouthpaw authored and jchip committed Dec 3, 2020
1 parent 5e51141 commit a2deb69
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/xarc-app-dev/src/config/jest/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const optRequire = getOptArchetypeRequire(["@xarc/opt-jest", "electrode-archetyp

const jestPkg = optRequire("jest/package.json");
const jestMajVersion = parseInt(jestPkg.version.split(".")[0], 10);
// Jest changed its config setting for setup files on version 24
const SETUP_FILES_VERSION_SPLIT = 24;

import { loadXarcOptions } from "../../lib/utils";

Expand Down Expand Up @@ -44,18 +46,15 @@ const jestDefaultConfig = {
testURL: "http://localhost/"
};

const jestVersionSpecificConfig = {
23: {
setupTestFrameworkScriptFile: frameworkMock
},
24: {
setupFilesAfterEnv: [frameworkMock]
}
};
const jestSetupFilesDeprecated = { setupTestFrameworkScriptFile: frameworkMock };
const jestSetupFilesNew = { setupFilesAfterEnv: [frameworkMock] };

const jestSetupFilesConfig =
jestMajVersion >= SETUP_FILES_VERSION_SPLIT ? jestSetupFilesNew : jestSetupFilesDeprecated;

module.exports = _.merge(
{},
_.pickBy(jestDefaultConfig, x => x !== undefined),
jestVersionSpecificConfig[jestMajVersion],
jestSetupFilesConfig,
xarcOptions.jest
);

0 comments on commit a2deb69

Please sign in to comment.