Skip to content

Commit 3b609bd

Browse files
Enoah NetzachEnoahNetzach
authored andcommitted
Test environment variables
1 parent 9c9edd3 commit 3b609bd

18 files changed

+157
-141
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
REACT_APP_ENV_FILE_MESSAGE=fromtheenvfile
1+
REACT_APP_FILE_ENV_MESSAGE=fromtheenvfile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import initDOM from './initDOM'
2+
3+
// eslint-disable-next-line no-undef
4+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000
5+
6+
describe('Integration', () => {
7+
describe('Environment variables', () => {
8+
it('NODE_PATH', async () => {
9+
const doc = await initDOM('node-path')
10+
11+
expect(doc.getElementById('feature-node-path').childElementCount).toBe(4)
12+
})
13+
14+
it('shell env variables', async () => {
15+
const doc = await initDOM('shell-env-variables')
16+
17+
expect(doc.getElementById('feature-shell-env-variables').textContent).toBe('fromtheshell.')
18+
})
19+
20+
it('file env variables', async () => {
21+
const doc = await initDOM('file-env-variables')
22+
23+
expect(doc.getElementById('feature-file-env-variables').textContent).toBe('fromtheenvfile.')
24+
})
25+
})
26+
})

packages/react-scripts/templates/kitchensink/integration/syntax.1.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000
55

