Skip to content

Commit c360cf5

Browse files
committedJan 24, 2020
tests for new version
1 parent 3e68692 commit c360cf5

24 files changed

+602
-459
lines changed
 

‎tap-snapshots/test-cmd.js-TAP.test.js

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* IMPORTANT
2+
* This snapshot file is auto-generated, but designed for humans.
3+
* It should be checked into source control and tracked carefully.
4+
* Re-generate by setting TAP_SNAPSHOT=1 and running tests.
5+
* Make sure to inspect the output below. Do not ignore changes!
6+
*/
7+
'use strict'
8+
exports[`test/cmd.js TAP -h --help prints usage > --help output 1`] = `
9+
Object {
10+
"code": 0,
11+
"signal": null,
12+
"stderr": "",
13+
"stdout": "\\nusage: mkdirp [DIR1,DIR2..] {OPTIONS}\\n\\n Create each supplied directory including any necessary parent directories\\n that don't yet exist.\\n\\n If the directory already exists, do nothing.\\n\\nOPTIONS are:\\n\\n -m<mode> If a directory needs to be created, set the mode as an octal\\n --mode=<mode> permission string.\\n\\n -v --version Print the mkdirp version number\\n\\n -h --help Print this helpful banner\\n\\n -p --print Print the first directories created for each path provided\\n\\n --manual Use manual implementation, even if native is available\\n\\n",
14+
}
15+
`
16+
17+
exports[`test/cmd.js TAP -v --version prints version > --version output 1`] = `
18+
Object {
19+
"code": 0,
20+
"signal": null,
21+
"stderr": "",
22+
"stdout": "4.2.0-69.lol\\n",
23+
}
24+
`
25+
26+
exports[`test/cmd.js TAP failures > expect resolving Promise 1`] = `
27+
Array [
28+
Object {
29+
"code": 1,
30+
"signal": null,
31+
"stderr": "nope\\n",
32+
"stdout": "",
33+
},
34+
Object {
35+
"code": 1,
36+
"signal": null,
37+
"stderr": "fail\\n code: EFAIL\\n",
38+
"stdout": "",
39+
},
40+
]
41+
`
42+
43+
exports[`test/cmd.js TAP invalid mode > expect resolving Promise 1`] = `
44+
Object {
45+
"code": 1,
46+
"signal": null,
47+
"stderr": "invalid mode argument: --mode=XYZ\\nMust be an octal number.\\n",
48+
"stdout": "",
49+
}
50+
`
51+
52+
exports[`test/cmd.js TAP make dir named --help > expect resolving Promise 1`] = `
53+
Object {
54+
"code": 0,
55+
"signal": null,
56+
"stderr": "",
57+
"stdout": "--help 0\\n",
58+
}
59+
`
60+
61+
exports[`test/cmd.js TAP making dirs > expect resolving Promise 1`] = `
62+
Object {
63+
"code": 0,
64+
"signal": null,
65+
"stderr": "",
66+
"stdout": "",
67+
}
68+
`
69+
70+
exports[`test/cmd.js TAP manual > expect resolving Promise 1`] = `
71+
Object {
72+
"code": 0,
73+
"signal": null,
74+
"stderr": "",
75+
"stdout": "MANUAL a 0\\nMANUAL b/c/d 0\\n",
76+
}
77+
`
78+
79+
exports[`test/cmd.js TAP no dirs -> stderr usage > expect resolving Promise 1`] = `
80+
Object {
81+
"code": 0,
82+
"signal": null,
83+
"stderr": "\\nusage: mkdirp [DIR1,DIR2..] {OPTIONS}\\n\\n Create each supplied directory including any necessary parent directories\\n that don't yet exist.\\n\\n If the directory already exists, do nothing.\\n\\nOPTIONS are:\\n\\n -m<mode> If a directory needs to be created, set the mode as an octal\\n --mode=<mode> permission string.\\n\\n -v --version Print the mkdirp version number\\n\\n -h --help Print this helpful banner\\n\\n -p --print Print the first directories created for each path provided\\n\\n --manual Use manual implementation, even if native is available\\n\\n",
84+
"stdout": "",
85+
}
86+
`
87+
88+
exports[`test/cmd.js TAP noisily > expect resolving Promise 1`] = `
89+
Object {
90+
"code": 0,
91+
"signal": null,
92+
"stderr": "",
93+
"stdout": "a 0\\nb/c/d 0\\n",
94+
}
95+
`
96+
97+
exports[`test/cmd.js TAP print modes > expect resolving Promise 1`] = `
98+
Object {
99+
"code": 0,
100+
"signal": null,
101+
"stderr": "",
102+
"stdout": "a 509\\n",
103+
}
104+
`

