1
1
import process from 'node:process' ;
2
2
import fs from 'node:fs' ;
3
3
import path from 'node:path' ;
4
- import { fileURLToPath } from 'node:url' ;
5
4
import test from 'ava' ;
6
5
import { deleteSync } from 'del' ;
7
6
import { temporaryDirectory } from 'tempy' ;
8
7
import findCacheDirectory from './index.js' ;
9
8
10
- const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
9
+ const { dirname } = import . meta;
11
10
12
11
test ( 'finds from a list of files' , t => {
13
- process . chdir ( path . join ( __dirname , '..' ) ) ;
14
- const files = [ 'foo/bar' , 'baz/quz' ] . map ( file => path . join ( __dirname , file ) ) ;
15
- t . is ( findCacheDirectory ( { files, name : 'blah' } ) , path . join ( __dirname , 'node_modules' , '.cache' , 'blah' ) ) ;
12
+ process . chdir ( path . join ( dirname , '..' ) ) ;
13
+ const files = [ 'foo/bar' , 'baz/quz' ] . map ( file => path . join ( dirname , file ) ) ;
14
+ t . is ( findCacheDirectory ( { files, name : 'blah' } ) , path . join ( dirname , 'node_modules' , '.cache' , 'blah' ) ) ;
16
15
} ) ;
17
16
18
17
test ( 'finds from process.cwd' , t => {
19
- process . chdir ( path . join ( __dirname ) ) ;
20
- t . is ( findCacheDirectory ( { name : 'foo' } ) , path . join ( __dirname , 'node_modules' , '.cache' , 'foo' ) ) ;
18
+ process . chdir ( path . join ( dirname ) ) ;
19
+ t . is ( findCacheDirectory ( { name : 'foo' } ) , path . join ( dirname , 'node_modules' , '.cache' , 'foo' ) ) ;
21
20
} ) ;
22
21
23
22
test ( 'finds from options.cwd' , t => {
24
- process . chdir ( path . join ( __dirname , '..' ) ) ;
25
- t . is ( findCacheDirectory ( { cwd : __dirname , name : 'bar' } ) , path . join ( __dirname , 'node_modules' , '.cache' , 'bar' ) ) ;
23
+ process . chdir ( path . join ( dirname , '..' ) ) ;
24
+ t . is ( findCacheDirectory ( { cwd : dirname , name : 'bar' } ) , path . join ( dirname , 'node_modules' , '.cache' , 'bar' ) ) ;
26
25
} ) ;
27
26
28
27
test ( 'creates directory' , t => {
29
- const directory = path . join ( __dirname , 'node_modules' , '.cache' , 'created' ) ;
28
+ const directory = path . join ( dirname , 'node_modules' , '.cache' , 'created' ) ;
30
29
deleteSync ( directory ) ;
31
- findCacheDirectory ( { create : true , name : 'created' , cwd : __dirname } ) ;
30
+ findCacheDirectory ( { create : true , name : 'created' , cwd : dirname } ) ;
32
31
t . true ( fs . existsSync ( directory ) ) ;
33
32
} ) ;
34
33
35
34
test ( 'returns undefined if it can\'t find package.json' , t => {
36
- process . chdir ( path . join ( __dirname , '..' ) ) ;
35
+ process . chdir ( path . join ( dirname , '..' ) ) ;
37
36
t . is ( findCacheDirectory ( { name : 'foo' } ) , undefined ) ;
38
37
} ) ;
39
38
@@ -53,5 +52,5 @@ test('supports CACHE_DIR environment variable', t => {
53
52
test ( 'ignores `false` for CACHE_DIR environment variable' , t => {
54
53
process . env . CACHE_DIR = 'false' ;
55
54
56
- t . not ( findCacheDirectory ( ) , path . resolve ( __dirname , 'false' , 'find-cache-directory' ) ) ;
55
+ t . not ( findCacheDirectory ( ) , path . resolve ( dirname , 'false' , 'find-cache-directory' ) ) ;
57
56
} ) ;
0 commit comments