Skip to content

Commit

Permalink
Run tests against source, CJS, and UMD builds (#6209)
Browse files Browse the repository at this point in the history
* Test react-router(-dom) source, CJS, and UMD

* Please go away, package-lock

* Test against new CJS builds

* Multi-test react-router-config

* Remove "resolved by" comments

* Retain original import order
  • Loading branch information
pshrmn authored and mjackson committed Oct 31, 2018
1 parent 33f221e commit cc4bfc4
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 7 deletions.
14 changes: 13 additions & 1 deletion packages/react-router-config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
let mappedModule;
switch (process.env.TEST_ENV) {
case "cjs":
mappedModule = "<rootDir>/cjs/react-router-config.js";
break;
case "umd":
mappedModule = "<rootDir>/umd/react-router-config.js";
break;
default:
mappedModule = "<rootDir>/modules/index";
}

module.exports = {
testRunner: "jest-circus/runner",
restoreMocks: true,
Expand All @@ -6,7 +18,7 @@ module.exports = {
},
moduleNameMapper: {
"^react-router$": "<rootDir>/../react-router/cjs/react-router.js",
"^react-router-config$": "<rootDir>/cjs/react-router-config.js"
"^react-router-config$": mappedModule
},
modulePaths: ["<rootDir>/node_modules"],
setupFiles: ["raf/polyfill"],
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"build": "del cjs esm umd && rollup -c",
"prepublishOnly": "del cjs esm umd && rollup -c",
"lint": "eslint modules",
"test": "jest"
"test": "node ./scripts/test.js"
},
"peerDependencies": {
"react": ">=15",
Expand Down
25 changes: 25 additions & 0 deletions packages/react-router-config/scripts/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const execSync = require("child_process").execSync;

const exec = (command, extraEnv) =>
execSync(command, {
stdio: "inherit",
env: Object.assign({}, process.env, extraEnv)
});

console.log("Testing source files");

exec("jest", {
TEST_ENV: "source"
});

console.log("Testing commonjs build");

exec("jest", {
TEST_ENV: "cjs"
});

console.log("Testing UMD build");

exec("jest", {
TEST_ENV: "umd"
});
14 changes: 13 additions & 1 deletion packages/react-router-dom/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
let mappedModule;
switch (process.env.TEST_ENV) {
case "cjs":
mappedModule = "<rootDir>/cjs/react-router-dom.js";
break;
case "umd":
mappedModule = "<rootDir>/umd/react-router-dom.js";
break;
default:
mappedModule = "<rootDir>/modules/index";
}

module.exports = {
testRunner: "jest-circus/runner",
restoreMocks: true,
globals: {
__DEV__: true
},
moduleNameMapper: {
"^react-router-dom$": "<rootDir>/cjs/react-router-dom.js"
"^react-router-dom$": mappedModule
},
modulePaths: ["<rootDir>/node_modules"],
setupFiles: ["raf/polyfill"],
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"build": "del cjs esm umd && rollup -c",
"prepublishOnly": "del cjs esm umd && rollup -c",
"lint": "eslint modules",
"test": "jest"
"test": "node ./scripts/test.js"
},
"peerDependencies": {
"react": ">=15"
Expand Down
25 changes: 25 additions & 0 deletions packages/react-router-dom/scripts/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const execSync = require("child_process").execSync;

const exec = (command, extraEnv) =>
execSync(command, {
stdio: "inherit",
env: Object.assign({}, process.env, extraEnv)
});

console.log("Testing source files");

exec("jest", {
TEST_ENV: "source"
});

console.log("Testing commonjs build");

exec("jest", {
TEST_ENV: "cjs"
});

console.log("Testing UMD build");

exec("jest", {
TEST_ENV: "umd"
});
14 changes: 13 additions & 1 deletion packages/react-router/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
let mappedModule;
switch (process.env.TEST_ENV) {
case "cjs":
mappedModule = "<rootDir>/cjs/react-router.js";
break;
case "umd":
mappedModule = "<rootDir>/umd/react-router.js";
break;
default:
mappedModule = "<rootDir>/modules/index";
}

module.exports = {
testRunner: "jest-circus/runner",
restoreMocks: true,
globals: {
__DEV__: true
},
moduleNameMapper: {
"^react-router$": "<rootDir>/cjs/react-router.js"
"^react-router$": mappedModule
},
modulePaths: ["<rootDir>/node_modules"],
setupFiles: ["raf/polyfill"],
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router/modules/__tests__/Route-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import ReactDOM from "react-dom";
import { createMemoryHistory as createHistory } from "history";
import { MemoryRouter, Route, Router } from "react-router";
import { MemoryRouter, Router, Route } from "react-router";

import renderStrict from "./utils/renderStrict";

Expand Down
2 changes: 1 addition & 1 deletion packages/react-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"build": "del cjs esm umd && rollup -c",
"prepublishOnly": "del cjs esm umd && rollup -c",
"lint": "eslint modules",
"test": "jest"
"test": "node ./scripts/test.js"
},
"peerDependencies": {
"react": ">=15"
Expand Down
25 changes: 25 additions & 0 deletions packages/react-router/scripts/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const execSync = require("child_process").execSync;

const exec = (command, extraEnv) =>
execSync(command, {
stdio: "inherit",
env: Object.assign({}, process.env, extraEnv)
});

console.log("Testing source files");

exec("jest", {
TEST_ENV: "source"
});

console.log("Testing commonjs build");

exec("jest", {
TEST_ENV: "cjs"
});

console.log("Testing UMD build");

exec("jest", {
TEST_ENV: "umd"
});

0 comments on commit cc4bfc4

Please sign in to comment.