Skip to content

Commit 3e3d202

Browse files
committed
fix: fixing test cases
1 parent 2a14127 commit 3e3d202

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

packages/core/src/test/shared/vscode/env.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,29 +365,60 @@ VERSION_ID="22.04"
365365
})
366366

367367
describe('getComputeEnvType', async function () {
368+
let fsExistsStub: sinon.SinonStub
369+
let fsReadFileStub: sinon.SinonStub
370+
let moduleLoadStub: sinon.SinonStub
371+
372+
beforeEach(function () {
373+
// Mock fs module for isAmazonLinux2() calls
374+
const fsMock = {
375+
existsSync: sandbox.stub().returns(false),
376+
readFileSync: sandbox.stub().returns(''),
377+
}
378+
fsExistsStub = fsMock.existsSync
379+
fsReadFileStub = fsMock.readFileSync
380+
381+
// Stub Module._load to intercept require calls
382+
const Module = require('module')
383+
moduleLoadStub = sandbox.stub(Module, '_load').callThrough()
384+
moduleLoadStub.withArgs('fs').returns(fsMock)
385+
})
386+
368387
it('cloudDesktop', async function () {
369388
sandbox.stub(process, 'platform').value('linux')
370389
sandbox.stub(vscode.env, 'remoteName').value('ssh-remote')
390+
sandbox.stub(globals, 'isWeb').returns(false)
371391
stubOsVersion('5.10.220-188.869.amzn2int.x86_64')
372392
sandbox.stub(ChildProcess.prototype, 'run').resolves({ exitCode: 0 } as any)
373393

394+
// Mock fs to return false so it falls back to kernel check (which should return true for AL2)
395+
fsExistsStub.returns(false)
396+
374397
assert.deepStrictEqual(await getComputeEnvType(), 'cloudDesktop-amzn')
375398
})
376399

377400
it('ec2-internal', async function () {
378401
sandbox.stub(process, 'platform').value('linux')
379402
sandbox.stub(vscode.env, 'remoteName').value('ssh-remote')
403+
sandbox.stub(globals, 'isWeb').returns(false)
380404
stubOsVersion('5.10.220-188.869.amzn2int.x86_64')
381405
sandbox.stub(ChildProcess.prototype, 'run').resolves({ exitCode: 1 } as any)
382406

407+
// Mock fs to return false so it falls back to kernel check (which should return true for AL2)
408+
fsExistsStub.returns(false)
409+
383410
assert.deepStrictEqual(await getComputeEnvType(), 'ec2-amzn')
384411
})
385412

386413
it('ec2', async function () {
387414
sandbox.stub(process, 'platform').value('linux')
388415
sandbox.stub(vscode.env, 'remoteName').value('ssh-remote')
416+
sandbox.stub(globals, 'isWeb').returns(false)
389417
stubOsVersion('5.10.220-188.869.NOT_INTERNAL.x86_64')
390418

419+
// Mock fs to return false so it falls back to kernel check (which should return false for non-AL2)
420+
fsExistsStub.returns(false)
421+
391422
assert.deepStrictEqual(await getComputeEnvType(), 'ec2')
392423
})
393424
})

0 commit comments

Comments
 (0)