0๐
โ
I figured out a way to do this. I created a react-pkg.json
:
{
"name": "react-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.2",
"react-dom": "^16.8.2",
"react-router-dom": "~4.3.1",
"react-scripts": "2.1.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
Then I modified my tsconfig.json
to support JSON import.
{
"compilerOptions": {
"resolveJsonModule": true,
"esModuleInterop": true
}
}
Then I imported this file in my test:
import packageJson from './react-pkg.json';
And then added it to the tree:
const tree = new UnitTestTree(new HostTree);
// Add package.json
tree.create('/package.json', JSON.stringify(packageJson));
You can see the full test here.
Source:stackexchange.com