Skip to content

Commit 834cfa6

Browse files
committed
feat(connect): add connect example
1 parent 0d74a5d commit 834cfa6

File tree

4 files changed

+42
-16
lines changed

4 files changed

+42
-16
lines changed

.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"semi": [
1616
2,
1717
"always"
18-
]
18+
],
19+
"no-console": 0
1920
},
2021
"env": {
2122
"es6": true,

.md.eslintrc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"rules": {
33
"no-undef": 0,
4-
"no-unused-vars": 0,
5-
"no-console": 0
4+
"no-unused-vars": 0
65
},
76
"plugins": [
87
"markdown"

src/connect/connect-example.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"use strict";
2+
import hello from "./hello";
3+
import nosniff from "./nosniff";
4+
import assert from "assert";
5+
import connect from "connect";
6+
import http from "http";
7+
import fetch from "node-fetch";
8+
const responseText = "response text";
9+
var app = connect();
10+
app.use(nosniff());
11+
app.use(hello(responseText));
12+
13+
var server = http.createServer(app).listen(3000, () => {
14+
fetch("http://localhost:3000")
15+
.then(res => res.text())
16+
.then(text => {
17+
assert.equal(text, responseText);
18+
server.close();
19+
}).catch(console.error.bind(console));
20+
});
21+
22+

test/connect/hello-test.js

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// LICENSE : MIT
22
"use strict";
33
import assert from "power-assert";
4-
import connect from "connect"
4+
import connect from "connect";
55
import nosniff from "../../src/connect/nosniff";
66
import hello from "../../src/connect/hello";
77
import http from "http";
88
import fetch from "node-fetch";
9-
describe("hello", function () {
9+
describe("connect", function () {
1010
var responseText = "test";
1111
var server;
1212
before(function (done) {
@@ -18,17 +18,21 @@ describe("hello", function () {
1818
after(function () {
1919
server.close();
2020
});
21-
it("should return response text", function () {
22-
return fetch("http://localhost:3000")
23-
.then(res => res.text())
24-
.then(text => {
25-
assert.equal(text, responseText);
26-
});
21+
describe("hello", function () {
22+
it("should return response text", function () {
23+
return fetch("http://localhost:3000")
24+
.then(res => res.text())
25+
.then(text => {
26+
assert.equal(text, responseText);
27+
});
28+
});
2729
});
28-
it("should return response has `X-Content-Type-Options` header", function () {
29-
return fetch("http://localhost:3000")
30-
.then(res => {
31-
assert.equal(res.headers.get("x-content-type-options"), "nosniff");
32-
})
30+
describe("sniff", function () {
31+
it("should return response has `X-Content-Type-Options` header", function () {
32+
return fetch("http://localhost:3000")
33+
.then(res => {
34+
assert.equal(res.headers.get("x-content-type-options"), "nosniff");
35+
});
36+
});
3337
});
3438
});

0 commit comments

Comments
 (0)