Skip to content

Commit

Permalink
feat(connect): add connect example
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Sep 11, 2015
1 parent 0d74a5d commit 834cfa6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"semi": [
2,
"always"
]
],
"no-console": 0
},
"env": {
"es6": true,
Expand Down
3 changes: 1 addition & 2 deletions .md.eslintrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"rules": {
"no-undef": 0,
"no-unused-vars": 0,
"no-console": 0
"no-unused-vars": 0
},
"plugins": [
"markdown"
Expand Down
22 changes: 22 additions & 0 deletions src/connect/connect-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use strict";
import hello from "./hello";
import nosniff from "./nosniff";
import assert from "assert";
import connect from "connect";
import http from "http";
import fetch from "node-fetch";
const responseText = "response text";
var app = connect();
app.use(nosniff());
app.use(hello(responseText));

var server = http.createServer(app).listen(3000, () => {
fetch("http://localhost:3000")
.then(res => res.text())
.then(text => {
assert.equal(text, responseText);
server.close();
}).catch(console.error.bind(console));
});


30 changes: 17 additions & 13 deletions test/connect/hello-test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// LICENSE : MIT
"use strict";
import assert from "power-assert";
import connect from "connect"
import connect from "connect";
import nosniff from "../../src/connect/nosniff";
import hello from "../../src/connect/hello";
import http from "http";
import fetch from "node-fetch";
describe("hello", function () {
describe("connect", function () {
var responseText = "test";
var server;
before(function (done) {
Expand All @@ -18,17 +18,21 @@ describe("hello", function () {
after(function () {
server.close();
});
it("should return response text", function () {
return fetch("http://localhost:3000")
.then(res => res.text())
.then(text => {
assert.equal(text, responseText);
});
describe("hello", function () {
it("should return response text", function () {
return fetch("http://localhost:3000")
.then(res => res.text())
.then(text => {
assert.equal(text, responseText);
});
});
});
it("should return response has `X-Content-Type-Options` header", function () {
return fetch("http://localhost:3000")
.then(res => {
assert.equal(res.headers.get("x-content-type-options"), "nosniff");
})
describe("sniff", function () {
it("should return response has `X-Content-Type-Options` header", function () {
return fetch("http://localhost:3000")
.then(res => {
assert.equal(res.headers.get("x-content-type-options"), "nosniff");
});
});
});
});

0 comments on commit 834cfa6

Please sign in to comment.