From 340bdcc4272d58ab393f6bce136dad232d26a27d Mon Sep 17 00:00:00 2001 From: Craig McNicholas Date: Wed, 21 Jul 2021 16:20:36 +0100 Subject: [PATCH 1/2] feat(api): adds check for http status 304 http status code should be considered successful --- src/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index e148f0c..8242c64 100644 --- a/src/index.js +++ b/src/index.js @@ -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) From 80b67ec07e41eab0cf2d96b7b3faff6806333a30 Mon Sep 17 00:00:00 2001 From: Craig McNicholas Date: Wed, 21 Jul 2021 22:16:50 +0100 Subject: [PATCH 2/2] feat(api): adds tests for http status code 304 --- .github/workflows/ci.yml | 1 + package.json | 2 ++ test/server-304.js | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 test/server-304.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4f01f75..4df8bac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/package.json b/package.json index db3b9de..b0574e5 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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'", diff --git a/test/server-304.js b/test/server-304.js new file mode 100644 index 0000000..8ae2e56 --- /dev/null +++ b/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')