@@ -7,9 +7,9 @@ import del from 'del';
7
7
import test from 'ava' ;
8
8
import uuid from 'uuid' ;
9
9
import sinon from 'sinon' ;
10
- import cpFile from '..' ;
11
10
import assertDateEqual from './helpers/_assert' ;
12
- import { buildEACCES , buildEIO , buildENOSPC , buildENOENT , buildEPERM } from './helpers/_fs-errors' ;
11
+ import { buildEACCES , buildEIO , buildENOSPC , buildENOENT , buildEPERM , buildERRSTREAMWRITEAFTEREND } from './helpers/_fs-errors' ;
12
+ import cpFile from '..' ;
13
13
14
14
const THREE_HUNDRED_KILO = ( 100 * 3 * 1024 ) + 1 ;
15
15
@@ -75,8 +75,9 @@ test('overwrite when options are undefined', async t => {
75
75
76
76
test ( 'do not overwrite when disabled' , async t => {
77
77
fs . writeFileSync ( t . context . destination , '' ) ;
78
- await cpFile ( 'license' , t . context . destination , { overwrite : false } ) ;
79
- t . is ( fs . readFileSync ( t . context . destination , 'utf8' ) , '' ) ;
78
+ const error = await t . throwsAsync ( cpFile ( 'license' , t . context . destination , { overwrite : false } ) ) ;
79
+ t . is ( error . name , 'CpFileError' , error . message ) ;
80
+ t . is ( error . code , 'EEXIST' , error . message ) ;
80
81
} ) ;
81
82
82
83
test ( 'do not create `destination` on unreadable `source`' , async t => {
@@ -245,7 +246,7 @@ test.serial('rethrow read after open errors', async t => {
245
246
const { createWriteStream, createReadStream} = fs ;
246
247
let calledWriteEnd = 0 ;
247
248
let readStream ;
248
- const readError = buildEIO ( ) ;
249
+ const readError = process . release . lts === 'Erbium' || parseInt ( process . versions . node . slice ( 0 , 2 ) , 10 ) > 12 ? buildERRSTREAMWRITEAFTEREND ( ) : buildEIO ( ) ;
249
250
250
251
fs . createWriteStream = ( ...args ) => {
251
252
const stream = createWriteStream ( ...args ) ;
@@ -275,8 +276,8 @@ test.serial('rethrow read after open errors', async t => {
275
276
const uncached = importFresh ( '..' ) ;
276
277
const error = await t . throwsAsync ( uncached ( 'license' , t . context . destination ) ) ;
277
278
t . is ( error . name , 'CpFileError' , error . message ) ;
278
- t . is ( error . errno , readError . errno , error . message ) ;
279
279
t . is ( error . code , readError . code , error . message ) ;
280
+ t . is ( error . errno , readError . errno , error . message ) ;
280
281
t . is ( calledWriteEnd , 1 ) ;
281
282
282
283
Object . assign ( fs , { createWriteStream, createReadStream} ) ;
0 commit comments