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.
38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import path from "node:path";
|
|
|
|
import { _exportLocale } from "@clusterio/host/dist/node/src/export.js";
|
|
import { FactorioServer } from "@clusterio/host/dist/node/src/server.js";
|
|
|
|
import { factorioDir, requiresFactorio } from "./index.js";
|
|
|
|
|
|
describe("Integration of lib/factorio/export", function() {
|
|
describe("exportLocale()", function() {
|
|
requiresFactorio(this);
|
|
it("returns a nested Map with base game locale information", async function() {
|
|
let writePath = path.join("temp", "test", "server");
|
|
let testServer = new FactorioServer(factorioDir, writePath, {});
|
|
await testServer.init();
|
|
|
|
let locale = await _exportLocale(testServer, new Map(), ["base"], "en");
|
|
|
|
assert(locale instanceof Map, "locale is not a map");
|
|
assert.equal(locale.get("entity-name.fish"), "Fish");
|
|
assert.equal(locale.get("entity-name.small-lamp"), "Lamp");
|
|
let empty_keys = 0;
|
|
for (let [key, value] of locale) {
|
|
// key is always a string
|
|
assert.equal(typeof key, "string");
|
|
|
|
// Value is always a string, nearly always truthy
|
|
if (!value) {
|
|
empty_keys += 1;
|
|
}
|
|
assert.equal(typeof value, "string");
|
|
}
|
|
assert(empty_keys < 10, `Got unusually high amount (${empty_keys}) of empty keys`);
|
|
});
|
|
});
|
|
});
|