Skip to content

Commit

Permalink
E2E tests: separate node project (#18806)
Browse files Browse the repository at this point in the history
* Added package.json and working env; some broken tests

* Fixed wrong paths

* Fixed working path in github actions

* Fixed env script path in github actions

* Revert CI check for console log output

* Updated clean command

* Removed unused dependencies

* Removed config dependency
  • Loading branch information
adimoldovan authored Feb 16, 2021
1 parent 997008f commit fb318a7
Show file tree
Hide file tree
Showing 12 changed files with 7,631 additions and 1,223 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,23 @@ jobs:
run: yarn build-production-concurrently

- name: Set up environment
working-directory: projects/plugins/jetpack
working-directory: projects/plugins/jetpack/tests/e2e
env:
NGROK_KEY: ${{ secrets.NGROK_KEY }}
CONFIG_KEY: ${{ secrets.E2E_CONFIG_KEY }}
run: |
yarn install
yarn test-decrypt-config
./tests/e2e/bin/env.sh start
./bin/env.sh start
- name: Run tests
if: matrix.gutenberg == 'no'
working-directory: projects/plugins/jetpack
working-directory: projects/plugins/jetpack/tests/e2e
run: yarn test-e2e

- name: Run tests (excluding updater)
if: matrix.gutenberg == 'latest'
working-directory: projects/plugins/jetpack
working-directory: projects/plugins/jetpack/tests/e2e
run: yarn test-e2e --testPathIgnorePatterns=updater

- name: Upload test artifacts
Expand Down
14 changes: 0 additions & 14 deletions projects/plugins/jetpack/.wp-env.json

This file was deleted.

14 changes: 1 addition & 13 deletions projects/plugins/jetpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
"install-if-deps-outdated": "yarn install --check-files --production=false --frozen-lockfile",
"test-adminpage": "yarn test-client && yarn test-gui",
"test-client": "NODE_ENV=test NODE_PATH=tests:_inc/client tests/runner.js",
"test-decrypt-config": "openssl enc -md sha1 -aes-256-cbc -d -pass env:CONFIG_KEY -in ./tests/e2e/config/encrypted.enc -out ./tests/e2e/config/local-test.js",
"test-e2e": "NODE_CONFIG_DIR='./tests/e2e/config' NODE_CONFIG_ENV=test jest --config ./tests/e2e/jest.config.js --runInBand --verbose",
"test-encrypt-config": "openssl enc -md sha1 -aes-256-cbc -pass env:CONFIG_KEY -in ./tests/e2e/config/local-test.js -out ./tests/e2e/config/encrypted.enc",
"test-extensions": "jest extensions",
"test-gui": "NODE_ENV=test NODE_PATH=tests:_inc/client tests/runner.js gui",
"test-lib": "NODE_ENV=test NODE_PATH=tests:_inc/client tests/runner.js lib",
Expand Down Expand Up @@ -156,22 +153,18 @@
"@babel/preset-react": "7.12.10",
"@babel/preset-typescript": "7.12.7",
"@size-limit/preset-app": "4.9.1",
"@slack/web-api": "6.0.0",
"@testing-library/jest-dom": "5.11.9",
"@testing-library/preact": "2.0.1",
"@wordpress/components": "9.2.6",
"@wordpress/core-data": "2.12.3",
"@wordpress/dependency-extraction-webpack-plugin": "2.4.0",
"@wordpress/e2e-test-utils": "4.3.1",
"@wordpress/editor": "9.12.7",
"@wordpress/env": "1.6.0",
"@wordpress/server-side-render": "1.8.6",
"babel-eslint": "10.1.0",
"chai": "4.2.0",
"chalk": "4.1.0",
"commander": "6.2.1",
"concurrently": "5.3.0",
"config": "3.3.3",
"css-loader": "5.0.1",
"enzyme": "3.11.0",
"eslint": "7.18.0",
Expand All @@ -188,17 +181,13 @@
"eslint-plugin-wpcalypso": "5.0.0",
"glob": "7.1.6",
"jest": "26.6.3",
"jest-allure": "0.1.3",
"jest-playwright-preset": "1.4.5",
"localtunnel": "2.0.1",
"lodash": "4.17.20",
"markdown-spellcheck": "1.3.1",
"mocha": "8.2.1",
"mockery": "2.1.0",
"nock": "13.0.7",
"node-wp-i18n": "1.2.4",
"nyc": "15.1.0",
"playwright": "1.8.0",
"prettier": "npm:wp-prettier@2.0.5",
"react-click-outside": "3.0.1",
"react-test-renderer": "16.13.1",
Expand All @@ -207,8 +196,7 @@
"sinon-chai": "3.5.0",
"size-limit": "4.9.1",
"style-loader": "2.0.0",
"url-loader": "4.1.1",
"winston": "3.3.3"
"url-loader": "4.1.1"
},
"optionalDependencies": {
"react": "16.13.1",
Expand Down
3 changes: 2 additions & 1 deletion projects/plugins/jetpack/tests/e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/node_modules
/config/local-*
/reports
/output
plan-data.txt
e2e_tunnels.txt
jetpack-private-options.txt
/allure-results
14 changes: 14 additions & 0 deletions projects/plugins/jetpack/tests/e2e/.wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"plugins": [ "./plugins/e2e-plan-data-interceptor.php" ],
"config": {
"WP_DEBUG": true,
"WP_DEBUG_LOG": true,
"WP_DEBUG_DISPLAY": false,
"JETPACK_BETA_BLOCKS": true
},
"mappings": {
"wp-content/plugins/jetpack-dev": "../..",
"wp-content/plugins/e2e-plugin-updater.php": "./plugins/e2e-plugin-updater.php",
"wp-content/packages": "../../../../packages/"
}
}
8 changes: 4 additions & 4 deletions projects/plugins/jetpack/tests/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Test environment is a bit complex (It's Jetpack, you know ;)). Tests expect to h
`wp-env` is a wrapper around `docker-compose` that makes it pretty easy to get up and running with E2E tests (and local development as well!). We use a wrapper around `wp-env` that updates some options to make `wp-env` containers to work with Jetpack tests. To setup tests environment:

1. Make sure that docker is installed locally
1. run `./tests/e2e/bin/env.sh start` to start a `wp-env` containers. It will start 2 wordpress installation (we would use only 1 though) & wp-cli container.
1. run `./bin/env.sh start` to start a `wp-env` containers. It will start 2 wordpress installation (we would use only 1 though) & wp-cli container.
1. run the tests: `yarn test-e2e`.

#### Environment variables
Expand All @@ -62,13 +62,13 @@ HEADLESS=false npm run test-e2e
To run an individual test, use the direct path to the spec. For example:

```bash
npm run test-e2e ./tests/e2e/specs/dummy.test.js
npm run test-e2e ./specs/dummy.test.js
```

For the best experience while debugging and/or writing new tests `E2E_DEBUG` constant is recommended to use. Also Jest's `-t` argument could be used to run single test from the test suite(file)

```bash
E2E_DEBUG=true HEADLESS=false npm run test-e2e ./tests/e2e/specs/some.test.js -t 'Test name'
E2E_DEBUG=true HEADLESS=false npm run test-e2e ./specs/some.test.js -t 'Test name'
```

## Writing tests
Expand All @@ -78,7 +78,7 @@ We use the following tools to write e2e tests:
- [Playwright](https://github.com/microsoft/playwright) – a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol
- [jest-playwright](https://github.com/playwright-community/jest-playwright) – provides all required configuration to run tests using Playwright

Tests are kept in `tests/e2e/specs` folder. Every file represents a test suite, which is designed around specific feature under test. Most of the tests rely on an active Jetpack Connection, so we connect a site before running the actual test suite. Its logic can be found in the [`setup-env#maybePreConnect`](./lib/setup-env.js) function. For test suites where pre-connection is not needed, it can be disabled by setting `SKIP_CONNECT` env var to false. Check [`connection.test.js`](./specs/connection.test.js) for example use.
Tests are kept in `/specs` folder. Every file represents a test suite, which is designed around specific feature under test. Most of the tests rely on an active Jetpack Connection, so we connect a site before running the actual test suite. Its logic can be found in the [`setup-env#maybePreConnect`](./lib/setup-env.js) function. For test suites where pre-connection is not needed, it can be disabled by setting `SKIP_CONNECT` env var to false. Check [`connection.test.js`](./specs/connection.test.js) for example use.

The following packages are being used to write tests:

Expand Down
12 changes: 12 additions & 0 deletions projects/plugins/jetpack/tests/e2e/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
esmodules: true,
},
},
],
],
};
4 changes: 2 additions & 2 deletions projects/plugins/jetpack/tests/e2e/config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const config = {
cardCountryCode: 'TR', // using Turkey to force Stripe as payment processor
cardPostCode: '4000',
},
testOutputDir: './tests/e2e/output',
configDir: './tests/e2e/config',
testOutputDir: './output',
configDir: './config',
};

