From 8263bf19dd6900dc09158658d9bb9eac49a24088 Mon Sep 17 00:00:00 2001 From: Paul Sherman Date: Sun, 17 Jun 2018 01:01:22 -0500 Subject: [PATCH] Test react-router(-dom) source, CJS, and UMD --- packages/react-router-dom/jest.config.js | 14 +- .../modules/__tests__/BrowserRouter-test.js | 4 +- .../modules/__tests__/HashRouter-test.js | 4 +- .../modules/__tests__/Link-test.js | 4 +- .../modules/__tests__/NavLink-test.js | 4 +- packages/react-router-dom/package.json | 2 +- packages/react-router-dom/scripts/test.js | 25 +++ packages/react-router-redux/package-lock.json | 190 ++++++++++++++++++ packages/react-router/jest.config.js | 14 +- .../modules/__tests__/MemoryRouter-test.js | 4 +- .../modules/__tests__/Redirect-test.js | 4 +- .../modules/__tests__/Route-test.js | 4 +- .../modules/__tests__/Router-test.js | 4 +- .../modules/__tests__/StaticRouter-test.js | 4 +- .../modules/__tests__/Switch-test.js | 4 +- .../modules/__tests__/SwitchMount-test.js | 4 +- .../modules/__tests__/integration-test.js | 4 +- .../modules/__tests__/withRouter-test.js | 4 +- packages/react-router/package.json | 2 +- packages/react-router/scripts/test.js | 25 +++ 20 files changed, 307 insertions(+), 17 deletions(-) create mode 100644 packages/react-router-dom/scripts/test.js create mode 100644 packages/react-router-redux/package-lock.json create mode 100644 packages/react-router/scripts/test.js diff --git a/packages/react-router-dom/jest.config.js b/packages/react-router-dom/jest.config.js index e96d01734d..043145185f 100644 --- a/packages/react-router-dom/jest.config.js +++ b/packages/react-router-dom/jest.config.js @@ -1,3 +1,15 @@ +let mappedModule; +switch (process.env.TEST_ENV) { + case "cjs": + mappedModule = "/index"; + break; + case "umd": + mappedModule = "/umd/react-router-dom.js"; + break; + default: + mappedModule = "/modules/index"; +} + module.exports = { testRunner: "jest-circus/runner", restoreMocks: true, @@ -5,7 +17,7 @@ module.exports = { __DEV__: true }, moduleNameMapper: { - "^react-router-dom$": "/cjs/react-router-dom.js" + "^react-router-dom$": mappedModule }, modulePaths: ["/node_modules"], setupFiles: ["raf/polyfill"], diff --git a/packages/react-router-dom/modules/__tests__/BrowserRouter-test.js b/packages/react-router-dom/modules/__tests__/BrowserRouter-test.js index cd88b2752b..9699937950 100644 --- a/packages/react-router-dom/modules/__tests__/BrowserRouter-test.js +++ b/packages/react-router-dom/modules/__tests__/BrowserRouter-test.js @@ -1,9 +1,11 @@ import React from "react"; import ReactDOM from "react-dom"; -import { BrowserRouter } from "react-router-dom"; import renderStrict from "./utils/renderStrict"; +// resolved by jest +import { BrowserRouter } from "react-router-dom"; + describe("A ", () => { const node = document.createElement("div"); diff --git a/packages/react-router-dom/modules/__tests__/HashRouter-test.js b/packages/react-router-dom/modules/__tests__/HashRouter-test.js index 4608b8878f..e0336a56ca 100644 --- a/packages/react-router-dom/modules/__tests__/HashRouter-test.js +++ b/packages/react-router-dom/modules/__tests__/HashRouter-test.js @@ -1,9 +1,11 @@ import React from "react"; import ReactDOM from "react-dom"; -import { HashRouter } from "react-router-dom"; import renderStrict from "./utils/renderStrict"; +// resolved by jest +import { HashRouter } from "react-router-dom"; + describe("A ", () => { const node = document.createElement("div"); diff --git a/packages/react-router-dom/modules/__tests__/Link-test.js b/packages/react-router-dom/modules/__tests__/Link-test.js index ae57190b3b..c002cff7fe 100644 --- a/packages/react-router-dom/modules/__tests__/Link-test.js +++ b/packages/react-router-dom/modules/__tests__/Link-test.js @@ -1,9 +1,11 @@ import React from "react"; import ReactDOM from "react-dom"; -import { MemoryRouter, HashRouter, Link } from "react-router-dom"; import renderStrict from "./utils/renderStrict"; +// resolved by jest +import { MemoryRouter, HashRouter, Link } from "react-router-dom"; + describe("A ", () => { const node = document.createElement("div"); diff --git a/packages/react-router-dom/modules/__tests__/NavLink-test.js b/packages/react-router-dom/modules/__tests__/NavLink-test.js index ade8f8d31b..e1a4cf846a 100644 --- a/packages/react-router-dom/modules/__tests__/NavLink-test.js +++ b/packages/react-router-dom/modules/__tests__/NavLink-test.js @@ -1,9 +1,11 @@ import React from "react"; import ReactDOM from "react-dom"; -import { MemoryRouter, NavLink, withRouter } from "react-router-dom"; import renderStrict from "./utils/renderStrict"; +// resolved by jest +import { MemoryRouter, NavLink, withRouter } from "react-router-dom"; + describe("A ", () => { const node = document.createElement("div"); diff --git a/packages/react-router-dom/package.json b/packages/react-router-dom/package.json index 1d1c1a6b72..db534e2a2a 100644 --- a/packages/react-router-dom/package.json +++ b/packages/react-router-dom/package.json @@ -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" diff --git a/packages/react-router-dom/scripts/test.js b/packages/react-router-dom/scripts/test.js new file mode 100644 index 0000000000..d215870ae6 --- /dev/null +++ b/packages/react-router-dom/scripts/test.js @@ -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" +}); diff --git a/packages/react-router-redux/package-lock.json b/packages/react-router-redux/package-lock.json new file mode 100644 index 0000000000..6518f10552 --- /dev/null +++ b/packages/react-router-redux/package-lock.json @@ -0,0 +1,190 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { +<<<<<<< HEAD + "react-test-renderer": { + "version": "16.5.2", + "resolved": "https://registry.npmjs.org/react-test-renderer/-/react-test-renderer-16.5.2.tgz", + "integrity": "sha512-AGbJYbCVx1J6jdUgI4s0hNp+9LxlgzKvXl0ROA3DHTrtjAr00Po1RhDZ/eAq2VC/ww8AHgpDXULh5V2rhEqqJg==", + "requires": { + "object-assign": "^4.1.1", + "prop-types": "^15.6.2", + "react-is": "^16.5.2", + "schedule": "^0.5.0" + }, + "dependencies": { + "js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" + }, + "loose-envify": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", + "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", + "requires": { + "js-tokens": "^3.0.0 || ^4.0.0" + } + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + }, + "prop-types": { + "version": "15.6.2", + "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.2.tgz", + "integrity": "sha512-3pboPvLiWD7dkI3qf3KbUe6hKFKa52w+AE0VCqECtf+QHAKgOL37tTaNCnuX1nAAQ4ZhyP+kYVKf8rLmJ/feDQ==", + "requires": { + "loose-envify": "^1.3.1", + "object-assign": "^4.1.1" + } + }, + "react-is": { + "version": "16.5.2", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.5.2.tgz", + "integrity": "sha512-hSl7E6l25GTjNEZATqZIuWOgSnpXb3kD0DVCujmg46K5zLxsbiKaaT6VO9slkSBDPZfYs30lwfJwbOFOnoEnKQ==" + }, + "schedule": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/schedule/-/schedule-0.5.0.tgz", + "integrity": "sha512-HUcJicG5Ou8xfR//c2rPT0lPIRR09vVvN81T9fqfVgBmhERUbDEQoYKjpBxbueJnCPpSu2ujXzOnRQt6x9o/jw==", + "requires": { + "object-assign": "^4.1.1" + } + } + } +======= + "asap": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", + "integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=" + }, + "encoding": { + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz", + "integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=", + "requires": { + "iconv-lite": "0.4.19" + } + }, + "fbjs": { + "version": "0.8.16", + "resolved": "https://registry.npmjs.org/fbjs/-/fbjs-0.8.16.tgz", + "integrity": "sha1-XmdDL1UNxBtXK/VYR7ispk5TN9s=", + "requires": { + "core-js": "1.2.7", + "isomorphic-fetch": "2.2.1", + "loose-envify": "1.3.1", + "object-assign": "4.1.1", + "promise": "7.3.1", + "setimmediate": "1.0.5", + "ua-parser-js": "0.7.17" + }, + "dependencies": { + "core-js": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz", + "integrity": "sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY=" + } + } + }, + "iconv-lite": { + "version": "0.4.19", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", + "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" + }, + "is-stream": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", + "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" + }, + "isomorphic-fetch": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz", + "integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=", + "requires": { + "node-fetch": "1.7.3", + "whatwg-fetch": "2.0.4" + } + }, + "js-tokens": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", + "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=" + }, + "loose-envify": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.3.1.tgz", + "integrity": "sha1-0aitM/qc4OcT1l/dCsi3SNR4yEg=", + "requires": { + "js-tokens": "3.0.2" + } + }, + "node-fetch": { + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", + "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", + "requires": { + "encoding": "0.1.12", + "is-stream": "1.1.0" + } + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + }, + "promise": { + "version": "7.3.1", + "resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz", + "integrity": "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==", + "requires": { + "asap": "2.0.6" + } + }, + "prop-types": { + "version": "15.6.1", + "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.1.tgz", + "integrity": "sha512-4ec7bY1Y66LymSUOH/zARVYObB23AT2h8cf6e/O6ZALB/N0sqZFEx7rq6EYPX2MkOdKORuooI/H5k9TlR4q7kQ==", + "requires": { + "fbjs": "0.8.16", + "loose-envify": "1.3.1", + "object-assign": "4.1.1" + } + }, + "react-is": { + "version": "16.4.0", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.4.0.tgz", + "integrity": "sha512-8ADZg/mBw+t2Fbr5Hm1K64v8q8Q6E+DprV5wQ5A8PSLW6XP0XJFMdUskVEW8efQ5oUgWHn8EYdHEPAMF0Co6hA==" + }, + "react-test-renderer": { + "version": "16.4.0", + "resolved": "https://registry.npmjs.org/react-test-renderer/-/react-test-renderer-16.4.0.tgz", + "integrity": "sha512-Seh1t9xFY6TKiV/hRlPzUkqX1xHOiKIMsctfU0cggo1ajsLjoIJFL520LlrxV+4/VIj+clrCeH6s/aVv/vTStg==", + "requires": { + "fbjs": "0.8.16", + "object-assign": "4.1.1", + "prop-types": "15.6.1", + "react-is": "16.4.0" + } + }, + "setimmediate": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", + "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=" + }, + "ua-parser-js": { + "version": "0.7.17", + "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.17.tgz", + "integrity": "sha512-uRdSdu1oA1rncCQL7sCj8vSyZkgtL7faaw9Tc9rZ3mGgraQ7+Pdx7w5mnOSF3gw9ZNG6oc+KXfkon3bKuROm0g==" + }, + "whatwg-fetch": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz", + "integrity": "sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng==" +>>>>>>> Test source, cjs, es, and umd + } + } +} diff --git a/packages/react-router/jest.config.js b/packages/react-router/jest.config.js index 3ad3973c4d..a85704b4fa 100644 --- a/packages/react-router/jest.config.js +++ b/packages/react-router/jest.config.js @@ -1,3 +1,15 @@ +let mappedModule; +switch (process.env.TEST_ENV) { + case "cjs": + mappedModule = "/index"; + break; + case "umd": + mappedModule = "/umd/react-router.js"; + break; + default: + mappedModule = "/modules/index"; +} + module.exports = { testRunner: "jest-circus/runner", restoreMocks: true, @@ -5,7 +17,7 @@ module.exports = { __DEV__: true }, moduleNameMapper: { - "^react-router$": "/cjs/react-router.js" + "^react-router$": mappedModule }, modulePaths: ["/node_modules"], setupFiles: ["raf/polyfill"], diff --git a/packages/react-router/modules/__tests__/MemoryRouter-test.js b/packages/react-router/modules/__tests__/MemoryRouter-test.js index ac7d134298..a77568b93c 100644 --- a/packages/react-router/modules/__tests__/MemoryRouter-test.js +++ b/packages/react-router/modules/__tests__/MemoryRouter-test.js @@ -1,9 +1,11 @@ import React from "react"; import ReactDOM from "react-dom"; -import { MemoryRouter } from "react-router"; import renderStrict from "./utils/renderStrict"; +// resolved by jest +import { MemoryRouter } from "react-router"; + describe("A ", () => { const node = document.createElement("div"); diff --git a/packages/react-router/modules/__tests__/Redirect-test.js b/packages/react-router/modules/__tests__/Redirect-test.js index dcee37c8d8..1899c262c5 100644 --- a/packages/react-router/modules/__tests__/Redirect-test.js +++ b/packages/react-router/modules/__tests__/Redirect-test.js @@ -1,9 +1,11 @@ import React from "react"; import ReactDOM from "react-dom"; -import { MemoryRouter, Redirect, Route, Switch } from "react-router"; import renderStrict from "./utils/renderStrict"; +// resolved by jest +import { MemoryRouter, Redirect, Route, Switch } from "react-router"; + describe("A ", () => { const node = document.createElement("div"); diff --git a/packages/react-router/modules/__tests__/Route-test.js b/packages/react-router/modules/__tests__/Route-test.js index feea7725b6..d7f476599c 100644 --- a/packages/react-router/modules/__tests__/Route-test.js +++ b/packages/react-router/modules/__tests__/Route-test.js @@ -1,10 +1,12 @@ import React from "react"; import ReactDOM from "react-dom"; import { createMemoryHistory as createHistory } from "history"; -import { MemoryRouter, Route, Router } from "react-router"; import renderStrict from "./utils/renderStrict"; +// resolved by jest +import { MemoryRouter, Router, Route } from "react-router"; + describe("A ", () => { const node = document.createElement("div"); diff --git a/packages/react-router/modules/__tests__/Router-test.js b/packages/react-router/modules/__tests__/Router-test.js index e1a6548d05..c5923001a0 100644 --- a/packages/react-router/modules/__tests__/Router-test.js +++ b/packages/react-router/modules/__tests__/Router-test.js @@ -1,10 +1,12 @@ import React from "react"; import ReactDOM from "react-dom"; import { createMemoryHistory as createHistory } from "history"; -import { Router } from "react-router"; import renderStrict from "./utils/renderStrict"; +// resolved by jest +import { Router } from "react-router"; + describe("A ", () => { const node = document.createElement("div"); diff --git a/packages/react-router/modules/__tests__/StaticRouter-test.js b/packages/react-router/modules/__tests__/StaticRouter-test.js index 5cc0b5a1c3..67b9d5e719 100644 --- a/packages/react-router/modules/__tests__/StaticRouter-test.js +++ b/packages/react-router/modules/__tests__/StaticRouter-test.js @@ -1,10 +1,12 @@ import React from "react"; import ReactDOM from "react-dom"; import ReactDOMServer from "react-dom/server"; -import { Route, Prompt, Redirect, StaticRouter } from "react-router"; import renderStrict from "./utils/renderStrict"; +// resolved by jest +import { StaticRouter, Redirect, Route, Prompt } from "react-router"; + describe("A ", () => { const node = document.createElement("div"); diff --git a/packages/react-router/modules/__tests__/Switch-test.js b/packages/react-router/modules/__tests__/Switch-test.js index b8e1be6dcf..b912d6d673 100644 --- a/packages/react-router/modules/__tests__/Switch-test.js +++ b/packages/react-router/modules/__tests__/Switch-test.js @@ -1,10 +1,12 @@ import React from "react"; import ReactDOM from "react-dom"; -import { MemoryRouter, Route, Redirect, Switch } from "react-router"; import renderStrict from "./utils/renderStrict"; import waitForRedirects from "./utils/waitForRedirects"; +// resolved by jest +import { MemoryRouter, Switch, Route, Redirect } from "react-router"; + describe("A ", () => { const node = document.createElement("div"); diff --git a/packages/react-router/modules/__tests__/SwitchMount-test.js b/packages/react-router/modules/__tests__/SwitchMount-test.js index c58984d828..05ff9afbfd 100644 --- a/packages/react-router/modules/__tests__/SwitchMount-test.js +++ b/packages/react-router/modules/__tests__/SwitchMount-test.js @@ -1,9 +1,11 @@ import React from "react"; import ReactDOM from "react-dom"; -import { MemoryRouter, Route, Switch } from "react-router"; import renderStrict from "./utils/renderStrict"; +// resolved by jest +import { MemoryRouter, Switch, Route } from "react-router"; + describe("A ", () => { const node = document.createElement("div"); diff --git a/packages/react-router/modules/__tests__/integration-test.js b/packages/react-router/modules/__tests__/integration-test.js index 14180846df..a25dd57da1 100644 --- a/packages/react-router/modules/__tests__/integration-test.js +++ b/packages/react-router/modules/__tests__/integration-test.js @@ -1,9 +1,11 @@ import React from "react"; import ReactDOM from "react-dom"; -import { MemoryRouter, Route } from "react-router"; import renderStrict from "./utils/renderStrict"; +// resolved by jest +import { MemoryRouter, Route } from "react-router"; + describe("Integration Tests", () => { const node = document.createElement("div"); diff --git a/packages/react-router/modules/__tests__/withRouter-test.js b/packages/react-router/modules/__tests__/withRouter-test.js index daa6e7aaa2..3bca13d539 100644 --- a/packages/react-router/modules/__tests__/withRouter-test.js +++ b/packages/react-router/modules/__tests__/withRouter-test.js @@ -1,9 +1,11 @@ import React from "react"; import ReactDOM from "react-dom"; -import { MemoryRouter, StaticRouter, Route, withRouter } from "react-router"; import renderStrict from "./utils/renderStrict"; +// resolved by jest +import { MemoryRouter, StaticRouter, Route, withRouter } from "react-router"; + describe("withRouter", () => { const node = document.createElement("div"); diff --git a/packages/react-router/package.json b/packages/react-router/package.json index dcf7adf4d7..e88df56a82 100644 --- a/packages/react-router/package.json +++ b/packages/react-router/package.json @@ -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" diff --git a/packages/react-router/scripts/test.js b/packages/react-router/scripts/test.js new file mode 100644 index 0000000000..d215870ae6 --- /dev/null +++ b/packages/react-router/scripts/test.js @@ -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" +});