-
Notifications
You must be signed in to change notification settings - Fork 880
/
package-utils_test.ts
97 lines (77 loc) · 2.12 KB
/
package-utils_test.ts
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
// eslint-disable-next-line import/extensions
import * as assert from 'uvu/assert';
import {suite} from 'uvu';
import {
installPackage,
buildPackage,
packPackage,
} from '../lib/package-utils.js';
import {FilesystemTestRig} from '@lit-internal/tests/utils/filesystem-test-rig.js';
const test = suite<{tempFs: FilesystemTestRig}>('test');
test.before(async (ctx) => {
ctx.tempFs = new FilesystemTestRig();
await ctx.tempFs.setup();
});
test.after(async ({tempFs}) => {
await tempFs.cleanup();
});
test('install package', async ({tempFs}) => {
await tempFs.write('package.json', {
name: 'test-package',
dependencies: {
lit: '^2.0.0',
},
});
await installPackage(tempFs.rootDir);
assert.ok((await tempFs.read('node_modules', 'lit', 'index.js')).length > 0);
});
test('install package with monorepo link', async ({tempFs}) => {
await tempFs.write('package.json', {
dependencies: {
lit: '^2.0.0',
},
});
await installPackage(tempFs.rootDir, {
lit: '../../lit',
});
assert.ok((await tempFs.read('node_modules', 'lit', 'index.js')).length > 0);
});
test('build package', async ({tempFs}) => {
await tempFs.write('package.json', {
scripts: {
build: 'echo hello>hello.txt',
},
});
await buildPackage(tempFs.rootDir);
assert.equal((await tempFs.read('hello.txt')).trim(), 'hello');
});
test('pack package', async ({tempFs}) => {
await tempFs.write('package.json', {
name: 'pack-test',
version: '1.2.3',
files: ['a', 'b/c'],
});
await tempFs.write('a', 'a');
await tempFs.write(['b', 'c'], 'c');
const tarballFile = await packPackage(tempFs.rootDir);
await tempFs.write(['test-output', 'package.json'], {
dependencies: {
'pack-test': `file:${tarballFile}`,
},
});
await installPackage(tempFs.resolve('test-output'));
assert.equal(
await tempFs.read('test-output', 'node_modules', 'pack-test', 'a'),
'a'
);
assert.equal(
await tempFs.read('test-output', 'node_modules', 'pack-test', 'b', 'c'),
'c'
);
});
test.run();