-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathconfig-loading.test.ts
More file actions
87 lines (68 loc) · 2.25 KB
/
config-loading.test.ts
File metadata and controls
87 lines (68 loc) · 2.25 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 fs from 'fs';
import os from 'os';
import path from 'path';
import { PgpmPackage } from '../src/core/class/pgpm';
describe('Config Loading', () => {
let tempDir: string;
beforeEach(() => {
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'launchql-config-test-'));
});
afterEach(() => {
fs.rmSync(tempDir, { recursive: true, force: true });
});
it('should load JSON config', () => {
const configContent = {
packages: ['packages/*', 'extensions/*']
};
fs.writeFileSync(
path.join(tempDir, 'pgpm.json'),
JSON.stringify(configContent, null, 2)
);
const project = new PgpmPackage(tempDir);
expect(project.config).toEqual(configContent);
expect(project.config?.packages).toEqual(['packages/*', 'extensions/*']);
});
it('should load JS config with JSDoc types', () => {
const configContent = `/** @type {import('@pgpmjs/types').LaunchQLWorkspaceConfig} */
module.exports = {
packages: ['packages/*', 'extensions/*'],
name: 'test-workspace',
settings: {
enableExperimentalFeatures: true
}
};`;
fs.writeFileSync(
path.join(tempDir, 'pgpm.config.js'),
configContent
);
const project = new PgpmPackage(tempDir);
expect(project.config?.packages).toEqual(['packages/*', 'extensions/*']);
expect(project.config?.name).toBe('test-workspace');
expect(project.config?.settings?.enableExperimentalFeatures).toBe(true);
});
it('should prefer JS config over JSON when both exist', () => {
const jsonConfig = {
packages: ['json-packages/*']
};
const jsConfig = `module.exports = {
packages: ['js-packages/*'],
name: 'js-workspace'
};`;
fs.writeFileSync(
path.join(tempDir, 'pgpm.json'),
JSON.stringify(jsonConfig, null, 2)
);
fs.writeFileSync(
path.join(tempDir, 'pgpm.config.js'),
jsConfig
);
const project = new PgpmPackage(tempDir);
expect(project.config?.packages).toEqual(['js-packages/*']);
expect(project.config?.name).toBe('js-workspace');
});
it('should have no config when no config file exists', () => {
const project = new PgpmPackage(tempDir);
expect(project.config).toBeUndefined();
expect(project.workspacePath).toBeUndefined();
});
});