From 49a29589e1701cedfdb7d2ace80d08d0054eb3e4 Mon Sep 17 00:00:00 2001 From: isaacs Date: Wed, 1 Mar 2023 12:12:50 -0800 Subject: [PATCH] formatting tests --- .gitignore | 2 + CHANGELOG.md | 2 +- test/default-tmp.js | 36 +++++---- test/delete-many-files.js | 6 +- test/ignore-enoent.js | 5 +- test/rimraf-manual.js | 15 +++- test/rimraf-move-remove.js | 9 ++- test/rimraf-native.js | 9 ++- test/rimraf-posix.js | 150 +++++++++++++++++++++---------------- test/rimraf-windows.js | 9 ++- 10 files changed, 143 insertions(+), 100 deletions(-) diff --git a/.gitignore b/.gitignore index 45b36f3..3c8bd51 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ /coverage /dist !/typedoc.json +!/tsconfig-*.json +!/.prettierignore diff --git a/CHANGELOG.md b/CHANGELOG.md index fa88994..bbd3c89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # v4.1 - Improved hybrid module with no need to look at the `.default` - dangly bit. `.default` preserved as a reference to `rimraf` + dangly bit. `.default` preserved as a reference to `rimraf` for compatibility with anyone who came to rely on it in v4.0. - Accept and ignore `-rf` and `-fr` arguments to the bin. diff --git a/test/default-tmp.js b/test/default-tmp.js index 18946f1..806c05a 100644 --- a/test/default-tmp.js +++ b/test/default-tmp.js @@ -2,9 +2,12 @@ const t = require('tap') t.test('posix platform', async t => { const { tmpdir } = require('os') - const { defaultTmp, defaultTmpSync } = t.mock('../dist/cjs/src/default-tmp.js', { - '../dist/cjs/src/platform.js': 'posix', - }) + const { defaultTmp, defaultTmpSync } = t.mock( + '../dist/cjs/src/default-tmp.js', + { + '../dist/cjs/src/platform.js': 'posix', + } + ) t.equal(defaultTmpSync('anything'), tmpdir()) t.equal(await defaultTmp('anything').then(t => t), tmpdir()) }) @@ -20,19 +23,22 @@ t.test('windows', async t => { throw Object.assign(new Error('no ents here'), { code: 'ENOENT' }) } } - const { defaultTmp, defaultTmpSync } = t.mock('../dist/cjs/src/default-tmp.js', { - os: { - tmpdir: () => 'C:\\Windows\\Temp', - }, - path: require('path').win32, - '../dist/cjs/src/platform.js': 'win32', - '../dist/cjs/src/fs.js': { - statSync: tempDirCheck, - promises: { - stat: async path => tempDirCheck(path), + const { defaultTmp, defaultTmpSync } = t.mock( + '../dist/cjs/src/default-tmp.js', + { + os: { + tmpdir: () => 'C:\\Windows\\Temp', + }, + path: require('path').win32, + '../dist/cjs/src/platform.js': 'win32', + '../dist/cjs/src/fs.js': { + statSync: tempDirCheck, + promises: { + stat: async path => tempDirCheck(path), + }, }, - }, - }) + } + ) const expect = { 'c:\\some\\path': 'C:\\Windows\\Temp', diff --git a/test/delete-many-files.js b/test/delete-many-files.js index f1bb137..c5c5bbb 100644 --- a/test/delete-many-files.js +++ b/test/delete-many-files.js @@ -13,11 +13,7 @@ const START = (process.env.RIMRAF_TEST_START_CHAR || 'a').charCodeAt(0) const END = (process.env.RIMRAF_TEST_END_CHAR || 'f').charCodeAt(0) const DEPTH = +process.env.RIMRAF_TEST_DEPTH || 4 -const { - statSync, - mkdirSync, - readdirSync, -} = require('../dist/cjs/src/fs.js') +const { statSync, mkdirSync, readdirSync } = require('../dist/cjs/src/fs.js') const { writeFileSync } = require('fs') const { resolve, dirname } = require('path') diff --git a/test/ignore-enoent.js b/test/ignore-enoent.js index 8690819..7f8ad61 100644 --- a/test/ignore-enoent.js +++ b/test/ignore-enoent.js @@ -1,5 +1,8 @@ const t = require('tap') -const { ignoreENOENT, ignoreENOENTSync } = require('../dist/cjs/src/ignore-enoent.js') +const { + ignoreENOENT, + ignoreENOENTSync, +} = require('../dist/cjs/src/ignore-enoent.js') const enoent = Object.assign(new Error('no ent'), { code: 'ENOENT' }) const eperm = Object.assign(new Error('eperm'), { code: 'EPERM' }) diff --git a/test/rimraf-manual.js b/test/rimraf-manual.js index d6c42d9..f7fcfb7 100644 --- a/test/rimraf-manual.js +++ b/test/rimraf-manual.js @@ -1,10 +1,19 @@ const t = require('tap') -const { rimrafWindows, rimrafWindowsSync } = require('../dist/cjs/src/rimraf-windows.js') +const { + rimrafWindows, + rimrafWindowsSync, +} = require('../dist/cjs/src/rimraf-windows.js') -const { rimrafPosix, rimrafPosixSync } = require('../dist/cjs/src/rimraf-posix.js') +const { + rimrafPosix, + rimrafPosixSync, +} = require('../dist/cjs/src/rimraf-posix.js') -const { rimrafManual, rimrafManualSync } = require('../dist/cjs/src/rimraf-manual.js') +const { + rimrafManual, + rimrafManualSync, +} = require('../dist/cjs/src/rimraf-manual.js') if (!process.env.__TESTING_RIMRAF_PLATFORM__) { const otherPlatform = process.platform !== 'win32' ? 'win32' : 'posix' diff --git a/test/rimraf-move-remove.js b/test/rimraf-move-remove.js index 91de76e..d6d9c54 100644 --- a/test/rimraf-move-remove.js +++ b/test/rimraf-move-remove.js @@ -57,9 +57,12 @@ t.only('actually delete some stuff', async t => { // but actually do wait to clean them up, though t.teardown(() => Promise.all(danglers)) - const { rimrafPosix, rimrafPosixSync } = t.mock('../dist/cjs/src/rimraf-posix.js', { - '../dist/cjs/src/fs.js': fsMock, - }) + const { rimrafPosix, rimrafPosixSync } = t.mock( + '../dist/cjs/src/rimraf-posix.js', + { + '../dist/cjs/src/fs.js': fsMock, + } + ) const { rimrafMoveRemove, rimrafMoveRemoveSync } = t.mock( '../dist/cjs/src/rimraf-move-remove.js', diff --git a/test/rimraf-native.js b/test/rimraf-native.js index 900cb3d..2e505eb 100644 --- a/test/rimraf-native.js +++ b/test/rimraf-native.js @@ -12,9 +12,12 @@ const fs = { }, } -const { rimrafNative, rimrafNativeSync } = t.mock('../dist/cjs/src/rimraf-native.js', { - '../dist/cjs/src/fs.js': fs, -}) +const { rimrafNative, rimrafNativeSync } = t.mock( + '../dist/cjs/src/rimraf-native.js', + { + '../dist/cjs/src/fs.js': fs, + } +) t.test('calls the right node function', async t => { await rimrafNative('path', { x: 'y' }) diff --git a/test/rimraf-posix.js b/test/rimraf-posix.js index 4ce1701..6172a4c 100644 --- a/test/rimraf-posix.js +++ b/test/rimraf-posix.js @@ -8,7 +8,10 @@ // } const t = require('tap') -const { rimrafPosix, rimrafPosixSync } = require('../dist/cjs/src/rimraf-posix.js') +const { + rimrafPosix, + rimrafPosixSync, +} = require('../dist/cjs/src/rimraf-posix.js') const fs = require('../dist/cjs/src/fs.js') @@ -56,92 +59,104 @@ t.test('actually delete some stuff', t => { }) t.test('throw unlink errors', async t => { - const { rimrafPosix, rimrafPosixSync } = t.mock('../dist/cjs/src/rimraf-posix.js', { - '../dist/cjs/src/fs.js': { - ...fs, - unlinkSync: path => { - throw Object.assign(new Error('cannot unlink'), { code: 'FOO' }) - }, - promises: { - ...fs.promises, - unlink: async path => { + const { rimrafPosix, rimrafPosixSync } = t.mock( + '../dist/cjs/src/rimraf-posix.js', + { + '../dist/cjs/src/fs.js': { + ...fs, + unlinkSync: path => { throw Object.assign(new Error('cannot unlink'), { code: 'FOO' }) }, + promises: { + ...fs.promises, + unlink: async path => { + throw Object.assign(new Error('cannot unlink'), { code: 'FOO' }) + }, + }, }, - }, - }) + } + ) const path = t.testdir(fixture) t.throws(() => rimrafPosixSync(path, {}), { code: 'FOO' }) t.rejects(rimrafPosix(path, {}), { code: 'FOO' }) }) t.test('throw rmdir errors', async t => { - const { rimrafPosix, rimrafPosixSync } = t.mock('../dist/cjs/src/rimraf-posix.js', { - '../dist/cjs/src/fs.js': { - ...fs, - rmdirSync: path => { - throw Object.assign(new Error('cannot rmdir'), { code: 'FOO' }) - }, - promises: { - ...fs.promises, - rmdir: async path => { + const { rimrafPosix, rimrafPosixSync } = t.mock( + '../dist/cjs/src/rimraf-posix.js', + { + '../dist/cjs/src/fs.js': { + ...fs, + rmdirSync: path => { throw Object.assign(new Error('cannot rmdir'), { code: 'FOO' }) }, + promises: { + ...fs.promises, + rmdir: async path => { + throw Object.assign(new Error('cannot rmdir'), { code: 'FOO' }) + }, + }, }, - }, - }) + } + ) const path = t.testdir(fixture) t.throws(() => rimrafPosixSync(path, {}), { code: 'FOO' }) t.rejects(rimrafPosix(path, {}), { code: 'FOO' }) }) t.test('throw unexpected readdir errors', async t => { - const { rimrafPosix, rimrafPosixSync } = t.mock('../dist/cjs/src/rimraf-posix.js', { - '../dist/cjs/src/fs.js': { - ...fs, - readdirSync: path => { - throw Object.assign(new Error('cannot readdir'), { code: 'FOO' }) - }, - promises: { - ...fs.promises, - readdir: async path => { + const { rimrafPosix, rimrafPosixSync } = t.mock( + '../dist/cjs/src/rimraf-posix.js', + { + '../dist/cjs/src/fs.js': { + ...fs, + readdirSync: path => { throw Object.assign(new Error('cannot readdir'), { code: 'FOO' }) }, + promises: { + ...fs.promises, + readdir: async path => { + throw Object.assign(new Error('cannot readdir'), { code: 'FOO' }) + }, + }, }, - }, - }) + } + ) const path = t.testdir(fixture) t.throws(() => rimrafPosixSync(path, {}), { code: 'FOO' }) t.rejects(rimrafPosix(path, {}), { code: 'FOO' }) }) t.test('ignore ENOENTs from unlink/rmdir', async t => { - const { rimrafPosix, rimrafPosixSync } = t.mock('../dist/cjs/src/rimraf-posix.js', { - '../dist/cjs/src/fs.js': { - ...fs, - // simulate a case where two rimrafs are happening in parallel, - // so the deletion happens AFTER the readdir, but before ours. - rmdirSync: path => { - fs.rmdirSync(path) - fs.rmdirSync(path) - }, - unlinkSync: path => { - fs.unlinkSync(path) - fs.unlinkSync(path) - }, - promises: { - ...fs.promises, - rmdir: async path => { + const { rimrafPosix, rimrafPosixSync } = t.mock( + '../dist/cjs/src/rimraf-posix.js', + { + '../dist/cjs/src/fs.js': { + ...fs, + // simulate a case where two rimrafs are happening in parallel, + // so the deletion happens AFTER the readdir, but before ours. + rmdirSync: path => { + fs.rmdirSync(path) fs.rmdirSync(path) - return fs.promises.rmdir(path) }, - unlink: async path => { + unlinkSync: path => { + fs.unlinkSync(path) fs.unlinkSync(path) - return fs.promises.unlink(path) + }, + promises: { + ...fs.promises, + rmdir: async path => { + fs.rmdirSync(path) + return fs.promises.rmdir(path) + }, + unlink: async path => { + fs.unlinkSync(path) + return fs.promises.unlink(path) + }, }, }, - }, - }) + } + ) const { statSync } = fs t.test('sync', t => { const path = t.testdir(fixture) @@ -161,18 +176,21 @@ t.test('ignore ENOENTs from unlink/rmdir', async t => { t.test('rimraffing root, do not actually rmdir root', async t => { let ROOT = null const { parse } = require('path') - const { rimrafPosix, rimrafPosixSync } = t.mock('../dist/cjs/src/rimraf-posix.js', { - path: { - ...require('path'), - parse: path => { - const p = parse(path) - if (path === ROOT) { - p.root = path - } - return p + const { rimrafPosix, rimrafPosixSync } = t.mock( + '../dist/cjs/src/rimraf-posix.js', + { + path: { + ...require('path'), + parse: path => { + const p = parse(path) + if (path === ROOT) { + p.root = path + } + return p + }, }, - }, - }) + } + ) t.test('async', async t => { ROOT = t.testdir(fixture) await rimrafPosix(ROOT, { preserveRoot: false }) diff --git a/test/rimraf-windows.js b/test/rimraf-windows.js index 7c15132..719bff6 100644 --- a/test/rimraf-windows.js +++ b/test/rimraf-windows.js @@ -57,9 +57,12 @@ t.only('actually delete some stuff', async t => { // but actually do wait to clean them up, though t.teardown(() => Promise.all(danglers)) - const { rimrafPosix, rimrafPosixSync } = t.mock('../dist/cjs/src/rimraf-posix.js', { - '../dist/cjs/src/fs.js': fsMock, - }) + const { rimrafPosix, rimrafPosixSync } = t.mock( + '../dist/cjs/src/rimraf-posix.js', + { + '../dist/cjs/src/fs.js': fsMock, + } + ) const { rimrafWindows, rimrafWindowsSync } = t.mock( '../dist/cjs/src/rimraf-windows.js',