UNPKG

@zendesk/zcli-themes

Version:

zcli theme commands live here

52 lines (51 loc) 2.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const sinon = require("sinon"); const fs = require("fs"); const test_1 = require("@oclif/test"); const getManifest_1 = require("./getManifest"); describe('getManifest', () => { beforeEach(() => { sinon.restore(); }); it('returns the manifest.json file parsed as json', () => { const existsSyncStub = sinon.stub(fs, 'existsSync'); const readFileSyncStub = sinon.stub(fs, 'readFileSync'); const manifest = { name: 'Copenhagen theme', author: 'Jane Doe', version: '1.0.1', api_version: 1, settings: [] }; existsSyncStub .withArgs('theme/path/manifest.json') .returns(true); readFileSyncStub .withArgs('theme/path/manifest.json') .returns(JSON.stringify(manifest)); (0, test_1.expect)((0, getManifest_1.default)('theme/path')).to.deep.equal(manifest); }); it('throws an error when it can\'t find a manifest.json file', () => { const existsSyncStub = sinon.stub(fs, 'existsSync'); existsSyncStub .withArgs('theme/path/manifest.json') .returns(false); (0, test_1.expect)(() => { (0, getManifest_1.default)('theme/path'); }).to.throw('Couldn\'t find a manifest.json file at path: "theme/path/manifest.json"'); }); it('throws an error when the manifest.json file is malformed', () => { const existsSyncStub = sinon.stub(fs, 'existsSync'); const readFileSyncStub = sinon.stub(fs, 'readFileSync'); existsSyncStub .withArgs('theme/path/manifest.json') .returns(true); readFileSyncStub .withArgs('theme/path/manifest.json') .returns('{"name": "Copenhagen theme",,, }'); (0, test_1.expect)(() => { (0, getManifest_1.default)('theme/path'); }).to.throw('manifest.json file was malformed at path: "theme/path/manifest.json"'); }); });