UNPKG

gitly

Version:

An API to download and/or extract git repositories

94 lines (93 loc) 4.79 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const node_fs_1 = require("node:fs"); const node_path_1 = require("node:path"); const shelljs_1 = require("shelljs"); const download_1 = __importDefault(require("../download")); const extract_1 = __importDefault(require("../extract")); describe('utils/extract', () => { const destination = (0, node_path_1.join)(__dirname, 'output', 'extract'); const options = { temp: (0, node_path_1.join)(__dirname, 'output', 'extract', '.gitcopy'), }; beforeEach(() => { (0, shelljs_1.rm)('-rf', (0, node_path_1.join)(__dirname, 'output', 'extract', '.gitcopy')); }); afterEach(() => { (0, shelljs_1.rm)('-rf', destination); }); afterAll(() => { (0, shelljs_1.rm)('-rf', (0, node_path_1.join)(__dirname, 'output', 'extract')); }); it('should extract "lukeed/gittar"', async () => { // tslint:disable-next-line: no-floating-promises const path = await (0, download_1.default)('lukeed/gittar', options); expect(path).toBeTruthy(); expect((0, node_fs_1.existsSync)(path)).toBe(true); }); it('should extract "lukeed/gittar#v0.1.1"', async () => { // tslint:disable-next-line: no-floating-promises const source = await (0, download_1.default)('lukeed/gittar#v0.1.1', options); const path = await (0, extract_1.default)(source, destination, options); expect((0, node_fs_1.existsSync)(source)).toBe(true); expect(source).toBeTruthy(); expect((0, node_fs_1.existsSync)(path)).toBe(true); expect(path).toBeTruthy(); }); it('should extract "https://github.com/lukeed/gittar"', async () => { const source = await (0, download_1.default)('https://github.com/lukeed/gittar', options); const path = await (0, extract_1.default)(source, destination, options); expect((0, node_fs_1.existsSync)(source)).toBe(true); expect(source).toBeTruthy(); expect((0, node_fs_1.existsSync)(path)).toBe(true); expect(path).toBeTruthy(); }); it('should extract "https://github.com/lukeed/gittar#v0.1.1"', async () => { const source = await (0, download_1.default)('https://github.com/lukeed/gittar#v0.1.1', options); const path = await (0, extract_1.default)(source, destination, options); expect((0, node_fs_1.existsSync)(source)).toBe(true); expect(source).toBeTruthy(); expect((0, node_fs_1.existsSync)(path)).toBe(true); expect(path).toBeTruthy(); }); it('should extract "github.com/lukeed/gittar"', async () => { const source = await (0, download_1.default)('github.com/lukeed/gittar', options); const path = await (0, extract_1.default)(source, destination, options); expect((0, node_fs_1.existsSync)(source)).toBe(true); expect(source).toBeTruthy(); expect((0, node_fs_1.existsSync)(path)).toBe(true); expect(path).toBeTruthy(); }); it('should extract "github.com/lukeed/gittar#v0.1.1"', async () => { const source = await (0, download_1.default)('github.com/lukeed/gittar#v0.1.1', options); const path = await (0, extract_1.default)(source, destination, options); expect((0, node_fs_1.existsSync)(source)).toBe(true); expect(source).toBeTruthy(); expect((0, node_fs_1.existsSync)(path)).toBe(true); expect(path).toBeTruthy(); }); it('should extract "github:lukeed/gittar"', async () => { const source = await (0, download_1.default)('github:lukeed/gittar', options); const path = await (0, extract_1.default)(source, destination, options); expect((0, node_fs_1.existsSync)(source)).toBe(true); expect(source).toBeTruthy(); expect((0, node_fs_1.existsSync)(path)).toBe(true); expect(path).toBeTruthy(); }); it('should extract "github:lukeed/gittar#v0.1.1"', async () => { const source = await (0, download_1.default)('github:lukeed/gittar#v0.1.1', options); const path = await (0, extract_1.default)(source, destination, options); expect((0, node_fs_1.existsSync)(source)).toBe(true); expect(source).toBeTruthy(); expect((0, node_fs_1.existsSync)(path)).toBe(true); expect(path).toBeTruthy(); }); it('should error and return an empty string when extraction fails', async () => { const path = await (0, extract_1.default)((0, node_path_1.join)(__dirname, 'dummy'), destination, options); expect((0, node_fs_1.existsSync)(path)).toBe(false); expect(path).toBeFalsy(); }); });