-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Spitzer
committed
Apr 22, 2018
1 parent
71a2fc7
commit 14bc486
Showing
11 changed files
with
274 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env node | ||
|
||
process.env.BABEL_ENV = 'production'; | ||
process.env.NODE_ENV = 'production'; | ||
|
||
const webpackPreact = require('./patch/webpackPreact'); | ||
const webpackConfig = require('react-scripts/config/webpack.config.prod'); | ||
webpackPreact(webpackConfig); | ||
|
||
require('react-scripts/scripts/build'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Hack the webpack config to load Preact instead of React | ||
module.exports = webpackConfig => | ||
(webpackConfig.resolve.alias = Object.assign({}, webpackConfig.resolve.alias, { | ||
react: 'preact-compat', | ||
'react-dom': 'preact-compat' | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env node | ||
|
||
process.env.BABEL_ENV = 'development'; | ||
process.env.NODE_ENV = 'development'; | ||
|
||
const webpackPreact = require('./patch/webpackPreact'); | ||
const webpackConfig = require('react-scripts/config/webpack.config.dev'); | ||
webpackPreact(webpackConfig); | ||
|
||
require('react-scripts/scripts/start'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env node | ||
|
||
process.env.BABEL_ENV = 'test'; | ||
process.env.NODE_ENV = 'test'; | ||
|
||
// Load the create-react-app config. | ||
const jestConfig = require('react-scripts/scripts/utils/createJestConfig'); | ||
|
||
// Map React's testing classes to Preact | ||
const newJestConfig = function() { | ||
const config = jestConfig.apply(this, arguments); | ||
config.moduleNameMapper = Object.assign({}, config.moduleNameMapper, { | ||
'^react-dom/server$': '<rootDir>/node_modules/preact-render-to-string/dist/index.js', | ||
'^react-dom/test-utils$': '<rootDir>/node_modules/preact-test-utils/lib/index.js', | ||
'^react-dom$': '<rootDir>/node_modules/preact-compat-enzyme/lib/index.js', | ||
'^react-test-renderer/shallow$': '<rootDir>/node_modules/preact-test-utils/lib/index.js', | ||
'^react-test-renderer$': '<rootDir>/node_modules/preact-test-utils/lib/index.js', | ||
'^react-addons-test-utils$': '<rootDir>/node_modules/preact-test-utils/lib/index.js', | ||
'^react$': '<rootDir>/node_modules/preact-compat-enzyme/lib/index.js' | ||
}); | ||
return config; | ||
}; | ||
|
||
// HACK ALERT! | ||
module.constructor._cache[ | ||
require.resolve('react-scripts/scripts/utils/createJestConfig') | ||
].exports = newJestConfig; | ||
|
||
// Run the build. | ||
require('react-scripts/scripts/test'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`can render into snapshots 1`] = ` | ||
<div | ||
class="App" | ||
> | ||
<header | ||
class="App-header" | ||
> | ||
<img | ||
alt="logo" | ||
class="App-logo" | ||
src="logo.svg" | ||
/> | ||
<h1 | ||
class="App-title" | ||
> | ||
Welcome to React | ||
</h1> | ||
</header> | ||
<p | ||
class="App-intro" | ||
> | ||
To get started, edit | ||
<code> | ||
src/App.js | ||
</code> | ||
and save to reload. | ||
</p> | ||
<div | ||
class="thing" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`can shallow render into snapshots 1`] = ` | ||
<div | ||
class="App" | ||
> | ||
<header | ||
class="App-header" | ||
> | ||
<img | ||
alt="logo" | ||
class="App-logo" | ||
src="logo.svg" | ||
/> | ||
<h1 | ||
class="App-title" | ||
> | ||
Welcome to React | ||
</h1> | ||
</header> | ||
<p | ||
class="App-intro" | ||
> | ||
To get started, edit | ||
<code> | ||
src/App.js | ||
</code> | ||
and save to reload. | ||
</p> | ||
<Thing /> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import render, { shallowRender } from 'preact-render-to-json'; | ||
|
||
/** | ||
* Remove __self and __source from the list of attributes/properties. | ||
* babel-preset-react adds these for use with the React DevTools | ||
*/ | ||
function removeDevAttributes(vnode) { | ||
if (vnode) { | ||
if (vnode.children) { | ||
vnode.children.forEach(n => removeDevAttributes(n)); | ||
} | ||
if (vnode.props) { | ||
if (vnode.props.__source) { | ||
delete vnode.props.__source; | ||
} | ||
if (vnode.props.__self) { | ||
delete vnode.props.__self; | ||
} | ||
} | ||
} | ||
return vnode; | ||
} | ||
|
||
/** | ||
* Render Preact JSX + Components to an HTML string. | ||
* | ||
* @param {VNode} vnode JSX VNode to render. | ||
* @param {Object} [context={}] Optionally pass an initial context object through the render path. | ||
* @param {Object} [options={}] Rendering options | ||
*/ | ||
global.render = (vnode, context) => removeDevAttributes(render(vnode, context)); | ||
|
||
global.shallowRender = (vnode, context) => removeDevAttributes(shallowRender(vnode, context)); |
Oops, something went wrong.