|
2 | 2 | const test = require('brittle') |
3 | 3 | const tmp = require('test-tmp') |
4 | 4 | const Localdrive = require('localdrive') |
| 5 | +const fs = require('bare-fs') |
| 6 | +const path = require('bare-path') |
| 7 | +const { isWindows } = require('which-runtime') |
5 | 8 |
|
6 | 9 | const Helper = require('./helper') |
7 | 10 |
|
@@ -43,20 +46,13 @@ test('pear dump', async function ({ ok, plan, teardown }) { |
43 | 46 | ok(await dumped.exists('/package.json'), 'package.json should exist') |
44 | 47 | }) |
45 | 48 |
|
46 | | -test('pear dump dumping subdirectory', async function ({ |
| 49 | +test('pear dump dumping subdirectory from pear drive', async function ({ |
47 | 50 | ok, |
48 | 51 | absent, |
49 | 52 | plan, |
50 | 53 | teardown |
51 | 54 | }) { |
52 | 55 | plan(4) |
53 | | - const path = require('bare-path') |
54 | | - const fs = require('bare-fs') |
55 | | - const exists = (path) => |
56 | | - fs.promises.stat(path).then( |
57 | | - () => true, |
58 | | - () => false |
59 | | - ) |
60 | 56 | const helper = new Helper() |
61 | 57 | teardown(() => helper.close(), { order: Infinity }) |
62 | 58 | await helper.ready() |
@@ -93,6 +89,35 @@ test('pear dump dumping subdirectory', async function ({ |
93 | 89 | ok(await dumped.exists('/lib/pear.js'), 'lib/pear.js should exist') |
94 | 90 | }) |
95 | 91 |
|
| 92 | +test('pear dump dumping subdirectory from local drive', async function ({ |
| 93 | + ok, |
| 94 | + absent, |
| 95 | + plan, |
| 96 | + teardown |
| 97 | +}) { |
| 98 | + plan(4) |
| 99 | + const helper = new Helper() |
| 100 | + teardown(() => helper.close(), { order: Infinity }) |
| 101 | + await helper.ready() |
| 102 | + |
| 103 | + const src = Helper.fixture('dump') |
| 104 | + const link = isWindows |
| 105 | + ? `file://${src.split(path.win32.sep).join(path.posix.sep)}/lib` |
| 106 | + : `file://${src}/lib` |
| 107 | + const out = await tmp() |
| 108 | + |
| 109 | + teardown(() => Helper.gc(out)) |
| 110 | + const dump = await helper.dump({ link, dir: out }) |
| 111 | + teardown(() => Helper.teardownStream(dump)) |
| 112 | + const untilDump = await Helper.pick(dump, [{ tag: 'complete' }]) |
| 113 | + await untilDump.complete |
| 114 | + const dumped = new Localdrive(out) |
| 115 | + absent(await dumped.exists('/index.js'), 'index.js should not exist') |
| 116 | + absent(await dumped.exists('/package.json'), 'package.json should not exist') |
| 117 | + ok(await dumped.exists('/lib/dump.js'), 'lib/dump.js should exist') |
| 118 | + ok(await dumped.exists('/lib/pear.js'), 'lib/pear.js should exist') |
| 119 | +}) |
| 120 | + |
96 | 121 | test('pear dump dumping to existing dir', async function ({ |
97 | 122 | absent, |
98 | 123 | is, |
@@ -230,7 +255,7 @@ test('pear dump dumping a single file', async function ({ |
230 | 255 | absent(await dumped.exists('/package.json'), 'package.json should not exist') |
231 | 256 | }) |
232 | 257 |
|
233 | | -test('pear dump dumping a single file in a subdirectory', async function ({ |
| 258 | +test('pear dump dumping a single file in a subdirectory from pear drive', async function ({ |
234 | 259 | ok, |
235 | 260 | is, |
236 | 261 | plan, |
@@ -275,6 +300,73 @@ test('pear dump dumping a single file in a subdirectory', async function ({ |
275 | 300 | is(dirCount, 1, 'should have only one file in the lib directory') |
276 | 301 | }) |
277 | 302 |
|
| 303 | +test('pear dump should throw when dumping file outside a pear project', async function ({ |
| 304 | + plan, |
| 305 | + teardown, |
| 306 | + exception |
| 307 | +}) { |
| 308 | + plan(1) |
| 309 | + |
| 310 | + const helper = new Helper() |
| 311 | + teardown(() => helper.close(), { order: Infinity }) |
| 312 | + await helper.ready() |
| 313 | + |
| 314 | + const src = await tmp() |
| 315 | + const out = await tmp() |
| 316 | + teardown(async () => { |
| 317 | + await Helper.gc(out) |
| 318 | + await Helper.gc(src) |
| 319 | + }) |
| 320 | + await fs.promises.writeFile( |
| 321 | + path.join(src, 'test.js'), |
| 322 | + 'console.log("test")', |
| 323 | + { |
| 324 | + encoding: 'utf-8' |
| 325 | + } |
| 326 | + ) |
| 327 | + const link = isWindows |
| 328 | + ? `file://${src.split(path.win32.sep).join(path.posix.sep)}/test.js` |
| 329 | + : `file://${src}/test.js` |
| 330 | + |
| 331 | + await exception(async () => { |
| 332 | + const dump = helper.dump({ link, dir: out }) |
| 333 | + teardown(() => Helper.teardownStream(dump)) |
| 334 | + const untilDump = await Helper.pick(dump, [{ tag: 'complete' }]) |
| 335 | + await untilDump.complete |
| 336 | + }) |
| 337 | +}) |
| 338 | + |
| 339 | +test('pear dump dumping a single file in a subdirectory from local drive', async function ({ |
| 340 | + ok, |
| 341 | + is, |
| 342 | + plan, |
| 343 | + teardown |
| 344 | +}) { |
| 345 | + plan(2) |
| 346 | + |
| 347 | + const helper = new Helper() |
| 348 | + teardown(() => helper.close(), { order: Infinity }) |
| 349 | + await helper.ready() |
| 350 | + |
| 351 | + const src = Helper.fixture('dump') |
| 352 | + const link = isWindows |
| 353 | + ? `file://${src.split(path.win32.sep).join(path.posix.sep)}/lib/dump.js` |
| 354 | + : `file://${src}/lib/dump.js` |
| 355 | + |
| 356 | + const out = await tmp() |
| 357 | + |
| 358 | + teardown(() => Helper.gc(out)) |
| 359 | + const dump = await helper.dump({ link, dir: out }) |
| 360 | + teardown(() => Helper.teardownStream(dump)) |
| 361 | + const untilDump = await Helper.pick(dump, [{ tag: 'complete' }]) |
| 362 | + await untilDump.complete |
| 363 | + const dumped = new Localdrive(out) |
| 364 | + let dirCount = 0 |
| 365 | + for await (const _ of dumped.readdir()) dirCount++ |
| 366 | + ok(await dumped.exists('/lib/dump.js'), 'lib/dump.js should exist') |
| 367 | + is(dirCount, 1, 'should have only one file in the lib directory') |
| 368 | +}) |
| 369 | + |
278 | 370 | test('pear dump dumping to stdout', async function ({ ok, plan, teardown }) { |
279 | 371 | plan(4) |
280 | 372 |
|
|
0 commit comments