Skip to content

Commit

Permalink
Use better assertion functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Oct 31, 2024
1 parent 8ab7c25 commit d5ea87e
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import defer * as nsDeferred2 from "./dep_FIXTURE.js";
import { depDeferredNamespace as nsDeferred3 } from "./dep-defer-ns_FIXTURE.js";
const nsDeferred4 = await import.defer("./dep_FIXTURE.js");

assert(nsDeferred1 === nsDeferred2, "Deferred import of the same module twice gives the same object");
assert(nsDeferred1 === nsDeferred3, "Deferred import of the same module twice from different files gives the same object");
assert(nsDeferred1 === nsDeferred4, "Static and dynamic deferred import of the same module gives the same object");
assert(nsDeferred1 !== nsEager, "Deferred namespaces are distinct from eager namespaces");
assert.sameValue(nsDeferred1, nsDeferred2, "Deferred import of the same module twice gives the same object");
assert.sameValue(nsDeferred1, nsDeferred3, "Deferred import of the same module twice from different files gives the same object");
assert.sameValue(nsDeferred1, nsDeferred4, "Static and dynamic deferred import of the same module gives the same object");
assert.notSameValue(nsDeferred1, nsEager, "Deferred namespaces are distinct from eager namespaces");
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ info: |
flags: [module]
features: [import-defer]
includes: [propertyHelper.js, deepEqual.js]
includes: [propertyHelper.js, compareArray.js]
---*/

import defer * as ns from "./dep_FIXTURE.js";

assert(typeof ns === "object", "Deferred namespaces are objects");
assert.sameValue(typeof ns, "object", "Deferred namespaces are objects");

assert(Reflect.isExtensible(ns) === false, "Deferred namespaces are not extensible");
assert(Reflect.preventExtensions(ns) === true, "Deferred namespaces can made non-extensible");
assert(!Reflect.isExtensible(ns), "Deferred namespaces are not extensible");
assert.sameValue(Reflect.preventExtensions(ns), true, "Deferred namespaces can made non-extensible");

assert(Reflect.getPrototypeOf(ns) === null, "Deferred namespaces have a null prototype");
assert(Reflect.setPrototypeOf(ns, {}) === false, "Deferred namespaces' prototype cannot be changed");
assert(Reflect.setPrototypeOf(ns, null) === true, "Deferred namespaces' prototype can be 'set' to null");
assert.sameValue(Reflect.getPrototypeOf(ns), null, "Deferred namespaces have a null prototype");
assert.sameValue(Reflect.setPrototypeOf(ns, {}), false, "Deferred namespaces' prototype cannot be changed");
assert.sameValue(Reflect.setPrototypeOf(ns, null), true, "Deferred namespaces' prototype can be 'set' to null");

assert.throws(TypeError, () => Reflect.apply(ns, null, []), "Deferred namespaces are not callable");
assert.throws(TypeError, () => Reflect.construct(ns, null, []), "Deferred namespaces are not constructable");

