-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove custom promisification in favor of fs/promises (#54)
BREAKING CHANGE: this package no longer exports the full set of core fs functions
- Loading branch information
Showing
11 changed files
with
32 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
'use strict' | ||
|
||
const cp = require('./cp/index.js') | ||
const withTempDir = require('./with-temp-dir.js') | ||
|
||
module.exports = { | ||
...require('./fs.js'), | ||
cp: require('./cp/index.js'), | ||
withTempDir: require('./with-temp-dir.js'), | ||
cp, | ||
withTempDir, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,59 @@ | ||
const { lstat } = require('fs/promises') | ||
const { normalize } = require('path') | ||
const t = require('tap') | ||
|
||
const fs = require('../') | ||
const withTempDir = require('../lib/with-temp-dir.js') | ||
|
||
t.test('creates a temp directory and passes it to provided function', async (t) => { | ||
// normalize is necessary until https://github.com/tapjs/libtap/pull/40 is shipped | ||
const root = normalize(t.testdir()) | ||
const rootStat = await fs.lstat(root) | ||
const rootStat = await lstat(root) | ||
let tempDir | ||
await fs.withTempDir(root, async (dir) => { | ||
await withTempDir(root, async (dir) => { | ||
tempDir = dir | ||
t.type(dir, 'string') | ||
t.ok(dir.startsWith(root), 'dir is contained within the root') | ||
const stat = await fs.lstat(dir) | ||
const stat = await lstat(dir) | ||
t.ok(stat.isDirectory(), 'dir is an actual directory') | ||
t.equal(stat.uid, rootStat.uid, 'temp directory has same owning user') | ||
t.equal(stat.gid, rootStat.gid, 'temp directory has same owning group') | ||
}) | ||
await t.rejects(fs.lstat(tempDir), { code: 'ENOENT' }, 'temp directory was removed') | ||
await t.rejects(lstat(tempDir), { code: 'ENOENT' }, 'temp directory was removed') | ||
}) | ||
|
||
t.test('result from provided function bubbles out', async (t) => { | ||
// normalize is necessary until https://github.com/tapjs/libtap/pull/40 is shipped | ||
const root = normalize(t.testdir()) | ||
const rootStat = await fs.lstat(root) | ||
const rootStat = await lstat(root) | ||
let tempDir | ||
const result = await fs.withTempDir(root, async (dir) => { | ||
const result = await withTempDir(root, async (dir) => { | ||
tempDir = dir | ||
t.type(dir, 'string') | ||
t.ok(dir.startsWith(root), 'dir is contained within the root') | ||
const stat = await fs.lstat(dir) | ||
const stat = await lstat(dir) | ||
t.ok(stat.isDirectory(), 'dir is an actual directory') | ||
t.equal(stat.uid, rootStat.uid, 'temp directory has same owning user') | ||
t.equal(stat.gid, rootStat.gid, 'temp directory has same owning group') | ||
return 'finished' | ||
}) | ||
t.equal(result, 'finished', 'resolved value is returned') | ||
await t.rejects(fs.lstat(tempDir), { code: 'ENOENT' }, 'temp directory was removed') | ||
await t.rejects(lstat(tempDir), { code: 'ENOENT' }, 'temp directory was removed') | ||
}) | ||
|
||
t.test('cleans up when provided function rejects', async (t) => { | ||
// normalize is necessary until https://github.com/tapjs/libtap/pull/40 is shipped | ||
const root = normalize(t.testdir()) | ||
const rootStat = await fs.lstat(root) | ||
const rootStat = await lstat(root) | ||
let tempDir | ||
await t.rejects(fs.withTempDir(root, async (dir) => { | ||
await t.rejects(withTempDir(root, async (dir) => { | ||
tempDir = dir | ||
t.type(dir, 'string') | ||
t.ok(dir.startsWith(root), 'dir is contained within the root') | ||
const stat = await fs.lstat(dir) | ||
const stat = await lstat(dir) | ||
t.ok(stat.isDirectory(), 'dir is an actual directory') | ||
t.equal(stat.uid, rootStat.uid, 'temp directory has same owning user') | ||
t.equal(stat.gid, rootStat.gid, 'temp directory has same owning group') | ||
throw new Error('this is bad') | ||
}), { message: 'this is bad' }) | ||
await t.rejects(fs.lstat(tempDir), { code: 'ENOENT' }, 'temp directory was removed') | ||
await t.rejects(lstat(tempDir), { code: 'ENOENT' }, 'temp directory was removed') | ||
}) |