Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Commit

Permalink
CLI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ebidel committed Oct 31, 2015
1 parent 80231d1 commit 815cb2d
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// jshint node: true
let assert = require('assert');
let path = require('path');
let fs = require('fs');

const oldOld = console.log;
Expand Down Expand Up @@ -133,3 +134,60 @@ suite('manifest.js', () => {
});

});

suite('cli', () => {
var exec = require('child_process').exec;

let CMD = `${__dirname}/../bin/http2-push-manifest`;
let INPUT = `${__dirname}/html/basic.html`;
let INPUT2 = `${__dirname}/html/basic2.html`;
let NAME = 'push_manifest.json';

function process(cmd, cb) {
exec(cmd, (err, stdout, stderr) => {
assert(!err, 'error running cli');
cb(stdout);
});
}

suiteSetup(() => {
//manifest = new PushManifest({basePath: BASE, inputPath: INPUT});
});

test('single manifest', done => {
process(`${CMD} -f ${INPUT}`, stdout => {
assert(fs.statSync(NAME).isFile(), 'single file manifest written');
fs.unlinkSync(NAME); // cleanup
done();
});
});

test('custom manifest', done => {
let name = 'custom_manifest.json';
process(`${CMD} -f ${INPUT} -m ${name}`, stdout => {
assert(fs.statSync(name).isFile(), 'custom manifest written');
fs.unlinkSync(name); // cleanup
done();
});
});

test('multi manifest', done => {
process(`${CMD} -f ${INPUT} -f ${INPUT2}`, stdout => {
assert(fs.statSync(NAME).isFile(), 'multi file manifest written');

fs.readFile(NAME, (err, data) => {
assert(!err, 'error reading multi file manifest');

var json = JSON.parse(data);

// Check top-level keys are the input file names.
assert(path.basename(INPUT) in json);
assert(path.basename(INPUT2) in json);

fs.unlinkSync(NAME); // cleanup

done();
});
});
});
});

0 comments on commit 815cb2d

Please sign in to comment.