‎test/chmod.js

-41
This file was deleted.

‎test/clobber.js

-38
This file was deleted.

‎test/cmd.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const cmd = require.resolve('../bin/cmd.js')
2+
const requireInject = require('require-inject')
3+
4+
const {basename} = require('path')
5+
const fakeMkdirp = (path, opts) =>
6+
basename(path) === 'ERROR' ? Promise.reject(new Error('nope'))
7+
: basename(path) === 'EFAIL' ? Promise.reject(Object.assign(new Error('fail'), { code: 'EFAIL' }))
8+
: Promise.resolve(`${path} ${opts.mode || 0}`)
9+
10+
fakeMkdirp.manual = (path, opts) => fakeMkdirp(`MANUAL ${path}`, opts)
11+
12+
if (process.argv[2] === 'RUN') {
13+
process.argv = [process.execPath, cmd, ...process.argv.slice(3)]
14+
requireInject(cmd, {
15+
'../': fakeMkdirp,
16+
'../package.json': {
17+
version: '4.2.0-69.lol',
18+
},
19+
})
20+
} else {
21+
22+
const t = require('tap')
23+
24+
const {spawn} = require('child_process')
25+
const run = (...args) => new Promise((res, rej) => {
26+
const proc = spawn(process.execPath, [__filename, 'RUN', ...args])
27+
const out = []
28+
const err = []
29+
proc.stdout.on('data', c => out.push(c))
30+
proc.stderr.on('data', c => err.push(c))
31+
proc.on('close', (code, signal) => {
32+
res({
33+
code,
34+
signal,
35+
stdout: Buffer.concat(out).toString('utf8'),
36+
stderr: Buffer.concat(err).toString('utf8'),
37+
})
38+
})
39+
})
40+
41+
t.test('-h --help prints usage', t => Promise.all([
42+
run('-h'),
43+
run('--help'),
44+
]).then(res => {
45+
t.strictSame(res[0], res[1], 'same for -h and --help')
46+
t.matchSnapshot(res[0], '--help output')
47+
}))
48+
49+
t.test('no dirs -> stderr usage', t => t.resolveMatchSnapshot(run()))
50+
51+
t.test('-v --version prints version', t => Promise.all([
52+
run('-v'),
53+
run('--version'),
54+
]).then(res => {
55+
t.strictSame(res[0], res[1], 'same for -v and --version')
56+
t.matchSnapshot(res[0], '--version output')
57+
}))
58+
59+
t.test('making dirs', t => t.resolveMatchSnapshot(run('a', 'b/c/d', 'e')))
60+
t.test('noisily', t => t.resolveMatchSnapshot(run('a', 'b/c/d', '--print')))
61+
t.test('manual', t => t.resolveMatchSnapshot(run('a', 'b/c/d', '-p', '--manual')))
62+
t.test('print modes', t => t.resolveMatchSnapshot(run('a', '-m775', '-p')))
63+
t.test('invalid mode', t => t.resolveMatchSnapshot(run('--mode=XYZ')))
64+
t.test('make dir named --help', t => t.resolveMatchSnapshot(run('-p', '--', '--help')))
65+
t.test('failures', t => t.resolveMatchSnapshot(Promise.all([
66+
run('x/ERROR'),
67+
run('x/EFAIL'),
68+
])))
69+
}

