-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathextensions.test.ts
More file actions
106 lines (85 loc) · 3.11 KB
/
extensions.test.ts
File metadata and controls
106 lines (85 loc) · 3.11 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
jest.setTimeout(60000);
process.env.PGPM_SKIP_UPDATE_CHECK = 'true';
import { PgpmPackage } from '@pgpmjs/core';
import { sync as glob } from 'glob';
import { Inquirerer } from 'inquirerer';
import { ParsedArgs } from 'minimist';
import * as path from 'path';
import { commands } from '../src/commands';
import {
setupTests,
TestEnvironment,
TestFixture,
withInitDefaults
} from '../test-utils';
const beforeEachSetup = setupTests();
describe('cmds:extension', () => {
let environment: TestEnvironment;
let fixture: TestFixture;
beforeEach(() => {
environment = beforeEachSetup();
fixture = new TestFixture(); // empty fixture
});
afterEach(() => {
fixture.cleanup();
});
const runCommand = async (argv: ParsedArgs) => {
const prompter = new Inquirerer({
input: environment.mockInput,
output: environment.mockOutput,
noTty: true
});
const isInit = Array.isArray(argv._) && argv._.includes('init');
if (isInit) {
argv = withInitDefaults(argv);
}
// @ts-ignore
return commands(argv, prompter, {});
};
it('runs `extension` command after workspace and module setup', async () => {
const workspacePath = fixture.fixturePath('my-workspace');
const modulePath = path.join(workspacePath, 'packages', 'my-module');
// Step 1: Initialize workspace
await runCommand({
_: ['init', 'workspace'],
cwd: fixture.tempDir,
name: 'my-workspace',
workspace: true
});
// Step 2: Initialize module inside workspace
await runCommand({
_: ['init'],
cwd: workspacePath,
name: 'my-module',
moduleName: 'my-module',
extensions: ['mod-1', 'mod2']
});
// Step 2b: Snapshot initial control file and module dependencies
const initialProject = new PgpmPackage(modulePath);
expect(initialProject.getModuleControlFile()).toMatchSnapshot('initial - control file');
expect(initialProject.getModuleDependencies('my-module')).toMatchSnapshot('initial - module dependencies');
expect(initialProject.getRequiredModules()).toMatchSnapshot('initial - required modules');
// Step 3: Run `extension` command to update module
const extensionResult = await runCommand({
_: ['extension'],
cwd: modulePath,
extensions: ['plpgsql', 'module-c']
});
// Clean `cwd` for stable snapshot
extensionResult.cwd = '<CWD>';
const allFiles = glob('**/*', {
cwd: modulePath,
dot: true,
nodir: true,
absolute: true
});
const relativeFiles = allFiles.map(file => path.relative(modulePath, file));
expect(extensionResult).toMatchSnapshot('extension-update - result');
expect(relativeFiles).toMatchSnapshot('extension-update - files');
// Step 4: Re-init package and validate changes
const updatedProject = new PgpmPackage(modulePath);
expect(updatedProject.getModuleControlFile()).toMatchSnapshot('updated - control file');
expect(updatedProject.getModuleDependencies('my-module')).toMatchSnapshot('updated - module dependencies');
expect(updatedProject.getRequiredModules()).toMatchSnapshot('updated - required modules');
});
});