|
1 | 1 | import assert from 'node:assert'; |
| 2 | +import { mkdtempSync, writeFileSync } from 'node:fs'; |
| 3 | +import { tmpdir } from 'node:os'; |
| 4 | +import { join } from 'node:path'; |
2 | 5 | import { describe, it, mock, beforeEach } from 'node:test'; |
3 | 6 |
|
4 | 7 | // Mock dependencies |
@@ -96,6 +99,47 @@ describe('config.mjs', () => { |
96 | 99 | ); |
97 | 100 | assert.strictEqual(mockConfigSearch.mock.calls.length, 0); |
98 | 101 | }); |
| 102 | + |
| 103 | + it('should merge extends presets underneath the config file', async () => { |
| 104 | + const dir = mkdtempSync(join(tmpdir(), 'doc-kit-config-')); |
| 105 | + |
| 106 | + writeFileSync( |
| 107 | + join(dir, 'base.mjs'), |
| 108 | + 'export default { global: { project: "Base", ref: "base" }, html: { a: 1 } };' |
| 109 | + ); |
| 110 | + writeFileSync( |
| 111 | + join(dir, 'other.mjs'), |
| 112 | + 'export default { global: { project: "Other" }, html: { b: 2 } };' |
| 113 | + ); |
| 114 | + |
| 115 | + mockConfigLoad.mock.mockImplementationOnce(async () => ({ |
| 116 | + config: { |
| 117 | + extends: ['./base.mjs', './other.mjs'], |
| 118 | + global: { ref: 'own' }, |
| 119 | + }, |
| 120 | + filepath: join(dir, 'doc-kit.config.mjs'), |
| 121 | + })); |
| 122 | + |
| 123 | + const result = await loadConfigFile('any'); |
| 124 | + |
| 125 | + // Later presets win over earlier ones; the file itself wins over all |
| 126 | + assert.deepStrictEqual(result, { |
| 127 | + global: { project: 'Other', ref: 'own' }, |
| 128 | + html: { a: 1, b: 2 }, |
| 129 | + }); |
| 130 | + }); |
| 131 | + |
| 132 | + it('should resolve extends package specifiers from the config file', async () => { |
| 133 | + mockConfigLoad.mock.mockImplementationOnce(async () => ({ |
| 134 | + config: { extends: '@node-core/doc-kit/config' }, |
| 135 | + filepath: join(process.cwd(), 'doc-kit.config.mjs'), |
| 136 | + })); |
| 137 | + |
| 138 | + const result = await loadConfigFile('any'); |
| 139 | + |
| 140 | + assert.strictEqual(result.global.project, 'Node.js'); |
| 141 | + assert.strictEqual(result.global.repository, 'nodejs/node'); |
| 142 | + }); |
99 | 143 | }); |
100 | 144 |
|
101 | 145 | describe('createConfigFromCLIOptions', () => { |
@@ -250,6 +294,17 @@ describe('config.mjs', () => { |
250 | 294 | assert.strictEqual(mockConfigSearch.mock.calls.length, 1); |
251 | 295 | }); |
252 | 296 |
|
| 297 | + it('should default to project-neutral values', async () => { |
| 298 | + const config = await createRunConfiguration({}); |
| 299 | + |
| 300 | + // No repository, site, or release history is assumed; presets such as |
| 301 | + // @node-core/doc-kit/config opt back into the Node.js values |
| 302 | + assert.strictEqual(config.global.repository, undefined); |
| 303 | + assert.strictEqual(config.global.baseURL, undefined); |
| 304 | + assert.deepStrictEqual(config.global.changelog, []); |
| 305 | + assert.strictEqual(typeof config.global.project, 'string'); |
| 306 | + }); |
| 307 | + |
253 | 308 | it('should handle generator-specific overrides', async () => { |
254 | 309 | mockConfigLoad.mock.mockImplementationOnce(async () => ({ |
255 | 310 | config: createMockConfig({ |
|
0 commit comments