Skip to content

Commit

Permalink
chore: Add Windows to Travis
Browse files Browse the repository at this point in the history
This commit runs the unit tests on Windows. There is one test that is
failing on Windows that we skip. I spoke to Mathias B and we agreed to
defer debugging this for now in favour of getting tests running on
Windows. But we didn't want to ignore it forever, hence giving the test
a date at which it will start to fail.
  • Loading branch information
jackfranklin committed Apr 14, 2020
1 parent 2529ee6 commit 220c4f1
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 23 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Expand Up @@ -13,6 +13,13 @@ cache:
- node_modules
jobs:
include:
- os: "windows"
node_js: "10.19.0"
env:
- CHROMIUM=true
script:
- npm run tsc
- npm run unit
- node_js: "10.19.0"
dist: trusty
env:
Expand Down
21 changes: 20 additions & 1 deletion mocha-config/puppeteer-unit-tests.js
@@ -1,8 +1,27 @@
/**
* Copyright 2020 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const os = require('os');
const base = require('./base');

const longerTimeoutRequired = process.env.PUPPETEER_PRODUCT === 'firefox' || os.platform() === 'wind32';

module.exports = {
...base,
file: ['./test/mocha-utils.js'],
spec: 'test/*.spec.js',
timeout: process.env.PUPPETEER_PRODUCT === 'firefox' ? 15 * 1000 : 10 * 1000,
timeout: longerTimeoutRequired ? 20 * 1000 : 10 * 1000,
};
47 changes: 27 additions & 20 deletions test/headful.spec.js
Expand Up @@ -85,26 +85,33 @@ describeChromeOnly('headful tests', function() {
expect(pages).toEqual(['about:blank']);
await browser.close();
});
it('headless should be able to read cookies written by headful', async() => {
const { server, puppeteer } = getTestState();

const userDataDir = await mkdtempAsync(TMP_FOLDER);
// Write a cookie in headful chrome
const headfulBrowser = await puppeteer.launch(Object.assign({userDataDir}, headfulOptions));
const headfulPage = await headfulBrowser.newPage();
await headfulPage.goto(server.EMPTY_PAGE);
await headfulPage.evaluate(() => document.cookie = 'foo=true; expires=Fri, 31 Dec 9999 23:59:59 GMT');
await headfulBrowser.close();
// Read the cookie from headless chrome
const headlessBrowser = await puppeteer.launch(Object.assign({userDataDir}, headlessOptions));
const headlessPage = await headlessBrowser.newPage();
await headlessPage.goto(server.EMPTY_PAGE);
const cookie = await headlessPage.evaluate(() => document.cookie);
await headlessBrowser.close();
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
await rmAsync(userDataDir).catch(e => {});
expect(cookie).toBe('foo=true');
});
itFailsWindowsUntilDate(
/* We have deferred fixing this test on Windows in favour of
* getting all other Windows tests running on CI. Putting this
* date in to force us to come back and debug properly in the
* future.
*/
new Date(2020, 5, 1),
'headless should be able to read cookies written by headful', async() => {
const { server, puppeteer } = getTestState();

const userDataDir = await mkdtempAsync(TMP_FOLDER);
// Write a cookie in headful chrome
const headfulBrowser = await puppeteer.launch(Object.assign({userDataDir}, headfulOptions));
const headfulPage = await headfulBrowser.newPage();
await headfulPage.goto(server.EMPTY_PAGE);
await headfulPage.evaluate(() => document.cookie = 'foo=true; expires=Fri, 31 Dec 9999 23:59:59 GMT');
await headfulBrowser.close();
// Read the cookie from headless chrome
const headlessBrowser = await puppeteer.launch(Object.assign({userDataDir}, headlessOptions));
const headlessPage = await headlessBrowser.newPage();
await headlessPage.goto(server.EMPTY_PAGE);
const cookie = await headlessPage.evaluate(() => document.cookie);
await headlessBrowser.close();
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
await rmAsync(userDataDir).catch(e => {});
expect(cookie).toBe('foo=true');
});
// TODO: Support OOOPIF. @see https://github.com/puppeteer/puppeteer/issues/2548
xit('OOPIF: should report google.com frame', async() => {
const { server } = getTestState();
Expand Down
11 changes: 11 additions & 0 deletions test/mocha-utils.js
Expand Up @@ -17,6 +17,7 @@
const {TestServer} = require('../utils/testserver/index');
const path = require('path');
const fs = require('fs');
const os = require('os');
const puppeteer = require('../');
const utils = require('./utils');
const assertCoverage = require('./coverage-utils');
Expand Down Expand Up @@ -88,6 +89,16 @@ global.itFailsFirefox = (...args) => {
return it(...args);
};

global.itFailsWindowsUntilDate = (date, ...args) => {
const today = new Date();
if (os.platform() === 'win32' && today < date) {
// we are within the deferred time so skip the test
return xit(...args);
}

return it(...args);
};

global.describeFailsFirefox = (...args) => {
if (isFirefox)
return xdescribe(...args);
Expand Down
5 changes: 3 additions & 2 deletions test/network.spec.js
Expand Up @@ -15,6 +15,7 @@
*/

const fs = require('fs');
const os = require('os');
const path = require('path');
const utils = require('./utils');
const expect = require('expect');
Expand Down Expand Up @@ -189,15 +190,15 @@ describe('network', function() {
const { page, server } = getTestState();

const response = await page.goto(server.PREFIX + '/simple.json');
expect(await response.text()).toBe('{"foo": "bar"}\n');
expect(await response.text()).toBe(`{"foo": "bar"}${os.EOL}`);
});
it('should return uncompressed text', async() => {
const { page, server } = getTestState();

server.enableGzip('/simple.json');
const response = await page.goto(server.PREFIX + '/simple.json');
expect(response.headers()['content-encoding']).toBe('gzip');
expect(await response.text()).toBe('{"foo": "bar"}\n');
expect(await response.text()).toEqual(`{"foo": "bar"}${os.EOL}`);
});
it('should throw when requesting body of redirected response', async() => {
const { page, server } = getTestState();
Expand Down

0 comments on commit 220c4f1

Please sign in to comment.