UNPKG

alwaysai

Version:

The alwaysAI command-line interface (CLI)

81 lines 3.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = require("path"); const get_random_string_1 = require("../util/get-random-string"); const { join } = path_1.posix; function testASpawner(factory, ...args) { const spawner = factory(...args); const { resolvePath, mkdirp, rimraf, run, readdir, runForegroundSync, tar, untar, } = spawner; describe(factory.name, () => { describe(resolvePath.name, () => { it('returns the context path of the spawner if no args are passed', () => { const contextPath = resolvePath(); expect(typeof contextPath).toBe('string'); }); it('resolves a context-path-relative path', () => { const contextPath = resolvePath(); const path = resolvePath('foo'); expect(path).toBe(join(contextPath, 'foo')); }); it('resolves absolute paths to themselves', () => { const path = resolvePath('/foo'); expect(path).toBe('/foo'); }); it('acts like path.resolve (i.e. `cd x && cd y && cd z`) for multiple paths', () => { const path = resolvePath('foo', '/bar', 'baz'); expect(path).toBe('/bar/baz'); }); }); describe(mkdirp.name, () => { it('makes the context path directory if no args are provided', async () => { await spawner.mkdirp(); expect(await spawner.exists(resolvePath())).toBe(true); }); it('makes a context-path-relative directory if one is provided', async () => { const tmpId = get_random_string_1.getRandomString(); await spawner.mkdirp(tmpId); expect(await spawner.exists(join(resolvePath(), tmpId))).toBe(true); }); }); describe(rimraf.name, () => { it('removes an context-relative directory if one is provided', async () => { const tmpId = get_random_string_1.getRandomString(); await spawner.mkdirp(tmpId); expect(await spawner.exists(join(resolvePath(), tmpId))).toBe(true); await spawner.rimraf(tmpId); expect(await spawner.exists(join(resolvePath(), tmpId))).toBe(false); }); }); describe(readdir.name, () => { it('reads files and dot file names in a context-path-relative path if one is provided', async () => { await mkdirp('foo'); await run({ exe: 'touch', args: ['foo/a'], cwd: '.' }); expect(await readdir('foo')).toEqual(['a']); }); it('reads files and dot file names in an absolute path if one is provided', async () => { expect((await readdir('/')).length > 0).toBe(true); }); }); describe(runForegroundSync.name, () => { it('runs a command synchronously with inherited I/O', async () => { const tmpDir = await run({ exe: 'mktemp', args: ['-d'] }); runForegroundSync({ exe: 'ls', cwd: tmpDir }); }); }); describe(`${tar.name} and ${untar.name}`, () => { it('does tarring and untarring', async () => { const tmpDir0 = get_random_string_1.getRandomString(); const tmpDir1 = get_random_string_1.getRandomString(); await mkdirp(tmpDir0); await mkdirp(tmpDir1); await run({ exe: 'touch', args: ['foo'], cwd: tmpDir0 }); const stream = await tar(tmpDir0); await untar(stream, tmpDir1); const fileNames = await readdir(tmpDir1); expect(fileNames).toEqual([tmpDir0]); }); }); }); } exports.testASpawner = testASpawner; //# sourceMappingURL=test-a-spawner.js.map