From ae9ce7ec2adb6300155cb6a46f8c9ea601330d81 Mon Sep 17 00:00:00 2001 From: isaacs Date: Wed, 10 Apr 2024 09:34:54 -0700 Subject: [PATCH] test: fix normalize-unicode coverage on linux --- .../test/normalize-unicode.js-win32.test.cjs | 30 +++++++ .../test/normalize-unicode.js.test.cjs | 30 ------- test/normalize-unicode.js | 82 ++++++++++--------- 3 files changed, 74 insertions(+), 68 deletions(-) create mode 100644 tap-snapshots/test/normalize-unicode.js-win32.test.cjs delete mode 100644 tap-snapshots/test/normalize-unicode.js.test.cjs diff --git a/tap-snapshots/test/normalize-unicode.js-win32.test.cjs b/tap-snapshots/test/normalize-unicode.js-win32.test.cjs new file mode 100644 index 00000000..85e353d8 --- /dev/null +++ b/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 +` diff --git a/tap-snapshots/test/normalize-unicode.js.test.cjs b/tap-snapshots/test/normalize-unicode.js.test.cjs deleted file mode 100644 index 6c7be82a..00000000 --- a/tap-snapshots/test/normalize-unicode.js.test.cjs +++ /dev/null @@ -1,30 +0,0 @@ -/* 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 > TAP > normalize with strip slashes > "\\\\\eee\\\\\\" > normalized 1`] = ` -\\\\\eee\\\\\\ -` - -exports[`test/normalize-unicode.js > TAP > normalize with strip slashes > "\\\\a\\\\b\\\\c\\\\d\\\\" > normalized 1`] = ` -/a/b/c/d -` - -exports[`test/normalize-unicode.js > TAP > normalize with strip slashes > "﹨aaaa﹨dddd﹨" > normalized 1`] = ` -﹨aaaa﹨dddd﹨ -` - -exports[`test/normalize-unicode.js > TAP > normalize with strip slashes > "\bbb\eee\" > normalized 1`] = ` -\bbb\eee\ -` - -exports[`test/normalize-unicode.js > TAP > normalize with strip slashes > "1/4foo.txt" > normalized 1`] = ` -1/4foo.txt -` - -exports[`test/normalize-unicode.js > TAP > normalize with strip slashes > "¼foo.txt" > normalized 1`] = ` -¼foo.txt -` diff --git a/test/normalize-unicode.js b/test/normalize-unicode.js index 969ee6ca..ae3efd4d 100644 --- a/test/normalize-unicode.js +++ b/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() @@ -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', + } + }) +}