ensure the current working directory is searched first for --stack modules
This commit is contained in:
@ -3,7 +3,7 @@ const fetch = require('node-fetch')
|
||||
const LocalWebServer = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const tom = module.exports = new Tom('test')
|
||||
const tom = module.exports = new Tom('api')
|
||||
|
||||
tom.test('basic', async function () {
|
||||
const port = 9000 + this.index
|
37
test/cli.js
37
test/cli.js
@ -3,56 +3,41 @@ const a = require('assert')
|
||||
const WsCli = require('../lib/cli-app')
|
||||
const fetch = require('node-fetch')
|
||||
|
||||
const tom = module.exports = new Tom('cli')
|
||||
const tom = module.exports = new Tom('cli', { concurrency: 1 })
|
||||
|
||||
tom.test('cli.run', async function () {
|
||||
tom.test('simple', async function () {
|
||||
const port = 7500 + this.index
|
||||
const origArgv = process.argv.slice()
|
||||
process.argv = [ 'node', 'something', '--port', `${port}` ]
|
||||
const cli = new WsCli({ logError: function () {} })
|
||||
const server = cli.start()
|
||||
process.argv = origArgv
|
||||
const server = cli.start([ '--port', `${port}` ])
|
||||
const response = await fetch(`http://127.0.0.1:${port}/package.json`)
|
||||
server.close()
|
||||
a.strictEqual(response.status, 200)
|
||||
})
|
||||
|
||||
tom.test('cli.run: bad option', async function () {
|
||||
const origArgv = process.argv.slice()
|
||||
process.argv = [ 'node', 'something', '--should-fail' ]
|
||||
tom.test('bad option', async function () {
|
||||
const exitCode = process.exitCode
|
||||
const cli = new WsCli({ logError: function () {} })
|
||||
const server = cli.start()
|
||||
const server = cli.start([ '--should-fail' ])
|
||||
if (!exitCode) process.exitCode = 0
|
||||
process.argv = origArgv
|
||||
a.strictEqual(server, undefined)
|
||||
})
|
||||
|
||||
tom.test('cli.run: --help', async function () {
|
||||
const origArgv = process.argv.slice()
|
||||
process.argv = [ 'node', 'something', '--help' ]
|
||||
tom.test('--help', async function () {
|
||||
const cli = new WsCli({ log: function () {} })
|
||||
cli.start()
|
||||
process.argv = origArgv
|
||||
cli.start([ '--help' ])
|
||||
})
|
||||
|
||||
tom.test('cli.run: --version', async function () {
|
||||
const origArgv = process.argv.slice()
|
||||
process.argv = [ 'node', 'something', '--version' ]
|
||||
tom.test('--version', async function () {
|
||||
let logMsg = ''
|
||||
const cli = new WsCli({ log: function (msg) { logMsg = msg } })
|
||||
cli.start()
|
||||
cli.start([ '--version' ])
|
||||
const pkg = require('../package.json')
|
||||
a.strictEqual(logMsg.trim(), pkg.version)
|
||||
process.argv = origArgv
|
||||
})
|
||||
|
||||
tom.test('cli.run: default-stack', async function () {
|
||||
const origArgv = process.argv.slice()
|
||||
process.argv = [ 'node', 'something', '--default-stack' ]
|
||||
tom.test('default-stack', async function () {
|
||||
let logMsg = ''
|
||||
const cli = new WsCli({ log: function (msg) { logMsg = msg } })
|
||||
cli.start()
|
||||
cli.start([ '--default-stack' ])
|
||||
a.ok(/lws-static/.test(logMsg))
|
||||
process.argv = origArgv
|
||||
})
|
||||
|
3
test/fixture/middleware/index.js
Normal file
3
test/fixture/middleware/index.js
Normal file
@ -0,0 +1,3 @@
|
||||
class TestMiddleware {}
|
||||
|
||||
module.exports = TestMiddleware
|
35
test/sequential.js
Normal file
35
test/sequential.js
Normal file
@ -0,0 +1,35 @@
|
||||
const Tom = require('test-runner').Tom
|
||||
const fetch = require('node-fetch')
|
||||
const LocalWebServer = require('../')
|
||||
const WsCli = require('../lib/cli-app')
|
||||
const a = require('assert')
|
||||
|
||||
const tom = module.exports = new Tom('sequential', { concurrency: 1 })
|
||||
|
||||
let origCwd = ''
|
||||
|
||||
tom.test('before', async function () {
|
||||
origCwd = process.cwd()
|
||||
process.chdir('test/fixture/middleware')
|
||||
})
|
||||
|
||||
tom.test('cli: middleware named "index.js"', async function () {
|
||||
let logMsg = ''
|
||||
const cli = new WsCli({ log: function (msg) { logMsg = msg } })
|
||||
const lws = cli.start([ '--stack', 'index.js', '--config' ])
|
||||
a.ok(/TestMiddleware/.test(logMsg))
|
||||
})
|
||||
|
||||
tom.test('basic', async function () {
|
||||
const port = 9100 + this.index
|
||||
const ws = LocalWebServer.create({
|
||||
port: port,
|
||||
stack: 'index.js'
|
||||
})
|
||||
ws.server.close()
|
||||
a.strictEqual(ws.stack[0].constructor.name, 'TestMiddleware')
|
||||
})
|
||||
|
||||
tom.test('after', async function () {
|
||||
process.chdir(origCwd)
|
||||
})
|
Reference in New Issue
Block a user