|
1 | 1 | import { describe, expect, test } from '@jest/globals'; |
2 | 2 | import path from 'path'; |
3 | | -import getConfig from '../../transforms/helpers/config'; |
| 3 | +import getConfig, { mergeConfig } from '../../transforms/helpers/config'; |
4 | 4 | import { DEFAULT_OPTIONS } from '../../transforms/helpers/options'; |
5 | 5 |
|
6 | 6 | describe('config', () => { |
7 | | - test('it has default options', () => { |
8 | | - const config = getConfig(); |
9 | | - expect(config).toStrictEqual(DEFAULT_OPTIONS); |
| 7 | + describe('getConfig', () => { |
| 8 | + test('it has default options', () => { |
| 9 | + const config = getConfig(); |
| 10 | + expect(config).toStrictEqual(DEFAULT_OPTIONS); |
| 11 | + }); |
| 12 | + |
| 13 | + test.each(['json', 'js', 'cjs', 'yml', 'yaml', 'package'])( |
| 14 | + 'should read %s config', |
| 15 | + (fixture) => { |
| 16 | + const config = getConfig(pathFor(fixture)); |
| 17 | + expect(config).toStrictEqual( |
| 18 | + mergeConfig(DEFAULT_OPTIONS, { |
| 19 | + classFields: false, |
| 20 | + quote: 'double', |
| 21 | + decorators: { |
| 22 | + inObjectLiterals: [`${fixture}DecOne`, `${fixture}DecTwo`], |
| 23 | + }, |
| 24 | + }) |
| 25 | + ); |
| 26 | + } |
| 27 | + ); |
10 | 28 | }); |
11 | 29 |
|
12 | | - test.each(['json', 'js', 'cjs', 'yml', 'yaml', 'package'])( |
13 | | - 'should read %s config', |
14 | | - (fixture) => { |
15 | | - const config = getConfig(pathFor(fixture)); |
16 | | - expect(config).toStrictEqual({ |
| 30 | + describe('mergeConfig', () => { |
| 31 | + test('it allows overwriting the ignoreLeakingState config', () => { |
| 32 | + expect( |
| 33 | + mergeConfig(DEFAULT_OPTIONS, { |
| 34 | + ignoreLeakingState: ['queryParams', 'ignoreMyLeakyState'], |
| 35 | + }) |
| 36 | + ).toStrictEqual({ |
17 | 37 | ...DEFAULT_OPTIONS, |
18 | | - classFields: false, |
19 | | - quote: 'double', |
20 | | - objectLiteralDecorators: [`${fixture}DecOne`, `${fixture}DecTwo`], |
| 38 | + ignoreLeakingState: ['queryParams', 'ignoreMyLeakyState'], |
21 | 39 | }); |
22 | | - } |
23 | | - ); |
| 40 | + }); |
| 41 | + |
| 42 | + test('it deep merges the decorators config', () => { |
| 43 | + expect( |
| 44 | + mergeConfig(DEFAULT_OPTIONS, { |
| 45 | + decorators: { |
| 46 | + inObjectLiterals: ['computer'], |
| 47 | + }, |
| 48 | + }) |
| 49 | + ).toStrictEqual({ |
| 50 | + ...DEFAULT_OPTIONS, |
| 51 | + decorators: { |
| 52 | + inObjectLiterals: ['computer'], |
| 53 | + }, |
| 54 | + }); |
| 55 | + }); |
| 56 | + }); |
24 | 57 | }); |
25 | 58 |
|
26 | 59 | function pathFor(extension: string): string { |
|
0 commit comments