-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make our internal
rc
into a function that accepts a namespace arg (…
…defaults to `sails`) This allows `node app.js` to share in the glory of humanized env vars, and protects against the returned object getting mutated
- Loading branch information
Showing
12 changed files
with
118 additions
and
63 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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* Module dependencies | ||
*/ | ||
|
||
var rc = require('rc'); | ||
var rc = require('../lib/app/configuration/rc'); | ||
|
||
|
||
/** | ||
|
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
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
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
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
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -6,7 +6,10 @@ var path = require('path'); | |
var util = require('util'); | ||
var tmp = require('tmp'); | ||
var request = require('request'); | ||
var assert = require('assert'); | ||
var _ = require('@sailshq/lodash'); | ||
var MProcess = require('machinepack-process'); | ||
var Filesystem = require('machinepack-fs'); | ||
var testSpawningSailsLiftChildProcessInCwd = require('../helpers/test-spawning-sails-lift-child-process-in-cwd'); | ||
var appHelper = require('./helpers/appHelper'); | ||
|
||
|
@@ -46,20 +49,65 @@ describe('Starting sails server with `sails lift`', function() { | |
// And CD in. | ||
before(function (){ | ||
process.chdir(pathToTestApp); | ||
Filesystem.writeSync({ | ||
force: true, | ||
destination: 'api/controllers/getconf.js', | ||
string: 'module.exports = function (req, res) { return res.json(sails.config); }' | ||
}).execSync(); | ||
|
||
}); | ||
|
||
// Test `sails lift` in the CWD. | ||
describe('running `sails lift`', function (){ | ||
testSpawningSailsLiftChildProcessInCwd({ | ||
pathToSailsCLI: pathToSailsCLI, | ||
liftCliArgs: ['--hooks.pubsub=false'], | ||
envVars: _.extend({ 'sails_foo__bar': '{"abc": 123}'}, process.env), | ||
httpRequestInstructions: { | ||
method: 'GET', | ||
uri: 'http://localhost:1337', | ||
}, | ||
fnWithAdditionalTests: function (){ | ||
it('should humanize the config passed in via env vars', function (done){ | ||
request({ | ||
method: 'GET', | ||
uri: 'http://localhost:1337/getconf', | ||
}, function(err, response, body) { | ||
if (err) { return done(err); } | ||
body = JSON.parse(body); | ||
This comment has been minimized.
Sorry, something went wrong.
mikermcneil
Member
|
||
assert.equal(body.foo && body.foo.bar && body.foo.bar.abc, 123); | ||
return done(); | ||
}); | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
// Test `sails lift` in the CWD with env vars for config. | ||
describe('running `node app.js`', function (){ | ||
|
||
testSpawningSailsLiftChildProcessInCwd({ | ||
pathToSailsCLI: pathToSailsCLI, | ||
cliArgs: ['app.js', '--hooks.pubsub=false'], | ||
envVars: _.extend({ 'sails_foo__bar': '{"abc": 123}'}, process.env), | ||
fnWithAdditionalTests: function (){ | ||
it('should humanize the config passed in via env vars', function (done){ | ||
request({ | ||
method: 'GET', | ||
uri: 'http://localhost:1337/getconf', | ||
}, function(err, response, body) { | ||
if (err) { return done(err); } | ||
body = JSON.parse(body); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
assert.equal(body.foo && body.foo.bar && body.foo.bar.abc, 123); | ||
return done(); | ||
}); | ||
}); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
|
||
// Test `sails lift --port=1492` in the CWD. | ||
describe('running `sails lift --port=1492`', function (){ | ||
testSpawningSailsLiftChildProcessInCwd({ | ||
|
1 comment
on commit bd455af
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future reference, the test is failing because:
stdout: info: No local Sails install detected; using globally-installed Sails.
...
...
stderr: debug: -------------------------------------------------------
✓ should still be lifted
✓ should respond with a 200 status code when a `GET` request is sent to `http://localhost:1337`
✓ should humanize the config passed in via env vars
running `node app.js`
and then waiting for a bit
stderr: Encountered an error when attempting to require('sails'):
stderr: Error: Cannot find module 'sails'
at Function.Module._resolveFilename (module.js:326:15)
at Function.Module._load (module.js:277:25)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/private/var/folders/_s/347n05_x2rgb_0w6s6y0ytr00000gn/T/tmp-291179ZUWIae91wSm/testApp/app.js:35:11)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
stderr: --
stderr: To run an app using `node app.js`, you usually need to have a version of `sails` installed in the same directory as your app.
To do that, run `npm install sails`
stderr:
Alternatively, if you have sails installed globally (i.e. you did `npm install -g sails`), you can use `sails lift`.
When you run `sails lift`, your app will still use a local `./node_modules/sails` dependency if it exists,
stderr: but if it doesn't, the app will run with the global sails instead!
✓ should still be lifted
1) should humanize the config passed in via env vars
2) "after all" hook
@sgress454 re: cliArgs - this test util was intended to be for
sails lift
-- so i'd rather not have it testnode app
or other stuff. Looks like it's only being used this place at one point in the code though, so easy to change.Also, if we're adding
envVars
(which I think is a good idea), then we've just got to add them to the comments above as well.