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 Sep 28, 2018
1 parent afebe67 commit 4a4c8c8
Show file tree
Hide file tree
Showing 25 changed files with 988 additions and 531 deletions.
1,177 changes: 729 additions & 448 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/react-router-dom/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ es
node_modules
umd
/*.js
!jest.config.js
!rollup.config.js
25 changes: 25 additions & 0 deletions packages/react-router-dom/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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 = {
testMatch: ["<rootDir>/modules/__tests__/*-test.js"],
moduleNameMapper: {
"^react-router-dom$": mappedModule
},
globals: {
"__DEV__": true
},
setupFiles: [
"raf/polyfill"
],
testURL: "http://localhost/"
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import ReactDOM from "react-dom";

import BrowserRouter from "../BrowserRouter";
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,7 +1,7 @@
import React from "react";
import ReactDOM from "react-dom";

import HashRouter from "../HashRouter";
import { HashRouter } from "react-router-dom";

describe("A <HashRouter>", () => {
const node = document.createElement("div");
Expand Down
4 changes: 1 addition & 3 deletions packages/react-router-dom/modules/__tests__/Link-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React from "react";
import ReactDOM from "react-dom";
import { MemoryRouter } from "react-router";

import HashRouter from "../HashRouter";
import Link from "../Link";
import { MemoryRouter, HashRouter, Link } from "react-router-dom";

describe("A <Link>", () => {
const node = document.createElement("div");
Expand Down
4 changes: 1 addition & 3 deletions packages/react-router-dom/modules/__tests__/NavLink-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React from "react";
import ReactDOM from "react-dom";
import { MemoryRouter } from "react-router";

import NavLink from "../NavLink";
import withRouter from "../withRouter";
import { MemoryRouter, NavLink, withRouter } from "react-router-dom";

describe("A <NavLink>", () => {
const node = document.createElement("div");
Expand Down
11 changes: 1 addition & 10 deletions packages/react-router-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"prepublishOnly": "node ./scripts/build.js",
"clean": "git clean -fdX .",
"lint": "eslint modules",
"test": "jest"
"test": "node ./scripts/test.js"
},
"peerDependencies": {
"react": ">=15"
Expand Down Expand Up @@ -82,15 +82,6 @@
"loose-envify"
]
},
"jest": {
"globals": {
"__DEV__": true
},
"setupFiles": [
"raf/polyfill"
],
"testURL": "http://localhost/"
},
"keywords": [
"react",
"router",
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"
});
131 changes: 131 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.

1 change: 1 addition & 0 deletions packages/react-router/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules
umd
utils
/*.js
!jest.config.js
!rollup.config.js
25 changes: 25 additions & 0 deletions packages/react-router/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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 = {
testMatch: ["<rootDir>/modules/__tests__/*-test.js"],
moduleNameMapper: {
"^react-router$": mappedModule
},
globals: {
"__DEV__": true
},
setupFiles: [
"raf/polyfill"
],
testURL: "http://localhost/"
};
19 changes: 5 additions & 14 deletions packages/react-router/modules/__tests__/MemoryRouter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import React from "react";
import ReactDOM from "react-dom";
import PropTypes from "prop-types";

import MemoryRouter from "../MemoryRouter";
import RouterContext from "../RouterContext";
import { MemoryRouter, withRouter } from "react-router";

describe("A <MemoryRouter>", () => {
const node = document.createElement("div");
Expand All @@ -27,18 +26,10 @@ describe("A <MemoryRouter>", () => {

describe("context", () => {
let context;
class ContextChecker extends React.Component {
render() {
return (
<RouterContext.Consumer>
{value => {
context = value;
return null;
}}
</RouterContext.Consumer>
);
}
}
const ContextChecker = withRouter(value => {
context = value;
return null;
});

afterEach(() => {
context = undefined;
Expand Down
5 changes: 1 addition & 4 deletions packages/react-router/modules/__tests__/Redirect-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import React from "react";
import ReactDOM from "react-dom";

import MemoryRouter from "../MemoryRouter";
import Redirect from "../Redirect";
import Route from "../Route";
import Switch from "../Switch";
import { MemoryRouter, Redirect, Route, Switch } from "react-router";

describe("A <Redirect>", () => {
const node = document.createElement("div");
Expand Down
6 changes: 2 additions & 4 deletions packages/react-router/modules/__tests__/Route-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import React from "react";
import ReactDOM from "react-dom";
import { createMemoryHistory as createHistory } from "history";
import { createMemoryHistory as createHistory} from "history";

import MemoryRouter from "../MemoryRouter";
import Route from "../Route";
import Router from "../Router";
import { MemoryRouter, Router, Route } from "react-router";

describe("A <Route>", () => {
const node = document.createElement("div");
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router/modules/__tests__/Router-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import ReactDOM from "react-dom";
import { createMemoryHistory as createHistory } from "history";

import Router from "../Router";
import { Router } from "react-router";

describe("A <Router>", () => {
const node = document.createElement("div");
Expand Down

0 comments on commit 4a4c8c8

Please sign in to comment.