From 0e6d14b12d5dc93b729b903efbb2589497ab9e39 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Mon, 8 Mar 2021 15:07:29 -0400 Subject: [PATCH 01/13] create screenshot on e2e test failure --- .gitignore | 1 + tests/e2e/env/bin/e2e-test-integration.js | 9 +++ tests/e2e/env/config/jest.config.js | 1 + tests/e2e/env/package.json | 1 + tests/e2e/env/src/setup/jest.failure.js | 99 +++++++++++++++++++++++ 5 files changed, 111 insertions(+) create mode 100644 tests/e2e/env/src/setup/jest.failure.js diff --git a/.gitignore b/.gitignore index c86c350cc91..d5584c21452 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,7 @@ tests/cli/vendor /tests/e2e/env/docker/wp-cli/initialize.sh /tests/e2e/env/build/ /tests/e2e/env/build-module/ +/tests/e2e/screenshots /tests/e2e/utils/build/ /tests/e2e/utils/build-module/ diff --git a/tests/e2e/env/bin/e2e-test-integration.js b/tests/e2e/env/bin/e2e-test-integration.js index 4279bf652b8..577a5bb8bc4 100755 --- a/tests/e2e/env/bin/e2e-test-integration.js +++ b/tests/e2e/env/bin/e2e-test-integration.js @@ -15,6 +15,15 @@ program const appPath = getAppRoot(); +// clear the screenshots folder before running tests. +const screenshotPath = path.resolve( appPath, 'tests/e2e/screenshots' ); +if ( fs.existsSync( screenshotPath ) ) { + fs.readdirSync( screenshotPath ).forEach( ( file, index ) => { + const filename = path.join( screenshotPath, file ); + fs.unlinkSync( filename ); + }); +} + const nodeConfigDirs = [ path.resolve( __dirname, '../config' ), ]; diff --git a/tests/e2e/env/config/jest.config.js b/tests/e2e/env/config/jest.config.js index abbaaa1b60e..5514019fa30 100644 --- a/tests/e2e/env/config/jest.config.js +++ b/tests/e2e/env/config/jest.config.js @@ -12,6 +12,7 @@ const { getAppRoot } = require( '../utils' ); let setupFilesAfterEnv = [ path.resolve( __dirname, '../build/setup/jest.setup.js' ), + path.resolve( __dirname, '../build/setup/jest.failure.js' ), 'expect-puppeteer', ]; diff --git a/tests/e2e/env/package.json b/tests/e2e/env/package.json index 92d3348cc2a..14bcec1da6c 100644 --- a/tests/e2e/env/package.json +++ b/tests/e2e/env/package.json @@ -27,6 +27,7 @@ "@wordpress/jest-preset-default": "^6.4.0", "app-root-path": "^3.0.0", "jest": "^25.1.0", + "jest-each": "^26.6.2", "jest-puppeteer": "^4.4.0" }, "devDependencies": { diff --git a/tests/e2e/env/src/setup/jest.failure.js b/tests/e2e/env/src/setup/jest.failure.js new file mode 100644 index 00000000000..36d87e03cc2 --- /dev/null +++ b/tests/e2e/env/src/setup/jest.failure.js @@ -0,0 +1,99 @@ +/** @format */ +/* +import { + sendFailedTestScreenshotToSlack, + sendFailedTestMessageToSlack +} from "./lib/reporter/slack-reporter"; +*/ +const path = require( 'path' ); +const mkdirp = require( 'mkdirp' ); +import { bind } from 'jest-each'; +const { getAppRoot } = require( '../../utils' ); + +/** + * Override the test case method so we can take screenshots of assertion failures. + * + * See: https://github.com/smooth-code/jest-puppeteer/issues/131#issuecomment-469439666 + */ +let currentBlock; + +/** + * We need to reference the original version of Jest. + */ +const originalDescribe = global.describe; +const originalIt = global.it; + +global.describe = (() => { + const describe = ( blockName, callback ) => { + currentBlock = blockName; + + try { + originalDescribe( blockName, callback ); + } catch ( e ) { + throw e; + } + + }; + const only = ( blockName, callback ) => { + originalDescribe.only( blockName, callback ); + }; + const skip = ( blockName, callback ) => { + originalDescribe.skip( blockName, callback ); + }; + + describe.each = bind( describe, false ); + only.each = bind( only, false ); + skip.each = bind( skip, false ); + describe.only = only; + describe.skip = skip; + + return describe; +})(); + +global.it = (() => { + const test = async ( testName, callback ) => { + const testCallback = async () => screenshotTest( testName, callback ); + return originalIt( testName, testCallback ); + }; + const only = ( blockName, callback ) => { + return originalIt.only( blockName, callback ); + }; + const skip = ( blockName, callback ) => { + return originalIt.skip( blockName, callback ); + }; + + test.each = bind( test, false ); + only.each = bind( only, false ); + skip.each = bind( skip, false ); + test.only = only; + test.skip = skip; + + return test; +})(); + +const screenshotTest = async ( testName, callback ) => { + try { + await callback(); + } catch ( e ) { + const testTitle = `${ currentBlock } - ${ testName }`.replace( /\.$/, '' ); + const appPath = getAppRoot(); + const savePath = path.resolve( appPath, 'tests/e2e/screenshots' ); + const filePath = path.join( + savePath, + `${ testTitle }.png`.replace( /[^a-z0-9.-]+/gi, '-' ) + ); + + mkdirp.sync( savePath ); + await page.screenshot( { + path: filePath, + fullPage: true, + } ); + +/* + await sendFailedTestMessageToSlack( testTitle ); + await sendFailedTestScreenshotToSlack( filePath ); +*/ + + throw ( e ); + } +}; From b686a45339d08b160f0f2181f8fa1b05b23c3bac Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Mon, 8 Mar 2021 16:17:27 -0400 Subject: [PATCH 02/13] update package depenendencies --- package-lock.json | 244 ++++++++++++++++++++++++++++++++----- package.json | 2 +- tests/e2e/env/package.json | 2 +- 3 files changed, 213 insertions(+), 35 deletions(-) diff --git a/package-lock.json b/package-lock.json index 687029b381d..55efc99c637 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9141,6 +9141,7 @@ "@wordpress/jest-preset-default": "^6.4.0", "app-root-path": "^3.0.0", "jest": "^25.1.0", + "jest-each": "25.5.0", "jest-puppeteer": "^4.4.0" }, "dependencies": { @@ -9208,7 +9209,7 @@ } }, "prettier": { - "version": "npm:prettier@1.19.1", + "version": "npm:wp-prettier@1.19.1", "resolved": "https://registry.npmjs.org/wp-prettier/-/wp-prettier-1.19.1.tgz", "integrity": "sha512-mqAC2r1NDmRjG+z3KCJ/i61tycKlmADIjxnDhQab+KBxSAGbF/W7/zwB2guy/ypIeKrrftNsIYkNZZQKf3vJcg==", "dev": true @@ -16894,16 +16895,134 @@ } }, "jest-each": { - "version": "24.9.0", - "resolved": "https://registry.npmjs.org/jest-each/-/jest-each-24.9.0.tgz", - "integrity": "sha512-ONi0R4BvW45cw8s2Lrx8YgbeXL1oCQ/wIDwmsM3CqM/nlblNCPmnC3IPQlMbRFZu3wKdQ2U8BqM6lh3LJ5Bsog==", + "version": "25.5.0", + "resolved": "https://registry.npmjs.org/jest-each/-/jest-each-25.5.0.tgz", + "integrity": "sha512-QBogUxna3D8vtiItvn54xXde7+vuzqRrEeaw8r1s+1TG9eZLVJE5ZkKoSUlqFwRjnlaA4hyKGiu9OlkFIuKnjA==", "dev": true, "requires": { - "@jest/types": "^24.9.0", - "chalk": "^2.0.1", - "jest-get-type": "^24.9.0", - "jest-util": "^24.9.0", - "pretty-format": "^24.9.0" + "@jest/types": "^25.5.0", + "chalk": "^3.0.0", + "jest-get-type": "^25.2.6", + "jest-util": "^25.5.0", + "pretty-format": "^25.5.0" + }, + "dependencies": { + "@jest/types": { + "version": "25.5.0", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-25.5.0.tgz", + "integrity": "sha512-OXD0RgQ86Tu3MazKo8bnrkDRaDXXMGUqd+kTtLtK1Zb7CRzQcaSRPPPV37SvYTdevXEBVxe0HXylEjs8ibkmCw==", + "dev": true, + "requires": { + "@types/istanbul-lib-coverage": "^2.0.0", + "@types/istanbul-reports": "^1.1.1", + "@types/yargs": "^15.0.0", + "chalk": "^3.0.0" + } + }, + "@types/yargs": { + "version": "15.0.13", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.13.tgz", + "integrity": "sha512-kQ5JNTrbDv3Rp5X2n/iUu37IJBDU2gsZ5R/g1/KHOOEc5IKfUFjXT6DENPGduh08I/pamwtEq4oul7gUqKTQDQ==", + "dev": true, + "requires": { + "@types/yargs-parser": "*" + } + }, + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "requires": { + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, + "jest-get-type": { + "version": "25.2.6", + "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-25.2.6.tgz", + "integrity": "sha512-DxjtyzOHjObRM+sM1knti6or+eOgcGU4xVSb2HNP1TqO4ahsT+rqZg+nyqHWJSvWgKC5cG3QjGFBqxLghiF/Ig==", + "dev": true + }, + "jest-util": { + "version": "25.5.0", + "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-25.5.0.tgz", + "integrity": "sha512-KVlX+WWg1zUTB9ktvhsg2PXZVdkI1NBevOJSkTKYAyXyH4QSvh+Lay/e/v+bmaFfrkfx43xD8QTfgobzlEXdIA==", + "dev": true, + "requires": { + "@jest/types": "^25.5.0", + "chalk": "^3.0.0", + "graceful-fs": "^4.2.4", + "is-ci": "^2.0.0", + "make-dir": "^3.0.0" + } + }, + "make-dir": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", + "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", + "dev": true, + "requires": { + "semver": "^6.0.0" + } + }, + "pretty-format": { + "version": "25.5.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-25.5.0.tgz", + "integrity": "sha512-kbo/kq2LQ/A/is0PQwsEHM7Ca6//bGPPvU6UnsdDRSKTWxT/ru/xb88v4BJf6a69H+uTytOEsTusT9ksd/1iWQ==", + "dev": true, + "requires": { + "@jest/types": "^25.5.0", + "ansi-regex": "^5.0.0", + "ansi-styles": "^4.0.0", + "react-is": "^16.12.0" + } + }, + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "requires": { + "has-flag": "^4.0.0" + } + } } }, "jest-environment-jsdom": { @@ -17045,6 +17164,21 @@ "jest-util": "^24.9.0", "pretty-format": "^24.9.0", "throat": "^4.0.0" + }, + "dependencies": { + "jest-each": { + "version": "24.9.0", + "resolved": "https://registry.npmjs.org/jest-each/-/jest-each-24.9.0.tgz", + "integrity": "sha512-ONi0R4BvW45cw8s2Lrx8YgbeXL1oCQ/wIDwmsM3CqM/nlblNCPmnC3IPQlMbRFZu3wKdQ2U8BqM6lh3LJ5Bsog==", + "dev": true, + "requires": { + "@jest/types": "^24.9.0", + "chalk": "^2.0.1", + "jest-get-type": "^24.9.0", + "jest-util": "^24.9.0", + "pretty-format": "^24.9.0" + } + } } }, "jest-leak-detector": { @@ -18467,7 +18601,7 @@ "integrity": "sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=" }, "prettier": { - "version": "npm:prettier@1.19.1", + "version": "npm:wp-prettier@1.19.1", "resolved": "https://registry.npmjs.org/wp-prettier/-/wp-prettier-1.19.1.tgz", "integrity": "sha512-mqAC2r1NDmRjG+z3KCJ/i61tycKlmADIjxnDhQab+KBxSAGbF/W7/zwB2guy/ypIeKrrftNsIYkNZZQKf3vJcg==" }, @@ -20923,16 +21057,27 @@ } }, "@wordpress/e2e-test-utils": { - "version": "4.15.0", - "resolved": "https://registry.npmjs.org/@wordpress/e2e-test-utils/-/e2e-test-utils-4.15.0.tgz", - "integrity": "sha512-mCOlNDX/yERd7hIAFB+y9x56iCQ2XyDZkWNlQNMYRH0+EdrQ5H5zE7MSxzycideIC7grxKw/j4RcuyxUdSWGDw==", + "version": "4.16.1", + "resolved": "https://registry.npmjs.org/@wordpress/e2e-test-utils/-/e2e-test-utils-4.16.1.tgz", + "integrity": "sha512-Dpsq5m0VSvjIhro2MjACSzkOkOf1jGEryzgEMW1ikbT6YI+motspHfGtisKXgYhZJOnjV4PwuEg+9lPVnd971g==", "dev": true, "requires": { - "@babel/runtime": "^7.11.2", - "@wordpress/keycodes": "^2.16.0", - "@wordpress/url": "^2.19.0", + "@babel/runtime": "^7.12.5", + "@wordpress/keycodes": "^2.18.0", + "@wordpress/url": "^2.21.0", "lodash": "^4.17.19", "node-fetch": "^2.6.0" + }, + "dependencies": { + "@babel/runtime": { + "version": "7.13.9", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.13.9.tgz", + "integrity": "sha512-aY2kU+xgJ3dJ1eU6FMB9EH8dIe8dmusF1xEku52joLvw6eAFN0AI+WxCLDnpev2LEejWBAy2sBvBOBAjI3zmvA==", + "dev": true, + "requires": { + "regenerator-runtime": "^0.13.4" + } + } } }, "@wordpress/eslint-plugin": { @@ -21001,17 +21146,29 @@ } }, "@wordpress/i18n": { - "version": "3.16.0", - "resolved": "https://registry.npmjs.org/@wordpress/i18n/-/i18n-3.16.0.tgz", - "integrity": "sha512-ZyRWplETgD90caVaBuGBFcnYVpcogji1g9Ctbb5AO2bGFeHpmPpjvWm0NE64iQTtLFEJoaCiq6oqUvAOPIQJpw==", + "version": "3.18.0", + "resolved": "https://registry.npmjs.org/@wordpress/i18n/-/i18n-3.18.0.tgz", + "integrity": "sha512-e1uFWhWYnT0B6s3hyy+xS0S3bwabrvkZA84xxitiIcQvGnZDUPntqv6M9+VrgJVlmd2MR2TbCGJ5xKFAVFr/gA==", "dev": true, "requires": { - "@babel/runtime": "^7.11.2", + "@babel/runtime": "^7.12.5", + "@wordpress/hooks": "^2.11.1", "gettext-parser": "^1.3.1", "lodash": "^4.17.19", "memize": "^1.1.0", "sprintf-js": "^1.1.1", "tannin": "^1.2.0" + }, + "dependencies": { + "@babel/runtime": { + "version": "7.13.9", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.13.9.tgz", + "integrity": "sha512-aY2kU+xgJ3dJ1eU6FMB9EH8dIe8dmusF1xEku52joLvw6eAFN0AI+WxCLDnpev2LEejWBAy2sBvBOBAjI3zmvA==", + "dev": true, + "requires": { + "regenerator-runtime": "^0.13.4" + } + } } }, "@wordpress/jest-console": { @@ -21040,14 +21197,25 @@ } }, "@wordpress/keycodes": { - "version": "2.16.0", - "resolved": "https://registry.npmjs.org/@wordpress/keycodes/-/keycodes-2.16.0.tgz", - "integrity": "sha512-8CfxB+9f08FXMUsaO625abmbx2ZinFUz6upzXbe0Da8W3oy7+/TZz6EWsMVBEWz+alSR3Z2FUZ7xUuopHZFcow==", + "version": "2.18.3", + "resolved": "https://registry.npmjs.org/@wordpress/keycodes/-/keycodes-2.18.3.tgz", + "integrity": "sha512-Lenyw+K2KgiqddBv5fDCh2JRfXFrONWNvPfv1DKXzHXTvBSI0JkU1RVP5WZTcVuEtctCZWL5JbhrkG2I26w68g==", "dev": true, "requires": { - "@babel/runtime": "^7.11.2", - "@wordpress/i18n": "^3.16.0", + "@babel/runtime": "^7.12.5", + "@wordpress/i18n": "^3.18.0", "lodash": "^4.17.19" + }, + "dependencies": { + "@babel/runtime": { + "version": "7.13.9", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.13.9.tgz", + "integrity": "sha512-aY2kU+xgJ3dJ1eU6FMB9EH8dIe8dmusF1xEku52joLvw6eAFN0AI+WxCLDnpev2LEejWBAy2sBvBOBAjI3zmvA==", + "dev": true, + "requires": { + "regenerator-runtime": "^0.13.4" + } + } } }, "@wordpress/prettier-config": { @@ -21057,15 +21225,25 @@ "dev": true }, "@wordpress/url": { - "version": "2.19.0", - "resolved": "https://registry.npmjs.org/@wordpress/url/-/url-2.19.0.tgz", - "integrity": "sha512-RizWbBxYmWBlNd+q89r3N6Y2XO8eCG3VncnXDgbGnhV4e+2z9fjzp1/9C/SORftEn+ix/qBKbqygmkmBqb+wuw==", + "version": "2.21.2", + "resolved": "https://registry.npmjs.org/@wordpress/url/-/url-2.21.2.tgz", + "integrity": "sha512-bLHg4pTo/9mQUkK1s1MU/Sjgnzfy2AkPvPn4ObGA8/4CFkMsDhQGAVhhw5YuezcxvaJkBiKJ+BxgFJ1QKksF6w==", "dev": true, "requires": { - "@babel/runtime": "^7.11.2", + "@babel/runtime": "^7.12.5", "lodash": "^4.17.19", - "qs": "^6.5.2", "react-native-url-polyfill": "^1.1.2" + }, + "dependencies": { + "@babel/runtime": { + "version": "7.13.9", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.13.9.tgz", + "integrity": "sha512-aY2kU+xgJ3dJ1eU6FMB9EH8dIe8dmusF1xEku52joLvw6eAFN0AI+WxCLDnpev2LEejWBAy2sBvBOBAjI3zmvA==", + "dev": true, + "requires": { + "regenerator-runtime": "^0.13.4" + } + } } }, "@xtuc/ieee754": { @@ -34417,9 +34595,9 @@ "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" }, "react-native-url-polyfill": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/react-native-url-polyfill/-/react-native-url-polyfill-1.2.0.tgz", - "integrity": "sha512-hpLZ8RyS3oGVyTOe/HjoqVoCOSkeJvrCoEB3bJsY7t9uh7kpQDV6kgvdlECEafYpxe3RzMrKLVcmWRbPU7CuAw==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/react-native-url-polyfill/-/react-native-url-polyfill-1.3.0.tgz", + "integrity": "sha512-w9JfSkvpqqlix9UjDvJjm1EjSt652zVQ6iwCIj1cVVkwXf4jQhQgTNXY6EVTwuAmUjg6BC6k9RHCBynoLFo3IQ==", "dev": true, "requires": { "whatwg-url-without-unicode": "8.0.0-3" diff --git a/package.json b/package.json index 210c07c286d..da06d881283 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "@woocommerce/e2e-utils": "file:tests/e2e/utils", "@wordpress/babel-plugin-import-jsx-pragma": "1.1.3", "@wordpress/babel-preset-default": "3.0.2", - "@wordpress/e2e-test-utils": "^4.6.0", + "@wordpress/e2e-test-utils": "^4.16.1", "@wordpress/eslint-plugin": "7.3.0", "autoprefixer": "9.8.6", "babel-eslint": "10.1.0", diff --git a/tests/e2e/env/package.json b/tests/e2e/env/package.json index 14bcec1da6c..78cf6d70a6e 100644 --- a/tests/e2e/env/package.json +++ b/tests/e2e/env/package.json @@ -27,7 +27,7 @@ "@wordpress/jest-preset-default": "^6.4.0", "app-root-path": "^3.0.0", "jest": "^25.1.0", - "jest-each": "^26.6.2", + "jest-each": "25.5.0", "jest-puppeteer": "^4.4.0" }, "devDependencies": { From 50e9ff278323d3ea9ef9dd8475e5eeb1fe7071e1 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Mon, 8 Mar 2021 16:56:47 -0400 Subject: [PATCH 03/13] make screenshots optional --- tests/e2e/env/CHANGELOG.md | 9 +++++---- tests/e2e/env/README.md | 10 ++++++++++ tests/e2e/env/bin/e2e-test-integration.js | 16 +++++++++------- tests/e2e/env/config/jest.config.js | 7 ++++++- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/tests/e2e/env/CHANGELOG.md b/tests/e2e/env/CHANGELOG.md index 8e6272ba44b..e7aaafd6fc4 100644 --- a/tests/e2e/env/CHANGELOG.md +++ b/tests/e2e/env/CHANGELOG.md @@ -1,11 +1,11 @@ # Unreleased +## Added + +- Support for screenshots on test errors + # 0.2.0 -## Fixed - -- Return jest exit code from `npx wc-e2e test:e2e*` - ## Added - support for custom container name @@ -15,6 +15,7 @@ ## Fixed +- Return jest exit code from `npx wc-e2e test:e2e*` - Remove redundant `puppeteer` dependency - Support for admin user configuration from `default.json` diff --git a/tests/e2e/env/README.md b/tests/e2e/env/README.md index f9998325c85..c109dc4f162 100644 --- a/tests/e2e/env/README.md +++ b/tests/e2e/env/README.md @@ -71,6 +71,16 @@ module.exports = jestConfig; **NOTE:** Your project's Jest config file is expected to be: `tests/e2e/config/jest.config.js`. +#### Test Screenshots + +The test sequencer provides a screenshot function for test failures. To enable screenshots on test failure use + +```shell script +WC_E2E_SCREENSHOTS=1 npx wc-e2e test:e2e +``` + +Screenshots will be saved to `tests/e2e/screenshots` + ### Jest Puppeteer Config The test sequencer uses the following default Puppeteer configuration: diff --git a/tests/e2e/env/bin/e2e-test-integration.js b/tests/e2e/env/bin/e2e-test-integration.js index 577a5bb8bc4..46d457d974b 100755 --- a/tests/e2e/env/bin/e2e-test-integration.js +++ b/tests/e2e/env/bin/e2e-test-integration.js @@ -5,7 +5,7 @@ const program = require( 'commander' ); const path = require( 'path' ); const fs = require( 'fs' ); const { getAppRoot } = require( '../utils' ); -const { JEST_PUPPETEER_CONFIG } = process.env; +const { WC_E2E_SCREENSHOTS, JEST_PUPPETEER_CONFIG } = process.env; program .usage( ' [options]' ) @@ -16,12 +16,14 @@ program const appPath = getAppRoot(); // clear the screenshots folder before running tests. -const screenshotPath = path.resolve( appPath, 'tests/e2e/screenshots' ); -if ( fs.existsSync( screenshotPath ) ) { - fs.readdirSync( screenshotPath ).forEach( ( file, index ) => { - const filename = path.join( screenshotPath, file ); - fs.unlinkSync( filename ); - }); +if ( WC_E2E_SCREENSHOTS ) { + const screenshotPath = path.resolve(appPath, 'tests/e2e/screenshots'); + if (fs.existsSync(screenshotPath)) { + fs.readdirSync(screenshotPath).forEach((file, index) => { + const filename = path.join(screenshotPath, file); + fs.unlinkSync(filename); + }); + } } const nodeConfigDirs = [ diff --git a/tests/e2e/env/config/jest.config.js b/tests/e2e/env/config/jest.config.js index 5514019fa30..0f87fa06527 100644 --- a/tests/e2e/env/config/jest.config.js +++ b/tests/e2e/env/config/jest.config.js @@ -2,6 +2,7 @@ * External Dependencies */ const { jestConfig } = require( '@automattic/puppeteer-utils' ); +const { WC_E2E_SCREENSHOTS } = process.env; const path = require( 'path' ); const fs = require( 'fs' ); @@ -10,9 +11,13 @@ const fs = require( 'fs' ); */ const { getAppRoot } = require( '../utils' ); +let failureSetup = []; +if ( WC_E2E_SCREENSHOTS ) { + failureSetup.push( path.resolve( __dirname, '../build/setup/jest.failure.js' ) ); +} let setupFilesAfterEnv = [ path.resolve( __dirname, '../build/setup/jest.setup.js' ), - path.resolve( __dirname, '../build/setup/jest.failure.js' ), + ...failureSetup, 'expect-puppeteer', ]; From 4c8897303996006849951bcd72f7560d16827989 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Mon, 8 Mar 2021 19:22:55 -0400 Subject: [PATCH 04/13] add slack channel support --- .github/workflows/pr-build-and-e2e-tests.yml | 2 + tests/e2e/env/src/setup/jest.failure.js | 25 +++- tests/e2e/env/src/slack/index.js | 1 + tests/e2e/env/src/slack/reporter.js | 124 +++++++++++++++++++ 4 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 tests/e2e/env/src/slack/index.js create mode 100644 tests/e2e/env/src/slack/reporter.js diff --git a/.github/workflows/pr-build-and-e2e-tests.yml b/.github/workflows/pr-build-and-e2e-tests.yml index bb66e43bc44..e82982eecc7 100644 --- a/.github/workflows/pr-build-and-e2e-tests.yml +++ b/.github/workflows/pr-build-and-e2e-tests.yml @@ -106,4 +106,6 @@ jobs: - name: Run tests command. working-directory: code/woocommerce + env: + WC_E2E_SCREENSHOTS: 1 run: npx wc-e2e test:e2e diff --git a/tests/e2e/env/src/setup/jest.failure.js b/tests/e2e/env/src/setup/jest.failure.js index 36d87e03cc2..2a613b6a29a 100644 --- a/tests/e2e/env/src/setup/jest.failure.js +++ b/tests/e2e/env/src/setup/jest.failure.js @@ -1,10 +1,9 @@ /** @format */ -/* import { sendFailedTestScreenshotToSlack, - sendFailedTestMessageToSlack -} from "./lib/reporter/slack-reporter"; -*/ + sendFailedTestMessageToSlack, +} from '../slack'; + const path = require( 'path' ); const mkdirp = require( 'mkdirp' ); import { bind } from 'jest-each'; @@ -23,6 +22,10 @@ let currentBlock; const originalDescribe = global.describe; const originalIt = global.it; +/** + * A custom describe function that stores the name of the describe block. + * @type {describe} + */ global.describe = (() => { const describe = ( blockName, callback ) => { currentBlock = blockName; @@ -50,6 +53,12 @@ global.describe = (() => { return describe; })(); +/** + * A custom it function that wraps the test function in a callback + * which takes a screenshot on test failure. + * + * @type {function(*=, *=): *} + */ global.it = (() => { const test = async ( testName, callback ) => { const testCallback = async () => screenshotTest( testName, callback ); @@ -71,6 +80,12 @@ global.it = (() => { return test; })(); +/** + * Save a screenshot during a test if the test fails. + * @param testName + * @param callback + * @returns {Promise} + */ const screenshotTest = async ( testName, callback ) => { try { await callback(); @@ -89,10 +104,8 @@ const screenshotTest = async ( testName, callback ) => { fullPage: true, } ); -/* await sendFailedTestMessageToSlack( testTitle ); await sendFailedTestScreenshotToSlack( filePath ); -*/ throw ( e ); } diff --git a/tests/e2e/env/src/slack/index.js b/tests/e2e/env/src/slack/index.js new file mode 100644 index 00000000000..aeab8f42dd6 --- /dev/null +++ b/tests/e2e/env/src/slack/index.js @@ -0,0 +1 @@ +export * from './reporter'; diff --git a/tests/e2e/env/src/slack/reporter.js b/tests/e2e/env/src/slack/reporter.js new file mode 100644 index 00000000000..e99d689ec20 --- /dev/null +++ b/tests/e2e/env/src/slack/reporter.js @@ -0,0 +1,124 @@ +const { createReadStream } = require( 'fs' ); +const { WebClient, ErrorCode } = require( '@slack/web-api' ); +const { + GITHUB_ACTIONS, + GITHUB_REF, + GITHUB_SHA, + GITHUB_REPOSITORY, + GITHUB_RUN_ID, + TRAVIS_PULL_REQUEST_BRANCH, + TRAVIS_COMMIT, + TRAVIS_BUILD_WEB_URL, + SLACK_TOKEN, + SLACK_CHANNEL, + WC_E2E_SCREENSHOTS, +} = process.env; + +let web; + +/** + * Initialize the Slack web client. + * + * @returns {WebClient} + */ +const initializeWeb = () => { + if ( ! web ) { + web = new WebClient( SLACK_TOKEN ); + } + return web; +}; + +/** + * Initialize Slack parameters if tests are running in CI. + * @returns {Object|boolean} + */ +const initializeSlack = () => { + if ( ! WC_E2E_SCREENSHOTS || ! SLACK_TOKEN ) { + return false; + } + if ( ! GITHUB_ACTIONS && ! TRAVIS_PULL_REQUEST_BRANCH ) { + return false; + } + // Build PR info + if ( GITHUB_ACTIONS ) { + const refArray = GITHUB_REF.split( '/' ); + const branch = refArray.pop(); + return { + branch, + commit: GITHUB_SHA, + webUrl: `https://github.com/${ GITHUB_REPOSITORY }/actions/runs/${ GITHUB_RUN_ID }`, + }; + } + + return { + branch: TRAVIS_PULL_REQUEST_BRANCH, + commit: TRAVIS_COMMIT, + webUrl: TRAVIS_BUILD_WEB_URL, + }; +}; + +/** + * Post a message to a Slack channel for a failed test. + * + * @param testName + * @returns {Promise} + */ +export async function sendFailedTestMessageToSlack( testName ) { + const pr = initializeSlack(); + if ( ! pr ) { + return; + } + const web = initializeWeb(); + + try { + // For details, see: https://api.slack.com/methods/chat.postMessage + await web.chat.postMessage({ + text: `Test failed on *${ pr.branch }* branch. \n + The commit this build is testing is *${ pr.commit }*. \n + The name of the test that failed: *${ testName }*. \n + See screenshot of the failed test below. *Build log* could be found here: ${ pr.webUrl }`, + channel: SLACK_CHANNEL, + }); + } catch ( error ) { + // Check the code property and log the response + if ( error.code === ErrorCode.PlatformError || error.code === ErrorCode.RequestError || + error.code === ErrorCode.RateLimitedError || error.code === ErrorCode.HTTPError ) { + console.log( error.data ); + } else { + // Some other error, oh no! + console.log( 'The error occurred does not match an error we are checking for in this block.' ); + } + } +} + +/** + * Post a screenshot to a Slack channel for a failed test. + * @param screenshotOfFailedTest + * @returns {Promise} + */ +export async function sendFailedTestScreenshotToSlack( screenshotOfFailedTest ) { + const pr = initializeSlack(); + if ( ! pr ) { + return; + } + const web = initializeWeb(); + const filename = 'screenshot_of_failed_test.png'; + + try { + // For details, see: https://api.slack.com/methods/files.upload + await web.files.upload({ + filename, + file: createReadStream( screenshotOfFailedTest ), + channels: SLACK_CHANNEL, + }); + } catch ( error ) { + // Check the code property and log the response + if ( error.code === ErrorCode.PlatformError || error.code === ErrorCode.RequestError || + error.code === ErrorCode.RateLimitedError || error.code === ErrorCode.HTTPError ) { + console.log( error.data ); + } else { + // Some other error, oh no! + console.log( 'The error occurred does not match an error we are checking for in this block.' ); + } + } +} From 2d8ab6e2f8123c7a334b72414801315583690ac7 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Tue, 9 Mar 2021 10:19:43 -0400 Subject: [PATCH 05/13] include the current block in screenshot params --- tests/e2e/env/src/setup/jest.failure.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/e2e/env/src/setup/jest.failure.js b/tests/e2e/env/src/setup/jest.failure.js index 2a613b6a29a..de8c655ec2e 100644 --- a/tests/e2e/env/src/setup/jest.failure.js +++ b/tests/e2e/env/src/setup/jest.failure.js @@ -61,14 +61,14 @@ global.describe = (() => { */ global.it = (() => { const test = async ( testName, callback ) => { - const testCallback = async () => screenshotTest( testName, callback ); + const testCallback = async () => screenshotTest( currentBlock, testName, callback ); return originalIt( testName, testCallback ); }; - const only = ( blockName, callback ) => { - return originalIt.only( blockName, callback ); + const only = ( testName, callback ) => { + return originalIt.only( testName, callback ); }; - const skip = ( blockName, callback ) => { - return originalIt.skip( blockName, callback ); + const skip = ( testName, callback ) => { + return originalIt.skip( testName, callback ); }; test.each = bind( test, false ); @@ -86,11 +86,11 @@ global.it = (() => { * @param callback * @returns {Promise} */ -const screenshotTest = async ( testName, callback ) => { +const screenshotTest = async ( blockName, testName, callback ) => { try { await callback(); } catch ( e ) { - const testTitle = `${ currentBlock } - ${ testName }`.replace( /\.$/, '' ); + const testTitle = `${ blockName } - ${ testName }`.replace( /\.$/, '' ); const appPath = getAppRoot(); const savePath = path.resolve( appPath, 'tests/e2e/screenshots' ); const filePath = path.join( From 0395457e0c10c08e9b3236b4c577821794329d68 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Tue, 9 Mar 2021 11:33:29 -0400 Subject: [PATCH 06/13] fix api package build errors --- tests/e2e/api/src/framework/model-repository.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/e2e/api/src/framework/model-repository.ts b/tests/e2e/api/src/framework/model-repository.ts index ca598404b93..9c30993a83a 100644 --- a/tests/e2e/api/src/framework/model-repository.ts +++ b/tests/e2e/api/src/framework/model-repository.ts @@ -401,7 +401,7 @@ export class ModelRepository< T extends ModelRepositoryParams > implements } return ( this.listHook as ListChildFn< T > )( - paramsOrParent as ParentID< T >, + ( paramsOrParent as unknown ) as ParentID< T >, params, ); } @@ -428,7 +428,7 @@ export class ModelRepository< T extends ModelRepositoryParams > implements } return ( this.createHook as CreateChildFn< T > )( - propertiesOrParent as ParentID, + ( propertiesOrParent as unknown ) as ParentID, properties as Partial< ModelClass >, ); } @@ -455,7 +455,7 @@ export class ModelRepository< T extends ModelRepositoryParams > implements } return ( this.readHook as ReadChildFn< T > )( - idOrParent as ParentID< T >, + ( idOrParent as unknown ) as ParentID< T >, childID, ); } @@ -480,14 +480,14 @@ export class ModelRepository< T extends ModelRepositoryParams > implements if ( properties === undefined ) { return ( this.updateHook as UpdateFn< T > )( idOrParent as ModelID, - propertiesOrChildID as UpdateParams< T >, + ( propertiesOrChildID as unknown ) as UpdateParams< T >, ); } return ( this.updateHook as UpdateChildFn< T > )( - idOrParent as ParentID< T >, + ( idOrParent as unknown ) as ParentID< T >, propertiesOrChildID as ModelID, - properties, + ( properties as unknown ) as UpdateParams< T >, ); } @@ -513,7 +513,7 @@ export class ModelRepository< T extends ModelRepositoryParams > implements } return ( this.deleteHook as DeleteChildFn< T > )( - idOrParent as ParentID< T >, + ( idOrParent as unknown ) as ParentID< T >, childID, ); } From bb907a6acdd2b7ff73d63cda4dfdbf80367b3f6e Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Tue, 9 Mar 2021 16:11:48 -0400 Subject: [PATCH 07/13] add slack secrets, deliberately break test --- .github/workflows/pr-build-and-e2e-tests.yml | 2 ++ .../specs/shopper/front-end-my-account.test.js | 2 +- tests/e2e/env/src/slack/reporter.js | 12 ++++++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr-build-and-e2e-tests.yml b/.github/workflows/pr-build-and-e2e-tests.yml index e82982eecc7..d43ee761be2 100644 --- a/.github/workflows/pr-build-and-e2e-tests.yml +++ b/.github/workflows/pr-build-and-e2e-tests.yml @@ -108,4 +108,6 @@ jobs: working-directory: code/woocommerce env: WC_E2E_SCREENSHOTS: 1 + E2E_SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} + E2E_SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }} run: npx wc-e2e test:e2e diff --git a/tests/e2e/core-tests/specs/shopper/front-end-my-account.test.js b/tests/e2e/core-tests/specs/shopper/front-end-my-account.test.js index ac283f2f20a..5ad893c0a1e 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-my-account.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-my-account.test.js @@ -11,7 +11,7 @@ const runMyAccountPageTest = () => { describe('My account page', () => { it('allows customer to login', async () => { await merchant.logout(); - await shopper.login(); +// await shopper.login(); await expect(page).toMatch('Hello'); await expect(page).toMatchElement('.woocommerce-MyAccount-navigation-link', {text: 'Dashboard'}); await expect(page).toMatchElement('.woocommerce-MyAccount-navigation-link', {text: 'Orders'}); diff --git a/tests/e2e/env/src/slack/reporter.js b/tests/e2e/env/src/slack/reporter.js index e99d689ec20..fedb5593280 100644 --- a/tests/e2e/env/src/slack/reporter.js +++ b/tests/e2e/env/src/slack/reporter.js @@ -9,8 +9,8 @@ const { TRAVIS_PULL_REQUEST_BRANCH, TRAVIS_COMMIT, TRAVIS_BUILD_WEB_URL, - SLACK_TOKEN, - SLACK_CHANNEL, + E2E_SLACK_TOKEN, + E2E_SLACK_CHANNEL, WC_E2E_SCREENSHOTS, } = process.env; @@ -23,7 +23,7 @@ let web; */ const initializeWeb = () => { if ( ! web ) { - web = new WebClient( SLACK_TOKEN ); + web = new WebClient( E2E_SLACK_TOKEN ); } return web; }; @@ -33,7 +33,7 @@ const initializeWeb = () => { * @returns {Object|boolean} */ const initializeSlack = () => { - if ( ! WC_E2E_SCREENSHOTS || ! SLACK_TOKEN ) { + if ( ! WC_E2E_SCREENSHOTS || ! E2E_SLACK_TOKEN ) { return false; } if ( ! GITHUB_ACTIONS && ! TRAVIS_PULL_REQUEST_BRANCH ) { @@ -77,7 +77,7 @@ export async function sendFailedTestMessageToSlack( testName ) { The commit this build is testing is *${ pr.commit }*. \n The name of the test that failed: *${ testName }*. \n See screenshot of the failed test below. *Build log* could be found here: ${ pr.webUrl }`, - channel: SLACK_CHANNEL, + channel: E2E_SLACK_CHANNEL, }); } catch ( error ) { // Check the code property and log the response @@ -109,7 +109,7 @@ export async function sendFailedTestScreenshotToSlack( screenshotOfFailedTest ) await web.files.upload({ filename, file: createReadStream( screenshotOfFailedTest ), - channels: SLACK_CHANNEL, + channels: E2E_SLACK_CHANNEL, }); } catch ( error ) { // Check the code property and log the response From 12c0793217a2bc9cfde86cffb29627ffc1a9195b Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Tue, 9 Mar 2021 16:49:47 -0400 Subject: [PATCH 08/13] add token to calls, remove block from test title --- tests/e2e/env/src/setup/jest.failure.js | 8 +++----- tests/e2e/env/src/slack/reporter.js | 6 ++++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/e2e/env/src/setup/jest.failure.js b/tests/e2e/env/src/setup/jest.failure.js index de8c655ec2e..31a906a10ee 100644 --- a/tests/e2e/env/src/setup/jest.failure.js +++ b/tests/e2e/env/src/setup/jest.failure.js @@ -14,7 +14,6 @@ const { getAppRoot } = require( '../../utils' ); * * See: https://github.com/smooth-code/jest-puppeteer/issues/131#issuecomment-469439666 */ -let currentBlock; /** * We need to reference the original version of Jest. @@ -28,7 +27,6 @@ const originalIt = global.it; */ global.describe = (() => { const describe = ( blockName, callback ) => { - currentBlock = blockName; try { originalDescribe( blockName, callback ); @@ -61,7 +59,7 @@ global.describe = (() => { */ global.it = (() => { const test = async ( testName, callback ) => { - const testCallback = async () => screenshotTest( currentBlock, testName, callback ); + const testCallback = async () => screenshotTest( testName, callback ); return originalIt( testName, testCallback ); }; const only = ( testName, callback ) => { @@ -86,11 +84,11 @@ global.it = (() => { * @param callback * @returns {Promise} */ -const screenshotTest = async ( blockName, testName, callback ) => { +const screenshotTest = async ( testName, callback ) => { try { await callback(); } catch ( e ) { - const testTitle = `${ blockName } - ${ testName }`.replace( /\.$/, '' ); + const testTitle = testName.replace( /\.$/, '' ); const appPath = getAppRoot(); const savePath = path.resolve( appPath, 'tests/e2e/screenshots' ); const filePath = path.join( diff --git a/tests/e2e/env/src/slack/reporter.js b/tests/e2e/env/src/slack/reporter.js index fedb5593280..9c63467e668 100644 --- a/tests/e2e/env/src/slack/reporter.js +++ b/tests/e2e/env/src/slack/reporter.js @@ -73,11 +73,12 @@ export async function sendFailedTestMessageToSlack( testName ) { try { // For details, see: https://api.slack.com/methods/chat.postMessage await web.chat.postMessage({ + channel: E2E_SLACK_CHANNEL, + token: E2E_SLACK_TOKEN, text: `Test failed on *${ pr.branch }* branch. \n The commit this build is testing is *${ pr.commit }*. \n The name of the test that failed: *${ testName }*. \n See screenshot of the failed test below. *Build log* could be found here: ${ pr.webUrl }`, - channel: E2E_SLACK_CHANNEL, }); } catch ( error ) { // Check the code property and log the response @@ -107,9 +108,10 @@ export async function sendFailedTestScreenshotToSlack( screenshotOfFailedTest ) try { // For details, see: https://api.slack.com/methods/files.upload await web.files.upload({ + channels: E2E_SLACK_CHANNEL, + token: E2E_SLACK_TOKEN, filename, file: createReadStream( screenshotOfFailedTest ), - channels: E2E_SLACK_CHANNEL, }); } catch ( error ) { // Check the code property and log the response From ac94f70a16bd99864d5d0998c95740ab8c2ffecf Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Wed, 10 Mar 2021 14:51:18 -0400 Subject: [PATCH 09/13] update secret names with E2E_ --- .github/workflows/pr-build-and-e2e-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-build-and-e2e-tests.yml b/.github/workflows/pr-build-and-e2e-tests.yml index d43ee761be2..936752e6090 100644 --- a/.github/workflows/pr-build-and-e2e-tests.yml +++ b/.github/workflows/pr-build-and-e2e-tests.yml @@ -108,6 +108,6 @@ jobs: working-directory: code/woocommerce env: WC_E2E_SCREENSHOTS: 1 - E2E_SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} - E2E_SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }} + E2E_SLACK_TOKEN: ${{ secrets.E2E_SLACK_TOKEN }} + E2E_SLACK_CHANNEL: ${{ secrets.E2E_SLACK_CHANNEL }} run: npx wc-e2e test:e2e From d683e242599238e4a8e3d9c9cc0eebf2ac9f439b Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Thu, 11 Mar 2021 10:46:04 -0400 Subject: [PATCH 10/13] explicitly join the slack channel --- tests/e2e/env/src/slack/reporter.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/e2e/env/src/slack/reporter.js b/tests/e2e/env/src/slack/reporter.js index 9c63467e668..a1f43c5a233 100644 --- a/tests/e2e/env/src/slack/reporter.js +++ b/tests/e2e/env/src/slack/reporter.js @@ -71,6 +71,8 @@ export async function sendFailedTestMessageToSlack( testName ) { const web = initializeWeb(); try { + // Adding the app does not add the app user to the channel + await web.conversations.join( E2E_SLACK_CHANNEL ); // For details, see: https://api.slack.com/methods/chat.postMessage await web.chat.postMessage({ channel: E2E_SLACK_CHANNEL, From 025b92d5da32fd575e744a895fe6d66e90859d7a Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Fri, 12 Mar 2021 12:39:03 -0400 Subject: [PATCH 11/13] output error on unknown error, expand PR info --- tests/e2e/env/src/slack/reporter.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/e2e/env/src/slack/reporter.js b/tests/e2e/env/src/slack/reporter.js index a1f43c5a233..83e74fd8a4c 100644 --- a/tests/e2e/env/src/slack/reporter.js +++ b/tests/e2e/env/src/slack/reporter.js @@ -64,8 +64,8 @@ const initializeSlack = () => { * @returns {Promise} */ export async function sendFailedTestMessageToSlack( testName ) { - const pr = initializeSlack(); - if ( ! pr ) { + const { branch, commit, webUrl } = initializeSlack(); + if ( ! branch ) { return; } const web = initializeWeb(); @@ -77,10 +77,10 @@ export async function sendFailedTestMessageToSlack( testName ) { await web.chat.postMessage({ channel: E2E_SLACK_CHANNEL, token: E2E_SLACK_TOKEN, - text: `Test failed on *${ pr.branch }* branch. \n - The commit this build is testing is *${ pr.commit }*. \n + text: `Test failed on *${ branch }* branch. \n + The commit this build is testing is *${ commit }*. \n The name of the test that failed: *${ testName }*. \n - See screenshot of the failed test below. *Build log* could be found here: ${ pr.webUrl }`, + See screenshot of the failed test below. *Build log* could be found here: ${ webUrl }`, }); } catch ( error ) { // Check the code property and log the response @@ -89,7 +89,10 @@ export async function sendFailedTestMessageToSlack( testName ) { console.log( error.data ); } else { // Some other error, oh no! - console.log( 'The error occurred does not match an error we are checking for in this block.' ); + console.log( + 'The error occurred does not match an error we are checking for in this block.', + error + ); } } } From 3fa03509dbea88c52fe608b019d5ff8f183ecf04 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Fri, 12 Mar 2021 14:00:23 -0400 Subject: [PATCH 12/13] add token to channel join call, update package-lock --- package-lock.json | 268 ++++++++++++++++------------ tests/e2e/env/package.json | 1 + tests/e2e/env/src/slack/reporter.js | 19 +- 3 files changed, 176 insertions(+), 112 deletions(-) diff --git a/package-lock.json b/package-lock.json index 55efc99c637..a23aaf9bbeb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3890,6 +3890,70 @@ "@sinonjs/commons": "^1.7.0" } }, + "@slack/logger": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@slack/logger/-/logger-2.0.0.tgz", + "integrity": "sha512-OkIJpiU2fz6HOJujhlhfIGrc8hB4ibqtf7nnbJQDerG0BqwZCfmgtK5sWzZ0TkXVRBKD5MpLrTmCYyMxoMCgPw==", + "dev": true, + "requires": { + "@types/node": ">=8.9.0" + } + }, + "@slack/types": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/@slack/types/-/types-1.10.0.tgz", + "integrity": "sha512-tA7GG7Tj479vojfV3AoxbckalA48aK6giGjNtgH6ihpLwTyHE3fIgRrvt8TWfLwW8X8dyu7vgmAsGLRG7hWWOg==", + "dev": true + }, + "@slack/web-api": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/@slack/web-api/-/web-api-6.1.0.tgz", + "integrity": "sha512-9MVHw+rDBaFvkvzm8lDNH/nlkvJCDKRIjFGMdpbyZlVLsm4rcht4qyiL71bqdyLATHXJnWknb/sl0FQGLLobIA==", + "dev": true, + "requires": { + "@slack/logger": ">=1.0.0 <3.0.0", + "@slack/types": "^1.7.0", + "@types/is-stream": "^1.1.0", + "@types/node": ">=12.0.0", + "axios": "^0.21.1", + "eventemitter3": "^3.1.0", + "form-data": "^2.5.0", + "is-stream": "^1.1.0", + "p-queue": "^6.6.1", + "p-retry": "^4.0.0" + }, + "dependencies": { + "form-data": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz", + "integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==", + "dev": true, + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.6", + "mime-types": "^2.1.12" + } + }, + "p-queue": { + "version": "6.6.2", + "resolved": "https://registry.npmjs.org/p-queue/-/p-queue-6.6.2.tgz", + "integrity": "sha512-RwFpb72c/BhQLEXIZ5K2e+AhgNVmIejGlTgiB9MzZ0e93GRvqZ7uSi0dvRF7/XIXDeNkra2fNHBxTyPDGySpjQ==", + "dev": true, + "requires": { + "eventemitter3": "^4.0.4", + "p-timeout": "^3.2.0" + }, + "dependencies": { + "eventemitter3": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", + "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==", + "dev": true + } + } + } + } + }, "@tannin/compile": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@tannin/compile/-/compile-1.1.0.tgz", @@ -4002,6 +4066,15 @@ "@types/node": "*" } }, + "@types/is-stream": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@types/is-stream/-/is-stream-1.1.0.tgz", + "integrity": "sha512-jkZatu4QVbR60mpIzjINmtS1ZF4a/FqdTUTBeQDVOQ2PYyidtwFKr0B5G6ERukKwliq+7mIXvxyppwzG5EgRYg==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/istanbul-lib-coverage": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz", @@ -4069,6 +4142,12 @@ "integrity": "sha512-5qOlnZscTn4xxM5MeGXAMOsIOIKIbh9e85zJWfBRVPlRMEVawzoPhINYbRGkBZCI8LxvBe7tJCdWiarA99OZfQ==", "dev": true }, + "@types/retry": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.0.tgz", + "integrity": "sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==", + "dev": true + }, "@types/stack-utils": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-1.0.1.tgz", @@ -9137,6 +9216,7 @@ "requires": { "@automattic/puppeteer-utils": "github:Automattic/puppeteer-utils#0f3ec50", "@jest/test-sequencer": "^25.5.4", + "@slack/web-api": "^6.1.0", "@wordpress/e2e-test-utils": "^4.15.0", "@wordpress/jest-preset-default": "^6.4.0", "app-root-path": "^3.0.0", @@ -9162,6 +9242,24 @@ "puppeteer": "^2.0.0" }, "dependencies": { + "@slack/web-api": { + "version": "5.15.0", + "resolved": "https://registry.npmjs.org/@slack/web-api/-/web-api-5.15.0.tgz", + "integrity": "sha512-tjQ8Zqv/Fmj9SOL9yIEd7IpTiKfKHi9DKAkfRVeotoX0clMr3SqQtBqO+KZMX27gm7dmgJsQaDKlILyzdCO+IA==", + "dev": true, + "requires": { + "@slack/logger": ">=1.0.0 <3.0.0", + "@slack/types": "^1.7.0", + "@types/is-stream": "^1.1.0", + "@types/node": ">=8.9.0", + "axios": "^0.21.1", + "eventemitter3": "^3.1.0", + "form-data": "^2.5.0", + "is-stream": "^1.1.0", + "p-queue": "^6.6.1", + "p-retry": "^4.0.0" + } + }, "@wordpress/e2e-test-utils": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@wordpress/e2e-test-utils/-/e2e-test-utils-3.0.0.tgz", @@ -11901,40 +11999,6 @@ "type-detect": "4.0.8" } }, - "@slack/logger": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@slack/logger/-/logger-2.0.0.tgz", - "integrity": "sha512-OkIJpiU2fz6HOJujhlhfIGrc8hB4ibqtf7nnbJQDerG0BqwZCfmgtK5sWzZ0TkXVRBKD5MpLrTmCYyMxoMCgPw==", - "dev": true, - "requires": { - "@types/node": ">=8.9.0" - } - }, - "@slack/types": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/@slack/types/-/types-1.9.0.tgz", - "integrity": "sha512-RmwgMWqOtzd2JPXdiaD/tyrDD0vtjjRDFdxN1I3tAxwBbg4aryzDUVqFc8na16A+3Xik/UN8X1hvVTw8J4EB9w==", - "dev": true - }, - "@slack/web-api": { - "version": "5.12.0", - "resolved": "https://registry.npmjs.org/@slack/web-api/-/web-api-5.12.0.tgz", - "integrity": "sha512-ygSnNHVid7PltGo7W36f2SNVHyliemkzxn9uSwgnWNF7CHmWBKWAylU/eoDml9l5K7akMOxbousiurOw4XqOFg==", - "dev": true, - "requires": { - "@slack/logger": ">=1.0.0 <3.0.0", - "@slack/types": "^1.7.0", - "@types/is-stream": "^1.1.0", - "@types/node": ">=8.9.0", - "@types/p-queue": "^2.3.2", - "axios": "^0.19.0", - "eventemitter3": "^3.1.0", - "form-data": "^2.5.0", - "is-stream": "^1.1.0", - "p-queue": "^2.4.2", - "p-retry": "^4.0.0" - } - }, "@tannin/compile": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@tannin/compile/-/compile-1.1.0.tgz", @@ -12022,15 +12086,6 @@ "@types/node": "*" } }, - "@types/is-stream": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@types/is-stream/-/is-stream-1.1.0.tgz", - "integrity": "sha512-jkZatu4QVbR60mpIzjINmtS1ZF4a/FqdTUTBeQDVOQ2PYyidtwFKr0B5G6ERukKwliq+7mIXvxyppwzG5EgRYg==", - "dev": true, - "requires": { - "@types/node": "*" - } - }, "@types/istanbul-lib-coverage": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz", @@ -12079,24 +12134,12 @@ "integrity": "sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA==", "dev": true }, - "@types/p-queue": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/@types/p-queue/-/p-queue-2.3.2.tgz", - "integrity": "sha512-eKAv5Ql6k78dh3ULCsSBxX6bFNuGjTmof5Q/T6PiECDq0Yf8IIn46jCyp3RJvCi8owaEmm3DZH1PEImjBMd/vQ==", - "dev": true - }, "@types/prettier": { "version": "1.19.1", "resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-1.19.1.tgz", "integrity": "sha512-5qOlnZscTn4xxM5MeGXAMOsIOIKIbh9e85zJWfBRVPlRMEVawzoPhINYbRGkBZCI8LxvBe7tJCdWiarA99OZfQ==", "dev": true }, - "@types/retry": { - "version": "0.12.0", - "resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.0.tgz", - "integrity": "sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==", - "dev": true - }, "@types/stack-utils": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-1.0.1.tgz", @@ -12627,15 +12670,6 @@ "resolved": "https://registry.npmjs.org/axe-core/-/axe-core-3.5.5.tgz", "integrity": "sha512-5P0QZ6J5xGikH780pghEdbEKijCTrruK9KxtPZCFWUpef0f6GipO+xEZ5GKCb020mmqgbiNO6TcA55CriL784Q==" }, - "axios": { - "version": "0.19.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz", - "integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==", - "dev": true, - "requires": { - "follow-redirects": "1.5.10" - } - }, "axobject-query": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-2.2.0.tgz", @@ -14025,12 +14059,6 @@ "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==" }, - "eventemitter3": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-3.1.2.tgz", - "integrity": "sha512-tvtQIeLVHjDkJYnzf2dgVMxfuSGJeM/7UCG17TT4EumTfNtF+0nebF/4zWOIkCreAbtNqhGEboB6BWrwqNaw4Q==", - "dev": true - }, "exec-sh": { "version": "0.3.4", "resolved": "https://registry.npmjs.org/exec-sh/-/exec-sh-0.3.4.tgz", @@ -14405,26 +14433,6 @@ "integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==", "dev": true }, - "follow-redirects": { - "version": "1.5.10", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", - "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", - "dev": true, - "requires": { - "debug": "=3.1.0" - }, - "dependencies": { - "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "dev": true, - "requires": { - "ms": "2.0.0" - } - } - } - }, "for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", @@ -18405,10 +18413,22 @@ } }, "p-queue": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/p-queue/-/p-queue-2.4.2.tgz", - "integrity": "sha512-n8/y+yDJwBjoLQe1GSJbbaYQLTI7QHNZI2+rpmCDbe++WLf9HC3gf6iqj5yfPAV71W4UF3ql5W1+UBPXoXTxng==", - "dev": true + "version": "6.6.2", + "resolved": "https://registry.npmjs.org/p-queue/-/p-queue-6.6.2.tgz", + "integrity": "sha512-RwFpb72c/BhQLEXIZ5K2e+AhgNVmIejGlTgiB9MzZ0e93GRvqZ7uSi0dvRF7/XIXDeNkra2fNHBxTyPDGySpjQ==", + "dev": true, + "requires": { + "eventemitter3": "^4.0.4", + "p-timeout": "^3.2.0" + }, + "dependencies": { + "eventemitter3": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", + "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==", + "dev": true + } + } }, "p-reduce": { "version": "1.0.0", @@ -18416,16 +18436,6 @@ "integrity": "sha1-GMKw3ZNqRpClKfgjH1ig/bakffo=", "dev": true }, - "p-retry": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/p-retry/-/p-retry-4.2.0.tgz", - "integrity": "sha512-jPH38/MRh263KKcq0wBNOGFJbm+U6784RilTmHjB/HM9kH9V8WlCpVUcdOmip9cjXOh6MxZ5yk1z2SjDUJfWmA==", - "dev": true, - "requires": { - "@types/retry": "^0.12.0", - "retry": "^0.12.0" - } - }, "p-try": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", @@ -18601,7 +18611,7 @@ "integrity": "sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=" }, "prettier": { - "version": "npm:wp-prettier@1.19.1", + "version": "npm:prettier@1.19.1", "resolved": "https://registry.npmjs.org/wp-prettier/-/wp-prettier-1.19.1.tgz", "integrity": "sha512-mqAC2r1NDmRjG+z3KCJ/i61tycKlmADIjxnDhQab+KBxSAGbF/W7/zwB2guy/ypIeKrrftNsIYkNZZQKf3vJcg==" }, @@ -19187,12 +19197,6 @@ "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==", "dev": true }, - "retry": { - "version": "0.12.0", - "resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz", - "integrity": "sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs=", - "dev": true - }, "rimraf": { "version": "2.6.3", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", @@ -21900,6 +21904,15 @@ "integrity": "sha512-arU1h31OGFu+LPrOLGZ7nB45v940NMDMEJeNmbutu57P+UFDVnkZg3e+J1I2HJRZ9hT7gO8J91dn/PMrAiKakA==", "dev": true }, + "axios": { + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", + "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", + "dev": true, + "requires": { + "follow-redirects": "^1.10.0" + } + }, "axobject-query": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-2.2.0.tgz", @@ -26104,6 +26117,12 @@ "readable-stream": "^2.3.6" } }, + "follow-redirects": { + "version": "1.13.3", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.3.tgz", + "integrity": "sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA==", + "dev": true + }, "for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", @@ -33774,6 +33793,33 @@ "integrity": "sha1-GMKw3ZNqRpClKfgjH1ig/bakffo=", "dev": true }, + "p-retry": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/p-retry/-/p-retry-4.4.0.tgz", + "integrity": "sha512-gVB/tBsG+3AHI1SyDHRrX6n9ZL0Bcbifps9W9/Bgu3Oyu4/OrAh8SvDzDsvpP0oxfCt3oWNT+0fQ9LyUGwBTLg==", + "dev": true, + "requires": { + "@types/retry": "^0.12.0", + "retry": "^0.12.0" + }, + "dependencies": { + "retry": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz", + "integrity": "sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs=", + "dev": true + } + } + }, + "p-timeout": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-3.2.0.tgz", + "integrity": "sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==", + "dev": true, + "requires": { + "p-finally": "^1.0.0" + } + }, "p-try": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", diff --git a/tests/e2e/env/package.json b/tests/e2e/env/package.json index 78cf6d70a6e..210eba5dcc8 100644 --- a/tests/e2e/env/package.json +++ b/tests/e2e/env/package.json @@ -23,6 +23,7 @@ "dependencies": { "@automattic/puppeteer-utils": "github:Automattic/puppeteer-utils#0f3ec50", "@jest/test-sequencer": "^25.5.4", + "@slack/web-api": "^6.1.0", "@wordpress/e2e-test-utils": "^4.15.0", "@wordpress/jest-preset-default": "^6.4.0", "app-root-path": "^3.0.0", diff --git a/tests/e2e/env/src/slack/reporter.js b/tests/e2e/env/src/slack/reporter.js index 83e74fd8a4c..7e690102dbf 100644 --- a/tests/e2e/env/src/slack/reporter.js +++ b/tests/e2e/env/src/slack/reporter.js @@ -72,7 +72,24 @@ export async function sendFailedTestMessageToSlack( testName ) { try { // Adding the app does not add the app user to the channel - await web.conversations.join( E2E_SLACK_CHANNEL ); + await web.conversations.join({ + channel: E2E_SLACK_CHANNEL, + token: E2E_SLACK_TOKEN, + }); + } catch ( error ) { + // Check the code property and log the response + if ( error.code === ErrorCode.PlatformError || error.code === ErrorCode.RequestError || + error.code === ErrorCode.RateLimitedError || error.code === ErrorCode.HTTPError ) { + console.log( error.data ); + } else { + // Some other error, oh no! + console.log( + 'Error joining channel', + error + ); + } + } + try { // For details, see: https://api.slack.com/methods/chat.postMessage await web.chat.postMessage({ channel: E2E_SLACK_CHANNEL, From 91a4283075aaca2233c548d88c1b12f0c85355ba Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Fri, 12 Mar 2021 16:40:20 -0400 Subject: [PATCH 13/13] update changelog, readme, fix test broken to test the bot --- .../shopper/front-end-my-account.test.js | 2 +- tests/e2e/env/CHANGELOG.md | 1 + tests/e2e/env/README.md | 21 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/e2e/core-tests/specs/shopper/front-end-my-account.test.js b/tests/e2e/core-tests/specs/shopper/front-end-my-account.test.js index 5ad893c0a1e..ac283f2f20a 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-my-account.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-my-account.test.js @@ -11,7 +11,7 @@ const runMyAccountPageTest = () => { describe('My account page', () => { it('allows customer to login', async () => { await merchant.logout(); -// await shopper.login(); + await shopper.login(); await expect(page).toMatch('Hello'); await expect(page).toMatchElement('.woocommerce-MyAccount-navigation-link', {text: 'Dashboard'}); await expect(page).toMatchElement('.woocommerce-MyAccount-navigation-link', {text: 'Orders'}); diff --git a/tests/e2e/env/CHANGELOG.md b/tests/e2e/env/CHANGELOG.md index d598349bc2e..67cfcb4979a 100644 --- a/tests/e2e/env/CHANGELOG.md +++ b/tests/e2e/env/CHANGELOG.md @@ -3,6 +3,7 @@ ## Added - Support for screenshots on test errors +- Slackbot to report errors to Slack channel ## Fixed diff --git a/tests/e2e/env/README.md b/tests/e2e/env/README.md index c109dc4f162..6ab21205bab 100644 --- a/tests/e2e/env/README.md +++ b/tests/e2e/env/README.md @@ -134,6 +134,27 @@ Depending on the project and testing scenario, the built in testing environment - [Built In Container](https://github.com/woocommerce/woocommerce/tree/trunk/tests/e2e/env/builtin.md) - [External Container](https://github.com/woocommerce/woocommerce/tree/trunk/tests/e2e/env/external.md) +### Slackbot Setup + +The 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. + +To implement the Slackbot in your CI: + +- Create a [Slackbot App](https://slack.com/help/articles/115005265703-Create-a-bot-for-your-workspace) +- Give the app the following permissions: + - `channel:join` + - `chat:write` + - `files:write` + - `incoming-webhook` +- Add the app to your channel +- In your CI environment + - Add the environment variable `WC_E2E_SCREENSHOTS=1` + - Add your app Oauth token to a CI secret `E2E_SLACK_TOKEN` + - Add the Slack channel name (without the #) to a CI secret `E2E_SLACK_CHANNEL` + - Add the secrets to the test run using the same variable names + +To test your setup, create a pull request that triggers an error in the E2E tests. + ## Additional information Refer to [`tests/e2e/core-tests`](https://github.com/woocommerce/woocommerce/tree/trunk/tests/e2e/core-tests) for some test examples, and [`tests/e2e`](https://github.com/woocommerce/woocommerce/tree/trunk/tests/e2e) for general information on e2e tests.