Skip to content

Commit

Permalink
fix(server): set index correctly if serveStaticOptions: {index: <path…
Browse files Browse the repository at this point in the history
…>} given
  • Loading branch information
shakyShane committed Apr 12, 2015
1 parent 182832e commit 34816a7
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ function setServerOpts(item) {
index: indexarg
}));
} else {
item.setIn(optPath.concat(["index"]), indexarg);
if (!item.hasIn(optPath.concat(["index"]))) {
item.setIn(optPath.concat(["index"]), indexarg);
}
}

// cli extensions
Expand Down
67 changes: 67 additions & 0 deletions test/specs/e2e/server/e2e.server.serveStatic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"use strict";

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

describe("E2E server test with serve static options", function () {

it("sets the index of serve-static", function (done) {

browserSync.reset();

var config = {
server: {
baseDir: "test/fixtures",
serveStaticOptions: {
index: "inputs.html"
}
},
logLevel: "silent",
open: false
};

browserSync.create().init(config, function (err, bs) {
assert.equal(bs.options.getIn(["server", "serveStaticOptions", "index"]), "inputs.html");
request(bs.server)
.get("/")
.expect(200)
.end(function (err, res) {
assert.deepEqual(
require("fs").readFileSync("test/fixtures/inputs.html", "utf-8"),
res.text
);
bs.cleanup();
done();
});
});
});
it("sets uses the default for serve static index", function (done) {

browserSync.reset();

var config = {
server: {
baseDir: "test/fixtures",
serveStaticOptions: {}
},
logLevel: "silent",
open: false
};

browserSync.create().init(config, function (err, bs) {
assert.equal(bs.options.getIn(["server", "serveStaticOptions", "index"]), "index.html");
request(bs.server)
.get("/")
.expect(200)
.end(function (err, res) {
assert.deepEqual(
require("fs").readFileSync("test/fixtures/index.html", "utf-8"),
res.text
);
bs.cleanup();
done();
});
});
});
});

0 comments on commit 34816a7

Please sign in to comment.