‎test/find-made.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const t = require('tap')
2+
const requireInject = require('require-inject')
3+
4+
const {basename, posix} = require('path')
5+
const {promisify} = require('util')
6+
const fs = require('fs')
7+
8+
const statAsync = (path) =>
9+
basename(path) === 'error'
10+
? Promise.reject(new Error('not a real error'))
11+
: promisify(fs.stat)(path)
12+
13+
const statSync = path => {
14+
if (basename(path) === 'error')
15+
throw new Error('not a real error')
16+
else
17+
return fs.statSync(path)
18+
}
19+
20+
const {findMade, findMadeSync} = requireInject('../lib/find-made.js', {
21+
path: posix,
22+
})
23+
24+
t.test('find what dir will be made', t => {
25+
const dir = t.testdir({
26+
file: 'txt',
27+
subdir: {},
28+
})
29+
30+
const o = {statAsync, statSync}
31+
32+
t.equal(findMadeSync(o, `${dir}/subdir/x/y/z`), `${dir}/subdir/x`)
33+
t.equal(findMadeSync(o, `${dir}/subdir`), undefined)
34+
t.equal(findMadeSync(o, `${dir}/file/x/y/z`), undefined)
35+
t.equal(findMadeSync(o, `${dir}/file`, `${dir}/file/x`), undefined)
36+
t.equal(findMadeSync(o, `${dir}/subdir/error`), undefined)
37+
t.equal(findMadeSync(o, '/', '/'), undefined)
38+
return Promise.all([
39+
findMade(o, `${dir}/subdir/x/y/z`),
40+
findMade(o, `${dir}/subdir`),
41+
findMade(o, `${dir}/file/x/y/z`),
42+
findMade(o, `${dir}/file`, `${dir}/file/x`),
43+
findMade(o, `${dir}/subdir/error`),
44+
findMade(o, '/', '/'),
45+
]).then(made => t.strictSame(made, [
46+
`${dir}/subdir/x`,
47+
undefined,
48+
undefined,
49+
undefined,
50+
undefined,
51+
undefined,
52+
]))
53+
})

‎test/index.js

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const t = require('tap')
2+
const mkdirp = require('../')
3+
4+
t.test('module shape', t => {
5+
t.isa(mkdirp, Function)
6+
t.isa(mkdirp.sync, Function)
7+
t.isa(mkdirp.manual, Function)
8+
t.isa(mkdirp.manualSync, Function)
9+
t.isa(mkdirp.native, Function)
10+
t.isa(mkdirp.nativeSync, Function)
11+
t.end()
12+
})
13+
14+
t.test('basic making of dirs should work', t => {
15+
const dir = t.testdir({ a: {} })
16+
const {statSync, mkdir, mkdirSync} = require('fs')
17+
const check = d => t.ok(statSync(d).isDirectory())
18+
t.equal(mkdirp.sync(`${dir}/a/sync`), `${dir}/a/sync`)
19+
check(`${dir}/a/sync`)
20+
t.equal(mkdirp.sync(`${dir}/a/sync`), undefined)
21+
22+
t.equal(mkdirp.manualSync(`${dir}/a/manual-sync`), `${dir}/a/manual-sync`)
23+
check(`${dir}/a/manual-sync`)
24+
t.equal(mkdirp.manualSync(`${dir}/a/manual-sync`), undefined)
25+
26+
t.equal(mkdirp.nativeSync(`${dir}/a/native-sync`), `${dir}/a/native-sync`)
27+
check(`${dir}/a/native-sync`)
28+
t.equal(mkdirp.nativeSync(`${dir}/a/native-sync`), undefined)
29+
30+
// override to force the manual option
31+
const myMkdir = (path, opts, cb) => mkdir(path, opts, cb)
32+
const myMkdirSync = (path, opts) => mkdirSync(path, opts)
33+
const opts = { mkdir: myMkdir, mkdirSync: myMkdirSync }
34+
t.equal(mkdirp.sync(`${dir}/a/custom-sync`, opts), `${dir}/a/custom-sync`)
35+
check(`${dir}/a/custom-sync`)
36+
t.equal(mkdirp.sync(`${dir}/a/custom-sync`, opts), undefined)
37+
38+
return Promise.all([
39+
mkdirp(`${dir}/a/async`),
40+
mkdirp.manual(`${dir}/a/manual-async`),
41+
mkdirp.native(`${dir}/a/native-async`),
42+
mkdirp(`${dir}/a/custom-async`, opts),
43+
]).then(made => {
44+
t.strictSame(made, [
45+
`${dir}/a/async`,
46+
`${dir}/a/manual-async`,
47+
`${dir}/a/native-async`,
48+
`${dir}/a/custom-async`,
49+
])
50+
check(`${dir}/a/async`)
51+
check(`${dir}/a/manual-async`)
52+
check(`${dir}/a/native-async`)
53+
check(`${dir}/a/custom-async`)
54+
return Promise.all([
55+
mkdirp(`${dir}/a/async`),
56+
mkdirp.manual(`${dir}/a/manual-async`),
57+
mkdirp.native(`${dir}/a/native-async`),
58+
mkdirp(`${dir}/a/custom-async`, opts),
59+
])
60+
}).then(made => t.strictSame(made, [undefined, undefined, undefined, undefined]))
61+
})

