Skip to content

Commit

Permalink
chore: added exec param to ./bin/server
Browse files Browse the repository at this point in the history
  • Loading branch information
lquixada committed Aug 4, 2021
1 parent 7e4b657 commit 80c46c1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
50 changes: 26 additions & 24 deletions bin/server
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env node
const yargs = require('yargs/yargs')
const { spawn } = require('child_process')
const express = require('express')
const bodyParser = require('body-parser')
const serveIndex = require('serve-index');
const serveIndex = require('serve-index')
const path = require('path')
const app = express()
const dir = path.join(__dirname, '..')
Expand All @@ -19,9 +20,9 @@ app.patch('/request', processRequest)
app.delete('/request', processRequest)

// This line needs to be at the end, otherwise it will block any method different than GET
app.use(express.static(dir), serveIndex(dir, {'icons': true, view: 'details'}))
app.use(express.static(dir), serveIndex(dir, { icons: true, view: 'details' }))

function processRequest(req, res) {
function processRequest (req, res) {
const headers = {}
const isDelete = req.method === 'DELETE'

Expand All @@ -39,39 +40,40 @@ function processRequest(req, res) {
})
}

function processFileUrl(argv) {
const args = argv.slice(2)
function processFileUrl (args) {
const fileParamIndex = args.indexOf('-f')

if (fileParamIndex > 0) {
const fileIndex = fileParamIndex + 1
args[fileIndex] = args[fileIndex].replace(/^\.\//, `http://localhost:${port}/`)
}

return args
}

const hostname = '127.0.0.1'
const port = 8000
const args = processFileUrl(process.argv)
const { argv } = yargs(process.argv.slice(2))

const server = app.listen(port, hostname, () => {
if (args.length === 0) {
console.log(`Test server listening at http://localhost:${port}`)
return
}
console.log(`Test server listening at http://localhost:${port}`)

const command = args[0]
const params = args.slice(1)
const child = spawn(command, params, {
env: {
...process.env,
FORCE_COLOR: true // ensure mocha outputs colors on node test
}
})
if (argv.exec) {
const args = processFileUrl(argv.exec.split(' '))
const command = args[0]
const params = args.slice(1)
const child = spawn(command, params, {
env: {
...process.env,
FORCE_COLOR: true // ensure mocha outputs colors on node test
}
})

child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stdout)
child.on('exit', code => {
server.close()
process.exit(code)
})
child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stdout)
child.on('exit', code => {
server.close()
process.exit(code)
})
}
})
2 changes: 1 addition & 1 deletion test/fetch/browser/run.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
browser="./node_modules/.bin/mocha-headless-chrome"
./bin/server $browser -f "$(dirname $0)/index.html?globals=on"
./bin/server --exec "$browser -f $(dirname $0)/index.html?globals=on"
2 changes: 1 addition & 1 deletion test/fetch/node/run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
nyc="./node_modules/.bin/nyc"
mocha="./node_modules/.bin/mocha"
./bin/server $nyc $mocha $(dirname "$0")/index.js
./bin/server --exec "$nyc $mocha $(dirname $0)/index.js"
2 changes: 1 addition & 1 deletion test/fetch/whatwg/run.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
browser="./node_modules/.bin/mocha-headless-chrome"
./bin/server $browser -f "$(dirname $0)/index.html?globals=off"
./bin/server --exec "$browser -f $(dirname $0)/index.html?globals=off"

0 comments on commit 80c46c1

Please sign in to comment.