From a460114945f8f979e43655ce1e7b7b10daac5843 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Wed, 20 Jun 2018 13:52:36 -0700 Subject: [PATCH] test: fix appveyour flakiness (#2779) Crashpad sometimes prevents us from removing a folder in tests. References #2778. --- test/puppeteer.spec.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test/puppeteer.spec.js b/test/puppeteer.spec.js index 468c309509f..e427c5e4d01 100644 --- a/test/puppeteer.spec.js +++ b/test/puppeteer.spec.js @@ -15,9 +15,9 @@ */ const fs = require('fs'); const os = require('os'); -const rm = require('rimraf').sync; const path = require('path'); const {helper} = require('../lib/helper'); +const rmAsync = helper.promisify(require('rimraf')); const mkdtempAsync = helper.promisify(fs.mkdtemp); const readFileAsync = helper.promisify(fs.readFile); const statAsync = helper.promisify(fs.stat); @@ -57,7 +57,7 @@ module.exports.addTests = function({testRunner, expect, PROJECT_ROOT, defaultBro expect(await browserFetcher.localRevisions()).toEqual(['123456']); await browserFetcher.remove('123456'); expect(await browserFetcher.localRevisions()).toEqual([]); - rm(downloadsFolder); + await rmAsync(downloadsFolder); }); }); describe('AppMode', function() { @@ -96,7 +96,8 @@ module.exports.addTests = function({testRunner, expect, PROJECT_ROOT, defaultBro expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0); await browser.close(); expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0); - rm(userDataDir); + // This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778 + await rmAsync(userDataDir).catch(e => {}); }); it('userDataDir argument', async({server}) => { const userDataDir = await mkdtempAsync(TMP_FOLDER); @@ -106,7 +107,8 @@ module.exports.addTests = function({testRunner, expect, PROJECT_ROOT, defaultBro expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0); await browser.close(); expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0); - rm(userDataDir); + // This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778 + await rmAsync(userDataDir).catch(e => {}); }); it('userDataDir option should restore state', async({server}) => { const userDataDir = await mkdtempAsync(TMP_FOLDER); @@ -122,7 +124,8 @@ module.exports.addTests = function({testRunner, expect, PROJECT_ROOT, defaultBro await page2.goto(server.EMPTY_PAGE); expect(await page2.evaluate(() => localStorage.hey)).toBe('hello'); await browser2.close(); - rm(userDataDir); + // This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778 + await rmAsync(userDataDir).catch(e => {}); }); it('userDataDir option should restore cookies', async({server}) => { const userDataDir = await mkdtempAsync(TMP_FOLDER); @@ -138,7 +141,8 @@ module.exports.addTests = function({testRunner, expect, PROJECT_ROOT, defaultBro await page2.goto(server.EMPTY_PAGE); expect(await page2.evaluate(() => document.cookie)).toBe('doSomethingOnlyOnce=true'); await browser2.close(); - rm(userDataDir); + // This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778 + await rmAsync(userDataDir).catch(e => {}); }); it('should return the default chrome arguments', async() => { const args = puppeteer.defaultArgs();