Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(system): improve hasInstance check #940

Merged
merged 1 commit into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class System {
*/
hasInstance(instance) {
const instances = this.globalConfig.get('instances', {});
return some(instances, ({cwd}) => cwd === instance.dir);
return some(instances, ({cwd}, name) => cwd === instance.dir && name === instance.name);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion test/unit/system-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,17 @@ describe('Unit: System', function () {
it('hasInstance works', function () {
const System = require(modulePath);
const system = new System({}, []);
system.globalConfig.set('instances', {test: {cwd: '/dir/a'}});
system.globalConfig.set('instances', {test: {cwd: '/dir/a'}, test2: {cwd: '/dir/c'}});
const instanceA = new Instance({}, system, '/dir/a');
instanceA._cliConfig.set('name', 'test');

const instanceB = new Instance({}, system, '/dir/b');
const instanceC = new Instance({}, system, '/dir/c');
instanceC._cliConfig.set('name', 'different');

expect(system.hasInstance(instanceA)).to.be.true;
expect(system.hasInstance(instanceB)).to.be.false;
expect(system.hasInstance(instanceC)).to.be.false;
});

it('cachedInstance loads instance and caches it', function () {
Expand Down