-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(runner): Manually walk up filesystem looking for node_modules/.b…
…in/serve (and cypress)
- Loading branch information
1 parent
118ede2
commit ab81837
Showing
4 changed files
with
60 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env node | ||
|
||
const { launchCypress } = require('./cypress-runner'); | ||
const yargs = require('yargs') | ||
.usage('Usage: $0 [open|run] [options]') | ||
.command('open', 'Open the cypress UI') | ||
.command('run', 'Runs the cypress test suite') | ||
.demandCommand(1, 'Specify either "open" or "run"') | ||
.option('path', { | ||
description: 'The path to serve files from', | ||
default: 'dist', | ||
}) | ||
.option('port', { | ||
description: 'The port to serve files from', | ||
default: 4000, | ||
}).argv; | ||
|
||
const { path, port } = yargs; | ||
const [ cypressCmd ] = yargs._; | ||
|
||
launchCypress(cypressCmd, path, port); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,42 @@ | ||
#!/usr/bin/env node | ||
|
||
const fs = require('fs'); | ||
const { resolve } = require('path'); | ||
const yargs = require('yargs') | ||
.usage('Usage: $0 [open|run] [options]') | ||
.command('open', 'Open the cypress UI') | ||
.command('run', 'Runs the cypress test suite') | ||
.demandCommand(1, 'Specify either "open" or "run"') | ||
.option('path', { | ||
description: 'The path to serve files from', | ||
default: 'dist', | ||
}) | ||
.option('port', { | ||
description: 'The port to serve files from', | ||
default: 4000, | ||
}).argv; | ||
|
||
const { path, port } = yargs; | ||
const [ cypressCmd ] = yargs._; | ||
|
||
if (!fs.existsSync(path)) { | ||
console.error(`${resolve(path)} doesn't exist, can't serve files`); | ||
process.exit(); | ||
const { resolve } = require('path'); | ||
|
||
function findBinary(binaryName, path) { | ||
const binary = resolve(path, 'node_modules', '.bin', binaryName); | ||
if (fs.existsSync(binary)) { | ||
return binary; | ||
} | ||
|
||
const parent = resolve(path, '..'); | ||
if (parent === path) { | ||
throw new Error(`Couldn't find **/node_modules/.bin/${binaryName} in parents of ${path.resolve()}`); | ||
} | ||
|
||
return findBinary(binaryName, parent); | ||
} | ||
|
||
const { fork } = require('child_process'); | ||
const browserSync = fork('npx', ['serve', '-n', '-s', '-p', port, path]); | ||
const cypress = fork('npx', ['cypress', cypressCmd]); | ||
function launchCypress(cypressCmd, path, port) { | ||
if (!fs.existsSync(path)) { | ||
console.error(`${resolve(path)} doesn't exist, can't serve files`); | ||
process.exit(); | ||
} | ||
|
||
process.on('SIGINT', function() { | ||
browserSync.kill(); | ||
cypress.kill(); | ||
}); | ||
const { fork } = require('child_process'); | ||
const serveBinary = findBinary('serve', '.'); | ||
const cypressBinary = findBinary('cypress', '.'); | ||
const browserSync = fork(serveBinary, [ '-n', '-s', '-p', port, path ]); | ||
const cypress = fork(cypressBinary, [ cypressCmd ]); | ||
|
||
process.on('SIGINT', function () { | ||
browserSync.kill(); | ||
cypress.kill(); | ||
}); | ||
|
||
browserSync.on('exit', () => cypress.kill()); | ||
cypress.on('exit', (code) => { | ||
browserSync.kill(); | ||
process.exit(code) | ||
}); | ||
} | ||
|
||
browserSync.on('exit', () => cypress.kill()); | ||
cypress.on('exit', (code) => { browserSync.kill(); process.exit(code) }); | ||
module.exports.launchCypress = launchCypress; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './cypress-runner'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters