{
  "name": "@woocommerce/e2e-environment",
  "version": "0.3.0",
  "description": "WooCommerce End to End Testing Environment Configuration.",
  "author": "Automattic",
  "license": "GPL-3.0-or-later",
  "keywords": [
    "wordpress",
    "woocommerce",
    "e2e",
    "puppeteer"
  ],
  "homepage": "https://github.com/woocommerce/woocommerce/tree/trunk/packages/js/e2e-environment/README.md",
  "bugs": {
    "url": "https://github.com/woocommerce/woocommerce/issues"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/woocommerce/woocommerce.git"
  },
  "main": "index.js",
  "module": "build-module/index.js",
  "dependencies": {
    "@automattic/puppeteer-utils": "github:Automattic/puppeteer-utils#0f3ec50",
    "@jest/test-sequencer": "^25.5.4",
    "@slack/web-api": "^6.1.0",
    "@woocommerce/api": "^0.2.0",
    "@wordpress/e2e-test-utils": "^4.16.1",
    "@wordpress/jest-preset-default": "^7.1.3",
    "app-root-path": "^3.0.0",
    "commander": "4.1.1",
    "config": "3.3.3",
    "jest": "^25.1.0",
    "jest-circus": "25.1.0",
    "jest-each": "25.5.0",
    "jest-puppeteer": "^4.4.0",
    "node-stream-zip": "^1.13.6",
    "puppeteer": "2.1.1",
    "readline-sync": "^1.4.10",
    "request": "^2.88.2",
    "sprintf-js": "^1.1.2"
  },
  "devDependencies": {
    "@babel/cli": "7.12.8",
    "@babel/core": "7.12.9",
    "@babel/plugin-proposal-async-generator-functions": "^7.16.4",
    "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
    "@babel/plugin-transform-react-jsx": "^7.16.0",
    "@babel/plugin-transform-runtime": "^7.16.4",
    "@babel/polyfill": "7.12.1",
    "@babel/preset-env": "7.12.7",
    "@wordpress/babel-plugin-import-jsx-pragma": "1.1.3",
    "@wordpress/babel-preset-default": "3.0.2",
    "@wordpress/browserslist-config": "^4.1.0",
    "@wordpress/eslint-plugin": "7.3.0",
    "eslint": "^8.1.0",
    "ndb": "^1.1.5",
    "semver": "^7.3.2"
  },
  "publishConfig": {
    "access": "public"
  },
  "bin": {
    "wc-e2e": "bin/wc-e2e.sh"
  },
  "scripts": {
    "clean": "rm -rf ./build ./build-module",
    "compile": "node ./../bin/build.js",
    "build": "pnpm run clean && pnpm run compile",
    "docker:up": "./bin/docker-compose.sh up",
    "docker:down": "./bin/docker-compose.sh down",
    "docker:clear-all": "docker rmi --force $(docker images -q)",
    "docker:ssh": "docker exec -it $(node utils/get-app-name.js)_wordpress-www /bin/bash",
    "test:e2e": "bash ./bin/wait-for-build.sh && ./bin/e2e-test-integration.js",
    "test:e2e-debug": "bash ./bin/wait-for-build.sh && ./bin/e2e-test-integration.js --dev --debug",
    "test:e2e-dev": "bash ./bin/wait-for-build.sh && ./bin/e2e-test-integration.js --dev",
    "lint": "eslint src"
  },
  "readme": "# End to End Testing Environment\n\nA reusable and extendable E2E testing environment for WooCommerce extensions.\n\n## Installation\n\n```bash\nnpm install @woocommerce/e2e-environment --save\nnpm install jest --global\n```\n\n### Version 0.3.0 and newer\n\nVersion 0.3.0 added a test installer that will populate the `tests/e2e/*` folder with test scripts and configuration files. The installer will create test scripts for E2E test packages that include support for the installer.\n\n- [Adding test scaffolding to E2E test packages](https://github.com/woocommerce/woocommerce/tree/trunk/packages/js/e2e-environment/test-packages.md)\n\n#### Using the installer\n\n- Install a default test environment: `npx wc-e2e install`\n- Install test specs from an E2E tests package: `npx wc-e2e install @woocommerce-e2e-tests [--format cjs] [--ext spec.js]`\n- The default test spec format and extension are `ES6` and `test.js`\n- Remove test specs for an E2E tests package: `npx wc-e2e uninstall @woocommerce-e2e-tests`\n\n## Configuration\n\nThe `@woocommerce/e2e-environment` package exports configuration objects that can be consumed in JavaScript config files in your project. Additionally, it includes a basic hosting container for running tests and includes instructions for creating your Travis CI setup.\n\n### Babel Config\n\nMake sure you `npm install @babel/preset-env --save` if you have not already done so. Afterwards, extend your project's `babel.config.js` to contain the expected presets for E2E testing.\n\n```js\nconst { useE2EBabelConfig } = require( '@woocommerce/e2e-environment' );\n\nmodule.exports = function( api ) {\n\tapi.cache( true );\n\n\treturn useE2EBabelConfig( {\n\t\tpresets: [\n\t\t\t'@wordpress/babel-preset-default',\n\t\t],\n\t} );\n};\n```\n\n### ES Lint Config\n\nThe E2E environment uses Puppeteer for headless browser testing, which uses certain globals variables. Avoid ES Lint errors by extending the config.\n\n```js\nconst { useE2EEsLintConfig } = require( '@woocommerce/e2e-environment' );\n\nmodule.exports = useE2EEsLintConfig( {\n\troot: true,\n\tenv: {\n\t\tbrowser: true,\n\t\tes6: true,\n\t\tnode: true\n\t},\n\tglobals: {\n\t\twp: true,\n\t\twpApiSettings: true,\n\t\twcSettings: true,\n\t\tes6: true\n\t},\n} );\n```\n\n### Jest Config\n\nThe E2E environment uses Jest as a test runner. Extending the base config is necessary in order for Jest to run your project's test files.\n\n```js\nconst path = require( 'path' );\nconst { useE2EJestConfig, resolveLocalE2ePath } = require( '@woocommerce/e2e-environment' );\n\nconst jestConfig = useE2EJestConfig( {\n\troots: [ resolveLocalE2ePath( 'specs' ) ],\n} );\n\nmodule.exports = jestConfig;\n```\n\n**NOTE:** Your project's Jest config file is: `tests/e2e/config/jest.config.js`.\n\n### The Jest Object\n\nThe E2E environment has the following methods to let us control Jest's overall behavior.\n\n|  Function |  Parameters | Description  |\n|-----------|-------------|--------------|\n| `setupJestRetries` | `retries` | Sets the amount of retries on failed tests \n\n**NOTE:** The amount of times failed tests are retried can also be set using the `E2E_RETRY_TIMES` environment variable when executing tests. This can be done using the command below: \n\n```\nE2E_RETRY_TIMES=2 pnpx wc-e2e test:e2e\n```\n\n#### Test Screenshots\n\nThe test sequencer provides a screenshot function for test failures. To enable screenshots on test failure use\n\n```shell script\nWC_E2E_SCREENSHOTS=1 npx wc-e2e test:e2e\n```\n\nTo take adhoc in test screenshots use\n\n```js\nawait takeScreenshotFor( 'name of current step' );\n```\n\nScreenshots will be saved to `tests/e2e/screenshots`. This folder is cleared at the beginning of each test run.\n\n#### Test results\n\nThe test results are saved in `json` format in `tests/e2e/test-results.json`.\n\n### Override default test timeout\n\nTo override the default timeout for the tests, you can use the `DEFAULT_TIMEOUT_OVERRIDE` flag and pass in a maximum timeout in milliseconds. For example, you can pass it in when running the tests from the command line:\n\n```bash\nDEFAULT_TIMEOUT_OVERRIDE=35000 npx wc-e2e test:e2e\n```\n\nThis value will override the default Jest timeout as well as pass the timeout to the following Puppeteer methods:\n\n* page.setDefaultTimeout();\n* page.setDefaultNavigationTimeout();\n\nFor a list of the methods that the above timeout affects, please see the Puppeteer documentation for [`page.setDefaultTimeout()`](https://pptr.dev/#?product=Puppeteer&version=v10.2.0&show=api-pagesetdefaulttimeouttimeout) and [`page.setDefaultNavigationTimeout`](https://pptr.dev/#?product=Puppeteer&version=v10.2.0&show=api-pagesetdefaultnavigationtimeouttimeout) for more information.\n\n### Test Against Previous WordPress Versions\n\nYou can use the `LATEST_WP_VERSION_MINUS` flag to determine how many versions back from the current WordPress version to use in the Docker environment. This is calculated from the current WordPress version minus the set value. For example, if `LATEST_WP_VERSION_MINUS` is set to 1, it will calculate the current WordPress version minus one, and use that for the WordPress Docker container.\n\nFor example, you could run the following command:\n\n```bash\nLATEST_WP_VERSION_MINUS=2 npx wc-e2e docker:up\n```\n\nIn this example, if the current WordPress version is 6.0, this will go two versions back and use the WordPress 5.8 Docker image for the tests.\n\n### Jest Puppeteer Config\n\nThe test sequencer uses the following default Puppeteer configuration:\n\n```js\n// headless\n\tpuppeteerConfig = {\n\t\tlaunch: {\n\t\t\t// Required for the logged out and logged in tests so they don't share app state/token.\n\t\t\tbrowserContext: 'incognito',\n\t\t},\n\t};\n// dev mode\n\tpuppeteerConfig = {\n\t\tlaunch: {\n\t\t\t...jestPuppeteerConfig.launch, // @automattic/puppeteer-utils\n\t\t\tignoreHTTPSErrors: true,\n\t\t\theadless: false,\n\t\t\targs: [ '--window-size=1920,1080', '--user-agent=chrome' ],\n\t\t\tdevtools: true,\n\t\t\tdefaultViewport: {\n\t\t\t\twidth: 1280,\n\t\t\t\theight: 800,\n\t\t\t},\n\t\t},\n\t};\n```\n\nYou can customize the configuration in [`config/jest-puppeteer.config.js`](config/jest-puppeteer.config.js)\n\n```js\nconst { useE2EJestPuppeteerConfig } = require( '@woocommerce/e2e-environment' );\n\nconst puppeteerConfig = useE2EJestPuppeteerConfig( {\n\tlaunch: {\n\t\theadless: false,\n\t}\n} );\n\nmodule.exports = puppeteerConfig;\n```\n\n### Jest Setup\n\nJest provides [setup and teardown functions](https://jestjs.io/docs/setup-teardown) similar to PHPUnit. The default setup and teardown is in [`src/setup/jest.setup.js`](src/setup/jest.setup.js). Additional setup and teardown functions can be added to [`tests/e2e/config/jest.setup.js`](../../../plugins/woocommerce/tests/e2e/config/jest.setup.js)\n\n#### Console filtering\n\n**Added version 0.2.3**\nBy default, messages logged to the console are included in the test results. The test runner suppresses 404 not found and proxy connection messages.\n\nPages that you are testing may contain repetitive console output that you expect. Use `addConsoleSuppression` in your jest setup script to filter these repetitive messages:\n\n```js\naddConsoleSuppression( 'suppress this after the first instance' );\naddConsoleSuppression( 'suppress this completely', false );\n```\n\nConsole suppressions can be removed with `removeConsoleSuppression`. The `searchString` parameter needs to match the `addConsoleSuppression` parameter:\n\n```js\nremoveConsoleSuppression( 'suppress this after the first instance' );\n```\n\n### Container Setup\n\nDepending on the project and testing scenario, the built in testing environment container might not be the best solution for testing. This could be local testing where there is already a testing container, a repository that isn't a plugin or theme and there are multiple folders mapped into the container, or similar. The `e2e-environment` test runner supports using either the built in container or an external container. See the appropriate readme for  details:\n\n- [Built In Container](https://github.com/woocommerce/woocommerce/tree/trunk/packages/js/e2e-environment/builtin.md)\n- [External Container](https://github.com/woocommerce/woocommerce/tree/trunk/packages/js/e2e-environment/external.md)\n\n### Slackbot Setup\n\nThe test runner has support for posting a message and screenshot to a Slack channel when there is an error in a test. It currently supports both Travis CI and Github actions.\n\nTo implement the Slackbot in your CI:\n\n- Create a [Slackbot App](https://slack.com/help/articles/115005265703-Create-a-bot-for-your-workspace)\n- Give the app the following permissions:\n  - `channels:join`\n  - `chat:write`\n  - `files:write`\n  - `incoming-webhook`\n- Add the app to your channel\n- Invite the Slack app user to your channel `/invite @your-slackbot-user`\n- In your CI environment\n  - Add the environment variable `WC_E2E_SCREENSHOTS=1`\n  - Add your app Oauth token to a CI secret `E2E_SLACK_TOKEN`\n  - Add the Slack channel name (without the #) to a CI secret `E2E_SLACK_CHANNEL`\n  - Add the secrets to the test run using the same variable names\n\nTo test your setup, create a pull request that triggers an error in the E2E tests.\n\n## Plugin functions\n\nDepending on the testing scenario, you may wish to upload a plugin that can be used in the tests from a remote location.\n\nTo download a zip file, you can use `getRemotePluginZip( fileUrl )` to get the remote zip. This returns the filepath of the location where the zip file was downloaded to. For example, you could use this method to download the latest nightly version of WooCommerce:\n\n```javascript\nconst pluginZipUrl = 'https://github.com/woocommerce/woocommerce/releases/download/nightly/woocommerce-trunk-nightly.zip';\nawait getRemotePluginZip( pluginZipUrl );\n```\n\nThe above method also makes use of the following utility methods which can also be used:\n\n- `checkNestedZip( zipFilePath, savePath )` used to check a plugin zip file for any nested zip files. If one is found, it is extracted. Returns the path where the zip file is located.\n- `downloadZip( fileUrl, downloadPath )` can be used to directly download a plugin zip file from a remote location to the provided path.\n\n### Get the latest released zip URL\n\nIf you would like to get the latest release zip URL, which can be used in the methods mentioned above, you can use the following helper function to do so:\n\n`getLatestReleaseZipUrl( repository, authorizationToken, getPrerelease, perPage )`\n\nThis will return a string with the latest release URL. Optionally, you can use the `getPrerelease` boolean flag, which defaults to false, on whether or not to get a prerelease instead. The `perPage` flag can be used to return more results when getting the list of releases. The default value is 3. If the repository requires authorization to access, the authorization token can be passed in to the `authorizationToken` argument.\n\n## Additional information\n\nRefer to [`@woocommerce/e2e-core-tests`](https://github.com/woocommerce/woocommerce/tree/trunk/packages/js/e2e-core-tests) for some test examples, and [`plugins/woocommerce/tests/e2e`](https://github.com/woocommerce/woocommerce/tree/trunk/plugins/woocommerce/tests/e2e) for general information on e2e tests.\n"
}