Skip to content

Commit 51f34f1

Browse files
authored
Add linked modules test (0.9.x) (#1912)
* Add linked modules test * Keep fallback after eject
1 parent 4b92fd3 commit 51f34f1

File tree

8 files changed

+81
-16
lines changed

8 files changed

+81
-16
lines changed

packages/react-scripts/config/webpack.config.dev.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,16 @@ module.exports = {
9696
'react-native': 'react-native-web'
9797
}
9898
},
99-
// @remove-on-eject-begin
100-
// Resolve loaders (webpack plugins for CSS, images, transpilation) from the
101-
// directory of `react-scripts` itself rather than the project directory.
10299
resolveLoader: {
100+
// @remove-on-eject-begin
101+
// Resolve loaders (webpack plugins for CSS, images, transpilation) from the
102+
// directory of `react-scripts` itself rather than the project directory.
103103
root: paths.ownNodeModules,
104+
moduleTemplates: ['*-loader'],
105+
// @remove-on-eject-end
104106
// Fallback to any hoisted modules when dealing with linked libraries
105-
fallback: paths.appNodeModules,
106-
moduleTemplates: ['*-loader']
107+
fallback: paths.appNodeModules
107108
},
108-
// @remove-on-eject-end
109109
module: {
110110
// First, run the linter.
111111
// It's important to do this before Babel processes the JS.

packages/react-scripts/config/webpack.config.prod.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,16 @@ module.exports = {
100100
'react-native': 'react-native-web'
101101
}
102102
},
103-
// @remove-on-eject-begin
104-
// Resolve loaders (webpack plugins for CSS, images, transpilation) from the
105-
// directory of `react-scripts` itself rather than the project directory.
106103
resolveLoader: {
104+
// @remove-on-eject-begin
105+
// Resolve loaders (webpack plugins for CSS, images, transpilation) from the
106+
// directory of `react-scripts` itself rather than the project directory.
107107
root: paths.ownNodeModules,
108+
moduleTemplates: ['*-loader'],
109+
// @remove-on-eject-end
108110
// Fallback to any hoisted modules when dealing with linked libraries
109-
fallback: paths.appNodeModules,
110-
moduleTemplates: ['*-loader']
111+
fallback: paths.appNodeModules
111112
},
112-
// @remove-on-eject-end
113113
module: {
114114
// First, run the linter.
115115
// It's important to do this before Babel processes the JS.

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

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

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

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ describe('Integration', () => {
3838
expect(doc.getElementById('feature-json-inclusion').textContent).to.equal('This is an abstract.')
3939
})
4040

41+
it('linked modules', async () => {
42+
const doc = await initDOM('linked-modules')
43+
44+
expect(doc.getElementById('feature-linked-modules').textContent).to.equal('2.0.0')
45+
})
46+
4147
it('svg inclusion', async () => {
4248
const doc = await initDOM('svg-inclusion')
4349

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

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ class App extends Component {
9494
case 'json-inclusion':
9595
require.ensure([], () => this.setFeature(require('./features/webpack/JsonInclusion').default));
9696
break;
97+
case 'linked-modules':
98+
require.ensure([], () => this.setFeature(require('./features/webpack/LinkedModules').default));
99+
break;
97100
case 'node-path':
98101
require.ensure([], () => this.setFeature(require('./features/env/NodePath').default));
99102
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

+13-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 \
@@ -185,6 +193,8 @@ npm link "$root_path"/packages/react-scripts
185193

186194
# ...and we need to remove template's .babelrc
187195
rm .babelrc
196+
# Link to test module
197+
npm link "$temp_module_path/node_modules/test-integrity"
188198

189199
# Test the build
190200
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \

0 commit comments

Comments
 (0)