Last active
October 24, 2019 02:16
-
-
Save ajs139/3ddc10e807ee9b94b581c80a762de587 to your computer and use it in GitHub Desktop.
Revisions
-
ajs139 revised this gist
May 1, 2019 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,8 +13,7 @@ const saveScreenshot = async (screenshot, testName) => { const fileName = toFilename(`${new Date().toISOString()}_${testName}_screenshot.png`); const filePath = path.join(screenshotsPath, fileName); await writeFile(filePath, screenshot); return filePath; }; let currentTest = ''; @@ -30,7 +29,8 @@ if (isCI) { if (status === 'failed') { if(currentScreenshot) { try { const filePath = await saveScreenshot(currentScreenshot, currentTest); console.error(`FAILED ${fullName}: screenshot @ ${filePath}`); } catch (e) { console.error(`FAILED ${fullName}: could not save screenshot.`, e); } -
ajs139 revised this gist
May 1, 2019 . 1 changed file with 8 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,10 +28,14 @@ if (isCI) { }, specDone: async ({ status, fullName }) => { if (status === 'failed') { if(currentScreenshot) { try { await saveScreenshot(currentScreenshot, currentTest); } catch (e) { console.error(`FAILED ${fullName}: could not save screenshot.`, e); } } else { console.error(`FAILED ${fullName}: sadly, no screenshot could be taken.`); } } }, -
ajs139 created this gist
May 1, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ require('expect-puppeteer'); const isCI = require('is-ci'); const path = require('path'); const { mkdirp, writeFile } = require('fs-extra'); const screenshotsPath = path.resolve(__dirname, '../reports/screenshots'); const toFilename = s => s.replace(/[^a-z0-9.-]+/gi, '_'); const saveScreenshot = async (screenshot, testName) => { await mkdirp(screenshotsPath); const fileName = toFilename(`${new Date().toISOString()}_${testName}_screenshot.png`); const filePath = path.join(screenshotsPath, fileName); await writeFile(filePath, screenshot); console.error(`FAILED ${testName}: screenshot @ ${filePath}`); return screenshot; }; let currentTest = ''; let currentScreenshot = null; if (isCI) { jasmine.getEnv().addReporter({ specStarted: ({ fullName }) => { currentTest = fullName; currentScreenshot = null; }, specDone: async ({ status, fullName }) => { if (status === 'failed') { try { await saveScreenshot(currentScreenshot, currentTest); } catch (e) { console.error(`FAILED ${fullName}: sadly, no screenshot could be taken.`, e); } } }, }); afterEach(async () => { currentScreenshot = await page.screenshot(); }); } else { jest.setTimeout(120e3); }