assert.deepEqual(
assert.compareArray(
Reflect.ownKeys(ns),
["bar", "foo", Symbol.toStringTag],
"Deferred namespaces' keys are the exports sorted alphabetically, followed by @@toStringTag"
Expand All @@ -49,4 +49,4 @@ verifyProperty(ns, "foo", {
enumerable: true,
configurable: false,
});
assert(Reflect.getOwnPropertyDescriptor(ns, "non-existent") === undefined, "No descriptors for non-exports");
assert.sameValue(Reflect.getOwnPropertyDescriptor(ns, "non-existent"), undefined, "No descriptors for non-exports");
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ first.then(() => {
return third.then(() => {
// dep-1 is now in the ~evaluated~ state
let foo = ns.foo;
assert(foo === 1, "Once it finished evaluating, the module can be accessed");
assert.sameValue(foo, 1, "Once it finished evaluating, the module can be accessed");
})
}).then(resolveDone, rejectDone);
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import defer * as dep2 from "./dep-2_FIXTURE.js";

globalThis.dep3evaluated = false;
assert.throws(TypeError, () => dep2.foo);
assert(globalThis.dep3evaluated === false, "the 'evaluable' dependencies of dep-2 are not evaluated");
assert.sameValue(globalThis.dep3evaluated, false, "the 'evaluable' dependencies of dep-2 are not evaluated");
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ first.then(() => {
return third.then(() => {
// ns is now in the ~evaluated~ state
let foo = ns.foo;
assert(foo === 1, "Once it finished evaluating, the module can be accessed");
assert.sameValue(foo, 1, "Once it finished evaluating, the module can be accessed");
})
}).then(resolveDone, rejectDone);
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import "./setup_FIXTURE.js";

import defer * as ns1 from "./dep-1_FIXTURE.js";

assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation");
assert.sameValue(globalThis.evaluations.length, 0, "import defer does not trigger evaluation");

ns1[Symbol.toStringTag];
ns1[Symbol()];

assert(globalThis.evaluations.length === 0, "[[Get]] of a symbol does not trigger evaluation");
assert.sameValue(globalThis.evaluations.length, 0, "[[Get]] of a symbol does not trigger evaluation");
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import "./setup_FIXTURE.js";

import defer * as ns1 from "./dep-1_FIXTURE.js";

assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation");
assert.sameValue(globalThis.evaluations.length, 0, "import defer does not trigger evaluation");

Object.getPrototypeOf(ns1);

assert(globalThis.evaluations.length === 0, "[[GetPrototypeOf]] does not trigger evaluation");
assert.sameValue(globalThis.evaluations.length, 0, "[[GetPrototypeOf]] does not trigger evaluation");
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import "./setup_FIXTURE.js";

import defer * as ns1 from "./dep-1_FIXTURE.js";

assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation");
assert.sameValue(globalThis.evaluations.length, 0, "import defer does not trigger evaluation");

Object.isExtensible(ns1);

assert(globalThis.evaluations.length === 0, "[[GetPrototypeOf]] does not trigger evaluation");
assert.sameValue(globalThis.evaluations.length, 0, "[[GetPrototypeOf]] does not trigger evaluation");
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import "./setup_FIXTURE.js";

import defer * as ns1 from "./dep-1_FIXTURE.js";

assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation");
assert.sameValue(globalThis.evaluations.length, 0, "import defer does not trigger evaluation");

Object.preventExtensions(ns1);

assert(globalThis.evaluations.length === 0, "[[GetPrototypeOf]] does not trigger evaluation");
assert.sameValue(globalThis.evaluations.length, 0, "[[GetPrototypeOf]] does not trigger evaluation");
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import "./setup_FIXTURE.js";

import defer * as ns1 from "./dep-1_FIXTURE.js";

assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation");
assert.sameValue(globalThis.evaluations.length, 0, "import defer does not trigger evaluation");

try {
ns1.foo = 2;
Expand All @@ -26,4 +26,4 @@ try {
ns1.ns_1_2 = 3;
} catch {}

assert(globalThis.evaluations.length === 0, "[[Set]] of a symbol does not trigger evaluation");
assert.sameValue(globalThis.evaluations.length, 0, "[[Set]] of a symbol does not trigger evaluation");
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import "./setup_FIXTURE.js";

import defer * as ns1 from "./dep-1_FIXTURE.js";

assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation");
assert.sameValue(globalThis.evaluations.length, 0, "import defer does not trigger evaluation");

Reflect.setPrototypeOf(ns1, null);
Reflect.setPrototypeOf(ns1, {});

assert(globalThis.evaluations.length === 0, "[[GetPrototypeOf]] does not trigger evaluation");
assert.sameValue(globalThis.evaluations.length, 0, "[[GetPrototypeOf]] does not trigger evaluation");
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import "./setup_FIXTURE.js";

import defer * as ns1 from "./dep-1_FIXTURE.js";

assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation");
assert.sameValue(globalThis.evaluations.length, 0, "import defer does not trigger evaluation");

ns1.foo;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ info: |
flags: [module]
features: [import-defer]
includes: [deepEqual.js]
includes: [compareArray.js]
---*/

import "./setup_FIXTURE.js";

import defer * as ns1 from "./dep-1_FIXTURE.js";

assert(globalThis.evaluations.length === 0, "import defer does not trigger evaluation");
assert.sameValue(globalThis.evaluations.length, 0, "import defer does not trigger evaluation");

const ns_1_2 = ns1.ns_1_2;

assert.deepEqual(globalThis.evaluations, [1.1, 1], "when evaluation is triggered, deferred sub-dependencies are not evaluated");
assert.compareArray(globalThis.evaluations, [1.1, 1], "when evaluation is triggered, deferred sub-dependencies are not evaluated");

ns1.ns_1_2;

assert.deepEqual(globalThis.evaluations, [1.1, 1], "the module is not re-executed");
assert.compareArray(globalThis.evaluations, [1.1, 1], "the module is not re-executed");

ns_1_2.foo;

assert.deepEqual(globalThis.evaluations, [1.1, 1, 1.2]);
assert.compareArray(globalThis.evaluations, [1.1, 1, 1.2]);
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ info: |
flags: [module]
features: [import-defer]
includes: [deepEqual.js]
includes: [compareArray.js]
---*/

import "./setup_FIXTURE.js";
Expand All @@ -48,4 +48,4 @@ import defer * as ns1 from "./dep-1_FIXTURE.js";
import "./dep-2_FIXTURE.js";
import "./dep-1_FIXTURE.js";

assert.deepEqual(globalThis.evaluations, [2, 1.1, 1], "the module is evaluated in the order where it's imported as non-deferred");
assert.compareArray(globalThis.evaluations, [2, 1.1, 1], "the module is evaluated in the order where it's imported as non-deferred");
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ info: |
flags: [module, async]
features: [import-defer, top-level-await]
includes: [compareArray.js]
---*/

import "../setup_FIXTURE.js";
Expand All @@ -52,7 +53,7 @@ import "./dep-3.js";
import defer * as ns4 from "./dep-4.js";
import "./dep-5.js";

assert.deepEqual(globalThis.evaluations, [
assert.compareArray(globalThis.evaluations, [
"1",
"2.1.1 start",
"2.2.1",
Expand All @@ -67,10 +68,10 @@ assert.deepEqual(globalThis.evaluations, [

globalThis.evaluations = [];
ns2.x;
assert.deepEqual(globalThis.evaluations, ["2.1", "2"]);
assert.compareArray(globalThis.evaluations, ["2.1", "2"]);

globalThis.evaluations = [];
ns4.x;
assert.deepEqual(globalThis.evaluations, ["4"]);
assert.compareArray(globalThis.evaluations, ["4"]);

$DONE();
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ info: |
flags: [module, async]
features: [import-defer, top-level-await]
includes: [compareArray.js]
---*/

import "../setup_FIXTURE.js";
import defer * as ns from "./tla_FIXTURE.js";

assert.deepEqual(globalThis.evaluations, ["tla start", "tla end"]);
assert.compareArray(globalThis.evaluations, ["tla start", "tla end"]);
ns.x;
assert.deepEqual(globalThis.evaluations, ["tla start", "tla end"]);
assert.compareArray(globalThis.evaluations, ["tla start", "tla end"]);

$DONE();
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ info: |
flags: [module, async]
features: [import-defer, top-level-await]
includes: [compareArray.js]
---*/

import "../setup_FIXTURE.js";
import defer * as ns "./imports-tla_FIXTURE.js";

assert.deepEqual(globalThis.evaluations, ["tla start", "tla end"]);
assert.compareArray(globalThis.evaluations, ["tla start", "tla end"]);
ns.x;
assert.deepEqual(globalThis.evaluations, ["imports-dla"]);
assert.compareArray(globalThis.evaluations, ["imports-dla"]);

$DONE();
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,18 @@ info: |
flags: [module, async]
features: [import-defer, top-level-await]
includes: [compareArray.js]
---*/

import "../setup_FIXTURE.js";
import defer * as ns from "./imports-tla-with-dep_FIXTURE.js";

assert.deepEqual(
assert.compareArray(
globalThis.evaluations,
["dep", "tla-with-dep start", "tla-with-dep end"]
);
ns.x;
assert.deepEqual(
assert.compareArray(
globalThis.evaluations,
["dep", "tla-with-dep start", "tla-with-dep end", "imports-tla-with-dep"]
);
Expand Down

0 comments on commit d5ea87e

Please sign in to comment.