import assert from "assert"; import fs from "fs"; import path from "path"; import moment from "moment"; import shared from "./imports/shared"; import { Meteor as ImportedMeteor } from "meteor/meteor"; describe("app modules", () => { it("can be imported using absolute identifiers", () => { assert.strictEqual(require("/tests"), exports); }); it("can have different file extensions", () => { assert.strictEqual( require("./eager-jsx").extension, ".jsx" ); assert.strictEqual( require("./eager-coffee").extension, ".coffee" ); assert.strictEqual( 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(() => { assert.strictEqual(shared["/imports/lazy1.js"], void 0); assert.strictEqual(shared["/imports/lazy2.js"], void 0); var reset1 = 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. require("./imports/lazy2").reset(); reset1(); done(); }, delayMs); }); it("cannot import server modules on client", () => { let error; let result; try { result = require("./server/only").default; } catch (expectedOnClient) { error = expectedOnClient; } if (Meteor.isServer) { assert.strictEqual(typeof error, "undefined"); assert.strictEqual(result, "/server/only.js"); assert.strictEqual(require("./server/only"), 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 not be parsed in strictMode", () => { let foo = 1234; delete foo; }); it("should have access to filename and dirname", () => { assert.strictEqual(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