Skip to content

Commit

Permalink
fix: add expected default value 200, closes #349
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Feb 13, 2023
1 parent 2ebf1ba commit 9e8713b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ $ start-test --expect 403 start :9000 test:e2e

See `demo-expect-403` NPM script.

Default expected value is 200.

## `npx` and `yarn`

If you have [npx](https://www.npmjs.com/package/npx) available, you can execute locally installed tools from the shell. For example, if the `package.json` has the following local tools:
Expand Down
4 changes: 4 additions & 0 deletions src/bin/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ if (!Array.isArray(services)) {
throw new Error(`Could not parse arguments %o, got %o`, args, parsed)
}

if (!namedArguments.expect) {
namedArguments.expect = 200
}

utils.printArguments({ services, test, namedArguments })

startAndTest({ services, test, namedArguments }).catch(e => {
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ function startAndTest ({ services, test, namedArguments }) {
throw new Error('Got zero services to start ...')
}

la(
is.number(namedArguments.expect),
'expected status should be a number',
namedArguments.expect
)

if (services.length === 1) {
const runTests = runTheTests(test)
debug('single service "%s" to run and test', services[0].start)
Expand Down
6 changes: 6 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ const normalizeUrl = input => {
}

function printArguments ({ services, test, namedArguments }) {
la(
is.number(namedArguments.expect),
'expected status code should be a number',
namedArguments.expect
)

services.forEach((service, k) => {
console.log('%d: starting server using command "%s"', k + 1, service.start)
console.log(
Expand Down

0 comments on commit 9e8713b

Please sign in to comment.