Skip to content

Commit 28fc47f

Browse files
committed
🧪 Tests exec without workspace
1 parent 0064a09 commit 28fc47f

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"clean": "npm-run-all clean-dist clean-built",
3838
"clean-dist": "rimraf dist",
3939
"clean-built": "rimraf built",
40-
"test": "env TS_NODE_PROJECT=src/test/tsconfig.json mocha -r ts-node/register --exit src/test/container-features/lockfile.test.ts",
40+
"test": "env TS_NODE_PROJECT=src/test/tsconfig.json mocha -r ts-node/register --exit src/test/cli.exec.buildKit.1.test.ts",
4141
"test-matrix": "env TS_NODE_PROJECT=src/test/tsconfig.json mocha -r ts-node/register --exit",
4242
"test-container-features": "env TS_NODE_PROJECT=src/test/tsconfig.json mocha -r ts-node/register --exit src/test/container-features/*.test.ts",
4343
"test-container-features-cli": "env TS_NODE_PROJECT=src/test/tsconfig.json mocha -r ts-node/register --exit src/test/container-features/featuresCLICommands.test.ts",

src/test/cli.exec.base.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function describeTests1({ text, options }: BuildKitOption) {
1414
describe('Dev Containers CLI', function () {
1515
this.timeout('360s');
1616

17-
const tmp = path.relative(process.cwd(), path.join(__dirname, 'tmp'));
17+
const tmp = path.join(__dirname, 'tmp');
1818
const cli = `npx --prefix ${tmp} devcontainer`;
1919

2020
before('Install', async () => {
@@ -30,12 +30,18 @@ export function describeTests1({ text, options }: BuildKitOption) {
3030
const testFolder = `${__dirname}/configs/image`;
3131
beforeEach(async () => containerId = (await devContainerUp(cli, testFolder, options)).containerId);
3232
afterEach(async () => await devContainerDown({ containerId }));
33-
it('should execute successfully', async () => {
33+
it.only('should execute successfully', async () => {
3434
const res = await shellBufferExec(`${cli} exec --workspace-folder ${testFolder} echo hi`);
3535
assert.strictEqual(res.code, 0);
3636
assert.equal(res.signal, undefined);
3737
assert.strictEqual(res.stdout.toString(), 'hi\n');
3838
});
39+
it.only('should execute without a workspace folder', async () => {
40+
const res = await shellBufferExec(`${cli} exec echo hi`, { cwd: testFolder});
41+
assert.strictEqual(res.code, 0);
42+
assert.equal(res.signal, undefined);
43+
assert.strictEqual(res.stdout.toString(), 'hi\n');
44+
});
3945
it('should not run in a terminal', async () => {
4046
const res = await shellBufferExec(`${cli} exec --workspace-folder ${testFolder} [ ! -t 1 ]`);
4147
assert.strictEqual(res.code, 0);

src/test/testUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ export interface BufferExecResult {
5959
signal?: string | null;
6060
}
6161

62-
export async function shellBufferExec(command: string, options: { stdin?: Buffer } = {}): Promise<BufferExecResult> {
63-
const exec = await plainExec(undefined);
62+
export async function shellBufferExec(command: string, options: { stdin?: Buffer, cwd?: string } = {}): Promise<BufferExecResult> {
63+
const exec = await plainExec(options.cwd);
6464
return runCommandNoPty({
6565
exec,
6666
cmd: '/bin/sh',

0 commit comments

Comments
 (0)