Skip to content

Commit

Permalink
chore: add test for NODE_ENV in server process for #184
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Jul 9, 2019
1 parent 542a44e commit 9c984c5
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 1 deletion.
69 changes: 69 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"pretty": "prettier-standard 'src/**/*.js'",
"size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";",
"test": "npm run unit",
"unit": "mocha src/*-spec.js",
"unit": "mocha --timeout 30000 'src/*-spec.js' 'test/*spec.js'",
"unused-deps": "dependency-check --unused --no-dev .",
"semantic-release": "semantic-release",
"start": "node test/server.js",
Expand Down Expand Up @@ -97,6 +97,7 @@
"dependency-check": "3.4.1",
"deps-ok": "1.4.1",
"dont-crack": "1.2.1",
"execa-wrap": "1.4.0",
"git-issues": "1.3.1",
"got": "9.6.0",
"license-checker": "24.1.0",
Expand Down
24 changes: 24 additions & 0 deletions test/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-env mocha */
const la = require('lazy-ass')
const execaWrap = require('execa-wrap')
const path = require('path')

describe('test-node-env', () => {
// for https://github.com/bahmutov/start-server-and-test/issues/184
it('passes NODE_ENV to the server process', () => {
const cwd = path.join(__dirname, 'test-node-env')
return execaWrap('npm', ['run', 'demo'], {
env: {
NODE_ENV: 'test'
},
cwd,
filter: ['stdout']
}).then(result => {
la(
result.includes('server has NODE_ENV=test'),
'result does not pass the right NODE_ENV to the server process',
result
)
})
})
})
8 changes: 8 additions & 0 deletions test/test-node-env/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "test-node-env",
"scripts": {
"start": "node ../server",
"test": "echo server has NODE_ENV=$NODE_ENV",
"demo": "node ../../src/bin/start.js 9000"
}
}

0 comments on commit 9c984c5

Please sign in to comment.