UNPKG

code-theme-converter

Version:

Convert any vscode theme with ease!

54 lines (53 loc) 2.85 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const mock_fs_1 = __importDefault(require("mock-fs")); const download_git_repo_1 = __importDefault(require("download-git-repo")); const fetchRepo_1 = require("../fetchRepo"); jest.mock('../util/fs', () => ({ __esModule: true, createTempDir: jest.fn(() => '/var/tmp/code-theme-converter') })); jest.mock('download-git-repo', () => ({ __esModule: true, default: jest.fn((_repository, _destination, _options, callback) => callback()) })); describe('fetchRepo', () => { beforeEach(() => jest.clearAllMocks()); afterEach(() => mock_fs_1.default.restore()); it('should be defined', () => { expect(fetchRepo_1.fetchRepo).toBeDefined(); }); it('should fetch the given repository into a temp dir', () => __awaiter(void 0, void 0, void 0, function* () { mock_fs_1.default({ '/var/tmp/code-theme-converter': {} }); const converterRepo = yield fetchRepo_1.fetchRepo('https://github.com/tobiastimm/raiju.git'); expect(converterRepo).toEqual({ repo: '/var/tmp/code-theme-converter/repo', root: '/var/tmp/code-theme-converter' }); expect(download_git_repo_1.default).toHaveBeenCalled(); expect(download_git_repo_1.default).toHaveBeenCalledWith('direct:https://github.com/tobiastimm/raiju.git', '/var/tmp/code-theme-converter/repo', { clone: true }, expect.any(Function)); })); it('should throw an error, if anything goes wrong', () => __awaiter(void 0, void 0, void 0, function* () { expect.assertions(1); mock_fs_1.default({ '/var/tmp/code-theme-converter': {} }); const downloadMock = download_git_repo_1.default; downloadMock.mockImplementation((repository, destination, options, callback) => callback(new Error('Not valid url'))); return expect(fetchRepo_1.fetchRepo('https://github.com/tobiastimm/raiju.git')).rejects.toThrowError('Not valid url'); })); });