Skip to content

Commit 98c3316

Browse files
committed
build test
1 parent d2d47d6 commit 98c3316

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/test/cli.build.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,5 +433,49 @@ describe('Dev Containers CLI', function () {
433433
const details = JSON.parse((await shellExec(`docker inspect ${response.imageName}`)).stdout)[0] as ImageDetails;
434434
assert.strictEqual(details.Config.Labels?.test_build_options, 'success');
435435
});
436+
437+
it('should use current directory for build when no workspace-folder provided', async function () {
438+
const testFolder = `${__dirname}/configs/image`; // Use simpler config without features
439+
const absoluteTmpPath = path.resolve(__dirname, 'tmp');
440+
const absoluteCli = `npx --prefix ${absoluteTmpPath} devcontainer`;
441+
const originalCwd = process.cwd();
442+
console.log(`Original cwd: ${originalCwd}`);
443+
console.log(`Changing to test folder: ${testFolder}`);
444+
try {
445+
process.chdir(testFolder);
446+
const res = await shellExec(`${absoluteCli} build`);
447+
const response = JSON.parse(res.stdout);
448+
assert.equal(response.outcome, 'success');
449+
assert.ok(response.imageName);
450+
} finally {
451+
process.chdir(originalCwd);
452+
}
453+
});
454+
455+
it('should fail gracefully when no workspace-folder and no config in current directory', async function () {
456+
const tempDir = path.join(os.tmpdir(), 'devcontainer-build-test-' + Date.now());
457+
await shellExec(`mkdir -p ${tempDir}`);
458+
const absoluteTmpPath = path.resolve(__dirname, 'tmp');
459+
const absoluteCli = `npx --prefix ${absoluteTmpPath} devcontainer`;
460+
const originalCwd = process.cwd();
461+
try {
462+
process.chdir(tempDir);
463+
let success = false;
464+
try {
465+
await shellExec(`${absoluteCli} build`);
466+
success = true;
467+
} catch (error) {
468+
assert.equal(error.error.code, 1, 'Should fail with exit code 1');
469+
const res = JSON.parse(error.stdout);
470+
assert.equal(res.outcome, 'error');
471+
assert.match(res.message, /Dev container config .* not found/);
472+
}
473+
assert.equal(success, false, 'expect non-successful call');
474+
} finally {
475+
process.chdir(originalCwd);
476+
await shellExec(`rm -rf ${tempDir}`);
477+
}
478+
});
479+
436480
});
437481
});

0 commit comments

Comments
 (0)