Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-dockyard committed Feb 6, 2017
1 parent 0999694 commit 20ba75a
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 3 deletions.
45 changes: 43 additions & 2 deletions node-tests/acceptance-test.js
Expand Up @@ -2,15 +2,18 @@ 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');

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 +44,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) {
spawnSync('lighthouse', [
'--output', 'json',
'--output-path', `${__dirname}/lighthouse-results.json`,
'--config-path', `${__dirname}/fixtures/lighthouse-config.json`,
'http://localhost:4242']);

results = require('./lighthouse-results.json');
done();
}
});
});

after(function() {
emberServer.kill();
fs.unlinkSync(`${__dirname}/lighthouse-results.json`);
cleanup(fixturePath);
});

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

function runEmberCommand(packagePath, command) {
Expand All @@ -53,6 +88,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
31 changes: 31 additions & 0 deletions node-tests/fixtures/lighthouse-config.json
@@ -0,0 +1,31 @@
{
"passes": [{
"recordNetwork": true,
"recordTrace": true,
"gatherers": [
"url",
"service-worker",
"offline"]
}],

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

"aggregations": [{
"name": "Perf metrics",
"description": "",
"scored": true,
"categorizable": true,
"items": [{
"name": "Page load performance is fast",
"description": "",
"audits": {
"service-worker": {
"expectedValue": true,
"weight": 1
}
}
}]
}]
}
1 change: 0 additions & 1 deletion node-tests/fixtures/simple-app/package.json
Expand Up @@ -38,7 +38,6 @@
"ember-load-initializers": "^0.5.1",
"ember-resolver": "^2.0.3",
"ember-service-worker": "file:../../..",
"ember-welcome-page": "^1.0.1",
"loader.js": "^4.0.1"
},
"ember-addon": {
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -19,6 +19,7 @@
"devDependencies": {
"broccoli-test-helpers": "0.0.9",
"chai": "^3.5.0",
"lighthouse": "^1.4.1",
"mocha": "^2.5.3",
"rimraf": "^2.5.3"
},
Expand Down

0 comments on commit 20ba75a

Please sign in to comment.