66
describe('Integration', () => {
77
describe('Language syntax', () => {
8-
it('array-destructuring', async () => {
8+
it('array destructuring', async () => {
99
const doc = await initDOM('array-destructuring')
1010

1111
expect(doc.getElementById('feature-array-destructuring').childElementCount).toBe(4)
1212
})
1313

14-
it('array-spread', async () => {
14+
it('array spread', async () => {
1515
const doc = await initDOM('array-spread')
1616

1717
expect(doc.getElementById('feature-array-spread').childElementCount).toBe(4)
@@ -59,7 +59,7 @@ describe('Integration', () => {
5959
expect(doc.getElementById('feature-generators').childElementCount).toBe(4)
6060
})
6161

62-
it('object-destructuring', async () => {
62+
it('object destructuring', async () => {
6363
const doc = await initDOM('object-destructuring')
6464

6565
expect(doc.getElementById('feature-object-destructuring').childElementCount).toBe(4)

packages/react-scripts/templates/kitchensink/integration/syntax.2.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000
55

66
describe('Integration', () => {
77
describe('Language syntax', () => {
8-
it('object-spread', async () => {
8+
it('object spread', async () => {
99
const doc = await initDOM('object-spread')
1010

1111
expect(doc.getElementById('feature-object-spread').childElementCount).toBe(4)

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,21 @@ class App extends React.Component {
4949
this.setState({ feature: require('./features/syntax/DestructuringAndAwait').default })
5050
);
5151
break;
52+
case 'file-env-variables':
53+
require.ensure(['./features/env/FileEnvVariables'], () =>
54+
this.setState({ feature: require('./features/env/FileEnvVariables').default })
55+
);
56+
break;
5257
case 'generators':
5358
require.ensure(['./features/syntax/Generators'], () =>
5459
this.setState({ feature: require('./features/syntax/Generators').default })
5560
);
5661
break;
62+
case 'node-path':
63+
require.ensure(['./features/env/NodePath'], () =>
64+
this.setState({ feature: require('./features/env/NodePath').default })
65+
);
66+
break;
5767
case 'object-destructuring':
5868
require.ensure(['./features/syntax/ObjectDestructuring'], () =>
5969
this.setState({ feature: require('./features/syntax/ObjectDestructuring').default })
@@ -79,6 +89,11 @@ class App extends React.Component {
7989
this.setState({ feature: require('./features/syntax/RestParameters').default })
8090
);
8191
break;
92+
case 'shell-env-variables':
93+
require.ensure(['./features/env/ShellEnvVariables'], () =>
94+
this.setState({ feature: require('./features/env/ShellEnvVariables').default })
95+
);
96+
break;
8297
case 'template-interpolation':
8398
require.ensure(['./features/syntax/TemplateInterpolation'], () =>
8499
this.setState({ feature: require('./features/syntax/TemplateInterpolation').default })

packages/react-scripts/templates/kitchensink/src/CommentsList.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

packages/react-scripts/templates/kitchensink/src/EnvVariableMessages.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/react-scripts/templates/kitchensink/src/UsersList.js

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default () => [
2+
{ id: 1, name: '1' },
3+
{ id: 2, name: '2' },
4+
{ id: 3, name: '3' },
5+
{ id: 4, name: '4' }
6+
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react'
2+
3+
export default () => (
4+
<span id="feature-file-env-variables">{process.env.REACT_APP_FILE_ENV_MESSAGE}.</span>
5+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import FileEnvVariables from './FileEnvVariables';
4+
5+
describe('.env variables', () => {
6+
it('renders without crashing', () => {
7+
const div = document.createElement('div');
8+
ReactDOM.render(<FileEnvVariables />, div);
9+
});
10+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react'
2+
import load from 'absoluteLoad'
3+
4+
export default class extends React.Component {
5+
constructor(props) {
6+
super(props);
7+
8+
this.state = { users: [] };
9+
}
10+
11+
async componentDidMount() {
12+
const users = load();
13+
this.setState({ users });
14+
}
15+
16+
render() {
17+
return (
18+
<div id="feature-node-path">
19+
{this.state.users.map(user => (
20+
<div key={user.id}>{user.name}</div>
21+
))}
22+
</div>
23+
);
24+
}
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import NodePath from './NodePath';
4+
5+
describe('NODE_PATH', () => {
6+
it('renders without crashing', () => {
7+
const div = document.createElement('div');
8+
ReactDOM.render(<NodePath />, div);
9+
});
10+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react'
2+
3+
export default () => (
4+
<span id="feature-shell-env-variables">{process.env.REACT_APP_SHELL_ENV_MESSAGE}.</span>
5+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import ShellEnvVariables from './ShellEnvVariables';
4+
5+
describe('shell env variables', () => {
6+
it('renders without crashing', () => {
7+
const div = document.createElement('div');
8+
ReactDOM.render(<ShellEnvVariables />, div);
9+
});
10+
});

packages/react-scripts/templates/kitchensink/src/loadComments.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

packages/react-scripts/templates/kitchensink/src/userGenerator.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

tasks/e2e.sh

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ create_react_app --scripts-version=$scripts_path --template=kitchensink test-app
149149
cd test-app
150150

151151
# Test the build
152-
NODE_PATH=src npm run build
152+
NODE_PATH=src REACT_APP_SHELL_ENV_MESSAGE=fromtheshell npm run build
153153
# Check for expected output
154154
test -e build/*.html
155155
test -e build/static/js/main.*.js
@@ -158,14 +158,29 @@ test -e build/static/css/main.*.css
158158
# test -e build/favicon.ico # TODO uncomment this line
159159

160160
# Unit tests
161-
CI=true NODE_PATH=src npm test -- --no-cache --testPathPattern="/src"
161+
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
162+
CI=true \
163+
NODE_PATH=src \
164+
npm test -- --no-cache --testPathPattern="/src/"
165+
162166
# Test "development" environment
163167
tmp_server_log=`mktemp`
164-
PORT=3001 nohup npm start &>$tmp_server_log &
168+
PORT=3001 \
169+
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
170+
NODE_PATH=src \
171+
nohup npm start &>$tmp_server_log &
165172
grep -q 'The app is running at:' <(tail -f $tmp_server_log)
166-
E2E_URL="http://localhost:3001" CI=true NODE_PATH=src npm test -- --no-cache --testPathPattern="/integration/"
173+
E2E_URL="http://localhost:3001" \
174+
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
175+
CI=true NODE_PATH=src \
176+
npm test -- --no-cache --testPathPattern="/integration/"
177+
167178
# Test "production" environment
168-
E2E_FILE=./build/index.html CI=true NODE_PATH=src npm test -- --no-cache --testPathPattern="/integration/"
179+
E2E_FILE=./build/index.html \
180+
CI=true \
181+
NODE_PATH=src \
182+
npm test -- --no-cache --testPathPattern="/integration/"
183+
169184
# Uncomment when snapshot testing is enabled by default:
170185
# test -e src/__snapshots__/App.test.js.snap
171186

@@ -186,7 +201,7 @@ npm link $root_path/packages/react-dev-utils
186201
npm link $root_path/packages/react-scripts
187202

188203
# Test the build
189-
NODE_PATH=src npm run build
204+
NODE_PATH=src REACT_APP_SHELL_ENV_MESSAGE=fromtheshell npm run build
190205
# Check for expected output
191206
test -e build/*.html
192207
test -e build/static/js/main.*.js
@@ -195,14 +210,29 @@ test -e build/static/css/main.*.css
195210
# test -e build/favicon.ico # TODO uncomment this line
196211

197212
# Unit tests
198-
CI=true NODE_PATH=src npm test -- --no-cache --testPathPattern="/src"
213+
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
214+
CI=true \
215+
NODE_PATH=src \
216+
npm test -- --no-cache --testPathPattern="/src/"
217+
199218
# Test "development" environment
200219
tmp_server_log=`mktemp`
201-
PORT=3002 nohup npm start &>$tmp_server_log &
220+
PORT=3002 \
221+
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
222+
NODE_PATH=src \
223+
nohup npm start &>$tmp_server_log &
202224
grep -q 'The app is running at:' <(tail -f $tmp_server_log)
203-
E2E_URL="http://localhost:3002" CI=true NODE_PATH=src npm test -- --no-cache --testPathPattern="/integration/"
225+
E2E_URL="http://localhost:3002" \
226+
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
227+
CI=true NODE_PATH=src \
228+
npm test -- --no-cache --testPathPattern="/integration/"
229+
204230
# Test "production" environment
205-
E2E_FILE=./build/index.html CI=true NODE_PATH=src npm test -- --no-cache --testPathPattern="/integration/"
231+
E2E_FILE=./build/index.html \
232+
CI=true \
233+
NODE_PATH=src \
234+
npm test -- --no-cache --testPathPattern="/integration/"
235+
206236
# Uncomment when snapshot testing is enabled by default:
207237
# test -e src/__snapshots__/App.test.js.snap
208238

0 commit comments

Comments
 (0)