import assert from "assert"; import fs from "fs"; import { Meteor as ImportedMeteor } from "meteor/meteor"; import moment from "moment"; import path from "path"; import shared from "./imports/shared"; describe("app modules", () => { it("can be imported using absolute identifiers", async () => { assert.strictEqual(await require("/tests"), exports); }); it("can have different file extensions", async () => { assert.strictEqual( (await require("./eager-jsx")).extension, ".jsx" ); assert.strictEqual( require("./eager-coffee").extension, ".coffee" ); assert.strictEqual( (await require("/eager-jsx")).extension, ".jsx" ); assert.strictEqual( require("/eager-coffee").extension, ".coffee" ); }); it("are eagerly evaluated if outside imports/", () => { assert.strictEqual(shared["/eager-jsx.jsx"], "eager jsx"); assert.strictEqual(shared["/eager-coffee.coffee"], "eager coffee"); }); it("are lazily evaluated if inside imports/", (done) => { const delayMs = 200; setTimeout(async () => { assert.strictEqual(shared["/imports/lazy1.js"], void 0); assert.strictEqual(shared["/imports/lazy2.js"], void 0); var reset1 = (await require("./imports/lazy1")).reset; assert.strictEqual(shared["/imports/lazy1.js"], 1); assert.strictEqual(shared["/imports/lazy2.js"], 2); // Make sure this test can run again without starting a new process. (await require("./imports/lazy2")).reset(); reset1(); done(); }, delayMs); }); it("cannot import server modules on client", async () => { let error; let result; try { result = (await require("./server/only")).default; } catch (expectedOnClient) { error = expectedOnClient; } if (Meteor.isServer) { assert.strictEqual(typeof error, "undefined"); assert.strictEqual(result, "/server/only.js"); assert.strictEqual(await require("./server/only"), await require("/server/only")); } if (Meteor.isClient) { assert.ok(error instanceof Error); } }); it("cannot import client modules on server", () => { let error; let result; try { result = require("./client/only").default; } catch (expectedOnServer) { error = expectedOnServer; } if (Meteor.isClient) { assert.strictEqual(typeof error, "undefined"); assert.strictEqual(result, "/client/only.js"); assert.strictEqual(require("./client/only"), require("/client/only")); } if (Meteor.isServer) { assert.ok(error instanceof Error); } }); it("should have access to filename and dirname", async () => { assert.strictEqual(await require(__filename), exports); assert.strictEqual( require("path").relative(__dirname, __filename), "tests.js" ); }); it("can be implemented by directories", () => { assert.strictEqual( require("./imports/dir").fellBackTo, "/imports/dir/index.js" ); }); }); describe("template modules", () => { Meteor.isClient && it("should be importable on the client", () => { assert.strictEqual(typeof Template, "function"); assert.ok(! Object.prototype.hasOwnProperty.call(Template, "lazy")); require("./imports/lazy.html"); assert.ok(Object.prototype.hasOwnProperty.call(Template, "lazy")); assert.ok(Template.lazy instanceof Template); }); Meteor.isServer && it("should not be importable on the server", () => { let error; try { require("./imports/lazy.html"); } catch (expected) { error = expected; } assert.ok(error instanceof Error); }); }); Meteor.isClient && describe("css modules", () => { it("should be loaded eagerly unless lazy", () => { assert.strictEqual( $(".app-eager-css").css("display"), "none" ); // Eager CSS is added unconditionally to a combined