Skip to content

Commit

Permalink
test: fix normalize-unicode coverage on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Apr 10, 2024
1 parent dfb6b6c commit ae9ce7e
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 68 deletions.
30 changes: 30 additions & 0 deletions tap-snapshots/test/normalize-unicode.js-win32.test.cjs
@@ -0,0 +1,30 @@
/* IMPORTANT
* This snapshot file is auto-generated, but designed for humans.
* It should be checked into source control and tracked carefully.
* Re-generate by setting TAP_SNAPSHOT=1 and running tests.
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`test/normalize-unicode.js win32 > TAP > normalize with strip slashes > "\\\\\eee\\\\\\" > normalized 1`] = `
\\\\\eee\\\\\\
`

exports[`test/normalize-unicode.js win32 > TAP > normalize with strip slashes > "\\\\a\\\\b\\\\c\\\\d\\\\" > normalized 1`] = `
/a/b/c/d
`

exports[`test/normalize-unicode.js win32 > TAP > normalize with strip slashes > "﹨aaaa﹨dddd﹨" > normalized 1`] = `
﹨aaaa﹨dddd﹨
`

exports[`test/normalize-unicode.js win32 > TAP > normalize with strip slashes > "\bbb\eee\" > normalized 1`] = `
\bbb\eee\
`

exports[`test/normalize-unicode.js win32 > TAP > normalize with strip slashes > "1/4foo.txt" > normalized 1`] = `
1/4foo.txt
`

exports[`test/normalize-unicode.js win32 > TAP > normalize with strip slashes > "¼foo.txt" > normalized 1`] = `
¼foo.txt
`
30 changes: 0 additions & 30 deletions tap-snapshots/test/normalize-unicode.js.test.cjs

This file was deleted.

82 changes: 44 additions & 38 deletions test/normalize-unicode.js
@@ -1,16 +1,11 @@
import t from 'tap'
import { fileURLToPath } from 'url'
import { normalizeUnicode } from '../dist/esm/normalize-unicode.js'
import { stripTrailingSlashes } from '../dist/esm/strip-trailing-slashes.js'
import { normalizeWindowsPath } from '../dist/esm/normalize-windows-path.js'

process.env.TESTING_TAR_FAKE_PLATFORM = 'win32'

const [
{ normalizeUnicode },
{ stripTrailingSlashes },
{ normalizeWindowsPath },
] = await Promise.all([
import('../dist/esm/normalize-unicode.js'),
import('../dist/esm/strip-trailing-slashes.js'),
import('../dist/esm/normalize-windows-path.js'),
])
const __filename = fileURLToPath(import.meta.url)
const fakePlatform = process.env.TESTING_TAR_FAKE_PLATFORM

// café
const cafe1 = Buffer.from([0x63, 0x61, 0x66, 0xc3, 0xa9]).toString()
Expand All @@ -28,30 +23,41 @@ t.equal(
t.equal(normalizeUnicode(cafe1), normalizeUnicode(cafe2), 'cached')
t.equal(normalizeUnicode('foo'), 'foo', 'non-unicode string')

t.test('normalize with strip slashes', t => {
const paths = [
'\\a\\b\\c\\d\\',
'﹨aaaa﹨dddd﹨',
'\bbb\eee\',
'\\\\\eee\\\\\\',
'¼foo.txt',
'1/4foo.txt',
]

t.plan(paths.length)

for (const path of paths) {
t.test(JSON.stringify(path), t => {
const a = normalizeUnicode(
stripTrailingSlashes(normalizeWindowsPath(path)),
)
const b = stripTrailingSlashes(
normalizeWindowsPath(normalizeUnicode(path)),
)
t.matchSnapshot(a, 'normalized')
t.equal(a, b, 'order should not matter')
t.end()
})
}
t.end()
})
if (fakePlatform === 'win32') {
t.test('normalize with strip slashes', t => {
const paths = [
'\\a\\b\\c\\d\\',
'﹨aaaa﹨dddd﹨',
'\bbb\eee\',
'\\\\\eee\\\\\\',
'¼foo.txt',
'1/4foo.txt',
]

t.plan(paths.length)

for (const path of paths) {
t.test(JSON.stringify(path), t => {
const a = normalizeUnicode(
stripTrailingSlashes(normalizeWindowsPath(path)),
)
const b = stripTrailingSlashes(
normalizeWindowsPath(normalizeUnicode(path)),
)
t.matchSnapshot(a, 'normalized')
t.equal(a, b, 'order should not matter')
t.end()
})
}
t.end()
})
}

if (fakePlatform !== 'win32') {
t.spawn(process.execPath, [__filename, 'win32'], {
env: {
...process.env,
TESTING_TAR_FAKE_PLATFORM: 'win32',
}
})
}

0 comments on commit ae9ce7e

Please sign in to comment.