diff --git a/cjs/index.js b/cjs/index.js
index 0877a5f..3eecbce 100644
--- a/cjs/index.js
+++ b/cjs/index.js
@@ -80,7 +80,7 @@ let detector;
enumerable: false,
},
version: {
- value: "v1.0.20",
+ value: "v1.0.21",
enumerable: true,
},
});
diff --git a/esm/index.mjs b/esm/index.mjs
index 7fdba08..1a47919 100644
--- a/esm/index.mjs
+++ b/esm/index.mjs
@@ -77,7 +77,7 @@ let detector;
enumerable: false,
},
version: {
- value: "v1.0.20",
+ value: "v1.0.21",
enumerable: true,
},
});
diff --git a/logs/dots_test-result.json b/logs/dots_test-result.json
new file mode 100644
index 0000000..609ebbc
--- /dev/null
+++ b/logs/dots_test-result.json
@@ -0,0 +1,20 @@
+{
+ "linux": {
+ "options: use default(undefined)": "C",
+ "options: {\"spawn\":false}": "en-US",
+ "options: {\"spawn\":true,\"cache\":false}": "C",
+ "options: {\"spawn\":false,\"cache\":false}": "en-US"
+ },
+ "win32": {
+ "options: use default(undefined)": "ja-JP",
+ "options: {\"spawn\":false}": "ja-JP",
+ "options: {\"spawn\":true,\"cache\":false}": "ja-JP",
+ "options: {\"spawn\":false,\"cache\":false}": "en-US"
+ },
+ "darwin": {
+ "options: use default(undefined)": "en-US",
+ "options: {\"spawn\":false}": "en-US",
+ "options: {\"spawn\":true,\"cache\":false}": "en-US",
+ "options: {\"spawn\":false,\"cache\":false}": "en-US"
+ }
+}
\ No newline at end of file
diff --git a/package.json b/package.json
index 17fbe90..33b18a5 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "os-locale-s",
- "version": "1.0.20",
+ "version": "1.0.21",
"description": "Its a light weight version that minimizes the dependency module of `os-locale`",
"private": false,
"main": "./cjs/index.js",
diff --git a/test.js b/test.js
index afd1bcd..3a38948 100644
--- a/test.js
+++ b/test.js
@@ -10,10 +10,12 @@
///
// @ts-ignore
///
+const fs = require("fs");
/**
* @typedef {typeof process.platform} TOSTokens
* @typedef {keyof typeof global} TGThisKeys
* @typedef {[spawn?: boolean, cache?: boolean]} TDetectorOptValues
+ * @typedef {Record>} TLocaleResultMap
* @typedef TProcessCache
* @prop {typeof process["env"]} env
* @prop {TOSTokens} platform
@@ -96,16 +98,24 @@ const tryMatch = (lc) => {
* @param {string} locale
* @param {XReadonly=} opt
*/
-const printInfo = (prefix, locale, opt) => console.log(`${prefix}[platform: ${process.platform}, options: ${opt ? JSON.stringify(opt) : "use default(undefined)"}]: ${locale}`);
+const printInfo = (prefix, locale, opt) => {
+ console.log(`${prefix}[platform: ${process.platform}, options: ${opt ? JSON.stringify(opt) : "use default(undefined)"}]: ${locale}`);
+};
/**
+ * @param {TLocaleResultMap} localeResult
* @param {TDetectorOptValues=} detectorOpt [spawn, cache]
* @param {true=} async
*/
-const emitCallback = (detectorOpt, async) => async () => {
+const emitCallback = (localeResult, detectorOpt, async) => async () => {
const opt = makeOption(detectorOpt);
const fn = async ? osLocale : osLocale.sync;
const result = fn(opt);
const locale = /** @type {string} */ (async ? await result : result);
+ let root = localeResult[process.platform];
+ if (!root) {
+ root = localeResult[process.platform] = {};
+ }
+ root[`options: ${opt ? JSON.stringify(opt).replace(/\\"/g, "") : "use default(undefined)"}`] = locale;
debug && printInfo(async ? "async " : "", locale, opt);
tryMatch(locale);
};
@@ -116,6 +126,8 @@ eachModule(".");
*/
function eachModule(path) {
describe(` ====================== running test: [os-locale-s], module - "${path}" ======================`, function () {
+ /** @type {TLocaleResultMap} */
+ const localeResult = {};
beforeAll(/** @type {() => Promise} */ () => {
process.env = {};
return new Promise(resolve => {
@@ -125,46 +137,54 @@ function eachModule(path) {
});
});
});
+ afterAll(() => {
+ const logRoot = "./logs/";
+ if (!fs.existsSync(logRoot)) {
+ fs.mkdirSync(logRoot);
+ }
+ const outputJsonPath = logRoot + path.replace(/[.]+/g, "dots").replace(/[/\\]/g, "_") + "_test-result.json";
+ fs.writeFileSync(outputJsonPath, JSON.stringify(localeResult, null, 2));
+ });
describe.each([
[/** @type {TOSTokens} */ ("linux"), LINUX], [/** @type {TOSTokens} */ ("win32"), WIN], [/** @type {TOSTokens} */ ("darwin"), DARWIN]
])("[[[ Platform: %s (process.env.platform) ]]]", (name, enable) => {
if (enable) {
beforeEach(setPlatformOf(name));
describe("locale detection with default options", function () {
- it("async detection", emitCallback(void 0, true));
- it("sync detection", emitCallback());
+ it("async detection", emitCallback(localeResult, void 0, true));
+ it("sync detection", emitCallback(localeResult));
});
describe("locale detection with default options (no spawn)", function () {
- it("async detection", emitCallback([false], true));
- it("sync detection", emitCallback([false]));
+ it("async detection", emitCallback(localeResult, [false], true));
+ it("sync detection", emitCallback(localeResult, [false]));
});
describe("locale detection with default options (no cache)", function () {
- it("async detection", emitCallback([true, false], true));
- it("sync detection", emitCallback([true, false]));
+ it("async detection", emitCallback(localeResult, [true, false], true));
+ it("sync detection", emitCallback(localeResult, [true, false]));
});
describe("locale detection with no spawn, no cache", function () {
- it("async detection", emitCallback([false, false], true));
- it("sync detection", emitCallback([false, false]));
+ it("async detection", emitCallback(localeResult, [false, false], true));
+ it("sync detection", emitCallback(localeResult, [false, false]));
});
}
});
DEFAULT && describe("[[[ OS: default (**Test depending on the actual platform) ]]]", () => {
beforeAll(setPlatformOf(cache.platform, () => process.env = cache.env));
describe("locale detection with default options", function () {
- it("async detection", emitCallback(void 0, true));
- it("sync detection", emitCallback());
+ it("async detection", emitCallback(localeResult, void 0, true));
+ it("sync detection", emitCallback(localeResult));
});
describe("locale detection with default options (no spawn)", function () {
- it("async detection", emitCallback([false], true));
- it("sync detection", emitCallback([false]));
+ it("async detection", emitCallback(localeResult, [false], true));
+ it("sync detection", emitCallback(localeResult, [false]));
});
describe("locale detection with default options (no cache)", function () {
- it("async detection", emitCallback([true, false], true));
- it("sync detection", emitCallback([true, false]));
+ it("async detection", emitCallback(localeResult, [true, false], true));
+ it("sync detection", emitCallback(localeResult, [true, false]));
});
describe("locale detection with no spawn, no cache", function () {
- it("async detection", emitCallback([false, false], true));
- it("sync detection", emitCallback([false, false]));
+ it("async detection", emitCallback(localeResult, [false, false], true));
+ it("sync detection", emitCallback(localeResult, [false, false]));
});
});
});