UNPKG

@zendesk/zcli-themes

Version:

zcli theme commands live here

48 lines (47 loc) 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const sinon = require("sinon"); const fs = require("fs"); const test_1 = require("@oclif/test"); const getAssets_1 = require("./getAssets"); const flags = { bind: 'localhost', port: 1000, logs: true, livereload: true }; describe('getAssets', () => { beforeEach(() => { sinon.restore(); }); it('returns an array of tuples containing the parsed path and url for each asset', () => { const existsSyncStub = sinon.stub(fs, 'existsSync'); const readdirSyncStub = sinon.stub(fs, 'readdirSync'); existsSyncStub .withArgs('theme/path/assets') .returns(true); readdirSyncStub.returns(['.gitkeep', 'foo.png', 'bar.png']); const assets = (0, getAssets_1.default)('theme/path', flags); (0, test_1.expect)(assets).to.deep.equal([ [ { base: 'foo.png', dir: '', ext: '.png', name: 'foo', root: '' }, 'http://localhost:1000/guide/assets/foo.png' ], [ { base: 'bar.png', dir: '', ext: '.png', name: 'bar', root: '' }, 'http://localhost:1000/guide/assets/bar.png' ] ]); }); it('throws an error when an asset has illegal characters in its name', () => { const existsSyncStub = sinon.stub(fs, 'existsSync'); const readdirSyncStub = sinon.stub(fs, 'readdirSync'); existsSyncStub .withArgs('theme/path/assets') .returns(true); readdirSyncStub.returns(['unsuported file name.png']); (0, test_1.expect)(() => { (0, getAssets_1.default)('theme/path', flags); }).to.throw('The asset "unsuported file name.png" has illegal characters in its name. Filenames should only have alpha-numerical characters, ., _, -, and +'); }); });