mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 07:04:52 +09:00
Migrate the usage of CommonJS specific code and imports to ESM. Roughly summarised this: - Changes all require() calls to import statement or expressions. - Changes usage of module.exports to export statements. - Replaces require.resolve with import.meta.resolve. - Replaces conditional imports with conditional subpath imports. - Replaces module === require.main with import.meta.main. - Adds the full filename with extention to all relative imports. - Changes all usage of __dirname and __filename to their import.meta equivalents. - Sets "type": "module" in package.json files. - Removes usage of "use strict". - Adds .ts an an alias of .js for the webpack build. Due to differences in how require and import resolves files the plugin entrypoints will have to include the filename and extension after this migration in order to work.
24 lines
981 B
JavaScript
24 lines
981 B
JavaScript
import assert from "node:assert/strict";
|
|
|
|
import * as lib from "@clusterio/lib";
|
|
|
|
describe("lib/errors", function() {
|
|
describe("class InvalidMessage", function() {
|
|
it("should include validation errors in the stack", function() {
|
|
let errors = [{ instancePath: "/value", message: "must be number" }];
|
|
let err = new lib.InvalidMessage("Request Test failed validation", errors);
|
|
assert.equal(err.message, "Request Test failed validation");
|
|
assert.equal(err.errors, errors);
|
|
assert(err.stack.startsWith("Error: Request Test failed validation\n"));
|
|
assert(err.stack.endsWith(`\n${JSON.stringify(errors, null, "\t")}`));
|
|
});
|
|
it("should leave the stack alone without errors", function() {
|
|
let err = new lib.InvalidMessage("Unrecognized request Test");
|
|
assert.equal(err.errors, undefined);
|
|
assert(!err.stack.includes("\n["));
|
|
let nullErr = new lib.InvalidMessage("Unrecognized request Test", null);
|
|
assert.equal(nullErr.errors, null);
|
|
});
|
|
});
|
|
});
|