Skip to content

Commit 22f2e0e

Browse files
committed
test: @putout/cli-cache: coverage
1 parent 45f3bca commit 22f2e0e

File tree

6 files changed

+46
-8
lines changed

6 files changed

+46
-8
lines changed

packages/cli-cache/lib/cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ const createGetOptionsCache = ({version}) => (options) => {
156156
};
157157

158158
async function _findCachePath() {
159-
const findCacheDir = await simpleImport('./find-cache-dir.mjs');
159+
const {findCacheDir} = await simpleImport('./find-cache-dir.mjs');
160160

161161
const cacheDir = await findCacheDir({
162162
name: 'putout',

packages/cli-cache/lib/cache.spec.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ test('putout: cli: cache: fileCache: fresh', async (t) => {
3131
});
3232

3333
const findCacheDir = stub().returns('node_modules/.cache');
34-
const simpleImport = stub().returns(findCacheDir);
34+
const simpleImport = stub().returns({
35+
findCacheDir,
36+
});
3537

3638
mockRequire('./simple-import', {
3739
simpleImport,
@@ -59,7 +61,9 @@ test(`putout: cli: cache: find up can't find`, async (t) => {
5961
});
6062

6163
const findCacheDir = stub();
62-
const simpleImport = stub().returns(findCacheDir);
64+
const simpleImport = stub().returns({
65+
findCacheDir,
66+
});
6367

6468
mockRequire('./simple-import', {
6569
simpleImport,

packages/cli-cache/lib/find-cache-dir.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {join} from 'node:path';
22
import {mkdir as _mkdir} from 'node:fs/promises';
33
import {findUp as _findUp} from './find-up.mjs';
44

5-
export default async function findCacheDir(overrides = {}) {
5+
export async function findCacheDir(overrides = {}) {
66
const {
77
name,
88
findUp = _findUp,

packages/cli-cache/lib/find-cache-dir.spec.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {test} from 'supertape';
2-
import findCacheDir from './find-cache-dir.mjs';
2+
import {findCacheDir} from './find-cache-dir.mjs';
33

44
test('putout: cli-cache: find-cache-dir', async (t) => {
55
const dir = await findCacheDir({

packages/cli-cache/lib/find-up.mjs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {join} from 'node:path';
22
import process from 'node:process';
3-
import escalade from 'escalade';
3+
import _escalade from 'escalade';
44

55
const {isArray} = Array;
66
const maybeArray = (a) => isArray(a) ? a : [a];
@@ -14,7 +14,11 @@ const includesName = (name) => (dir, names) => {
1414
return '';
1515
};
1616

17-
export const findUp = async (name, {cwd = process.cwd()} = {}) => {
17+
export const findUp = async (name, overrides = {}) => {
18+
const {
19+
cwd = process.cwd(),
20+
escalade = _escalade,
21+
} = overrides;
22+
1823
return await escalade(cwd, includesName(name));
1924
};
20-
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {test, stub} from 'supertape';
2+
import {findUp} from './find-up.mjs';
3+
4+
test('putout: cli-cache: find-up: name: array', async (t) => {
5+
const escalade = stub((dir, fn) => {
6+
fn(dir, []);
7+
});
8+
9+
await findUp(['hello'], {
10+
cwd: '/',
11+
escalade,
12+
});
13+
14+
t.calledWith(escalade, ['/', stub()]);
15+
t.end();
16+
});
17+
18+
test('putout: cli-cache: find-up', async (t) => {
19+
const escalade = stub((dir, fn) => {
20+
fn(dir, []);
21+
});
22+
23+
await findUp('hello', {
24+
cwd: '/',
25+
escalade,
26+
});
27+
28+
t.calledWith(escalade, ['/', stub()]);
29+
t.end();
30+
});

0 commit comments

Comments
 (0)