Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-dockyard committed Apr 26, 2017
1 parent 58861da commit 00f63fb
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 4 deletions.
15 changes: 13 additions & 2 deletions .travis.yml
@@ -1,11 +1,18 @@
---
language: node_js
node_js:
- "4"
- "6"
- "stable"

sudo: false
addons:
apt:
sources:
- google-chrome
packages:
- google-chrome-unstable

sudo: required
dist: trusty

cache:
directories:
Expand All @@ -30,5 +37,9 @@ install:
- cd node-tests/fixtures/simple-app && npm install && bower install && cd -
- npm install

before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"

script:
- npm run $TEST_SCENARIO
67 changes: 65 additions & 2 deletions node-tests/acceptance-test.js
Expand Up @@ -2,15 +2,40 @@ var assert = require('chai').assert;
var fs = require('fs');
var path = require('path');
var rimraf = require('rimraf').sync;
var spawnSync = require('child_process').spawnSync;
var childProcess = require('child_process');

var spawn = childProcess.spawn;
var spawnSync = childProcess.spawnSync;

var emberCLIPath = path.resolve(__dirname, './fixtures/simple-app/node_modules/ember-cli/bin/ember');

var Lighthouse = require('lighthouse');
var ChromeLauncher = require('lighthouse/lighthouse-cli/chrome-launcher').ChromeLauncher;

function runLighthouse(url, flags, config) {
var launcher = new ChromeLauncher({port: 9222, autoSelectChrome: true});
return launcher.isDebuggerReady()
.catch(() => {
if (flags.skipAutolaunch) {
return;
}
return launcher.run(); // Launch Chrome.
})
.then(() => Lighthouse(url, flags, config)) // Run Lighthouse.
.then(results => launcher.kill().then(() => results)) // Kill Chrome and return results.
.catch(err => {
// Kill Chrome if there's an error.
return launcher.kill().then(() => {
throw err;
}, console.error);
});
}

describe('Acceptance Tests', function() {
this.timeout(120000);
var fixturePath = path.resolve(__dirname, './fixtures/simple-app');

context('A Simple App', function() {
var fixturePath = path.resolve(__dirname, './fixtures/simple-app');

function dist(file) {
return path.join(fixturePath, 'dist', file);
Expand Down Expand Up @@ -41,6 +66,38 @@ describe('Acceptance Tests', function() {
contains(dist('sw-registration.js'), "self.hello = 'Hello from Ember Service Worker Test';");
});
});

context('SW', function() {
let results;
let emberServer;

before(function(done) {
emberServer = runEmberCommandAsync(fixturePath, ['server', '--port', '4242']);

emberServer.stdout.on('data', (data) => {
if (data.indexOf('Build successful') !== -1) {

runLighthouse('http://localhost:4242', {
output: 'json'
}, require('./fixtures/lighthouse-config.js'))
.then((lhResults) => {
results = lhResults;
done();
})
.catch(err => console.error(err));
}
});
});

after(function() {
emberServer.kill();
cleanup(fixturePath);
});

it('is registered', function() {
assert.ok(results.audits['service-worker'].score);
});
});
});

function runEmberCommand(packagePath, command) {
Expand All @@ -53,6 +110,12 @@ function runEmberCommand(packagePath, command) {
}
}

function runEmberCommandAsync(packagePath, command) {
return spawn(emberCLIPath, command, {
cwd: packagePath
});
}

function cleanup(packagePath) {
rimraf(path.join(packagePath, 'dist'));
rimraf(path.join(packagePath, 'tmp'));
Expand Down
54 changes: 54 additions & 0 deletions node-tests/fixtures/lighthouse-config.js
@@ -0,0 +1,54 @@
module.exports = {
"settings": {},
"passes": [{
"passName": "defaultPass",
"recordNetwork": true,
"recordTrace": true,
"pauseBeforeTraceEndMs": 5000,
"useThrottling": true,
"gatherers": [
"url"
]
},
{
"passName": "offlinePass",
"recordNetwork": true,
"useThrottling": false,
"gatherers": [
"service-worker",
"offline"
]
}],

"audits": [
"service-worker",
],

"aggregations": [{
"name": "Progressive Web App",
"id": "pwa",
"description": "These audits validate the aspects of a Progressive Web App. They are a subset of the [PWA Checklist](https://developers.google.com/web/progressive-web-apps/checklist).",
"scored": true,
"categorizable": true,
"items": [{
"name": "App can load on offline/flaky connections",
"description": "Ensuring your web app can respond when the network connection is unavailable or flaky is critical to providing your users a good experience. This is achieved through use of a [Service Worker](https://developers.google.com/web/fundamentals/primers/service-worker/).",
"audits": {
"service-worker": {
"expectedValue": true,
"weight": 1
}
}
}]
}],
"categories": {
"pwa": {
"name": "Progressive Web App",
"weight": 1,
"description": "These audits validate the aspects of a Progressive Web App. They are a subset of the [PWA Checklist](https://developers.google.com/web/progressive-web-apps/checklist).",
"audits": [
{"id": "service-worker", "weight": 1},
]
}
}
}
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -22,6 +22,7 @@
"chai": "^3.5.0",
"ember-cli": "2.12.0",
"ember-fastboot-addon-tests": "^0.3.1",
"lighthouse": "1.6.5",
"mocha": "^2.5.3",
"rimraf": "^2.5.3"
},
Expand Down

0 comments on commit 00f63fb

Please sign in to comment.