Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

Commit fc31750

Browse files
committed
Update Tests For CI
1 parent 282cc80 commit fc31750

File tree

9 files changed

+1015
-18
lines changed

9 files changed

+1015
-18
lines changed

.travis.yml

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,10 @@
22
dist: trusty
33
language: node_js
44
node_js:
5-
- 8
65
- 9
76
cache:
87
directories:
98
- node_modules
10-
- packages/create-react-app/node_modules
11-
- packages/react-scripts/node_modules
129
install: true
1310
script:
14-
- 'if [ $TEST_SUITE = "simple" ]; then tasks/e2e-simple.sh; fi'
15-
- 'if [ $TEST_SUITE = "kitchensink" ]; then tasks/e2e-kitchensink.sh; fi'
16-
- 'if [ $TEST_SUITE = "old-node" ]; then tasks/e2e-old-node.sh; fi'
17-
# Disabled for the moment, since it requires additional work to be done.
18-
# - 'if [ $TEST_SUITE = "installs" ]; then tasks/e2e-installs.sh; fi'
19-
env:
20-
matrix:
21-
- TEST_SUITE=simple
22-
- TEST_SUITE=kitchensink
23-
# See comment above
24-
# - TEST_SUITE=installs
25-
matrix:
26-
include:
27-
- node_js: 6
28-
env: TEST_SUITE=kitchensink
11+
- 'tasks/e2e-simple.sh'

tasks/cra.js

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Copyright (c) 2015-present, Facebook, Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
const fs = require('fs');
12+
const path = require('path');
13+
const cp = require('child_process');
14+
15+
const cleanup = () => {
16+
console.log('Cleaning up.');
17+
// Uncomment when snapshot testing is enabled by default:
18+
// rm ./template/src/__snapshots__/App.test.js.snap
19+
};
20+
21+
const handleExit = () => {
22+
cleanup();
23+
console.log('Exiting without error.');
24+
process.exit();
25+
};
26+
27+
const handleError = e => {
28+
console.error('ERROR! An error was encountered while executing\n', e);
29+
cleanup();
30+
console.log('Exiting with error.');
31+
process.exit(1);
32+
};
33+
34+
process.on('SIGINT', handleExit);
35+
process.on('uncaughtException', handleError);
36+
37+
// ******************************************************************************
38+
// Pack react- scripts so we can verify they work.
39+
// ******************************************************************************
40+
41+
const rootDir = path.join(__dirname, '..');
42+
const reactScriptsDir = path.join(rootDir, 'packages', 'react-scripts');
43+
const packageJsonPath = path.join(reactScriptsDir, 'package.json');
44+
const packageJsonOrigPath = path.join(reactScriptsDir, 'package.json.orig');
45+
46+
// Install all our packages
47+
const lernaPath = path.join(rootDir, 'node_modules', '.bin', 'lerna');
48+
cp.execSync(`${lernaPath} bootstrap`, {
49+
cwd: rootDir,
50+
stdio: 'inherit',
51+
});
52+
53+
// Save package.json because we're going to touch it
54+
fs.writeFileSync(packageJsonOrigPath, fs.readFileSync(packageJsonPath));
55+
56+
// Replace own dependencies (those in the`packages` dir) with the local paths
57+
// of those packages
58+
const replaceOwnDepsPath = path.join(__dirname, 'replace-own-deps.js');
59+
cp.execSync(`node ${replaceOwnDepsPath}`, { stdio: 'inherit' });
60+
61+
// Finally, pack react-scripts
62+
// Don't redirect stdio as we want to capture the output that will be returned
63+
// from execSync(). In this case it will be the .tgz filename.
64+
const scriptsFileName = cp
65+
.execSync(`npm pack`, { cwd: reactScriptsDir })
66+
.toString()
67+
.trim();
68+
const scriptsPath = path.join(
69+
rootDir,
70+
'packages',
71+
'react-scripts',
72+
scriptsFileName
73+
);
74+
75+
// Restore package.json
76+
fs.unlinkSync(packageJsonPath);
77+
fs.writeFileSync(packageJsonPath, fs.readFileSync(packageJsonOrigPath));
78+
fs.unlinkSync(packageJsonOrigPath);
79+
80+
// ******************************************************************************
81+
// Now that we have packed them, call the global CLI.
82+
// ******************************************************************************
83+
84+
// If Yarn is installed, clean its cache because it may have cached react-scripts
85+
try {
86+
cp.execSync('yarn cache clean');
87+
} catch (e) {
88+
// We can safely ignore this as the user doesn't have yarn installed
89+
}
90+
91+
const args = process.argv.slice(2);
92+
93+
// Now run the CRA command
94+
const craScriptPath = path.join(
95+
rootDir,
96+
'packages',
97+
'create-react-app',
98+
'index.js'
99+
);
100+
cp.execSync(
101+
`node ${craScriptPath} --scripts-version="${scriptsPath}" ${args.join(' ')}`,
102+
{
103+
cwd: rootDir,
104+
stdio: 'inherit',
105+
}
106+
);
107+
108+
// Cleanup
109+
handleExit();

