Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

start-server-and-test

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

start-server-and-test - npm Package Compare versions

Comparing version 1.14.0 to 1.15.0

LICENSE

7

package.json
{
"name": "start-server-and-test",
"description": "Starts server, waits for URL, then runs test command; when the tests end, shuts down server",
"version": "1.14.0",
"version": "1.15.0",
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>",

@@ -51,3 +51,3 @@ "bugs": "https://github.com/bahmutov/start-server-and-test/issues",

"publishConfig": {
"registry": "http://registry.npmjs.org/"
"registry": "https://registry.npmjs.org/"
},

@@ -78,2 +78,3 @@ "repository": {

"start-304": "node test/server-304.js",
"start-403": "node test/server-403.js",
"start-cross-env": "cross-env FOO=bar node test/server.js",

@@ -97,2 +98,3 @@ "test2": "curl http://127.0.0.1:9000",

"demo12": "node src/bin/start.js start-304 9000 test2",
"demo-expect-403": "node src/bin/start.js --expect 403 start-403 9000 'echo Waited'",
"demo-interval": "WAIT_ON_INTERVAL=1000 node src/bin/start.js start http://127.0.0.1:9000 test2",

@@ -128,2 +130,3 @@ "demo-timeout": "WAIT_ON_TIMEOUT=10000 node src/bin/start.js start http://127.0.0.1:9000 test2",

"dependencies": {
"arg": "^5.0.2",
"bluebird": "3.7.2",

@@ -130,0 +133,0 @@ "check-more-types": "2.24.0",

@@ -170,2 +170,12 @@ # start-server-and-test

#### expected
The server might respond, but require authorization, returning an error HTTP code by default. You can still know that the server is responding by using `--expect` argument (or its alias `--expected`):
```
$ start-test --expect 403 start :9000 test:e2e
```
See `demo-expect-403` NPM script.
## `npx` and `yarn`

@@ -337,25 +347,4 @@

Copyright (c) 2017 Gleb Bahmutov &lt;gleb.bahmutov@gmail.com&gt;
See [LICENSE](./LICENSE)
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
[npm-icon]: https://nodei.co/npm/start-server-and-test.svg?downloads=true

@@ -362,0 +351,0 @@ [npm-url]: https://npmjs.org/package/start-server-and-test

@@ -7,4 +7,7 @@ #!/usr/bin/env node

const utils = require('../utils')
const namedArguments = utils.getNamedArguments(process.argv.slice(2))
debug('named arguments: %o', namedArguments)
const args = utils.crossArguments(process.argv.slice(2))
debug('parsing CLI arguments: %o', args)

@@ -19,7 +22,7 @@ const parsed = utils.getArguments(args)

utils.printArguments({ services, test })
utils.printArguments({ services, test, namedArguments })
startAndTest({ services, test }).catch(e => {
startAndTest({ services, test, namedArguments }).catch(e => {
console.error(e)
process.exit(1)
})

@@ -31,3 +31,3 @@ // @ts-check

function waitAndRun ({ start, url, runFn }) {
function waitAndRun ({ start, url, runFn, namedArguments }) {
la(is.unemptyString(start), 'missing start script name', start)

@@ -40,2 +40,7 @@ la(is.fn(runFn), 'missing test script name', runFn)

)
const isSuccessfulHttpCode = status =>
(status >= 200 && status < 300) || status === 304
const validateStatus = namedArguments.expect
? status => status === namedArguments.expect
: isSuccessfulHttpCode

@@ -94,4 +99,3 @@ debug('starting server with command "%s", verbose mode?', start, isDebug())

},
validateStatus: status =>
(status >= 200 && status < 300) || status === 304
validateStatus
}

@@ -127,3 +131,3 @@ debug('wait-on options %o', options)

*/
function startAndTest ({ services, test }) {
function startAndTest ({ services, test, namedArguments }) {
if (services.length === 0) {

@@ -139,2 +143,3 @@ throw new Error('Got zero services to start ...')

url: services[0].url,
namedArguments,
runFn: runTests

@@ -147,5 +152,6 @@ })

url: services[0].url,
namedArguments,
runFn: () => {
debug('previous service started, now going to the next one')
return startAndTest({ services: services.slice(1), test })
return startAndTest({ services: services.slice(1), test, namedArguments })
}

@@ -152,0 +158,0 @@ })

@@ -5,3 +5,9 @@ const la = require('lazy-ass')

const { existsSync } = require('fs')
const arg = require('arg')
const debug = require('debug')('start-server-and-test')
const namedArguments = {
'--expect': Number
}
/**

@@ -12,3 +18,11 @@ * Returns new array of command line arguments

*/
const crossArguments = cliArgs => {
const crossArguments = cliArguments => {
const args = arg(namedArguments, {
permissive: true,
argv: cliArguments
})
debug('initial parsed arguments %o', args)
// all other arguments
const cliArgs = args._
let concatModeChar = false

@@ -48,2 +62,15 @@ const indicationChars = ["'", '"', '`']

const getNamedArguments = cliArgs => {
const args = arg(namedArguments, {
permissive: true,
argv: cliArgs
})
debug('initial parsed arguments %o', args)
return {
expect: args['--expect'],
// aliases
'--expected': '--expect'
}
}
/**

@@ -196,8 +223,9 @@ * Returns parsed command line arguments.

function printArguments ({ services, test }) {
function printArguments ({ services, test, namedArguments }) {
services.forEach((service, k) => {
console.log('%d: starting server using command "%s"', k + 1, service.start)
console.log(
'and when url "%s" is responding with HTTP status code 200',
service.url
'and when url "%s" is responding with HTTP status code %d',
service.url,
namedArguments.expect
)

@@ -223,2 +251,3 @@ })

getArguments,
getNamedArguments,
isPackageScriptName,

@@ -225,0 +254,0 @@ isUrlOrPort,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc