From 60de8c8afc1b91d43862193f233b42d44a530895 Mon Sep 17 00:00:00 2001 From: Ruy Adorno Date: Sat, 23 Nov 2019 23:48:10 -0500 Subject: [PATCH] fix: add proper type cast to cache max value --- cli.js | 4 +-- test/unit/option-rerun.js | 70 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/cli.js b/cli.js index 394c8b1..92fe10f 100755 --- a/cli.js +++ b/cli.js @@ -42,7 +42,7 @@ const { argv } = yargs(getMainArgs()) .alias("s", "size") .describe("s", "Amount of lines to display at once") .alias("v", "version") - .describe("rerun", "Rerun last executed script") + .describe("rerun", "Repeat last executed script") .alias("r", "rerun") .boolean(["a", "A", "D", "d", "o", "h", "i", "m", "v", "r", "no-rerun-cache"]) .number(["s"]) @@ -132,7 +132,7 @@ function retrieveCache() { cacheName: rerunCacheName || process.env.NTL_RERUN_CACHE_NAME || "ntl-rerun-cache", cwd: rerunCacheDir || process.env.NTL_RERUN_CACHE_DIR, - max: process.env.NTL_RERUN_CACHE_MAX || 10 + max: parseInt(process.env.NTL_RERUN_CACHE_MAX, 10) || 10 }); } diff --git a/test/unit/option-rerun.js b/test/unit/option-rerun.js index 0ca1b0a..f6be22d 100644 --- a/test/unit/option-rerun.js +++ b/test/unit/option-rerun.js @@ -377,6 +377,76 @@ test("use custom NTL_RERUN_CACHE_MAX option", t => { }); }); +test("use string NTL_RERUN_CACHE_MAX option", t => { + setup(t, { + NTL_RERUN_CACHE_MAX: "3" + }); + t.plan(1); + const ntl = requireInject("../../cli", { + "read-pkg": { + sync: () => ({ + scripts: { + build: "make build", + test: "make test" + } + }) + }, + "lru-cache-fs": class { + constructor({ max }) { + t.equal(max, 3, "should use properly cast cache max value"); + } + }, + child_process: { + execSync: () => null + }, + ipt: () => Promise.resolve([]), + "simple-output": { + node: () => null, + success: () => null, + warn: () => null + }, + "yargs/yargs": mockYargs({ + _: [], + rerun: true + }) + }); +}); + +test("use undefined NTL_RERUN_CACHE_MAX option", t => { + setup(t, { + NTL_RERUN_CACHE_MAX: undefined + }); + t.plan(1); + const ntl = requireInject("../../cli", { + "read-pkg": { + sync: () => ({ + scripts: { + build: "make build", + test: "make test" + } + }) + }, + "lru-cache-fs": class { + constructor({ max }) { + t.equal(max, 10, "should use default cast cache max value"); + } + }, + child_process: { + execSync: () => null + }, + ipt: () => Promise.resolve([]), + "simple-output": { + node: () => null, + success: () => null, + warn: () => null + }, + "yargs/yargs": mockYargs({ + _: [], + rerun: true + }) + }); +}); + test("use custom --rerun-cache-dir option", t => { setup(t); t.plan(1);