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