11'use strict'
2- const test = require ( 'tape' )
2+ const { test } = require ( 'node:test' )
3+ const assert = require ( 'node:assert' )
34const canLink = require ( 'can-link' )
45
56const exdevErr = new Error ( 'EXDEV: cross-device link not permitted' )
@@ -11,88 +12,70 @@ eaccesErr.code = 'EACCES'
1112const epermErr = new Error ( 'EPERM: permission denied, link' )
1213epermErr . code = 'EPERM'
1314
14- test ( 'canLink.sync()' , t => {
15- t . ok ( canLink . sync ( 'package.json' , 'node_modules/package.json' ) )
16- t . notOk ( canLink . sync ( 'foo' , 'bar' , {
15+ test ( 'canLink.sync()' , ( ) => {
16+ assert . ok ( canLink . sync ( 'package.json' , 'node_modules/package.json' ) )
17+ assert . ok ( ! canLink . sync ( 'foo' , 'bar' , {
1718 linkSync : ( ) => { throw exdevErr } ,
1819 unlinkSync : ( ) => { }
19- } ) , 'cannot link on EXDEV error' )
20- t . notOk ( canLink . sync ( 'foo' , 'bar' , {
20+ } ) )
21+ assert . ok ( ! canLink . sync ( 'foo' , 'bar' , {
2122 linkSync : ( ) => { throw eaccesErr } ,
2223 unlinkSync : ( ) => { }
23- } ) , 'cannot link on EACCES error' )
24- t . notOk ( canLink . sync ( 'foo' , 'bar' , {
24+ } ) )
25+ assert . ok ( ! canLink . sync ( 'foo' , 'bar' , {
2526 linkSync : ( ) => { throw epermErr } ,
2627 unlinkSync : ( ) => { }
27- } ) , 'cannot link on EPERM error' )
28- t . throws ( ( ) => {
28+ } ) )
29+ assert . throws ( ( ) => {
2930 const fsMock = {
3031 linkSync : ( ) => { throw new Error ( 'Error' ) }
3132 }
3233 canLink . sync ( 'foo' , 'bar' , fsMock )
33- } , / E r r o r / , 'errors are passed through if they are not EXDEV' )
34- t . end ( )
34+ } , / E r r o r / )
3535} )
3636
37- test ( 'canLink() returns true' , t => {
38- canLink ( 'package.json' , 'node_modules/package.json' )
39- . then ( can => {
40- t . ok ( can )
41- t . end ( )
42- } )
43- . catch ( t . end )
37+ test ( 'canLink() returns true' , async ( ) => {
38+ const can = await canLink ( 'package.json' , 'node_modules/package.json' )
39+ assert . ok ( can )
4440} )
4541
46- test ( 'canLink() returns false' , t => {
47- canLink ( 'package.json' , 'node_modules/package.json' , {
42+ test ( 'canLink() returns false' , async ( ) => {
43+ const can = await canLink ( 'package.json' , 'node_modules/package.json' , {
4844 promises : {
4945 link : ( existingPath , newPath , cb ) => Promise . reject ( exdevErr ) ,
5046 unlink : ( p , cb ) => Promise . resolve ( )
5147 }
5248 } )
53- . then ( can => {
54- t . notOk ( can )
55- t . end ( )
56- } )
57- . catch ( t . end )
49+ assert . ok ( ! can )
5850} )
5951
60- test ( 'canLink() returns false on EACCES error' , t => {
61- canLink ( 'package.json' , 'node_modules/package.json' , {
52+ test ( 'canLink() returns false on EACCES error' , async ( ) => {
53+ const can = await canLink ( 'package.json' , 'node_modules/package.json' , {
6254 promises : {
6355 link : ( existingPath , newPath , cb ) => Promise . reject ( eaccesErr ) ,
6456 unlink : ( p , cb ) => Promise . resolve ( )
6557 }
6658 } )
67- . then ( can => {
68- t . notOk ( can )
69- t . end ( )
70- } )
71- . catch ( t . end )
59+ assert . ok ( ! can )
7260} )
7361
74- test ( 'canLink() returns false on EPERM error' , async t => {
62+ test ( 'canLink() returns false on EPERM error' , async ( ) => {
7563 const can = await canLink ( 'package.json' , 'node_modules/package.json' , {
7664 promises : {
7765 link : ( existingPath , newPath , cb ) => Promise . reject ( epermErr ) ,
78- unlink : ( p , cb ) => cb ( )
66+ unlink : ( p , cb ) => Promise . resolve ( )
7967 }
8068 } )
81- t . notOk ( can )
82- t . end ( )
69+ assert . ok ( ! can )
8370} )
8471
85- test ( 'canLink() non-exdev error passed through' , t => {
86- canLink ( 'package.json' , 'node_modules/package.json' , {
87- promises : {
88- link : ( existingPath , newPath , cb ) => Promise . reject ( new Error ( 'Error' ) )
89- }
90- } )
91- . then ( can => {
92- t . fail ( 'should have failed' )
93- } )
94- . catch ( err => {
95- t . ok ( err )
96- t . end ( )
97- } )
72+ test ( 'canLink() non-exdev error passed through' , async ( ) => {
73+ await assert . rejects (
74+ canLink ( 'package.json' , 'node_modules/package.json' , {
75+ promises : {
76+ link : ( existingPath , newPath , cb ) => Promise . reject ( new Error ( 'Error' ) )
77+ }
78+ } ) ,
79+ / E r r o r /
80+ )
9881} )
0 commit comments