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

Commit

Permalink
allow fusion-cli to test non-react projects
Browse files Browse the repository at this point in the history
  • Loading branch information
lhorie committed Aug 15, 2018
1 parent e2c5916 commit 7ecb04a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 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;
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

0 comments on commit 7ecb04a

Please sign in to comment.