MCPcopy Index your code
hub / github.com/devcontainers/cli / describeTests1

Function describeTests1

src/test/cli.exec.base.ts:13–210  ·  view source on GitHub ↗
({ text, options }: BuildKitOption)

Source from the content-addressed store, hash-verified

11const pkg = require('../../package.json');
12
13export function describeTests1({ text, options }: BuildKitOption) {
14
15 describe('Dev Containers CLI', function () {
16 this.timeout('360s');
17
18 const tmp = path.relative(process.cwd(), path.join(__dirname, 'tmp'));
19 const cli = `npx --prefix ${tmp} devcontainer`;
20
21 before('Install', async () => {
22 await shellExec(`rm -rf ${tmp}/node_modules`);
23 await shellExec(`mkdir -p ${tmp}`);
24 await shellExec(`npm --prefix ${tmp} install devcontainers-cli-${pkg.version}.tgz`);
25 });
26
27 describe('Command exec', () => {
28
29 describe(`with valid (image) config [${text}]`, () => {
30 let containerId: string | null = null;
31 const testFolder = `${__dirname}/configs/image`;
32 beforeEach(async () => containerId = (await devContainerUp(cli, testFolder, options)).containerId);
33 afterEach(async () => await devContainerDown({ containerId }));
34 it('should execute successfully', async () => {
35 const res = await shellBufferExec(`${cli} exec --workspace-folder ${testFolder} echo hi`);
36 assert.strictEqual(res.code, 0);
37 assert.equal(res.signal, undefined);
38 assert.strictEqual(res.stdout.toString(), 'hi\n');
39 });
40 it('should not run in a terminal', async () => {
41 const res = await shellBufferExec(`${cli} exec --workspace-folder ${testFolder} [ ! -t 1 ]`);
42 assert.strictEqual(res.code, 0);
43 assert.equal(res.signal, undefined);
44 });
45 it('should return exit code without terminal', async () => {
46 const res = await shellBufferExec(`${cli} exec --workspace-folder ${testFolder} sh -c 'exit 123'`);
47 assert.strictEqual(res.code, 123);
48 assert.equal(res.signal, undefined);
49 });
50 it('stream binary data', async () => {
51 const stdin = Buffer.alloc(256);
52 stdin.forEach((_, i) => stdin[i] = i);
53 const res = await shellBufferExec(`${cli} exec --workspace-folder ${testFolder} cat`, { stdin });
54 assert.strictEqual(res.code, 0);
55 assert.equal(res.signal, undefined);
56 assert.ok(res.stdout.equals(stdin), 'stdout does not match stdin: ' + res.stdout.toString('hex'));
57 });
58 it('should run in a terminal', async () => {
59 const res = await shellPtyExec(`${cli} exec --workspace-folder ${testFolder} [ -t 1 ]`);
60 assert.strictEqual(res.code, 0);
61 assert.equal(res.signal, undefined);
62 });
63 it('should return exit code without terminal', async () => {
64 const res = await shellPtyExec(`${cli} exec --workspace-folder ${testFolder} sh -c 'exit 123'`);
65 assert.strictEqual(res.code, 123);
66 assert.equal(res.signal, 0);
67 });
68 it('should connect stdin', async () => {
69 const res = await shellPtyExec(`${cli} exec --workspace-folder ${testFolder} sh`, { stdin: 'FOO=BAR\necho ${FOO}hi${FOO}\nexit\n' });
70 assert.strictEqual(res.code, 0);

Calls 5

shellExecFunction · 0.90
devContainerUpFunction · 0.90
devContainerDownFunction · 0.90
shellBufferExecFunction · 0.90
shellPtyExecFunction · 0.90

Tested by

no test coverage detected