Skip to content

Commit aad60a6

Browse files
authored
fix(system): improve hasInstance check (#940)
refs #936 - check if name matches global config name as well
1 parent 527104b commit aad60a6

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/system.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class System {
196196
*/
197197
hasInstance(instance) {
198198
const instances = this.globalConfig.get('instances', {});
199-
return some(instances, ({cwd}) => cwd === instance.dir);
199+
return some(instances, ({cwd}, name) => cwd === instance.dir && name === instance.name);
200200
}
201201

202202
/**

test/unit/system-spec.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,17 @@ describe('Unit: System', function () {
289289
it('hasInstance works', function () {
290290
const System = require(modulePath);
291291
const system = new System({}, []);
292-
system.globalConfig.set('instances', {test: {cwd: '/dir/a'}});
292+
system.globalConfig.set('instances', {test: {cwd: '/dir/a'}, test2: {cwd: '/dir/c'}});
293293
const instanceA = new Instance({}, system, '/dir/a');
294+
instanceA._cliConfig.set('name', 'test');
295+
294296
const instanceB = new Instance({}, system, '/dir/b');
297+
const instanceC = new Instance({}, system, '/dir/c');
298+
instanceC._cliConfig.set('name', 'different');
295299

296300
expect(system.hasInstance(instanceA)).to.be.true;
297301
expect(system.hasInstance(instanceB)).to.be.false;
302+
expect(system.hasInstance(instanceC)).to.be.false;
298303
});
299304

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

0 commit comments

Comments
 (0)