Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests against source, CJS, and UMD builds #6209

Merged
merged 6 commits into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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";
pshrmn marked this conversation as resolved.
Show resolved Hide resolved

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"
});
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
4 changes: 3 additions & 1 deletion packages/react-router/modules/__tests__/Switch-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 { 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 <Switch>", () => {
const node = document.createElement("div");

Expand Down
4 changes: 3 additions & 1 deletion packages/react-router/modules/__tests__/SwitchMount-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, Route, Switch } from "react-router";

import renderStrict from "./utils/renderStrict";

// resolved by jest
import { MemoryRouter, Switch, Route } from "react-router";

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

Expand Down
4 changes: 3 additions & 1 deletion packages/react-router/modules/__tests__/integration-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, 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");

Expand Down
4 changes: 3 additions & 1 deletion packages/react-router/modules/__tests__/withRouter-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, 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");

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"
});