Skip to content

Commit

Permalink
Allow different error codes on different Node versions
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanZim committed Feb 14, 2020
1 parent eac8cd9 commit b0d3a82
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/mkdirs/__tests__/issue-93.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const os = require('os')
const fse = require(process.cwd())
const path = require('path')
const assert = require('assert')
const util = require('util')

/* global before, describe, it */

Expand All @@ -23,13 +24,19 @@ describe('mkdirp: issue-93, win32, when drive does not exist, it should return a

it('should return a cleaner error than inifinite loop, stack crash', done => {
const file = 'R:\\afasd\\afaff\\fdfd' // hopefully drive 'r' does not exist on appveyor
// Different error codes on different Node versions (matches native mkdir behavior)
const assertErr = (err) => assert(
['EPERM', 'ENOENT'].includes(err.code),
`expected 'EPERM' or 'ENOENT', got ${util.inspect(err.code)}`
)

fse.mkdirp(file, err => {
assert.strictEqual(err.code, 'EPERM')
assertErr(err)

try {
fse.mkdirsSync(file)
} catch (err) {
assert.strictEqual(err.code, 'EPERM')
assertErr(err)
}

done()
Expand Down

0 comments on commit b0d3a82

Please sign in to comment.