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

Make react/enzyme dependency soft #473

Merged
merged 6 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're getting rid of this, we should remove the redbox-react dependency from package.json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good catch!

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;
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
"tape": "4.9.1"
},
"peerDependencies": {
"enzyme": "^3.3.0",
"fusion-core": "^1.5.0-beta.0",
"fusion-tokens": "^1.0.4"
},
Expand Down