diff --git a/index.js b/index.js index 216952e..e19e1b2 100644 --- a/index.js +++ b/index.js @@ -132,6 +132,7 @@ Liftoff.prototype.buildEnvironment = function(opts) { return { cwd: cwd, preload: preload, + completion: opts.completion, configNameSearch: configNameSearch, configPath: configPath, configBase: configBase, @@ -164,17 +165,17 @@ Liftoff.prototype.prepare = function(opts, fn) { process.title = this.processTitle; - var completion = opts.completion; - if (completion && this.completions) { - return this.completions(completion); - } - var env = this.buildEnvironment(opts); fn.call(this, env); }; Liftoff.prototype.execute = function(env, forcedFlags, fn) { + var completion = env.completion; + if (completion && this.completions) { + return this.completions(completion); + } + if (typeof forcedFlags === 'function') { fn = forcedFlags; forcedFlags = undefined; diff --git a/test/index.js b/test/index.js index 7c25499..af6abfb 100644 --- a/test/index.js +++ b/test/index.js @@ -132,16 +132,6 @@ describe('Liftoff', function() { expect(process.title).to.equal(app.moduleName); }); - it('should return early if completions are available and requested', function(done) { - var test = new Liftoff({ - name: 'whatever', - completions: function() { - done(); - }, - }); - test.prepare({ completion: true }, function() {}); - }); - it('should call prepare with liftoff instance as context', function(done) { app.prepare({}, function() { expect(this).to.equal(app); @@ -179,6 +169,18 @@ describe('Liftoff', function() { }).to.throw(); }); + it('should return early if completions are available and requested', function(done) { + var test = new Liftoff({ + name: 'whatever', + completions: function() { + done(); + }, + }); + test.prepare({ completion: true }, function(env) { + test.execute(env); + }); + }); + it('should skip respawning if process.argv has no values from v8flags in it', function(done) { exec('node test/fixtures/prepare-execute/v8flags.js', function(err, stdout, stderr) { expect(stderr).to.equal('\n');