1
1
import { resolve } from 'path'
2
- import { promises as fsAsync } from 'fs'
3
2
import { setTimeoutAsync } from '@dr-js/core/module/common/time.js'
4
3
import { getSampleRange } from '@dr-js/core/module/common/math/sample.js'
4
+ import { readText , writeText } from '@dr-js/core/module/node/fs/File.js'
5
5
import { createDirectory , resetDirectory } from '@dr-js/core/module/node/fs/Directory.js'
6
6
import { modifyDelete } from '@dr-js/core/module/node/fs/Modify.js'
7
7
@@ -38,19 +38,19 @@ const TEST_CONFIG = {
38
38
before ( async ( ) => {
39
39
await resetDirectory ( TEST_ROOT )
40
40
41
- await fsAsync . writeFile ( fromRoot ( 'sample-cache-file-0' ) , 'sample-cache-file-0' )
42
- await fsAsync . writeFile ( fromRoot ( 'sample-cache-file-1' ) , 'sample-cache-file-1' )
43
- await fsAsync . writeFile ( fromRoot ( 'sample-cache-file-2' ) , 'sample-cache-file-2' )
41
+ await writeText ( fromRoot ( 'sample-cache-file-0' ) , 'sample-cache-file-0' )
42
+ await writeText ( fromRoot ( 'sample-cache-file-1' ) , 'sample-cache-file-1' )
43
+ await writeText ( fromRoot ( 'sample-cache-file-2' ) , 'sample-cache-file-2' )
44
44
45
45
await createDirectory ( fromRoot ( 'sample-cache-dir-0' ) )
46
- for ( const index of getSampleRange ( 0 , 5 ) ) await fsAsync . writeFile ( fromRoot ( 'sample-cache-dir-0' , `dir-0-${ index } ` ) , `dir-0-${ index } ` )
46
+ for ( const index of getSampleRange ( 0 , 5 ) ) await writeText ( fromRoot ( 'sample-cache-dir-0' , `dir-0-${ index } ` ) , `dir-0-${ index } ` )
47
47
48
48
await setTimeoutAsync ( 50 )
49
49
50
- await fsAsync . writeFile ( fromRoot ( 'sample-cache-file-3' ) , 'sample-cache-file-3' )
50
+ await writeText ( fromRoot ( 'sample-cache-file-3' ) , 'sample-cache-file-3' )
51
51
52
52
await createDirectory ( fromRoot ( 'sample-cache-dir-1' ) )
53
- for ( const index of getSampleRange ( 0 , 5 ) ) await fsAsync . writeFile ( fromRoot ( 'sample-cache-dir-1' , `dir-1-${ index } ` ) , `dir-1-${ index } ` )
53
+ for ( const index of getSampleRange ( 0 , 5 ) ) await writeText ( fromRoot ( 'sample-cache-dir-1' , `dir-1-${ index } ` ) , `dir-1-${ index } ` )
54
54
} )
55
55
after ( async ( ) => {
56
56
await modifyDelete ( TEST_ROOT )
@@ -61,22 +61,22 @@ describe('Node.Cache.StaleCheck', () => {
61
61
await staleCheckSetup ( TEST_CONFIG )
62
62
await setTimeoutAsync ( 10 )
63
63
64
- await fsAsync . writeFile ( fromRoot ( 'sample-cache-file-4' ) , 'sample-cache-file-4' )
64
+ await writeText ( fromRoot ( 'sample-cache-file-4' ) , 'sample-cache-file-4' )
65
65
66
66
await createDirectory ( fromRoot ( 'sample-cache-dir-2' ) )
67
- for ( const index of getSampleRange ( 0 , 5 ) ) await fsAsync . writeFile ( fromRoot ( 'sample-cache-dir-2' , `dir-2-${ index } ` ) , `dir-2-${ index } ` )
67
+ for ( const index of getSampleRange ( 0 , 5 ) ) await writeText ( fromRoot ( 'sample-cache-dir-2' , `dir-2-${ index } ` ) , `dir-2-${ index } ` )
68
68
69
69
await createDirectory ( fromRoot ( 'sample-cache-dir-3' ) )
70
- for ( const index of getSampleRange ( 0 , 5 ) ) await fsAsync . writeFile ( fromRoot ( 'sample-cache-dir-3' , `dir-3-${ index } ` ) , `dir-3-${ index } ` )
70
+ for ( const index of getSampleRange ( 0 , 5 ) ) await writeText ( fromRoot ( 'sample-cache-dir-3' , `dir-3-${ index } ` ) , `dir-3-${ index } ` )
71
71
72
72
await staleCheckMark ( TEST_CONFIG )
73
73
await setTimeoutAsync ( 10 )
74
74
75
75
await createDirectory ( fromRoot ( 'sample-cache-dir-3' ) )
76
- for ( const index of getSampleRange ( 3 , 5 ) ) await fsAsync . readFile ( fromRoot ( 'sample-cache-dir-2' , `dir-2-${ index } ` ) )
77
- for ( const index of getSampleRange ( 0 , 5 ) ) await fsAsync . writeFile ( fromRoot ( 'sample-cache-dir-3' , `dir-3-${ index } ` ) , `dir-3-${ index } ` )
76
+ for ( const index of getSampleRange ( 3 , 5 ) ) await readText ( fromRoot ( 'sample-cache-dir-2' , `dir-2-${ index } ` ) )
77
+ for ( const index of getSampleRange ( 0 , 5 ) ) await writeText ( fromRoot ( 'sample-cache-dir-3' , `dir-3-${ index } ` ) , `dir-3-${ index } ` )
78
78
await createDirectory ( fromRoot ( 'sample-cache-dir-4' ) )
79
- for ( const index of getSampleRange ( 0 , 5 ) ) await fsAsync . writeFile ( fromRoot ( 'sample-cache-dir-4' , `dir-4-${ index } ` ) , `dir-4-${ index } ` )
79
+ for ( const index of getSampleRange ( 0 , 5 ) ) await writeText ( fromRoot ( 'sample-cache-dir-4' , `dir-4-${ index } ` ) , `dir-4-${ index } ` )
80
80
81
81
const { report } = await staleCheckCalcReport ( TEST_CONFIG )
82
82
0 commit comments