-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpackage.test.ts
More file actions
87 lines (69 loc) · 2.64 KB
/
package.test.ts
File metadata and controls
87 lines (69 loc) · 2.64 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
import { PgpmPackage } from '@pgpmjs/core';
import * as fs from 'fs';
import { sync as glob } from 'glob';
import { Inquirerer } from 'inquirerer';
import { ParsedArgs } from 'minimist';
import * as os from 'os';
import * as path from 'path';
import { commands } from '../src/commands';
import { setupTests, TestEnvironment } from '../test-utils';
const fixture = (name: string) =>
path.resolve(__dirname, '../../..', '__fixtures__', 'sqitch', name);
const beforeEachSetup = setupTests();
describe('cmds:package', () => {
let environment: TestEnvironment;
let tempDir: string;
beforeAll(() => {
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'launchql-test-'));
});
afterAll(() => {
fs.rmSync(tempDir, { recursive: true, force: true });
});
beforeEach(() => {
environment = beforeEachSetup();
});
const runCommand = async (argv: ParsedArgs) => {
const prompter = new Inquirerer({
input: environment.mockInput,
output: environment.mockOutput,
noTty: true
});
// @ts-ignore
return commands(argv, prompter, {});
};
it('updates module with `extension` and `package` commands in copied fixture workspace', async () => {
const fixtureWorkspace = fixture('launchql');
const workspacePath = path.join(tempDir, 'launchql');
fs.cpSync(fixtureWorkspace, workspacePath, { recursive: true });
const modulePath = path.join(workspacePath, 'packages', 'secrets');
const initialProject = new PgpmPackage(modulePath);
// Snapshot initial state
expect(initialProject.getModuleControlFile()).toMatchSnapshot('initial - control file');
expect(initialProject.getModuleDependencies('secrets')).toMatchSnapshot('initial - module dependencies');
expect(initialProject.getRequiredModules()).toMatchSnapshot('initial - required modules');
// Run extension update
await runCommand({
_: ['extension'],
cwd: modulePath,
extensions: ['plpgsql', 'module-c']
});
// Remove stale SQL to trigger regeneration
const { sqlFile } = initialProject.getModuleInfo();
fs.rmSync(path.join(modulePath, sqlFile));
// Rebuild SQL package
await runCommand({
_: ['package'],
cwd: modulePath
});
// Snapshot generated SQL
const sql = fs.readFileSync(path.join(modulePath, sqlFile), 'utf-8');
expect(sql).toMatchSnapshot('extension-update - sql');
// Snapshot resulting file structure
const relativeFiles = glob('**/*', {
cwd: modulePath,
dot: true,
nodir: true
}).map(file => path.relative(modulePath, path.resolve(modulePath, file)));
expect(relativeFiles).toMatchSnapshot('extension-update - files');
});
});