tasks/e2e-installs.sh

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
#!/bin/bash
2+
# Copyright (c) 2015-present, Facebook, Inc.
3+
#
4+
# This source code is licensed under the MIT license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# ******************************************************************************
8+
# This is an end-to-end test intended to run on CI.
9+
# You can also run it locally but it's slow.
10+
# ******************************************************************************
11+
12+
# Start in tasks/ even if run from root directory
13+
cd "$(dirname "$0")"
14+
15+
# CLI and app temporary locations
16+
# http://unix.stackexchange.com/a/84980
17+
temp_app_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_app_path'`
18+
custom_registry_url=http://localhost:4873
19+
original_npm_registry_url=`npm get registry`
20+
original_yarn_registry_url=`yarn config get registry`
21+
22+
function cleanup {
23+
echo 'Cleaning up.'
24+
cd "$root_path"
25+
rm -rf "$temp_app_path"
26+
npm set registry "$original_npm_registry_url"
27+
yarn config set registry "$original_yarn_registry_url"
28+
}
29+
30+
# Error messages are redirected to stderr
31+
function handle_error {
32+
echo "$(basename $0): ERROR! An error was encountered executing line $1." 1>&2;
33+
cleanup
34+
echo 'Exiting with error.' 1>&2;
35+
exit 1
36+
}
37+
38+
function handle_exit {
39+
cleanup
40+
echo 'Exiting without error.' 1>&2;
41+
exit
42+
}
43+
44+
# Check for the existence of one or more files.
45+
function exists {
46+
for f in $*; do
47+
test -e "$f"
48+
done
49+
}
50+
51+
# Check for accidental dependencies in package.json
52+
function checkDependencies {
53+
if ! awk '/"dependencies": {/{y=1;next}/},/{y=0; next}y' package.json | \
54+
grep -v -q -E '^\s*"react(-dom|-scripts)?"'; then
55+
echo "Dependencies are correct"
56+
else
57+
echo "There are extraneous dependencies in package.json"
58+
exit 1
59+
fi
60+
}
61+
62+
# Exit the script with a helpful error message when any error is encountered
63+
trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR
64+
65+
# Cleanup before exit on any termination signal
66+
trap 'set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP
67+
68+
# Echo every command being executed
69+
set -x
70+
71+
# Go to root
72+
cd ..
73+
root_path=$PWD
74+
75+
if hash npm 2>/dev/null
76+
then
77+
npm i -g npm@latest
78+
npm cache clean || npm cache verify
79+
fi
80+
81+
# Bootstrap monorepo
82+
yarn
83+
84+
# ******************************************************************************
85+
# First, publish the monorepo.
86+
# ******************************************************************************
87+
88+
# Start local registry
89+
tmp_registry_log=`mktemp`
90+
nohup npx verdaccio@2.7.2 &>$tmp_registry_log &
91+
# Wait for `verdaccio` to boot
92+
grep -q 'http address' <(tail -f $tmp_registry_log)
93+
94+
# Set registry to local registry
95+
npm set registry "$custom_registry_url"
96+
yarn config set registry "$custom_registry_url"
97+
98+
# Login so we can publish packages
99+
npx npm-cli-login@0.0.10 -u user -p password -e user@example.com -r "$custom_registry_url" --quotes
100+
101+
# Publish the monorepo
102+
git clean -df
103+
./tasks/publish.sh --yes --force-publish=* --skip-git --cd-version=prerelease --exact --npm-tag=latest
104+
105+
# ******************************************************************************
106+
# Test --scripts-version with a version number
107+
# ******************************************************************************
108+
109+
cd "$temp_app_path"
110+
npx create-react-app --scripts-version=1.0.17 test-app-version-number
111+
cd test-app-version-number
112+
113+
# Check corresponding scripts version is installed.
114+
exists node_modules/react-scripts
115+
grep '"version": "1.0.17"' node_modules/react-scripts/package.json
116+
checkDependencies
117+
118+
# ******************************************************************************
119+
# Test --use-npm flag
120+
# ******************************************************************************
121+
122+
cd "$temp_app_path"
123+
npx create-react-app --use-npm --scripts-version=1.0.17 test-use-npm-flag
124+
cd test-use-npm-flag
125+
126+
# Check corresponding scripts version is installed.
127+
exists node_modules/react-scripts
128+
[ ! -e "yarn.lock" ] && echo "yarn.lock correctly does not exist"
129+
grep '"version": "1.0.17"' node_modules/react-scripts/package.json
130+
checkDependencies
131+
132+
# ******************************************************************************
133+
# Test --scripts-version with a tarball url
134+
# ******************************************************************************
135+
136+
cd "$temp_app_path"
137+
npx create-react-app --scripts-version=https://registry.npmjs.org/react-scripts/-/react-scripts-1.0.17.tgz test-app-tarball-url
138+
cd test-app-tarball-url
139+
140+
# Check corresponding scripts version is installed.
141+
exists node_modules/react-scripts
142+
grep '"version": "1.0.17"' node_modules/react-scripts/package.json
143+
checkDependencies
144+
145+
# ******************************************************************************
146+
# Test --scripts-version with a custom fork of react-scripts
147+
# ******************************************************************************
148+
149+
cd "$temp_app_path"
150+
npx create-react-app --scripts-version=react-scripts-fork test-app-fork
151+
cd test-app-fork
152+
153+
# Check corresponding scripts version is installed.
154+
exists node_modules/react-scripts-fork
155+
156+
# ******************************************************************************
157+
# Test project folder is deleted on failing package installation
158+
# ******************************************************************************
159+
160+
cd "$temp_app_path"
161+
# we will install a non-existing package to simulate a failed installataion.
162+
npx create-react-app --scripts-version=`date +%s` test-app-should-not-exist || true
163+
# confirm that the project folder was deleted
164+
test ! -d test-app-should-not-exist
165+
166+
# ******************************************************************************
167+
# Test project folder is not deleted when creating app over existing folder
168+
# ******************************************************************************
169+
170+
cd "$temp_app_path"
171+
mkdir test-app-should-remain
172+
echo '## Hello' > ./test-app-should-remain/README.md
173+
# we will install a non-existing package to simulate a failed installataion.
174+
npx create-react-app --scripts-version=`date +%s` test-app-should-remain || true
175+
# confirm the file exist
176+
test -e test-app-should-remain/README.md
177+
# confirm only README.md is the only file in the directory
178+
if [ "$(ls -1 ./test-app-should-remain | wc -l | tr -d '[:space:]')" != "1" ]; then
179+
false
180+
fi
181+
182+
# ******************************************************************************
183+
# Test --scripts-version with a scoped fork tgz of react-scripts
184+
# ******************************************************************************
185+
186+
cd $temp_app_path
187+
curl "https://registry.npmjs.org/@enoah_netzach/react-scripts/-/react-scripts-0.9.0.tgz" -o enoah-scripts-0.9.0.tgz
188+
npx create-react-app --scripts-version=$temp_app_path/enoah-scripts-0.9.0.tgz test-app-scoped-fork-tgz
189+
cd test-app-scoped-fork-tgz
190+
191+
# Check corresponding scripts version is installed.
192+
exists node_modules/@enoah_netzach/react-scripts
193+
194+
# ******************************************************************************
195+
# Test nested folder path as the project name
196+
# ******************************************************************************
197+
198+
# Testing a path that exists
199+
cd "$temp_app_path"
200+
mkdir test-app-nested-paths-t1
201+
cd test-app-nested-paths-t1
202+
mkdir -p test-app-nested-paths-t1/aa/bb/cc/dd
203+
npx create-react-app test-app-nested-paths-t1/aa/bb/cc/dd
204+
cd test-app-nested-paths-t1/aa/bb/cc/dd
205+
yarn start --smoke-test
206+
207+
# Testing a path that does not exist
208+
cd "$temp_app_path"
209+
npx create-react-app test-app-nested-paths-t2/aa/bb/cc/dd
210+
cd test-app-nested-paths-t2/aa/bb/cc/dd
211+
yarn start --smoke-test
212+
213+
# Testing a path that is half exists
214+
cd "$temp_app_path"
215+
mkdir -p test-app-nested-paths-t3/aa
216+
npx create-react-app test-app-nested-paths-t3/aa/bb/cc/dd
217+
cd test-app-nested-paths-t3/aa/bb/cc/dd
218+
yarn start --smoke-test
219+
220+
# Cleanup
221+
cleanup

0 commit comments

Comments
 (0)