-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(cherry picked from commit 7e874f5)
- Loading branch information
Showing
6 changed files
with
101 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
var grunt = require('grunt'); | ||
|
||
var src = 'packages/react-test-renderer/'; | ||
var dest = 'build/packages/react-test-renderer/'; | ||
|
||
function buildRelease() { | ||
if (grunt.file.exists(dest)) { | ||
grunt.file.delete(dest); | ||
} | ||
|
||
// Copy to build/packages/react-native-renderer | ||
var mappings = [].concat( | ||
grunt.file.expandMapping('**/*', dest, {cwd: src}), | ||
grunt.file.expandMapping('{LICENSE,PATENTS}', dest) | ||
); | ||
mappings.forEach(function(mapping) { | ||
var mappingSrc = mapping.src[0]; | ||
var mappingDest = mapping.dest; | ||
if (grunt.file.isDir(mappingSrc)) { | ||
grunt.file.mkdir(mappingDest); | ||
} else { | ||
grunt.file.copy(mappingSrc, mappingDest); | ||
} | ||
}); | ||
} | ||
|
||
function packRelease() { | ||
var done = this.async(); | ||
var spawnCmd = { | ||
cmd: 'npm', | ||
args: ['pack', 'packages/react-test-renderer'], | ||
}; | ||
grunt.util.spawn(spawnCmd, function() { | ||
var buildSrc = 'react-test-renderer-' + grunt.config.data.pkg.version + '.tgz'; | ||
var buildDest = 'build/packages/react-test-renderer.tgz'; | ||
fs.rename(buildSrc, buildDest, done); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
buildRelease: buildRelease, | ||
packRelease: packRelease, | ||
}; |
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,22 @@ | ||
# `react-test-renderer` | ||
|
||
This package provides an experimental React renderer that can be used to render React components to pure JavaScript objects, without depending on the DOM or a native mobile environment. | ||
|
||
Essentially, this package makes it easy to grab a snapshot of the "DOM tree" rendered by a React DOM or React Native component without using a browser or jsdom. | ||
|
||
Usage: | ||
|
||
```jsx | ||
const ReactTestRenderer = require('react-test-renderer'); | ||
|
||
const renderer = ReactTestRenderer.create( | ||
<Link page="https://www.facebook.com/">Facebook</Link> | ||
); | ||
|
||
console.log(renderer.toJSON()); | ||
// { type: 'a', | ||
// props: { href: 'https://www.facebook.com/' }, | ||
// children: [ 'Facebook' ] } | ||
``` | ||
|
||
You can also use Jest's snapshot testing feature to automatically save a copy of the JSON tree to a file and check in your tests that it hasn't changed: http://facebook.github.io/jest/blog/2016/07/27/jest-14.html. |
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,4 @@ | ||
|
||
'use strict'; | ||
|
||
module.exports = require('react/lib/ReactTestRenderer'); |
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,21 @@ | ||
{ | ||
"name": "react-test-renderer", | ||
"version": "16.0.0-alpha", | ||
"description": "React package for snapshot testing.", | ||
"main": "index.js", | ||
"repository": "facebook/react", | ||
"keywords": [ | ||
"react", | ||
"react-native", | ||
"react-testing" | ||
], | ||
"license": "BSD-3-Clause", | ||
"bugs": { | ||
"url": "https://github.com/facebook/react/issues" | ||
}, | ||
"homepage": "https://facebook.github.io/react/", | ||
"peerDependencies": { | ||
"react": "^16.0.0-alpha" | ||
} | ||
} | ||
|