11const t = require ( 'tap' )
2- const fs = require ( 'fs' )
2+ const fs = require ( 'fs/promises ' )
33const path = require ( 'path' )
44
55const { load : loadMockNpm } = require ( '../../fixtures/mock-npm' )
@@ -11,6 +11,7 @@ const cleanCacheSha = (str) =>
1111 str . replace ( / c o n t e n t - v 2 \/ s h a 5 1 2 \/ [ ^ " ] + / g, 'content-v2/sha512/{sha}' )
1212
1313t . cleanSnapshot = p => cleanCacheSha ( cleanDate ( cleanCwd ( p ) ) )
14+ . replace ( / \s \( ( \{ C W D \} | n o d e : ) .* \d + : \d + \) $ / gm, ' {STACK}' )
1415
1516const npmManifest = ( version ) => {
1617 return {
@@ -389,15 +390,15 @@ t.test('incorrect owner', async t => {
389390 const { joinedOutput, logs, npm } = await loadMockNpm ( t , {
390391 mocks : {
391392 ...mocks ,
392- fs : {
393+ 'fs/promises' : {
393394 ...fs ,
394- lstat : ( p , cb ) => {
395- const stat = fs . lstatSync ( p )
395+ lstat : async ( p ) => {
396+ const stat = await fs . lstat ( p )
396397 if ( p . endsWith ( '_cacache' ) ) {
397398 stat . uid += 1
398399 stat . gid += 1
399400 }
400- return cb ( null , stat )
401+ return stat
401402 } ,
402403 } ,
403404 } ,
@@ -418,9 +419,9 @@ t.test('incorrect permissions', async t => {
418419 const { joinedOutput, logs, npm } = await loadMockNpm ( t , {
419420 mocks : {
420421 ...mocks ,
421- fs : {
422+ 'fs/promises' : {
422423 ...fs ,
423- access : ( ) => {
424+ access : async ( ) => {
424425 throw new Error ( 'Test Error' )
425426 } ,
426427 } ,
@@ -442,9 +443,13 @@ t.test('error reading directory', async t => {
442443 const { joinedOutput, logs, npm } = await loadMockNpm ( t , {
443444 mocks : {
444445 ...mocks ,
445- fs : {
446+ 'fs/promises' : {
446447 ...fs ,
447- readdir : ( ) => {
448+ readdir : async ( s , ...args ) => {
449+ if ( s . endsWith ( '_logs' ) ) {
450+ return fs . readdir ( s , ...args )
451+ }
452+ // if (s.endsWith)
448453 throw new Error ( 'Test Error' )
449454 } ,
450455 } ,
0 commit comments