Skip to content

Commit 3124328

Browse files
authored
Add linked modules test (#1913)
1 parent f61cba1 commit 3124328

File tree

6 files changed

+73
-4
lines changed

6 files changed

+73
-4
lines changed

packages/react-scripts/fixtures/kitchensink/.template.dependencies.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"babel-polyfill": "6.20.0",
66
"chai": "3.5.0",
77
"jsdom": "9.8.3",
8-
"mocha": "3.2.0"
8+
"mocha": "3.2.0",
9+
"test-integrity": "1.0.0"
910
}
1011
}

packages/react-scripts/fixtures/kitchensink/integration/webpack.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ describe('Integration', () => {
4444
);
4545
});
4646

47+
it('linked modules', async () => {
48+
const doc = await initDOM('linked-modules');
49+
50+
expect(doc.getElementById('feature-linked-modules').textContent).to.equal(
51+
'2.0.0'
52+
);
53+
});
54+
4755
it('svg inclusion', async () => {
4856
const doc = await initDOM('svg-inclusion');
4957

packages/react-scripts/fixtures/kitchensink/src/App.js

+4
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ class App extends Component {
111111
import('./features/webpack/JsonInclusion').then(f =>
112112
this.setFeature(f.default));
113113
break;
114+
case 'linked-modules':
115+
import('./features/webpack/LinkedModules').then(f =>
116+
this.setFeature(f.default));
117+
break;
114118
case 'node-path':
115119
import('./features/env/NodePath').then(f => this.setFeature(f.default));
116120
break;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
import React from 'react';
11+
import './assets/style.css';
12+
import { test, version } from 'test-integrity';
13+
14+
export default () => {
15+
const v = version();
16+
if (!test() || v !== '2.0.0') {
17+
throw new Error('Functionality test did not pass.');
18+
}
19+
return <p id="feature-linked-modules">{v}</p>;
20+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
import React from 'react';
11+
import ReactDOM from 'react-dom';
12+
import { test, version } from 'test-integrity';
13+
import LinkedModules from './LinkedModules';
14+
15+
describe('linked modules', () => {
16+
it('has integrity', () => {
17+
expect(test());
18+
expect(version() === '2.0.0');
19+
});
20+
21+
it('renders without crashing', () => {
22+
const div = document.createElement('div');
23+
ReactDOM.render(<LinkedModules />, div);
24+
});
25+
});

tasks/e2e-kitchensink.sh

+14-3
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@
1414
# Start in tasks/ even if run from root directory
1515
cd "$(dirname "$0")"
1616

17-
# CLI and app temporary locations
17+
# CLI, app, and test module temporary locations
1818
# http://unix.stackexchange.com/a/84980
1919
temp_cli_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_cli_path'`
2020
temp_app_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_app_path'`
21+
temp_module_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_module_path'`
2122

2223
function cleanup {
2324
echo 'Cleaning up.'
2425
ps -ef | grep 'react-scripts' | grep -v grep | awk '{print $2}' | xargs kill -s 9
2526
cd "$root_path"
2627
# TODO: fix "Device or resource busy" and remove ``|| $CI`
27-
rm -rf "$temp_cli_path" $temp_app_path || $CI
28+
rm -rf "$temp_cli_path" "$temp_app_path" "$temp_module_path" || $CI
2829
}
2930

3031
# Error messages are redirected to stderr
@@ -111,17 +112,24 @@ npm install "$cli_path"
111112
cd $temp_app_path
112113
create_react_app --scripts-version="$scripts_path" --internal-testing-template="$root_path"/packages/react-scripts/fixtures/kitchensink test-kitchensink
113114

115+
# Install the test module
116+
cd "$temp_module_path"
117+
npm install test-integrity@^2.0.1
118+
114119
# ******************************************************************************
115120
# Now that we used create-react-app to create an app depending on react-scripts,
116121
# let's make sure all npm scripts are in the working state.
117122
# ******************************************************************************
118123

119124
# Enter the app directory
120-
cd test-kitchensink
125+
cd "$temp_app_path/test-kitchensink"
121126

122127
# Link to our preset
123128
npm link "$root_path"/packages/babel-preset-react-app
124129

130+
# Link to test module
131+
npm link "$temp_module_path/node_modules/test-integrity"
132+
125133
# Test the build
126134
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
127135
NODE_PATH=src \
@@ -183,6 +191,9 @@ npm link "$root_path"/packages/eslint-config-react-app
183191
npm link "$root_path"/packages/react-dev-utils
184192
npm link "$root_path"/packages/react-scripts
185193

194+
# Link to test module
195+
npm link "$temp_module_path/node_modules/test-integrity"
196+
186197
# Test the build
187198
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
188199
NODE_PATH=src \

0 commit comments

Comments
 (0)