-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
E2E testing enhancements #2408
E2E testing enhancements #2408
Changes from 3 commits
45df6bf
33bca08
09010d4
d4e0baa
69f1611
63327c9
ef0eabc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Contributing to Create React App's E2E tests | ||
|
||
This test suite is a [kitchensink](FIXME: link needed), but has multiple usages in it. | ||
|
||
## Running the test suite | ||
|
||
Tests are automatically run by the CI tools. | ||
In order to run them locally, without having to manually install and configure everything, the `yarn e2e:docker` CLI command can be used. | ||
|
||
This is a simple script that runs a **Docker** container, where the node version, git branch to clone, test suite, and whether to run it with `yarn` or `npm` can be chosen. | ||
Simply run `yarn e2e:docker -- --help` to get additional info. | ||
|
||
N.B.: this command will clone the local repository in the docker container, so any uncommitted changes are ignored. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way to run this on uncommitted changes. As normally I'd make changes, write tests, run tests. And then if everything works commit changes. With this, I'd be making changes, committing, testing, making changes, committing, testing, etc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, coming soon! |
||
|
||
## Writing tests | ||
|
||
Each time a new feature is added, it is advised to add at least one test covering it. | ||
|
||
Features are categorized by their scope: | ||
|
||
- *env*, all those which deal with environment variables (e.g. `NODE_PATH`) | ||
|
||
- *syntax*, all those which showcase a single EcmaScript syntax feature that is expected to be transpiled by **Babel** | ||
|
||
- *webpack*, all those which make use of webpack settings, loaders or plugins | ||
|
||
### Using it as Unit Tests | ||
|
||
In it's most basic for this serve as a collection of unit tests on a single functionality. | ||
|
||
Unit tests are written in a `src/features/**/*.test.js` file located in the same folder as the feature they test, and usually consist of a simple `ReactDOM.render` call. | ||
|
||
These tests are run by **jest** and the environment is `test`, so that it resembles how a **Create React App** application is tested. | ||
|
||
### Using it as Integration Tests | ||
|
||
This suite tests how the single features as before behave while development and in production. | ||
A local HTTP server is started, then every single feature is loaded, one by one, to be tested. | ||
|
||
Test are written in `integration/{env|syntax|webpack}.test.js`, depending on their scope. | ||
|
||
For every test case added there is just a little chore to do: | ||
|
||
- a `case` statement must be added in `src/App.js`, which simply perform a dynamic `import()` of the feature | ||
|
||
- add a test case in the appropriate integration test file, which calls and awaits `initDOM` with the previous `SwitchCase` string | ||
|
||
An usual flow for the test itself is something similar to: | ||
|
||
- add an `id` attribute in a target HTML tag in the feature itself | ||
|
||
- since `initDOM` returns a `Document` element, the previous `id` attribute is used to target the feature's DOM and `expect` accordingly | ||
|
||
These tests are run by **mocha** (why not **jest**? See [this issue](https://github.com/facebook/jest/issues/2288)) and the environments used are both `development` and `production`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/usr/bin/env bash | ||
|
||
function print_help { | ||
echo "Usage: ${0} [OPTIONS]" | ||
echo "" | ||
echo "OPTIONS:" | ||
echo " --node-version <version> the node version to use while testing [6]" | ||
echo " --git-branch <branch> the git branch to checkout for testing [the current one]" | ||
echo " --test-suite <suite> which test suite to use ('simple', installs', 'kitchensink', 'all') ['all']" | ||
echo " --yarn if present, use yarn as the package manager" | ||
echo " --interactive gain a bash shell after the test run" | ||
echo " --help print this message and exit" | ||
echo "" | ||
} | ||
|
||
cd $(dirname $0) | ||
|
||
node_version=6 | ||
git_branch=`git rev-parse --abbrev-ref HEAD` | ||
use_yarn=no | ||
test_suite=all | ||
interactive=false | ||
|
||
while [ "$1" != "" ]; do | ||
case $1 in | ||
"--node-version") | ||
shift | ||
node_version=$1 | ||
;; | ||
"--git-branch") | ||
shift | ||
git_branch=$1 | ||
;; | ||
"--yarn") | ||
use_yarn=yes | ||
;; | ||
"--test-suite") | ||
shift | ||
test_suite=$1 | ||
;; | ||
"--interactive") | ||
interactive=true | ||
;; | ||
"--help") | ||
print_help | ||
exit 0 | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
test_command="./tasks/e2e-simple.sh && ./tasks/e2e-kitchensink.sh && ./tasks/e2e-installs.sh" | ||
case ${test_suite} in | ||
"all") | ||
;; | ||
"simple") | ||
test_command="./tasks/e2e-simple.sh" | ||
;; | ||
"kitchensink") | ||
test_command="./tasks/e2e-kitchensink.sh" | ||
;; | ||
"installs") | ||
test_command="./tasks/e2e-installs.sh" | ||
;; | ||
*) | ||
;; | ||
esac | ||
|
||
read -r -d '' command <<- CMD | ||
echo "prefix=~/.npm" > ~/.npmrc | ||
mkdir ~/.npm | ||
export PATH=\$PATH:~/.npm/bin | ||
set -x | ||
git clone /var/create-react-app create-react-app --branch ${git_branch} | ||
cd create-react-app | ||
node --version | ||
npm --version | ||
npm install | ||
set +x | ||
${test_command} && echo -e "\n\e[1;32m✔ Job passed\e[0m" || echo -e "\n\e[1;31m✘ Job failes\e[0m" | ||
$([[ ${interactive} == 'true' ]] && echo 'bash') | ||
CMD | ||
|
||
docker run \ | ||
--env CI=true \ | ||
--env NPM_CONFIG_QUIET=true \ | ||
--env USE_YARN=${use_yarn} \ | ||
--tty \ | ||
--user node \ | ||
--volume ${PWD}/..:/var/create-react-app \ | ||
--workdir /home/node \ | ||
$([[ ${interactive} == 'true' ]] && echo '--interactive') \ | ||
node:${node_version} \ | ||
bash -c "${command}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth putting in a TL:DR?