Skip to content

Commit

Permalink
fix: add proper type cast to cache max value
Browse files Browse the repository at this point in the history
  • Loading branch information
ruyadorno committed Nov 24, 2019
1 parent d4fdc0f commit 60de8c8
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cli.js
Expand Up @@ -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"])
Expand Down Expand Up @@ -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
});
}

Expand Down
70 changes: 70 additions & 0 deletions test/unit/option-rerun.js
Expand Up @@ -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);
Expand Down

0 comments on commit 60de8c8

Please sign in to comment.