UNPKG

@platform/react.ssr

Version:

A lightweight SSR (server-side-rendering) system for react apps bundled with ParcelJS and hosted on S3.

130 lines (129 loc) 5.99 kB
"use strict"; var _this = this; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var chai_1 = require("chai"); var common_1 = require("../common"); var util = require("./util"); var tmp = common_1.fs.resolve('tmp/bundler.util'); describe('bundler.util', function () { beforeEach(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { return [2, common_1.fs.remove(tmp)]; }); }); }); describe('dir', function () { var dirnames = ['0.1.0', 'bar.5', '0.1.1', '0.1.1-alpha.0', 'foo']; var dirs = dirnames.map(function (name) { return common_1.fs.join(tmp, name); }); var createDirs = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { var _i, dirs_1, dir; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, common_1.fs.remove(tmp)]; case 1: _a.sent(); _i = 0, dirs_1 = dirs; _a.label = 2; case 2: if (!(_i < dirs_1.length)) return [3, 5]; dir = dirs_1[_i]; return [4, common_1.fs.ensureDir(dir)]; case 3: _a.sent(); _a.label = 4; case 4: _i++; return [3, 2]; case 5: return [2]; } }); }); }; describe('sorted', function () { it('empty', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { var res1, res2; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, util.dir(tmp).semver()]; case 1: res1 = _a.sent(); chai_1.expect(res1).to.eql([]); return [4, common_1.fs.ensureDir(common_1.fs.join(tmp, 'foo'))]; case 2: _a.sent(); return [4, util.dir(tmp).semver()]; case 3: res2 = _a.sent(); chai_1.expect(res2).to.eql([]); return [2]; } }); }); }); it('sorted (ascending, default)', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { var res, dirnames; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, createDirs()]; case 1: _a.sent(); return [4, util.dir(tmp).semver()]; case 2: res = _a.sent(); dirnames = res.map(function (path) { return common_1.fs.basename(path); }); chai_1.expect(dirnames).to.eql(['0.1.0', '0.1.1-alpha.0', '0.1.1']); return [2]; } }); }); }); it('sorted (descending)', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { var res, dirnames; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, createDirs()]; case 1: _a.sent(); return [4, util.dir(tmp).semver({ sort: 'DESC' })]; case 2: res = _a.sent(); dirnames = res.map(function (path) { return common_1.fs.basename(path); }); chai_1.expect(dirnames).to.eql(['0.1.1', '0.1.1-alpha.0', '0.1.0']); return [2]; } }); }); }); }); describe('latestDir', function () { it('undefined (no semver dirs)', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { var res1, res2; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, util.dir(tmp).latest()]; case 1: res1 = _a.sent(); chai_1.expect(res1).to.eql(undefined); return [4, common_1.fs.ensureDir(common_1.fs.join(tmp, 'foo'))]; case 2: _a.sent(); return [4, util.dir(tmp).latest()]; case 3: res2 = _a.sent(); chai_1.expect(res2).to.eql(undefined); return [2]; } }); }); }); it('latest', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { var res; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, createDirs()]; case 1: _a.sent(); return [4, util.dir(tmp).latest()]; case 2: res = _a.sent(); chai_1.expect(common_1.fs.basename(res)).to.eql('0.1.1'); return [2]; } }); }); }); }); }); });