mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 07:33:12 +09:00
Flatten lib namespace
Move all functions and classes currently available through lib/name and libName to be under a single flat namespace in lib. This make reorganising the lib namespace much simpler as the location of symbols can move without breaking the consumers of lib. The multi-entrypoint design was already problematic for the web plugin system which couldn't effectively use it due to how webpack's shared module system is awkward to set up with multiple entrypoints per package.
This commit is contained in:
1 parent
bb58670597
commit
bfe119eaa3
143 files changed
+1798
-1918
No files matched your search
+15
-15
@@ -2,25 +2,25 @@
|
||||
const assert = require("assert").strict;
|
||||
const hrtime = process.hrtime.bigint;
|
||||
|
||||
const libHelpers = require("@clusterio/lib/helpers");
|
||||
const lib = require("@clusterio/lib");
|
||||
|
||||
|
||||
describe("lib/helpers", function() {
|
||||
describe("basicType()", function() {
|
||||
it("should return the expected values", function() {
|
||||
assert.equal(libHelpers.basicType("s"), "string");
|
||||
assert.equal(libHelpers.basicType(null), "null");
|
||||
assert.equal(libHelpers.basicType(undefined), "undefined");
|
||||
assert.equal(libHelpers.basicType([1, 2]), "array");
|
||||
assert.equal(libHelpers.basicType(7), "number");
|
||||
assert.equal(libHelpers.basicType({ a: 1 }), "object");
|
||||
assert.equal(lib.basicType("s"), "string");
|
||||
assert.equal(lib.basicType(null), "null");
|
||||
assert.equal(lib.basicType(undefined), "undefined");
|
||||
assert.equal(lib.basicType([1, 2]), "array");
|
||||
assert.equal(lib.basicType(7), "number");
|
||||
assert.equal(lib.basicType({ a: 1 }), "object");
|
||||
});
|
||||
});
|
||||
|
||||
describe("wait", function() {
|
||||
it("should wait the approximate amount of time given", async function() {
|
||||
let startNs = hrtime();
|
||||
await libHelpers.wait(100);
|
||||
await lib.wait(100);
|
||||
let duration = Number(hrtime() - startNs) / 1e6;
|
||||
|
||||
// On windows the time waited is normally up to 15 ms late with outliers in the 20ms range.
|
||||
@@ -30,22 +30,22 @@ describe("lib/helpers", function() {
|
||||
|
||||
describe("timeout", function() {
|
||||
it("should return the result of an already resolved promise", async function() {
|
||||
assert.equal(await libHelpers.timeout(Promise.resolve("value"), 10, "timeout"), "value");
|
||||
assert.equal(await lib.timeout(Promise.resolve("value"), 10, "timeout"), "value");
|
||||
});
|
||||
it("should return the result of the promise if received before timeout", async function() {
|
||||
assert.equal(await libHelpers.timeout(
|
||||
(async () => { await libHelpers.wait(10); return "value"; })(), 20, "timeout"
|
||||
assert.equal(await lib.timeout(
|
||||
(async () => { await lib.wait(10); return "value"; })(), 20, "timeout"
|
||||
), "value");
|
||||
});
|
||||
it("should return the timeoutResult if not received before timeout", async function() {
|
||||
assert.equal(await libHelpers.timeout(
|
||||
(async () => { await libHelpers.wait(20); return "value"; })(), 10, "timeout"
|
||||
assert.equal(await lib.timeout(
|
||||
(async () => { await lib.wait(20); return "value"; })(), 10, "timeout"
|
||||
), "timeout");
|
||||
});
|
||||
});
|
||||
|
||||
function parse(input, attributes) {
|
||||
const result = libHelpers.parseSearchString(input, attributes);
|
||||
const result = lib.parseSearchString(input, attributes);
|
||||
if (!result.issues.length) {
|
||||
return result.terms;
|
||||
}
|
||||
@@ -132,7 +132,7 @@ describe("lib/helpers", function() {
|
||||
});
|
||||
});
|
||||
describe("wordMatches()", function() {
|
||||
const match = libHelpers.wordMatches;
|
||||
const match = lib.wordMatches;
|
||||
it("should match any inputs", function() {
|
||||
assert(match(parse("word")[0], "a word in a string"), "one text");
|
||||
assert(!match(parse("word")[0], "a string without"), "one text no match");
|
||||
|
||||
Reference in new issue
Block a user