40 lines
1.6 KiB
JavaScript
40 lines
1.6 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.wait = exports.prepareTempDir = exports.prepareEnvironment = void 0;
|
|
const path_1 = __importDefault(require("path"));
|
|
const fs_1 = require("fs");
|
|
const util_1 = require("util");
|
|
const os_1 = require("os");
|
|
const child_process_1 = require("child_process");
|
|
const fsMakeTempDir = (0, util_1.promisify)(fs_1.mkdtemp);
|
|
const fsExec = (0, util_1.promisify)(child_process_1.exec);
|
|
const fsRemove = (0, util_1.promisify)(fs_1.rm);
|
|
/**
|
|
* Prepare the environment for the test
|
|
* Create a temporary git repository in the temp directory
|
|
*/
|
|
const prepareEnvironment = async () => {
|
|
const tempDir = await (0, exports.prepareTempDir)();
|
|
// Create a remote git repository int the temp directory. This is necessary to execute the `git push` command
|
|
await fsExec('git init --bare remote.git', { cwd: tempDir });
|
|
await fsExec('git clone remote.git test', { cwd: tempDir });
|
|
const gitDir = path_1.default.resolve(tempDir, 'test');
|
|
const cleanup = async () => {
|
|
return fsRemove(tempDir, { recursive: true });
|
|
};
|
|
return {
|
|
gitDir,
|
|
cleanup,
|
|
};
|
|
};
|
|
exports.prepareEnvironment = prepareEnvironment;
|
|
const prepareTempDir = async () => {
|
|
return await fsMakeTempDir(path_1.default.join((0, os_1.tmpdir)(), 'opencommit-test-'));
|
|
};
|
|
exports.prepareTempDir = prepareTempDir;
|
|
const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
exports.wait = wait;
|