Skip to content

Commit 4b4f3f2

Browse files
awaseemiansu
authored andcommitted
added e2e test for checking typescript template with unsupported node (#7844)
1 parent 3aaa3fa commit 4b4f3f2

File tree

3 files changed

+154
-80
lines changed

3 files changed

+154
-80
lines changed

azure-pipelines.yml

Lines changed: 92 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,92 @@
1-
#
2-
# Azure Pipelines configuration for building and testing create-react-app on Linux, Windows, and macOS.
3-
#
4-
5-
trigger:
6-
- master
7-
8-
variables:
9-
CI: true
10-
# Overrides the Yarn and NPM cache directories so they are on the same drive as the source. This helps improve build performance on Windows hosted agents.
11-
YARN_CACHE_FOLDER: $(Build.SourcesDirectory)/../yarn-cache
12-
NPM_CONFIG_CACHE: $(Build.SourcesDirectory)/../npm-cache
13-
# Sets TEMP to be on the same drive as the cloned source on Windows. This avoids test scripts that "cd" into a directory under TEMP from failing because this directory is on a different drive from the current directory.
14-
VSTS_OVERWRITE_TEMP: True
15-
# Override Verdaccio package to use. This is temporary and is needed to avoid socket timeouts on hosted Windows agent (on Azure). This also changes Verdaccio to return a 503 (service unavailable) instead of a 404 (not found) when the connection to the uplink timesout.
16-
VERDACCIO_PACKAGE: https://github.com/willsmythe/verdaccio/releases/download/create-react-app/verdaccio-4.0.0-alpha.8.tgz
17-
CRA_INTERNAL_TEST: true
18-
19-
# ******************************************************************************
20-
# Simple test suite
21-
# ******************************************************************************
22-
jobs:
23-
- template: azure-pipelines-test-job.yml
24-
parameters:
25-
name: Simple
26-
testScript: tasks/e2e-simple.sh
27-
28-
# ******************************************************************************
29-
# Installs test suite
30-
# ******************************************************************************
31-
- template: azure-pipelines-test-job.yml
32-
parameters:
33-
name: Installs
34-
testScript: tasks/e2e-installs.sh
35-
36-
# ******************************************************************************
37-
# Kitchensink test suite
38-
# ******************************************************************************
39-
- template: azure-pipelines-test-job.yml
40-
parameters:
41-
name: Kitchensink
42-
testScript: tasks/e2e-kitchensink.sh
43-
44-
# ******************************************************************************
45-
# Kitchensink Eject test suite
46-
# ******************************************************************************
47-
- template: azure-pipelines-test-job.yml
48-
parameters:
49-
name: KitchensinkEject
50-
testScript: tasks/e2e-kitchensink-eject.sh
51-
52-
# ******************************************************************************
53-
# Behavior test suite
54-
# ******************************************************************************
55-
- template: azure-pipelines-test-job.yml
56-
parameters:
57-
name: Behavior
58-
testScript: tasks/e2e-behavior.sh
59-
configurations:
60-
LinuxNode8: { vmImage: 'ubuntu-16.04', nodeVersion: 8.x }
61-
LinuxNode10: { vmImage: 'ubuntu-16.04', nodeVersion: 10.x }
62-
# WindowsNode8: { vmImage: 'vs2017-win2016', nodeVersion: 8.x }
63-
# WindowsNode10: { vmImage: 'vs2017-win2016', nodeVersion: 10.x }
64-
MacNode8: { vmImage: 'macOS-10.13', nodeVersion: 8.x }
65-
MacNode10: { vmImage: 'macOS-10.13', nodeVersion: 10.x }
66-
67-
# ******************************************************************************
68-
# Old Node test suite
69-
# ******************************************************************************
70-
- job: OldNode
71-
pool:
72-
vmImage: ubuntu-16.04
73-
steps:
74-
- task: NodeTool@0
75-
inputs:
76-
versionSpec: 6.x
77-
displayName: 'Install Node.js 6.x'
78-
- bash: tasks/e2e-old-node.sh
79-
displayName: 'Run tests'
1+
#
2+
# Azure Pipelines configuration for building and testing create-react-app on Linux, Windows, and macOS.
3+
#
4+
5+
trigger:
6+
- master
7+
8+
variables:
9+
CI: true
10+
# Overrides the Yarn and NPM cache directories so they are on the same drive as the source. This helps improve build performance on Windows hosted agents.
11+
YARN_CACHE_FOLDER: $(Build.SourcesDirectory)/../yarn-cache
12+
NPM_CONFIG_CACHE: $(Build.SourcesDirectory)/../npm-cache
13+
# Sets TEMP to be on the same drive as the cloned source on Windows. This avoids test scripts that "cd" into a directory under TEMP from failing because this directory is on a different drive from the current directory.
14+
VSTS_OVERWRITE_TEMP: True
15+
# Override Verdaccio package to use. This is temporary and is needed to avoid socket timeouts on hosted Windows agent (on Azure). This also changes Verdaccio to return a 503 (service unavailable) instead of a 404 (not found) when the connection to the uplink timesout.
16+
VERDACCIO_PACKAGE: https://github.com/willsmythe/verdaccio/releases/download/create-react-app/verdaccio-4.0.0-alpha.8.tgz
17+
CRA_INTERNAL_TEST: true
18+
19+
# ******************************************************************************
20+
# Simple test suite
21+
# ******************************************************************************
22+
jobs:
23+
- template: azure-pipelines-test-job.yml
24+
parameters:
25+
name: Simple
26+
testScript: tasks/e2e-simple.sh
27+
28+
# ******************************************************************************
29+
# Installs test suite
30+
# ******************************************************************************
31+
- template: azure-pipelines-test-job.yml
32+
parameters:
33+
name: Installs
34+
testScript: tasks/e2e-installs.sh
35+
36+
# ******************************************************************************
37+
# Kitchensink test suite
38+
# ******************************************************************************
39+
- template: azure-pipelines-test-job.yml
40+
parameters:
41+
name: Kitchensink
42+
testScript: tasks/e2e-kitchensink.sh
43+
44+
# ******************************************************************************
45+
# Kitchensink Eject test suite
46+
# ******************************************************************************
47+
- template: azure-pipelines-test-job.yml
48+
parameters:
49+
name: KitchensinkEject
50+
testScript: tasks/e2e-kitchensink-eject.sh
51+
52+
# ******************************************************************************
53+
# Behavior test suite
54+
# ******************************************************************************
55+
- template: azure-pipelines-test-job.yml
56+
parameters:
57+
name: Behavior
58+
testScript: tasks/e2e-behavior.sh
59+
configurations:
60+
LinuxNode8: { vmImage: 'ubuntu-16.04', nodeVersion: 8.x }
61+
LinuxNode10: { vmImage: 'ubuntu-16.04', nodeVersion: 10.x }
62+
# WindowsNode8: { vmImage: 'vs2017-win2016', nodeVersion: 8.x }
63+
# WindowsNode10: { vmImage: 'vs2017-win2016', nodeVersion: 10.x }
64+
MacNode8: { vmImage: 'macOS-10.13', nodeVersion: 8.x }
65+
MacNode10: { vmImage: 'macOS-10.13', nodeVersion: 10.x }
66+
67+
# ******************************************************************************
68+
# Old Node test suite
69+
# ******************************************************************************
70+
- job: OldNode
71+
pool:
72+
vmImage: ubuntu-16.04
73+
steps:
74+
- task: NodeTool@0
75+
inputs:
76+
versionSpec: 6.x
77+
displayName: 'Install Node.js 6.x'
78+
- bash: tasks/e2e-old-node.sh
79+
displayName: 'Run tests'
80+
# ******************************************************************************
81+
# Unsupported Node with TypeScript flag
82+
# ******************************************************************************
83+
- job: UnsupportedNodeWithTypeScript
84+
pool:
85+
vmImage: ubuntu-16.04
86+
steps:
87+
- task: NodeTool@0
88+
inputs:
89+
versionSpec: 8.9.x
90+
displayName: 'Install Node.js 8.9.x'
91+
- bash: tasks/e2e-typescript-unsupported-node.sh
92+
displayName: 'Run unsupported TypeScript test'

packages/create-react-app/createReactApp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function createApp(
217217
) {
218218
const unsupportedNodeVersion = !semver.satisfies(process.version, '>=8.10.0');
219219
if (unsupportedNodeVersion && useTypeScript) {
220-
console.log(
220+
console.error(
221221
chalk.red(
222222
`You are using Node ${process.version} with the TypeScript template. Node 8.10 or higher is required to use TypeScript.\n`
223223
)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
temp_app_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_app_path'`
16+
17+
function cleanup {
18+
echo 'Cleaning up.'
19+
cd "$root_path"
20+
rm -rf $temp_app_path
21+
}
22+
23+
# Error messages are redirected to stderr
24+
function handle_error {
25+
echo "$(basename $0): ERROR! An error was encountered executing line $1." 1>&2;
26+
cleanup
27+
echo 'Exiting with error.' 1>&2;
28+
exit 1
29+
}
30+
31+
function handle_exit {
32+
cleanup
33+
echo 'Exiting without error.' 1>&2;
34+
exit
35+
}
36+
37+
# Exit the script with a helpful error message when any error is encountered
38+
trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR
39+
40+
# Cleanup before exit on any termination signal
41+
trap 'set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP
42+
43+
# Echo every command being executed
44+
set -x
45+
46+
# Go to root
47+
cd ..
48+
root_path=$PWD
49+
50+
# We need to install create-react-app deps to test it
51+
cd "$root_path"/packages/create-react-app
52+
npm install
53+
cd "$root_path"
54+
55+
# If the node version is < 8.10 but greater then 8.0, the script with the typescript flag should just give an error.
56+
cd $temp_app_path
57+
err_output=`node "$root_path"/packages/create-react-app/index.js test-node-version --typescript 2>&1 > /dev/null || echo ''`
58+
[[ $err_output =~ You\ are\ using\ Node ]] && exit 0 || exit 1
59+
60+
# Cleanup
61+
cleanup

0 commit comments

Comments
 (0)