‎test/mkdirp-manual.js

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
const t = require('tap')
2+
const requireInject = require('require-inject')
3+
const {promisify} = require('util')
4+
5+
const {stat, statSync, mkdir, mkdirSync} = require('fs')
6+
const statAsync = promisify(stat)
7+
const mkdirAsync = promisify(mkdir)
8+
9+
const path = require('path').posix
10+
const {resolve} = path
11+
12+
const {mkdirpManual, mkdirpManualSync} =
13+
requireInject('../lib/mkdirp-manual.js', { path })
14+
15+
t.test('mkdirpManual / just calls implementation', t => {
16+
t.test('success is fine, of course', t => {
17+
const opt = {
18+
mkdirAsync: () => Promise.resolve('mkdirAsync impl'),
19+
mkdirSync: () => 'mkdirSync impl',
20+
recursive: true,
21+
}
22+
t.equal(mkdirpManualSync('/', opt), 'mkdirSync impl')
23+
t.equal(opt.recursive, false)
24+
opt.recursive = true
25+
return mkdirpManual('/', opt).then(res => {
26+
t.equal(res, 'mkdirAsync impl')
27+
t.equal(opt.recursive, false)
28+
})
29+
})
30+
31+
t.test('EISDIR is expected and ignored', t => {
32+
const opt = {
33+
mkdirAsync: () => Promise.reject(Object.assign(new Error('is dir'), { code: 'EISDIR' })),
34+
mkdirSync: () => {
35+
throw Object.assign(new Error('is dir'), { code: 'EISDIR' })
36+
},
37+
// ensure it gets reset
38+
recursive: true,
39+
}
40+
t.equal(mkdirpManualSync('/', opt), undefined)
41+
t.equal(opt.recursive, false)
42+
opt.recursive = true
43+
return mkdirpManual('/', opt).then(made => {
44+
t.equal(made, undefined)
45+
t.equal(opt.recursive, false)
46+
})
47+
})
48+
49+
t.test('other failures are failures', t => {
50+
const opt = {
51+
mkdirAsync: () => Promise.reject(Object.assign(new Error('grolb'), { code: 'blorg' })),
52+
mkdirSync: () => {
53+
throw Object.assign(new Error('grolb'), { code: 'blorg' })
54+
},
55+
// ensure it gets reset
56+
recursive: true,
57+
}
58+
t.throws(() => mkdirpManualSync('/', opt), { code: 'blorg' })
59+
return t.rejects(mkdirpManual('/', opt), { code: 'blorg' })
60+
})
61+
62+
t.end()
63+
})
64+
65+
t.test('recurse and return first dir made', t => {
66+
const dir = t.testdir()
67+
const opt = {
68+
stat,
69+
statAsync,
70+
statSync,
71+
mkdir,
72+
mkdirAsync,
73+
mkdirSync,
74+
}
75+
76+
t.equal(mkdirpManualSync(`${dir}/sync/a/b`, opt), `${dir}/sync`)
77+
t.equal(statSync(`${dir}/sync/a/b`).isDirectory(), true, 'made dir')
78+
t.equal(mkdirpManualSync(`${dir}/sync/a/b`, opt), undefined)
79+
80+
return mkdirpManual(`${dir}/async/a/b`, opt).then(made => {
81+
t.equal(made, `${dir}/async`)
82+
return mkdirpManual(`${dir}/async/a/b`, opt)
83+
}).then(made => t.equal(made, undefined))
84+
})
85+
86+
t.test('unknown failure types are failures', t => {
87+
const opt = {
88+
mkdirAsync: () => Promise.reject(Object.assign(new Error('grolb'), { code: 'blorg' })),
89+
mkdirSync: () => {
90+
throw Object.assign(new Error('grolb'), { code: 'blorg' })
91+
},
92+
// ensure it gets reset
93+
recursive: true,
94+
}
95+
t.throws(() => mkdirpManualSync('/x/y/z', opt), { code: 'blorg' })
96+
return t.rejects(mkdirpManual('/x/y/z', opt), { code: 'blorg' })
97+
})
98+
99+
t.test('cannot make dir over a file', t => {
100+
const dir = t.testdir({ file: 'txt' })
101+
const opt = {
102+
stat,
103+
statAsync,
104+
statSync,
105+
mkdir,
106+
mkdirAsync,
107+
mkdirSync,
108+
}
109+
110+
t.throws(() => mkdirpManualSync(`${dir}/file`, opt), { code: 'EEXIST' })
111+
return t.rejects(mkdirpManual(`${dir}/file`, opt), { code: 'EEXIST' })
112+
})
113+
114+
t.test('try to overwrite a file, then fail to stat it', t => {
115+
const dir = t.testdir({ file: 'txt' })
116+
const file = `${dir}/file`
117+
const er = Object.assign(new Error('nope'), { code: 'grob' })
118+
const opt = {
119+
statAsync: path => path === file
120+
? Promise.reject(er)
121+
: statAsync(path),
122+
statSync: path => {
123+
if (path === file)
124+
throw er
125+
else
126+
return statSync(path)
127+
},
128+
mkdirAsync,
129+
mkdirSync,
130+
}
131+
132+
t.throws(() => mkdirpManualSync(`${dir}/file`, opt), { code: 'EEXIST' })
133+
return t.rejects(mkdirpManual(`${dir}/file`, opt), { code: 'EEXIST' })
134+
})

