Skip to content

Commit

Permalink
Test react-router(-dom) source, CJS, and UMD
Browse files Browse the repository at this point in the history
  • Loading branch information
pshrmn committed Oct 31, 2018
1 parent e53af0f commit 8263bf1
Show file tree
Hide file tree
Showing 20 changed files with 307 additions and 17 deletions.
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>/index";
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
Original file line number Diff line number Diff line change
@@ -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 <BrowserRouter>", () => {
const node = document.createElement("div");

Expand Down
Original file line number Diff line number Diff line change
@@ -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 <HashRouter>", () => {
const node = document.createElement("div");

Expand Down
4 changes: 3 additions & 1 deletion packages/react-router-dom/modules/__tests__/Link-test.js
Original file line number Diff line number Diff line change
@@ -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 <Link>", () => {
const node = document.createElement("div");

Expand Down
4 changes: 3 additions & 1 deletion packages/react-router-dom/modules/__tests__/NavLink-test.js
Original file line number Diff line number Diff line change
@@ -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 <NavLink>", () => {
const node = document.createElement("div");

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"
});
190 changes: 190 additions & 0 deletions packages/react-router-redux/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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>/index";
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
4 changes: 3 additions & 1 deletion packages/react-router/modules/__tests__/MemoryRouter-test.js
Original file line number Diff line number Diff line change
@@ -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 <MemoryRouter>", () => {
const node = document.createElement("div");

Expand Down
4 changes: 3 additions & 1 deletion packages/react-router/modules/__tests__/Redirect-test.js
Original file line number Diff line number Diff line change
@@ -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 <Redirect>", () => {
const node = document.createElement("div");

Expand Down
4 changes: 3 additions & 1 deletion packages/react-router/modules/__tests__/Route-test.js
Original file line number Diff line number Diff line change
@@ -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 <Route>", () => {
const node = document.createElement("div");

Expand Down
4 changes: 3 additions & 1 deletion packages/react-router/modules/__tests__/Router-test.js
Original file line number Diff line number Diff line change
@@ -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 <Router>", () => {
const node = document.createElement("div");

Expand Down
4 changes: 3 additions & 1 deletion packages/react-router/modules/__tests__/StaticRouter-test.js
Original file line number Diff line number Diff line change
@@ -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 <StaticRouter>", () => {
const node = document.createElement("div");

Expand Down
Loading

0 comments on commit 8263bf1

Please sign in to comment.