Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit834cfa6

Browse files
committed
feat(connect): add connect example
1 parent0d74a5d commit834cfa6

File tree

4 files changed

+42
-16
lines changed

4 files changed

+42
-16
lines changed

‎.eslintrc

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"use strict";
2+
importhellofrom"./hello";
3+
importnosnifffrom"./nosniff";
4+
importassertfrom"assert";
5+
importconnectfrom"connect";
6+
importhttpfrom"http";
7+
importfetchfrom"node-fetch";
8+
constresponseText="response text";
9+
varapp=connect();
10+
app.use(nosniff());
11+
app.use(hello(responseText));
12+
13+
varserver=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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// LICENSE : MIT
22
"use strict";
33
importassertfrom"power-assert";
4-
importconnectfrom"connect"
4+
importconnectfrom"connect";
55
importnosnifffrom"../../src/connect/nosniff";
66
importhellofrom"../../src/connect/hello";
77
importhttpfrom"http";
88
importfetchfrom"node-fetch";
9-
describe("hello",function(){
9+
describe("connect",function(){
1010
varresponseText="test";
1111
varserver;
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-
returnfetch("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+
returnfetch("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-
returnfetch("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+
returnfetch("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)

[8]ページ先頭

©2009-2025 Movatter.jp