module.exports = config;
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/tests/e2e/lib/utils-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function getTunnelSiteUrl() {
}

export async function resetWordpressInstall() {
const cmd = './tests/e2e/bin/env.sh reset';
const cmd = './bin/env.sh reset';
await execShellCommand( cmd );
}

Expand Down
49 changes: 49 additions & 0 deletions projects/plugins/jetpack/tests/e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "jetpack-e2e-tests",
"private": true,
"description": "[Jetpack](https://jetpack.com/) is a WordPress plugin that supercharges your self-hosted WordPress site with the awesome cloud power of [WordPress.com](https://wordpress.com).",
"homepage": "https://jetpack.com",
"bugs": {
"url": "https://github.com/Automattic/jetpack/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/Automattic/jetpack.git"
},
"license": "GPL-2.0-or-later",
"author": "Automattic",
"scripts": {
"clean": "rm -rf output allure-results",
"distclean": "rm -rf node_modules && yarn clean",
"install-if-deps-outdated": "yarn install --check-files --production=false --frozen-lockfile",
"test-e2e-env": "./bin/env.sh start",
"test-decrypt-config": "openssl enc -md sha1 -aes-256-cbc -d -pass env:CONFIG_KEY -in ./config/encrypted.enc -out ./config/local-test.js",
"test-e2e": "NODE_CONFIG_DIR='./config' jest --config jest.config.js --runInBand --verbose",
"test-encrypt-config": "openssl enc -md sha1 -aes-256-cbc -pass env:CONFIG_KEY -in ./config/local-test.js -out ./config/encrypted.enc"
},
"devDependencies": {
"babel-jest": "26.6.3",
"@babel/core": "7.12.10",
"@babel/preset-env": "7.12.11",
"@slack/web-api": "6.0.0",
"@wordpress/e2e-test-utils": "4.3.1",
"@wordpress/env": "1.6.0",
"@wordpress/eslint-plugin": "8.0.2",
"axios": "0.21.1",
"config": "3.3.3",
"eslint": "7.18.0",
"eslint-plugin-jest": "24.1.3",
"jest": "26.6.3",
"jest-allure": "0.1.3",
"jest-playwright-preset": "1.4.5",
"localtunnel": "2.0.1",
"lodash": "4.17.20",
"mkdirp": "1.0.4",
"playwright": "1.8.0",
"winston": "3.3.3"
},
"engines": {
"node": "^12.20.1",
"yarn": "^1.3.2"
}
}
Loading

0 comments on commit fb318a7

Please sign in to comment.