Skip to content

Commit

Permalink
test: more windows path string fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jan 31, 2023
1 parent ebd167d commit 204e1a0
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
MkdirpOptionsResolved,
} from '../dist/cjs/src/opts-arg.js'

const s = (s: any) => typeof s !== 'string' ? s : s.replace(/\\/g, '/')
const s = (s: any) => (typeof s !== 'string' ? s : s.replace(/\\/g, '/'))

// node before 10.13 didn't native recursive mkdir
const doNative = !/^v([0-8]\.|10.([0-9]\.|10\.|11\.([0-9]|1[01])$))/.test(
Expand All @@ -28,16 +28,22 @@ t.test('module shape', t => {
t.test('basic making of dirs should work', async t => {
const dir = t.testdir({ a: {} })
const check = (d: string) => t.ok(statSync(d).isDirectory())
t.equal(s(mkdirp.sync(`${dir}/a/sync`)), `${dir}/a/sync`)
t.equal(s(mkdirp.sync(`${dir}/a/sync`)), s(`${dir}/a/sync`))
check(`${dir}/a/sync`)
t.equal(mkdirp.sync(`${dir}/a/sync`), undefined)

t.equal(s(mkdirp.manualSync(`${dir}/a/manual-sync`)), `${dir}/a/manual-sync`)
t.equal(
s(mkdirp.manualSync(`${dir}/a/manual-sync`)),
s(`${dir}/a/manual-sync`)
)
check(`${dir}/a/manual-sync`)
t.equal(s(mkdirp.manualSync(`${dir}/a/manual-sync`)), undefined)

if (doNative) {
t.equal(s(mkdirp.nativeSync(`${dir}/a/native-sync`)), `${dir}/a/native-sync`)
t.equal(
s(mkdirp.nativeSync(`${dir}/a/native-sync`)),
s(`${dir}/a/native-sync`)
)
check(`${dir}/a/native-sync`)
t.equal(mkdirp.nativeSync(`${dir}/a/native-sync`), undefined)
}
Expand Down Expand Up @@ -66,12 +72,15 @@ t.test('basic making of dirs should work', async t => {
mkdirp(`${dir}/a/custom-async`, opts),
])
.then(made => {
t.strictSame(made.map(m => s(m)), [
`${dir}/a/async`,
`${dir}/a/manual-async`,
doNative && `${dir}/a/native-async`,
`${dir}/a/custom-async`,
])
t.strictSame(
made.map(m => s(m)),
[
`${dir}/a/async`,
`${dir}/a/manual-async`,
doNative && `${dir}/a/native-async`,
`${dir}/a/custom-async`,
].map(m => s(m))
)
check(`${dir}/a/async`)
check(`${dir}/a/manual-async`)
doNative && check(`${dir}/a/native-async`)
Expand Down

0 comments on commit 204e1a0

Please sign in to comment.