start-server-and-test
Advanced tools
Comparing version 1.7.14 to 1.8.0
{ | ||
"name": "start-server-and-test", | ||
"description": "Starts server, waits for URL, then runs test command; when the tests end, shuts down server", | ||
"version": "1.7.14", | ||
"version": "1.8.0", | ||
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>", | ||
@@ -91,2 +91,3 @@ "bugs": "https://github.com/bahmutov/start-server-and-test/issues", | ||
"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'", | ||
"travis-deploy-once": "travis-deploy-once" | ||
@@ -101,3 +102,5 @@ }, | ||
"git-issues": "1.3.1", | ||
"got": "9.6.0", | ||
"license-checker": "24.1.0", | ||
"minimist": "1.2.0", | ||
"mocha": "6.1.4", | ||
@@ -104,0 +107,0 @@ "pre-git": "3.17.1", |
@@ -36,2 +36,10 @@ # start-server-and-test | ||
### Commands | ||
In addition to using NPM script names, you can pass entire commands (surround them with quotes so it is still a single string) that will be executed "as is". For example, to start globally installed `http-server` before running and recording [Cypress.io](https://www.cypress.io) tests you can use | ||
``` | ||
start-server-and-test 'http-server -c-1 --silent' 8000 './node_modules/.bin/cypress run --record' | ||
``` | ||
### Alias | ||
@@ -114,2 +122,4 @@ | ||
or for multiple ports simply: `server-test '8000|9000' test`. | ||
## Note for webpack-dev-server users | ||
@@ -116,0 +126,0 @@ |
@@ -9,5 +9,5 @@ #!/usr/bin/env node | ||
console.log(`starting server using command "npm run ${start}"`) | ||
console.log(`and when url "${url}" is responding`) | ||
console.log(`running tests using command "npm run ${test}"`) | ||
console.log('starting server using command "%s"', start) | ||
console.log('and when url "%s" is responding', url) | ||
console.log('running tests using command "%s"', test) | ||
@@ -14,0 +14,0 @@ startAndTest({ start, url, test }).catch(e => { |
@@ -25,5 +25,5 @@ 'use strict' | ||
debug('starting server, verbose mode?', isDebug()) | ||
debug('starting server with command "%s", verbose mode?', start, isDebug()) | ||
const server = execa('npm', ['run', start], { stdio: 'inherit' }) | ||
const server = execa.shell(start, { stdio: 'inherit' }) | ||
let serverStopped | ||
@@ -90,4 +90,4 @@ | ||
function runTests () { | ||
debug('running test script command', test) | ||
return execa('npm', ['run', test], { stdio: 'inherit' }) | ||
debug('running test script command: %s', test) | ||
return execa.shell(test, { stdio: 'inherit' }) | ||
} | ||
@@ -94,0 +94,0 @@ |
const la = require('lazy-ass') | ||
const is = require('check-more-types') | ||
const { join } = require('path') | ||
/** | ||
* Returns parsed command line arguments. | ||
* If start command is NPM script name defined in the package.json | ||
* file in the current working directory, returns 'npm run start' command. | ||
*/ | ||
@@ -43,2 +46,10 @@ const getArguments = cliArgs => { | ||
if (isPackageScriptName(start)) { | ||
start = `npm run ${start}` | ||
} | ||
if (isPackageScriptName(test)) { | ||
test = `npm run ${test}` | ||
} | ||
return { | ||
@@ -51,2 +62,17 @@ start, | ||
/** | ||
* Returns true if the given string is a name of a script in the package.json file | ||
* in the current working directory | ||
*/ | ||
const isPackageScriptName = command => { | ||
la(is.unemptyString(command), 'expected command name string', command) | ||
const packageFilename = join(process.cwd(), 'package.json') | ||
const packageJson = require(packageFilename) | ||
if (!packageJson.scripts) { | ||
return false | ||
} | ||
return Boolean(packageJson.scripts[command]) | ||
} | ||
const isUrlOrPort = input => { | ||
@@ -103,4 +129,5 @@ const str = is.string(input) ? input.split('|') : [input] | ||
getArguments, | ||
isUrlOrPort: isUrlOrPort, | ||
normalizeUrl: normalizeUrl | ||
isPackageScriptName, | ||
isUrlOrPort, | ||
normalizeUrl | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17450
211
209
17
4