add token to calls, remove block from test title

This commit is contained in:
Ron Rennick 2021-03-09 16:49:47 -04:00
parent bb907a6acd
commit 12c0793217
2 changed files with 7 additions and 7 deletions

View File

@ -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<void>}
*/
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(

View File

@ -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