From d3976cb0a50f4ce7075200d6fa7e92a0dead0a66 Mon Sep 17 00:00:00 2001 From: JoelEinbinder Date: Thu, 5 Oct 2017 17:08:35 -0700 Subject: [PATCH] test: add failing test for storing data in custom userDataDir Headless isn't closing gracefully, which sometimes causes data loss when Chrome closes before it finishes writing things to disk. See https://crbug.com/771830 References #921 --- test/test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/test.js b/test/test.js index 97ac21f89ae..ef7dbc638c5 100644 --- a/test/test.js +++ b/test/test.js @@ -121,6 +121,24 @@ describe('Puppeteer', function() { expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0); rm(userDataDir); })); + // Headless has issues shutting down gracefully + // @see https://crbug.com/771830 + (headless ? xit : it)('userDataDir option should restore state', SX(async function() { + const userDataDir = fs.mkdtempSync(path.join(__dirname, 'test-user-data-dir')); + const options = Object.assign({userDataDir}, defaultBrowserOptions); + const browser = await puppeteer.launch(options); + const page = await browser.newPage(); + await page.goto(EMPTY_PAGE); + await page.evaluate(() => localStorage.hey = 'hello'); + await browser.close(); + + const browser2 = await puppeteer.launch(options); + const page2 = await browser2.newPage(); + await page2.goto(EMPTY_PAGE); + expect(await page2.evaluate(() => localStorage.hey)).toBe('hello'); + await browser2.close(); + rm(userDataDir); + })); }); describe('Puppeteer.connect', function() { it('should work', SX(async function() {