Tests for --settings, and also Nick's review comments

This commit is contained in:
Naomi Seyfer
2012-12-03 15:35:18 -08:00
parent 4d5498424a
commit fb1d2b319a
4 changed files with 47 additions and 21 deletions

View File

@@ -120,7 +120,25 @@ kill $METEOR_PID
ps ax | grep -e "$MONGOMARK" | grep -v grep | awk '{print $1}' | xargs kill
echo "... settings"
cat > settings.json <<EOF
{ "foo" : "bar",
"baz" : "quux"
}
EOF
cat > settings.js <<EOF
if (Meteor.isServer) {
Meteor.startup(function () {
if (!Meteor.settings) process.exit(1);
if (Meteor.settings.foo !== "bar") process.exit(1);
process.exit(0);
});
}
EOF
$METEOR -p $PORT --settings='settings.json' --once > /dev/null
# XXX more tests here!

View File

@@ -83,6 +83,20 @@ var findCommand = function (name) {
process.exit(1);
};
var getSettings = function (filename) {
var str;
try {
str = fs.readFileSync(filename);
} catch (e) {
throw new Error("Could not find settings file " + argv.settings);
}
if (str.length > 0x10000) {
throw new Error("Settings file must be less than 64 KB long");
}
JSON.parse(str);
return str;
};
// XXX when the pass unexpected argument or unrecognized flags, print
// an error and fail out
@@ -101,9 +115,9 @@ Commands.push({
.describe('debug', 'Run in debug mode for node-inspector')
.boolean('debug-brk')
.describe('debug-brk', 'Run in debug mode and break on first line')
.describe('settings', 'Make the given JSON file\'s contents available in Meteor.settings')
.describe('settings', 'Set Meteor.settings to the contents of a JSON file; takes the filename as an argument')
.boolean('once')
.describe('once', 'Only run the project once, and return whatever exit code it returned.')
.describe('once', 'Disable automatic reloading. Only run the server once')
.usage(
"Usage: meteor run [options]\n" +
"\n" +
@@ -125,13 +139,8 @@ Commands.push({
process.stdout.write(opt.help());
process.exit(1);
}
if (argv.settings) {
try {
settings = fs.readFileSync(argv.settings);
} catch (e) {
process.stdout.write("Could not file settings file " + argv.settings + "\n");
process.exit(1);
}
if (new_argv.settings) {
settings = getSettings(new_argv.settings);
}
var app_dir = path.resolve(require_project("run", true)); // app or package

View File

@@ -19,18 +19,16 @@ var _ = require(path.join(__dirname, '..', 'lib', 'third', 'underscore.js'));
// list of log objects from the child process.
var server_log = [];
// port that mongo is running on
var Status = {
running: false, // is server running now?
crashing: false, // does server crash whenever we start it?
listening: false, // do we expect the server to be listening now.
counter: 0, // how many crashes in rapid succession
code: 0,
shouldRestart: true,
shuttingDown: false,
code: 0, // exit code last returned
shouldRestart: true, // true if we should be restarting the server
shuttingDown: false, // true if we're on the way to shutting down the server
justCrash : function () {
exitNow : function () {
var self = this;
log_to_clients({'exit': "Your application is exiting."});
self.shuttingDown = true;
@@ -49,7 +47,7 @@ var Status = {
hard_crashed: function () {
var self = this;
if (!self.shouldRestart) {
self.justCrash();
self.exitNow();
return;
}
log_to_clients({'exit': "Your application is crashing. Waiting for file change."});
@@ -59,7 +57,7 @@ var Status = {
soft_crashed: function () {
var self = this;
if (!self.shouldRestart) {
self.justCrash();
self.exitNow();
return;
}
if (this.counter === 0)
@@ -554,6 +552,8 @@ exports.run = function (app_dir, bundle_opts, port, once, settings, dbg) {
var watcher;
var start_watching = function () {
if (!Status.shouldRestart)
return;
if (deps_info) {
if (watcher)
watcher.destroy();

View File

@@ -4,10 +4,9 @@ Meteor = {
};
try {
Meteor.settings = JSON.parse(process.env.METEOR_SETTINGS);
if (process.env.METEOR_SETTINGS)
Meteor.settings = JSON.parse(process.env.METEOR_SETTINGS);
} catch (e) {
// If the settings aren't JSON, just treat them as a string, or
// undefined, or whatever they are.
Meteor.settings = process.env.METEOR_SETTINGS;
throw new Error("Settings are not valid JSON");
}