Browse Source

ensure the current working directory is searched first for --stack modules

master
Lloyd Brookes 6 years ago
parent
commit
19e5d2e217
  1. 2
      index.js
  2. 2
      lib/cli-app.js
  3. 40
      package-lock.json
  4. 4
      package.json
  5. 2
      test/api.js
  6. 37
      test/cli.js
  7. 3
      test/fixture/middleware/index.js
  8. 35
      test/sequential.js

2
index.js

@ -10,7 +10,7 @@ const Lws = require('lws')
class LocalWebServer extends Lws {
_getDefaultConfig () {
return Object.assign(super._getDefaultConfig(), {
moduleDir: [ __dirname, '.' ],
moduleDir: [ '.', __dirname ],
stack: require('./lib/default-stack')
})
}

2
lib/cli-app.js

@ -14,7 +14,7 @@ class WsCli extends LwsCli {
getDefaultOptions () {
return Object.assign(super.getDefaultOptions(), {
stack: require('./default-stack').slice(),
moduleDir: [ path.resolve(__dirname, '..'), '.' ]
moduleDir: [ '.', path.resolve(__dirname, '..') ]
})
}

40
package-lock.json

@ -550,9 +550,9 @@
"optional": true
},
"common-log-format": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/common-log-format/-/common-log-format-0.1.4.tgz",
"integrity": "sha512-BXcgq+wzr2htmBmnT7cL7YHzPAWketWbr4kozjoM9kWe4sk3+zMgjcH0HO+EddjDlEw2LZysqLpVRwbF318tDw=="
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/common-log-format/-/common-log-format-1.0.0.tgz",
"integrity": "sha512-fFn/WPNbsTCGTTwdCpZfVZSa5mgqMEkA0gMTRApFSlEsYN+9B2FPfiqch5FT+jsv5IV1RHV3GeZvCa7Qg+jssw=="
},
"common-sequence": {
"version": "1.0.2",
@ -1808,9 +1808,9 @@
}
},
"lws": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/lws/-/lws-2.0.0.tgz",
"integrity": "sha512-OgAJ7Od6nteHv1p8QQPc28xFNZrPLBkyOu8lHsVH0Eo4qYPiY/401LHnIKwJEAQZAV8YF0lSL7/mtSxAM+mAVg==",
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/lws/-/lws-2.0.1.tgz",
"integrity": "sha512-9aXsOibjPeHxb9xfPws5beM2YAyRW4QWj9rORBKOe/W9Pca67Ftx8zPSyUsgLTo7QUFi6hFK/J+xCYnvzGMzzw==",
"requires": {
"ansi-escape-sequences": "^4.1.0",
"array-back": "^3.1.0",
@ -1895,12 +1895,12 @@
}
},
"lws-log": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/lws-log/-/lws-log-1.0.2.tgz",
"integrity": "sha512-bJVcNiO43nnVtC/+QSnH1noNfBfgXJc98uLwCgofeDieTcQ56fWi+lX3DdXP5yN7p8J4ZrKVFBraA93TOF+p1g==",
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/lws-log/-/lws-log-1.0.3.tgz",
"integrity": "sha512-lxOsQgXbWd7Xwny5dVZnYUu7b6nSoT3o5A+OEuktxomEAG7Eirb6o8eOkeTMbfhE9/qfviXb5W2rFDcWk+UAlA==",
"requires": {
"koa-morgan": "^1.0.1",
"stream-log-stats": "^3.0.0"
"stream-log-stats": "^3.0.1"
}
},
"lws-mime": {
@ -2686,9 +2686,9 @@
}
},
"resolve": {
"version": "1.11.1",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.1.tgz",
"integrity": "sha512-vIpgF6wfuJOZI7KKKSP+HmiKggadPQAdsp5HiC1mvqnfp0gF1vdwgBWZIdrVft9pgqoMFQN+R7BSWZiBxx+BBw==",
"version": "1.11.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.0.tgz",
"integrity": "sha512-WL2pBDjqT6pGUNSUzMw00o4T7If+z4H2x3Gz893WoUQ5KW8Vr9txp00ykiP16VBaZF5+j/OcXJHZ9+PCvdiDKw==",
"dev": true,
"requires": {
"path-parse": "^1.0.6"
@ -2957,14 +2957,14 @@
}
},
"stream-log-stats": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/stream-log-stats/-/stream-log-stats-3.0.0.tgz",
"integrity": "sha512-rv7anqmc2fYKfCkLeISQbtw1ebyiapl34AltF04cknL/l1IGbffAB0DN2NvH3ec57kXwzJBOK6ZsjxP41Ai5IA==",
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/stream-log-stats/-/stream-log-stats-3.0.1.tgz",
"integrity": "sha512-FmaeaSGmhuYkYfD9HAnTJxmqH2nASpUvYl4/KiWF5mOUW3i0EEfqWJOka20M/rLKotsl8HEQM3OtNqd2xZnZfQ==",
"requires": {
"JSONStream": "^1.3.5",
"ansi-escape-sequences": "^4.1.0",
"byte-size": "^5.0.1",
"common-log-format": "~0.1.4",
"common-log-format": "^1.0.0",
"lodash.throttle": "^4.1.1",
"stream-via": "^1.0.4",
"table-layout": "~0.4.4"
@ -3438,9 +3438,9 @@
}
},
"yargs-parser": {
"version": "13.1.0",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.0.tgz",
"integrity": "sha512-Yq+32PrijHRri0vVKQEm+ys8mbqWjLiwQkMFNXEENutzLPP0bE4Lcd4iA3OQY5HF+GD3xXxf0MEHb8E4/SA3AA==",
"version": "13.1.1",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.1.tgz",
"integrity": "sha512-oVAVsHz6uFrg3XQheFII8ESO2ssAf9luWuAd6Wexsu4F3OtIW0o8IribPXYrD4WC24LWtPrJlGy87y5udK+dxQ==",
"dev": true,
"requires": {
"camelcase": "^5.0.0",

4
package.json

@ -39,7 +39,7 @@
"index.js"
],
"dependencies": {
"lws": "2.0.0",
"lws": "^2.0.1",
"lws-basic-auth": "^1.0.3",
"lws-blacklist": "^2.0.2",
"lws-body-parser": "^1.0.2",
@ -48,7 +48,7 @@
"lws-cors": "^2.0.1",
"lws-index": "^1.0.4",
"lws-json": "^1.0.1",
"lws-log": "^1.0.2",
"lws-log": "^1.0.3",
"lws-mime": "^1.0.1",
"lws-range": "^2.0.1",
"lws-request-monitor": "^1.0.4",

2
test/test.js → test/api.js

@ -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

@ -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

@ -0,0 +1,3 @@
class TestMiddleware {}
module.exports = TestMiddleware

35
test/sequential.js

@ -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)
})
Loading…
Cancel
Save