Skip to content

Commit

Permalink
feat(api): adds check for http status 304 (#311)
Browse files Browse the repository at this point in the history
* feat(api): adds check for http status 304

http status code should be considered successful

* feat(api): adds tests for http status code 304
  • Loading branch information
cmcnicholas committed Jul 22, 2021
1 parent 3b17fb0 commit c0adf51
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Expand Up @@ -24,6 +24,7 @@ jobs:
npm run demo7
# hmm why are some demos skipped?
npm run demo11
npm run demo12
START_SERVER_AND_TEST_INSECURE=1 npm run demo9
npm run demo-cross-env
npm run demo-commands
Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -73,6 +73,7 @@
"start-multiple": "node test/multiple-servers.js",
"start-https": "node test/https-server.js",
"start-fail": "node test/server-fail.js",
"start-304": "node test/server-304.js",
"start-cross-env": "cross-env FOO=bar node test/server.js",
"test2": "curl http://127.0.0.1:9000",
"test3": "curl http://127.0.0.1:9000 && curl http://127.0.0.1:9001",
Expand All @@ -90,6 +91,7 @@
"demo9": "node src/bin/start.js start-https \"https://127.0.0.1:9000\" test4",
"demo10": "node src/bin/start.js start-fail http://127.0.0.1:9000 test",
"demo11": "node src/bin/start.js http-get://127.0.0.1:9000",
"demo12": "node src/bin/start.js start-304 9000 test2",
"demo-cross-env": "node src/bin/start.js start-cross-env 9000",
"demo-commands": "node src/bin/start.js 'node test/server.js --port 8800' 8800 'node test/client --port 8800'",
"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'",
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Expand Up @@ -82,7 +82,8 @@ function waitAndRun ({ start, url, runFn }) {
log: isDebug(),
headers: {
Accept: 'text/html, application/json, text/plain, */*'
}
},
validateStatus: (status) => (status >= 200 && status < 300) || status === 304,
}
debug('wait-on options %o', options)

Expand Down
20 changes: 20 additions & 0 deletions test/server-304.js
@@ -0,0 +1,20 @@
const argv = require('minimist')(process.argv.slice(2), {
alias: {
port: 'p'
}
})
const http = require('http')
const server = http.createServer((req, res) => {
console.log(req.method)
if (req.method === 'GET') {
res.writeHead(304).end('All good\n\n')
} else {
res.end()
}
})
const port = argv.port || 9000
setTimeout(() => {
server.listen(port)
console.log('listening at port %d', port)
}, 5000)
console.log('sleeping for 5 seconds before starting')

0 comments on commit c0adf51

Please sign in to comment.