shaman-website-compiler
Version:
Compile raw HTML, CSS and Javascript into the smallest possible, SEO friendly website.
139 lines • 7.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
require("mocha");
var chai_1 = require("chai");
var sinon = require("sinon");
var _fsx = require("fs-extra");
var ts_auto_mock_1 = require("ts-auto-mock");
var app_composition_1 = require("../composition/app.composition");
var models_1 = require("../models");
var compiler_context_spec_1 = require("../data/compiler.context.spec");
var file_import_service_1 = require("./file-import.service");
describe('WebsiteRouter', function () {
var sandbox;
var config;
var globService;
var eventService;
var handlebarsService;
beforeEach(function () {
app_composition_1.IoC.snapshot();
sandbox = sinon.createSandbox();
config = new models_1.WebsiteConfig();
globService = (0, ts_auto_mock_1.createMock)();
eventService = (0, ts_auto_mock_1.createMock)();
handlebarsService = (0, ts_auto_mock_1.createMock)();
app_composition_1.IoC.bind(app_composition_1.TYPES.WebsiteConfig).toConstantValue(config);
app_composition_1.IoC.bind(app_composition_1.TYPES.GlobService).toConstantValue(globService);
app_composition_1.IoC.bind(app_composition_1.TYPES.CompilerEvents).toConstantValue(eventService);
app_composition_1.IoC.bind(app_composition_1.TYPES.HandlebarsService).toConstantValue(handlebarsService);
app_composition_1.IoC.bind(app_composition_1.TYPES.Logger).toConstantValue((0, ts_auto_mock_1.createMock)());
});
afterEach(function () {
app_composition_1.IoC.restore();
sandbox.restore();
});
it('should be created', function (done) {
(0, compiler_context_spec_1.CreateDataContext)(app_composition_1.IoC).then(function (_) {
var subject = new file_import_service_1.FileImportService();
(0, chai_1.expect)(subject).not.to.be.null;
done();
});
});
it('importPartialFilesFromGlobs should return empty result set', function (done) {
(0, compiler_context_spec_1.CreateDataContext)(app_composition_1.IoC).then(function (_) {
var subject = new file_import_service_1.FileImportService();
globService.GetFilesFromGlob = sandbox.stub().returns(Promise.resolve([]));
subject.importPartialFilesFromGlobs().then(function (result) {
(0, chai_1.expect)(result.length).to.equal(0);
done();
});
});
});
it('importPartialFilesFromGlobs should set partial file content', function (done) {
(0, compiler_context_spec_1.CreateDataContext)(app_composition_1.IoC).then(function (_) {
var subject = new file_import_service_1.FileImportService();
var file = new models_1.FileData("a.partial.html", "./a.partial.html");
globService.GetFilesFromGlob = sandbox.stub().returns(Promise.resolve([file]));
sandbox.stub(_fsx, 'readFile').returns(Promise.resolve('test'));
subject.importPartialFilesFromGlobs().then(function (result) {
(0, chai_1.expect)(result[0].content).to.equal('test');
done();
});
});
});
it('importPartialFilesFromGlobs should insert partials into database', function (done) {
(0, compiler_context_spec_1.CreateDataContext)(app_composition_1.IoC).then(function (context) {
var subject = new file_import_service_1.FileImportService();
var file = new models_1.FileData("a.partial.html", "./a.partial.html");
globService.GetFilesFromGlob = sandbox.stub().returns(Promise.resolve([file]));
handlebarsService.registerPartials = sandbox.stub().callsFake(function (f) { return (f); });
sandbox.stub(_fsx, 'readFile').returns(Promise.resolve('test'));
subject.importPartialFilesFromGlobs().then(function (_) {
var partials = context.models.files.filter(function (f) { return f.extension == 'partial.html'; });
(0, chai_1.expect)(partials.length).to.equal(1);
done();
});
});
});
it('importFilesFromGlobs should return empty result set', function (done) {
(0, compiler_context_spec_1.CreateDataContext)(app_composition_1.IoC).then(function (_) {
var subject = new file_import_service_1.FileImportService();
globService.GetFilesFromGlob = sandbox.stub().returns(Promise.resolve([]));
subject.importFilesFromGlobs().then(function (result) {
(0, chai_1.expect)(result.length).to.equal(0);
done();
});
});
});
it('importFilesFromGlobs should insert files into database', function (done) {
(0, compiler_context_spec_1.CreateDataContext)(app_composition_1.IoC).then(function (context) {
var subject = new file_import_service_1.FileImportService();
var globStub = globService.GetFilesFromGlob = sandbox.stub();
var html = new models_1.FileData("index.html", "./index.html");
var js = new models_1.FileData("index.js", "./index.js");
var css = new models_1.FileData("index.css", "./index.css");
globStub.withArgs(config.pages).returns(Promise.resolve([html]));
globStub.withArgs(config.scripts).returns(Promise.resolve([js]));
globStub.withArgs(config.styles).returns(Promise.resolve([css]));
subject.importFilesFromGlobs().then(function (result) {
var partials = context.models.files.filter(function (f) { return !!f; });
(0, chai_1.expect)(partials.length).to.equal(3);
done();
});
});
});
it('importAssetFilesFromGlobs should return empty result set', function (done) {
(0, compiler_context_spec_1.CreateDataContext)(app_composition_1.IoC).then(function (_) {
var subject = new file_import_service_1.FileImportService();
globService.GetFilesFromGlob = sandbox.stub().returns(Promise.resolve([]));
subject.importAssetFilesFromGlobs().then(function (result) {
(0, chai_1.expect)(result.length).to.equal(0);
done();
});
});
});
it('importAssetFilesFromGlobs should insert asset files into database', function (done) {
(0, compiler_context_spec_1.CreateDataContext)(app_composition_1.IoC).then(function (context) {
var subject = new file_import_service_1.FileImportService();
var globStub = globService.GetFilesFromGlob = sandbox.stub();
var asset = new models_1.FileData("sample.png", "./sample.png");
globStub.withArgs(config.assets).returns(Promise.resolve([asset]));
subject.importAssetFilesFromGlobs().then(function (_) {
var assets = context.models.assets.filter(function (a) { return !!a; });
(0, chai_1.expect)(assets.length).to.equal(1);
done();
});
});
});
it('importHelperFilesFromGlobs should return empty result set', function (done) {
(0, compiler_context_spec_1.CreateDataContext)(app_composition_1.IoC).then(function (_) {
var subject = new file_import_service_1.FileImportService();
globService.GetFilesFromGlob = sandbox.stub().returns(Promise.resolve([]));
subject.importHelperFilesFromGlobs().then(function (result) {
(0, chai_1.expect)(result.length).to.equal(0);
done();
});
});
});
});
//# sourceMappingURL=file-import.service.spec.js.map