Skip to content

Commit

Permalink
fix: Don’t always add "defaultIgnorePatterns" - fixes #1543
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed May 3, 2018
1 parent af79226 commit cc5118c
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 4 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -2,7 +2,6 @@ node_modules
.idea
npm-debug.log
.sass-cache
bower_components
test/fixtures/files/*
test/fixtures/js/*
example.server.js
Expand Down
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
14 changes: 14 additions & 0 deletions crossbow.yaml
Expand Up @@ -14,8 +14,13 @@ tasks:
test:
- build-all
- cypress:*
- cli:*

(cypress):
file-watching-ignore: >
@npm node cypress/setup/run.js
'../configs/file-watching-ignore.js'
cypress/integration/file-watching-ignore.js
file-reloading: >
@npm node cypress/setup/run.js
'../configs/file-reloading.js'
Expand Down Expand Up @@ -61,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'
7 changes: 7 additions & 0 deletions cypress/configs/file-watching-ignore.js
@@ -0,0 +1,7 @@
module.exports = {
server: 'test/fixtures',
open: false,
online: false,
minify: false,
files: 'test/fixtures',
};
14 changes: 14 additions & 0 deletions cypress/integration/file-watching-ignore.js
@@ -0,0 +1,14 @@
describe('Watching folders', function() {
context('files option', function () {
beforeEach(function () {
cy.visit(Cypress.env('BS_URL') + '/bower.html');
});
it('should reload single <link>', function () {
cy.exec('touch test/fixtures/bower_components/app.css');
cy.get('[id="css-style"]').should($link => {
const url = new URL($link.attr('href'));
expect(url.search).to.contain('?browsersync=');
});
});
});
});
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();
}
});
};
4 changes: 4 additions & 0 deletions lib/cli/transforms/addDefaultIgnorePatterns.ts
Expand Up @@ -10,6 +10,10 @@ const defaultIgnorePatterns = [
];

export function addDefaultIgnorePatterns(incoming) {
if (!incoming.get("watch")) {
return incoming;
}

return incoming.update("watchOptions", watchOptions => {
const userIgnored = List([])
.concat(watchOptions.get("ignored"))
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/transforms/copyCLIIgnoreToWatchOptions.ts
Expand Up @@ -4,7 +4,7 @@ export function copyCLIIgnoreToWatchOptions(incoming) {
if (!incoming.get("ignore")) {
return incoming;
}
return incoming.updateIn(["watchOptions", "ignored"], ignored => {
return incoming.updateIn(["watchOptions", "ignored"], List([]), ignored => {
const userIgnore = List([]).concat(incoming.get("ignore"));
return ignored.concat(userIgnore);
});
Expand Down
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
13 changes: 13 additions & 0 deletions test/fixtures/bower.html
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" id="css-style" href="bower_components/app.css">
</head>
<body>
<h1>Bower Components</h1>
</body>
</html>
3 changes: 3 additions & 0 deletions test/fixtures/bower_components/app.css
@@ -0,0 +1,3 @@
body {
background: orange;
}
14 changes: 14 additions & 0 deletions test/specs/cli/cli.options.watch.js
Expand Up @@ -16,6 +16,20 @@ describe("CLI: Options: Merging Watch Option", function() {
core: { globs: ["/shane", "."], objs: [] }
});
});
it("does not add default ignore paths if watch option is absent", function() {
var input = { server: true, files: ["/shane"] };
var config = merge(input).toJS();
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 config = merge(input).toJS();
assert.deepEqual(config.watchOptions.ignored, ["/shane/*.css"]);
});
it("watches from serveStatic option (no files given also)", function() {
var input = { serveStatic: ["./test"], watch: true };
var config = merge(input).toJS();
Expand Down

0 comments on commit cc5118c

Please sign in to comment.