‎test/mkdirp-native.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const t = require('tap')
2+
const requireInject = require('require-inject')
3+
const {promisify} = require('util')
4+
const {stat, statSync} = require('fs')
5+
const statAsync = promisify(stat)
6+
7+
const {mkdirpNative, mkdirpNativeSync} = requireInject('../lib/mkdirp-native', {
8+
// just return an indicator that it was called
9+
'../lib/mkdirp-manual.js': {
10+
mkdirpManual: () => 'mkdirpManual',
11+
mkdirpManualSync: () => 'mkdirpManualSync',
12+
},
13+
path: require('path').posix
14+
})
15+
16+
const {resolve} = require('path').posix
17+
18+
t.test('mkdirpNative / just calls implementation', t => {
19+
const opt = {
20+
mkdirAsync: () => 'mkdirAsync impl',
21+
mkdirSync: () => 'mkdirSync impl',
22+
}
23+
t.equal(mkdirpNative('/', opt), 'mkdirAsync impl')
24+
t.equal(opt.recursive, true)
25+
delete opt.recursive
26+
t.equal(mkdirpNativeSync('/', opt), 'mkdirSync impl')
27+
t.equal(opt.recursive, true)
28+
t.end()
29+
})
30+
31+
t.test('mkdirpNative calls impl and returns findMade', t => {
32+
const opt = {
33+
mkdirAsync: () => Promise.resolve(),
34+
mkdirSync: () => undefined,
35+
statAsync,
36+
statSync,
37+
}
38+
39+
const dir = t.testdir()
40+
t.equal(mkdirpNativeSync(`${dir}/sync/a/b/c`, opt), `${dir}/sync`)
41+
return mkdirpNative(`${dir}/async/a/b/c`, opt).then(made =>
42+
t.equal(made, `${dir}/async`))
43+
})
44+
45+
t.test('ENOENT error falls back to manual', t => {
46+
const opt = {
47+
mkdirAsync: () => Promise.reject(Object.assign(new Error('poo'), { code: 'ENOENT' })),
48+
mkdirSync: () => {
49+
throw Object.assign(new Error('poo'), { code: 'ENOENT' })
50+
},
51+
statAsync,
52+
statSync,
53+
}
54+
55+
const dir = t.testdir()
56+
t.equal(mkdirpNativeSync(`${dir}/sync/a/b/c`, opt), 'mkdirpManualSync')
57+
return mkdirpNative(`${dir}/async/a/b/c`, opt).then(made =>
58+
t.equal(made, 'mkdirpManual'))
59+
})
60+
61+
t.test('other errors are raised to caller', t => {
62+
const opt = {
63+
mkdirAsync: () => Promise.reject(Object.assign(new Error('poo'), { code: 'blorg' })),
64+
mkdirSync: () => {
65+
throw Object.assign(new Error('poo'), { code: 'blorg' })
66+
},
67+
statAsync,
68+
statSync,
69+
}
70+
71+
t.throws(() => mkdirpNativeSync('anything', opt), {code: 'blorg'})
72+
return t.rejects(mkdirpNative('at/all', opt), {code: 'blorg'})
73+
})

‎test/mkdirp.js

-28
This file was deleted.

