Skip to content

Commit

Permalink
fix!: call env.completion inside execute to allow additional config…
Browse files Browse the repository at this point in the history
…uration (#106)
  • Loading branch information
sttk authored and phated committed Nov 22, 2021
1 parent 596926a commit 2a1fc4b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
11 changes: 6 additions & 5 deletions index.js
Expand Up @@ -132,6 +132,7 @@ Liftoff.prototype.buildEnvironment = function(opts) {
return {
cwd: cwd,
preload: preload,
completion: opts.completion,
configNameSearch: configNameSearch,
configPath: configPath,
configBase: configBase,
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 12 additions & 10 deletions test/index.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 2a1fc4b

Please sign in to comment.