Skip to content

Commit

Permalink
fix(snippet): Add snippet.ignorePaths option - fixes #330
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Nov 16, 2014
1 parent 0181b48 commit dd9b284
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 7 deletions.
7 changes: 7 additions & 0 deletions lib/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ module.exports = {
*/
logSnippet: true,

/**
* @property snippetOptions
* @param {Boolean} [ignorePaths]
* @type Object
*/
snippetOptions: {},

/**
* @property tunnel
* @type String|Boolean
Expand Down
2 changes: 1 addition & 1 deletion lib/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function createServer (options, scripts, context) {
utils.addDirectory(app, server.baseDir);
}

app.use(snippetUtils.getSnippetMiddleware(options.snippet));
app.use(snippetUtils.getSnippetMiddleware(options.snippet, options.snippetOptions));

utils.addBaseDir(app, server.baseDir, index);

Expand Down
12 changes: 8 additions & 4 deletions lib/snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var messages = require("./messages");
var config = require("./config");

var lrSnippet = require("/Users/shakyshane/Sites/os-resp-modifier");
var lrSnippet = require("resp-modifier");
var path = require("path");
var _ = require("lodash");
var fs = require("fs");
Expand Down Expand Up @@ -52,14 +52,18 @@ var utils = {
},
/**
* @param {String} snippet
* @param {Object} [extraRules]
* @param {Object} [options]
* @returns {Function}
*/
getSnippetMiddleware: function (snippet) {
getSnippetMiddleware: function (snippet, options) {

var rules = [utils.getRegex(snippet)];
options = options || {};

return lrSnippet({rules: rules});
return lrSnippet({
rules: rules,
ignorePaths: options.ignorePaths
});
},
/**
* @param {String} scripts - the client side JS
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"opn": "^1.0.0",
"opt-merger": "^1.1.0",
"portscanner-plus": "^0.1.0",
"resp-modifier": "^0.1.2",
"resp-modifier": "^1.0.0",
"serve-index": "^1.1.5",
"serve-static": "^1.4.2",
"socket.io": "^1.1.0",
Expand Down
20 changes: 20 additions & 0 deletions test/fixtures/iframe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">
<title>Test HTML Page</title>
<link rel="stylesheet" href="assets/style.css"/>
<link rel="stylesheet" href="fonts/roboto/stylesheet.css"/>
</head>
<body>

<h1 style="font-family: robotoregular, serif">BrowserSync + iFrame</h1>
<a href="forms.html">Forms</a>
<a href="scrolling.html">Scrolling Window</a>

<iframe src="sass.html" frameborder="0"></iframe>

</body>
</html>
11 changes: 10 additions & 1 deletion test/protractor/tests/proxy.interactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('Interactions on proxy Pages', function() {
"scrolling.html",
"index-large.html",
"index-amd.html"

].forEach(function (url) {
browser.get(path.join(urls.local, url));
assertScripts();
Expand Down Expand Up @@ -80,7 +81,15 @@ describe('Interactions on proxy Pages', function() {
});

browser.get(urls.local + "/forms.html");
element(by.id("name")).sendKeys("Hi there");

var waitLoading = by.css('input[name="name"');

browser.wait(function() {
return ptor.isElementPresent(waitLoading);
}, 8000);

element(by.css('input[name="name"')).sendKeys("Hi there");

instance.cleanup();
});
});
Expand Down
40 changes: 40 additions & 0 deletions test/specs/e2e/e2e.options.snippet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"use strict";

var browserSync = require("../../../index");

var assert = require("chai").assert;
var request = require("supertest");

describe("E2E snippet ignore paths test", function () {

var instance;

before(function (done) {

var config = {
server: {
baseDir: "test/fixtures"
},
open: false,
snippetOptions: {
ignorePaths: "iframe.html"
}
};
instance = browserSync(config, done);
});

after(function () {
instance.cleanup();
});

it("does not inject the snippet when excluded path hit", function (done) {
request(instance.server)
.get("/iframe.html")
.set("accept", "text/html")
.expect(200)
.end(function (err, res) {
assert.notInclude(res.text, instance.options.snippet);
done();
});
});
});

0 comments on commit dd9b284

Please sign in to comment.