‎test/opts-arg.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const t = require('tap')
2+
const optsArg = require('../lib/opts-arg.js')
3+
const umask = process.umask()
4+
const mode = 0o777 & (~umask)
5+
const fs = require('fs')
6+
7+
const defFs = {
8+
fs,
9+
mkdir: fs.mkdir,
10+
mkdirSync: fs.mkdirSync,
11+
stat: fs.stat,
12+
statSync: fs.statSync,
13+
}
14+
15+
const stat = () => {}
16+
stat.fake = true
17+
const statSync = () => {}
18+
statSync.fake = true
19+
20+
// arg, expect
21+
const cases = {
22+
null: [null, { mode, ...defFs }],
23+
false: [false, { mode, ...defFs }],
24+
undefined: [undefined, { mode, ...defFs }],
25+
'empty object': [{}, { mode, ...defFs }],
26+
'numeric mode': [0o775, {mode: 0o775, ...defFs}],
27+
'string mode': ['775', {mode: 0o775, ...defFs}],
28+
'empty custom fs': [{fs: {}}, {mode, ...defFs, fs: {}}],
29+
'custom stat/statSync': [{stat, statSync}, {mode, ...defFs, stat, statSync}],
30+
'custom fs with stat/statSync': [{fs: {stat, statSync}}, {mode, ...defFs, fs: {stat, statSync}, stat, statSync}],
31+
}
32+
33+
for (const [name, c] of Object.entries(cases)) {
34+
const [arg, expect] = c
35+
t.match(optsArg(arg), expect, name)
36+
}
37+
38+
t.throws(() => optsArg(() => {}), TypeError('invalid options argument'))

‎test/opts_fs.js

-29
This file was deleted.

‎test/opts_fs_sync.js

-27
This file was deleted.

‎test/path-arg.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const t = require('tap')
2+
3+
if (!process.env.__TESTING_MKDIRP_PLATFORM__) {
4+
const fake = process.platform === 'win32' ? 'posix' : 'win32'
5+
t.spawn(process.execPath, [__filename], {
6+
env: {
7+
...process.env,
8+
__TESTING_MKDIRP_PLATFORM__: fake,
9+
},
10+
})
11+
}
12+
13+
const platform = process.env.__TESTING_MKDIRP_PLATFORM__ || process.platform
14+
const path = require('path').platform || require('path')
15+
const requireInject = require('require-inject')
16+
const pathArg = requireInject('../lib/path-arg.js', {
17+
path,
18+
})
19+
const {resolve} = path
20+
21+
t.equal(pathArg('a/b/c'), resolve('a/b/c'))
22+
t.throws(() => pathArg('a\0b'), Error('path must be a string without null bytes'))
23+
if (platform === 'win32') {
24+
const badPaths = [
25+
'c:\\a\\b:c',
26+
'c:\\a\\b*c',
27+
'c:\\a\\b?c',
28+
'c:\\a\\b<c',
29+
'c:\\a\\b>c',
30+
'c:\\a\\b|c',
31+
'c:\\a\\b"c',
32+
]
33+
for (const path of badPaths) {
34+
const er = Object.assign(new Error('Illegal characters in path'), {
35+
path,
36+
code: 'EINVAL',
37+
})
38+
t.throws(() => pathArg(path), er)
39+
}
40+
}

‎test/perm.js

-31
This file was deleted.

‎test/perm_sync.js

-36
This file was deleted.

‎test/race.js

-37
This file was deleted.

‎test/rel.js

-32
This file was deleted.

‎test/return.js

-25
This file was deleted.

‎test/return_sync.js

-24
This file was deleted.

‎test/root.js

-19
This file was deleted.

‎test/sync.js

-32
This file was deleted.

‎test/umask.js

-28
This file was deleted.

‎test/umask_sync.js

-32
This file was deleted.

‎test/use-native.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const t = require('tap')
2+
const {mkdir, mkdirSync} = require('fs')
3+
const {useNative, useNativeSync} = require('../lib/use-native.js')
4+
5+
if (!process.env.__TESTING_MKDIRP_NODE_VERSION__) {
6+
t.spawn(process.execPath, [__filename], {
7+
env: {
8+
...process.env,
9+
__TESTING_MKDIRP_NODE_VERSION__: 'v10.11.12',
10+
},
11+
})
12+
13+
t.spawn(process.execPath, [__filename], {
14+
env: {
15+
...process.env,
16+
__TESTING_MKDIRP_NODE_VERSION__: 'v8.9.10',
17+
},
18+
})
19+
20+
// this one has the native impl
21+
t.equal(useNative({mkdir}), true)
22+
t.equal(useNative({mkdir: 1243}), false)
23+
t.equal(useNativeSync({mkdirSync}), true)
24+
t.equal(useNativeSync({mkdirSync: 1243}), false)
25+
} else {
26+
t.equal(useNative({mkdir}), false)
27+
t.equal(useNative({mkdir: 1243}), false)
28+
t.equal(useNativeSync({mkdirSync}), false)
29+
t.equal(useNativeSync({mkdirSync: 1243}), false)
30+
}

0 commit comments

Comments
 (0)
Please sign in to comment.