Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
Make react/enzyme dependency soft (#473)
Browse files Browse the repository at this point in the history
* remove node-zopfli since we're not using it

* allow fusion-cli to test non-react projects

* remove redbox

* missed a file
  • Loading branch information
lhorie authored Aug 16, 2018
1 parent 0b52bc7 commit 16a40bb
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 59 deletions.
31 changes: 19 additions & 12 deletions build/jest/base-jest-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@
const testFolder = process.env.TEST_FOLDER || '__tests__';

function getReactVersion() {
// $FlowFixMe
const meta = require(process.cwd() + '/package.json');
const react =
(meta.dependencies && meta.dependencies.react) ||
(meta.devDependencies && meta.devDependencies.react) ||
(meta.peerDependencies && meta.peerDependencies.react);
return react
.split('.')
.shift()
.match(/\d+/);
}
function getReactSetup() {
try {
// $FlowFixMe
const meta = require(process.cwd() + '/package.json');
return meta.dependencies.react
.split('.')
.shift()
.match(/\d+/);
return [require.resolve(`./jest-framework-setup-${getReactVersion()}.js`)];
} catch (e) {
return '16';
return [];
}
}

const reactSetup = getReactSetup();

module.exports = {
cache: false,
coverageDirectory: `${process.cwd()}/coverage`,
Expand All @@ -32,11 +41,9 @@ module.exports = {
'^.+\\.js$': require.resolve('./jest-transformer.js'),
},
transformIgnorePatterns: ['/node_modules/(?!(fusion-cli.*build))'],
setupFiles: [
require.resolve('./jest-framework-shims.js'),
require.resolve(`./jest-framework-setup-${getReactVersion()}.js`),
],
snapshotSerializers: [require.resolve('enzyme-to-json/serializer')],
setupFiles: [require.resolve('./jest-framework-shims.js'), ...reactSetup],
snapshotSerializers:
reactSetup.length > 0 ? [require.resolve('enzyme-to-json/serializer')] : [],
testMatch: [`**/${testFolder}/**/*.js`],
testURL: 'http://localhost:3000/',
collectCoverageFrom: [
Expand Down
27 changes: 12 additions & 15 deletions build/server-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@

/* eslint-env node */

const React = require('react');
const RedBox = require('redbox-react').RedBoxError;
const ReactDOMServer = require('react-dom/server');

function renderError(error /*: any */ = {}) {
const content = [
'<!DOCTYPE html><html><head><title>Server error</title></head><body>',
];

let displayError;
if (error instanceof Error) {
displayError = error;
Expand All @@ -27,13 +19,18 @@ function renderError(error /*: any */ = {}) {
displayError.stack = error.stack;
displayError.name = error.name;
}
const errorComponent = ReactDOMServer.renderToString(
React.createElement(RedBox, {error: displayError})
);
content.push(errorComponent);

content.push('</body></html>');
return content.join('');
return `
<!DOCTYPE html>
<html>
<head>
<title>Server error</title>
<style>html {background:red;color:white;line-height:2;}</style>
</head>
<body>
<pre>${displayError.stack.replace(/\[\d\dm/gm, '')}</pre>
</body>
</html>
`;
}

module.exports.renderError = renderError;
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"progress-bar-webpack-plugin": "^1.11.0",
"range-parser": "^1.2.0",
"react-dev-utils": "^5.0.1",
"redbox-react": "^1.6.0",
"request": "^2.87.0",
"resolve-from": "^4.0.0",
"rimraf": "^2.6.2",
Expand Down Expand Up @@ -104,7 +103,6 @@
"tape": "4.9.1"
},
"peerDependencies": {
"enzyme": "^3.3.0",
"fusion-core": "^1.5.0-beta.0",
"fusion-tokens": "^1.0.4"
},
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/test-jest-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"react": "16.4.2"
}
}
31 changes: 1 addition & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2659,12 +2659,6 @@ error-inject@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/error-inject/-/error-inject-1.0.0.tgz#e2b3d91b54aed672f309d950d154850fa11d4f37"

error-stack-parser@^1.3.6:
version "1.3.6"
resolved "https://registry.npmjs.org/error-stack-parser/-/error-stack-parser-1.3.6.tgz#e0e73b93e417138d1cd7c0b746b1a4a14854c292"
dependencies:
stackframe "^0.3.1"

es-abstract@^1.10.0, es-abstract@^1.5.0, es-abstract@^1.5.1, es-abstract@^1.6.1, es-abstract@^1.7.0:
version "1.12.0"
resolved "https://registry.npmjs.org/es-abstract/-/es-abstract-1.12.0.tgz#9dbbdd27c6856f0001421ca18782d786bf8a6165"
Expand Down Expand Up @@ -6059,7 +6053,7 @@ prompts@^0.1.9:
kleur "^2.0.1"
sisteransi "^0.1.1"

prop-types@^15.5.4, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2:
prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2:
version "15.6.2"
resolved "https://registry.npmjs.org/prop-types/-/prop-types-15.6.2.tgz#05d5ca77b4453e985d60fc7ff8c859094a497102"
dependencies:
Expand Down Expand Up @@ -6392,15 +6386,6 @@ [email protected]:
dependencies:
minimatch "3.0.3"

redbox-react@^1.6.0:
version "1.6.0"
resolved "https://registry.npmjs.org/redbox-react/-/redbox-react-1.6.0.tgz#e753ac02595bc1bf695b3935889a4f5b1b5a21a1"
dependencies:
error-stack-parser "^1.3.6"
object-assign "^4.0.1"
prop-types "^15.5.4"
sourcemapped-stacktrace "^1.1.6"

regenerate-unicode-properties@^7.0.0:
version "7.0.0"
resolved "https://registry.npmjs.org/regenerate-unicode-properties/-/regenerate-unicode-properties-7.0.0.tgz#107405afcc4a190ec5ed450ecaa00ed0cafa7a4c"
Expand Down Expand Up @@ -6964,10 +6949,6 @@ source-map-url@^0.4.0:
version "0.4.0"
resolved "https://registry.npmjs.org/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3"

[email protected]:
version "0.5.6"
resolved "https://registry.npmjs.org/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"

source-map@^0.4.4:
version "0.4.4"
resolved "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz#eba4f5da9c0dc999de68032d8b4f76173652036b"
Expand All @@ -6986,12 +6967,6 @@ source-map@^0.7.2:
version "0.7.3"
resolved "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383"

sourcemapped-stacktrace@^1.1.6:
version "1.1.8"
resolved "https://registry.npmjs.org/sourcemapped-stacktrace/-/sourcemapped-stacktrace-1.1.8.tgz#6b7a3f1a6fb15f6d40e701e23ce404553480d688"
dependencies:
source-map "0.5.6"

spdx-correct@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.0.0.tgz#05a5b4d7153a195bc92c3c425b69f3b2a9524c82"
Expand Down Expand Up @@ -7057,10 +7032,6 @@ stack-utils@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/stack-utils/-/stack-utils-1.0.1.tgz#d4f33ab54e8e38778b0ca5cfd3b3afb12db68620"

stackframe@^0.3.1:
version "0.3.1"
resolved "https://registry.npmjs.org/stackframe/-/stackframe-0.3.1.tgz#33aa84f1177a5548c8935533cbfeb3420975f5a4"

static-extend@^0.1.1:
version "0.1.2"
resolved "https://registry.npmjs.org/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6"
Expand Down

0 comments on commit 16a40bb

Please sign in to comment.