-
-
Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathtest-unpack.js
75 lines (62 loc) · 1.6 KB
/
test-unpack.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { join } from 'path';
import { promises as fs } from 'fs';
import tap from 'tap';
import * as tempDirectory from '../lib/temp-directory.js';
import { unpack } from '../lib/unpack.js';
const { test } = tap;
test('unpack: context.unpack = null', async (t) => {
t.plan(1);
const context = {
unpack: null,
emit: function () {}
};
try {
await unpack(context);
} catch (err) {
t.same(
err,
new Error('Nothing to unpack... Ending'),
'it should error out'
);
}
});
test('unpack: context.unpack is invalid path', async (t) => {
t.plan(1);
const context = {
unpack: new URL('../fixtures/do-not-exist.tar.gz', import.meta.url),
emit: function () {}
};
try {
await unpack(context);
} catch (err) {
t.same(
err,
new Error('Nothing to unpack... Ending'),
'it should error out'
);
}
});
test('unpack: valid unpack', async (t) => {
t.plan(1);
const context = {
module: {
name: 'omg-i-pass'
},
unpack: './test/fixtures/omg-i-pass.tgz',
emit: function () {}
};
// FIXME I am not super convinced that the correct tar ball is being deflated
// FIXME There is a possibility that the npm cache is trumping this
await tempDirectory.create(context);
await unpack(context);
const stats = await fs.stat(join(context.path, 'omg-i-pass'));
t.ok(stats.isDirectory(), 'the untarred result should be a directory');
await tempDirectory.remove(context);
});
test('unpack: context.unpack = false', async () => {
const context = {
unpack: false,
emit: function () {}
};
await unpack(context);
});