Skip to content

Commit 993df59

Browse files
committed
download Chromium only when tests are run
1 parent 7d22d6b commit 993df59

File tree

5 files changed

+33
-7
lines changed

5 files changed

+33
-7
lines changed

.travis.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
language: node_js
22
dist: trusty
3-
addons:
4-
chrome: stable
53
node_js:
64
- 8
75
- node
86
env:
97
- NODE_ENV=production
10-
before_install:
11-
- google-chrome-stable --headless --no-sandbox --remote-debugging-port=9222 &
128
install:
139
- npm --production=false install
1410
- npm --production=false update

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"gh-pages": "^1.0.0",
3737
"jsdoc": "^3.5.5",
3838
"json": "^9.0.4",
39-
"puppeteer": "^2.0.0",
39+
"puppeteer-core": "^2.0.0",
4040
"scratch-vm": "0.2.0-prerelease.20190213162739",
4141
"tap": "^11.0.0",
4242
"travis-after-all": "^1.4.4",

test/helper/download-chromium.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const packageJson = require('puppeteer-core/package.json');
2+
const puppeteer = require('puppeteer-core');
3+
4+
const fetcher = puppeteer.createBrowserFetcher();
5+
const revision = packageJson.puppeteer.chromium_revision;
6+
7+
/* eslint-disable no-console */
8+
module.exports = async () => {
9+
const downloadedRevisions = await fetcher.localRevisions();
10+
if (downloadedRevisions.indexOf(revision) !== -1) {
11+
console.log('Chromium already downloaded');
12+
return Promise.resolve();
13+
}
14+
15+
console.log('Downloading Chromium...');
16+
return fetcher.download(revision)
17+
.then(() => {
18+
console.log('Downloaded Chromium successfully');
19+
})
20+
.catch(error => {
21+
console.error(error);
22+
process.exit(1);
23+
});
24+
};

test/integration/pick-tests.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/* global vm, render, Promise */
2-
const puppeteer = require('puppeteer');
2+
const puppeteer = require('puppeteer-core');
33
const test = require('tap').test;
44
const path = require('path');
55

6+
const downloadChromium = require('../helper/download-chromium');
7+
68
const indexHTML = path.resolve(__dirname, 'index.html');
79
const testDir = (...args) => path.resolve(__dirname, 'pick-tests', ...args);
810

@@ -19,6 +21,7 @@ const runFile = async (file, action, page, script) => {
1921

2022
// immediately invoked async function to let us wait for each test to finish before starting the next.
2123
(async () => {
24+
await downloadChromium();
2225
const browser = await puppeteer.launch();
2326
const page = await browser.newPage();
2427

test/integration/scratch-tests.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/* global vm, Promise */
2-
const puppeteer = require('puppeteer');
2+
const puppeteer = require('puppeteer-core');
33
const test = require('tap').test;
44
const path = require('path');
55
const fs = require('fs');
66

7+
const downloadChromium = require('../helper/download-chromium');
8+
79
const indexHTML = path.resolve(__dirname, 'index.html');
810
const testDir = (...args) => path.resolve(__dirname, 'scratch-tests', ...args);
911

@@ -103,6 +105,7 @@ const testFile = (file, page) => test(file, async t => {
103105

104106
// immediately invoked async function to let us wait for each test to finish before starting the next.
105107
(async () => {
108+
await downloadChromium();
106109
const browser = await puppeteer.launch();
107110
const page = await browser.newPage();
108111

0 commit comments

Comments
 (0)