Skip to content

Commit c0adf51

Browse files
authored
feat(api): adds check for http status 304 (#311)
* feat(api): adds check for http status 304 http status code should be considered successful * feat(api): adds tests for http status code 304
1 parent 3b17fb0 commit c0adf51

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
npm run demo7
2525
# hmm why are some demos skipped?
2626
npm run demo11
27+
npm run demo12
2728
START_SERVER_AND_TEST_INSECURE=1 npm run demo9
2829
npm run demo-cross-env
2930
npm run demo-commands

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"start-multiple": "node test/multiple-servers.js",
7474
"start-https": "node test/https-server.js",
7575
"start-fail": "node test/server-fail.js",
76+
"start-304": "node test/server-304.js",
7677
"start-cross-env": "cross-env FOO=bar node test/server.js",
7778
"test2": "curl http://127.0.0.1:9000",
7879
"test3": "curl http://127.0.0.1:9000 && curl http://127.0.0.1:9001",
@@ -90,6 +91,7 @@
9091
"demo9": "node src/bin/start.js start-https \"https://127.0.0.1:9000\" test4",
9192
"demo10": "node src/bin/start.js start-fail http://127.0.0.1:9000 test",
9293
"demo11": "node src/bin/start.js http-get://127.0.0.1:9000",
94+
"demo12": "node src/bin/start.js start-304 9000 test2",
9395
"demo-cross-env": "node src/bin/start.js start-cross-env 9000",
9496
"demo-commands": "node src/bin/start.js 'node test/server.js --port 8800' 8800 'node test/client --port 8800'",
9597
"demo-multiple": "node src/bin/start.js 'node test/server --port 6000' 6000 'node test/server --port 6010' 6010 'curl http://127.0.0.1:6000 && curl http://127.0.0.1:6010'",

src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ function waitAndRun ({ start, url, runFn }) {
8282
log: isDebug(),
8383
headers: {
8484
Accept: 'text/html, application/json, text/plain, */*'
85-
}
85+
},
86+
validateStatus: (status) => (status >= 200 && status < 300) || status === 304,
8687
}
8788
debug('wait-on options %o', options)
8889

test/server-304.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const argv = require('minimist')(process.argv.slice(2), {
2+
alias: {
3+
port: 'p'
4+
}
5+
})
6+
const http = require('http')
7+
const server = http.createServer((req, res) => {
8+
console.log(req.method)
9+
if (req.method === 'GET') {
10+
res.writeHead(304).end('All good\n\n')
11+
} else {
12+
res.end()
13+
}
14+
})
15+
const port = argv.port || 9000
16+
setTimeout(() => {
17+
server.listen(port)
18+
console.log('listening at port %d', port)
19+
}, 5000)
20+
console.log('sleeping for 5 seconds before starting')

0 commit comments

Comments
 (0)