-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinit.install.test.ts
More file actions
124 lines (99 loc) · 3.01 KB
/
init.install.test.ts
File metadata and controls
124 lines (99 loc) · 3.01 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
jest.setTimeout(60000);
process.env.PGPM_SKIP_UPDATE_CHECK = 'true';
import { PgpmPackage } from '@pgpmjs/core';
import * as fs from 'fs';
import * as glob from 'glob';
import * as path from 'path';
import { TestFixture } from '../test-utils';
describe('cmds:install - with initialized workspace and module', () => {
let fixture: TestFixture;
let workspaceDir: string;
let moduleDir: string;
beforeEach(async () => {
fixture = new TestFixture();
const workspaceName = 'my-workspace';
const moduleName = 'my-module';
workspaceDir = path.join(fixture.tempDir, workspaceName);
moduleDir = path.join(workspaceDir, 'packages', moduleName);
// Step 1: Create workspace
await fixture.runCmd({
_: ['init', 'workspace'],
cwd: fixture.tempDir,
name: workspaceName,
workspace: true,
});
// Step 2: Add module
await fixture.runCmd({
_: ['init'],
cwd: workspaceDir,
name: moduleName,
moduleName: moduleName,
extensions: ['uuid-ossp', 'plpgsql'],
});
});
afterEach(() => {
fixture.cleanup();
});
it('installs a module package', async () => {
const pkg = '@pgpm-testing/base32';
const version = '1.0.0';
await fixture.runCmd({
_: ['install', `${pkg}@${version}`],
cwd: moduleDir,
});
const pkgJson = JSON.parse(
fs.readFileSync(path.join(moduleDir, 'package.json'), 'utf-8')
);
expect(pkgJson).toMatchSnapshot();
const installedFiles = glob.sync('**/*', {
cwd: path.join(workspaceDir, 'extensions'),
dot: true,
nodir: true,
absolute: true,
});
const relativeFiles = installedFiles
.map((f: string) => path.relative(moduleDir, f))
.sort();
expect(relativeFiles).toMatchSnapshot();
// Snapshot control file
const mod = new PgpmPackage(moduleDir);
const controlFile = mod.getModuleControlFile();
expect(controlFile).toMatchSnapshot();
});
it('installs two modules', async () => {
const base32 = {
name: '@pgpm-testing/base32',
version: '1.0.0',
};
const utils = {
name: '@pgpm-testing/utils',
version: '1.0.0',
};
const pkgs = [base32, utils];
for (const { name, version } of pkgs) {
await fixture.runCmd({
_: ['install', `${name}@${version}`],
cwd: moduleDir,
});
}
const pkgJson = JSON.parse(
fs.readFileSync(path.join(moduleDir, 'package.json'), 'utf-8')
);
expect(pkgJson).toMatchSnapshot();
const extPath = path.join(workspaceDir, 'extensions');
const installedFiles = glob.sync('**/*', {
cwd: extPath,
dot: true,
nodir: true,
absolute: true,
});
const relativeFiles = installedFiles
.map((f: string) => path.relative(moduleDir, f))
.sort();
expect(relativeFiles).toMatchSnapshot();
// Snapshot control file after both installs
const mod = new PgpmPackage(moduleDir);
const controlFile = mod.getModuleControlFile();
expect(controlFile).toMatchSnapshot();
});
});