Skip to content

Commit

Permalink
Add CLI test for --files option
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed May 2, 2018
1 parent 6b1626e commit 5328192
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 4 deletions.
4 changes: 4 additions & 0 deletions cli-options/opts.start.json
Expand Up @@ -7,6 +7,10 @@
"type": "string",
"desc": "Working directory"
},
"json": {
"type": "boolean",
"desc": "If true, certain logs will output as json only"
},
"serveStatic": {
"type": "array",
"alias": "ss",
Expand Down
10 changes: 10 additions & 0 deletions crossbow.yaml
Expand Up @@ -14,6 +14,7 @@ tasks:
test:
- build-all
- cypress:*
- cli:*

(cypress):
file-watching-ignore: >
Expand Down Expand Up @@ -65,3 +66,12 @@ tasks:
client/lib/effects/*
client/lib/listeners/*
--write --tab-width 4
cli: cypress/setup/bs-cli.js

options:
cli:
file-watching-ignore:
method: 'run'
args: ['test/fixtures', '--files', 'test/fixtures', '--no-open', '--json']
spec: 'cypress/integration/file-watching-ignore.js'
46 changes: 46 additions & 0 deletions cypress/setup/bs-cli.js
@@ -0,0 +1,46 @@
const cypress = require('cypress');
const exec = require('child_process');
const assert = require('assert');
const {Observable} = require('rxjs/Observable');

module.exports = function(opts) {

assert.ok(Array.isArray(opts.args), '`args` should be an array of strings');
assert.ok(opts.args.every(arg => typeof arg === 'string'), '`args` should contain only strings');

return Observable.create(obs => {
const ls = exec.spawn('node', [
'dist/bin',
...opts.args
]);

ls.stdout.once('data', (data) => {
try {
const parsed = JSON.parse(String(data));
const {urls} = parsed["service:running"].options;

return cypress.run({
spec: opts.spec,
env: `BS_URL=${urls.local}`
})
.then((results) => {
// stop your server when it's complete
if (results.failures > 0) {
return obs.error(new Error('failed!'));
}
obs.complete();
})
} catch (e) {
console.error('Parsing Browsersync output failed', e);
return obs.error(new Error('failed!'));
}
});
ls.stderr.on('data', (data) => {
console.log(data);
return obs.error(new Error('failed!'));
});
return () => {
ls.kill();
}
});
};
10 changes: 8 additions & 2 deletions lib/logger.js
Expand Up @@ -121,8 +121,14 @@ module.exports.callbacks = {
* @param data
*/
"service:running": function(bs, data) {
var type = data.type;

const type = data.type;
if (bs.options.get('json')) {
return console.log(JSON.stringify({
"service:running": {
"options": bs.options.toJS()
}
}));
}
if (type === "server") {
var baseDir = bs.options.getIn(["server", "baseDir"]);

Expand Down
8 changes: 6 additions & 2 deletions test/specs/cli/cli.options.watch.js
Expand Up @@ -22,9 +22,13 @@ describe("CLI: Options: Merging Watch Option", function() {
assert.isUndefined(config.watchOptions.ignored);
});
it("does not add 'default' ignore options if 'ignore' provided in config", function() {
var input = { server: true, files: ["/shane"], ignore: ['/shane/*.css']};
var input = {
server: true,
files: ["/shane"],
ignore: ["/shane/*.css"]
};
var config = merge(input).toJS();
assert.deepEqual(config.watchOptions.ignored, ['/shane/*.css']);
assert.deepEqual(config.watchOptions.ignored, ["/shane/*.css"]);
});
it("watches from serveStatic option (no files given also)", function() {
var input = { serveStatic: ["./test"], watch: true };
Expand Down

0 comments on commit 5328192

Please sign in to comment.