|
1 | 1 | import path from 'path' |
2 | | -import { resolveConfig, resolveConfigFile } from './config' |
| 2 | +import { resolveConfig, resolveConfigFile, loadConfig } from './config' |
3 | 3 |
|
4 | 4 | describe('config', () => { |
5 | 5 | describe('#resolveConfig', () => { |
@@ -33,4 +33,130 @@ describe('config', () => { |
33 | 33 | expect(config).toMatch(/__fixtures__(\/|\\)svgr(\/|\\)\.svgrrc$/) |
34 | 34 | }) |
35 | 35 | }) |
| 36 | + |
| 37 | + describe('#loadConfig', () => { |
| 38 | + it('should use default config without state.filePath', async () => { |
| 39 | + const config = await loadConfig({ dimensions: false }) |
| 40 | + expect(config).toMatchInlineSnapshot(` |
| 41 | +Object { |
| 42 | + "dimensions": false, |
| 43 | + "expandProps": true, |
| 44 | + "h2xConfig": null, |
| 45 | + "icon": false, |
| 46 | + "native": false, |
| 47 | + "prettier": true, |
| 48 | + "prettierConfig": null, |
| 49 | + "ref": false, |
| 50 | + "replaceAttrValues": null, |
| 51 | + "runtimeConfig": true, |
| 52 | + "svgAttributes": null, |
| 53 | + "svgProps": null, |
| 54 | + "svgo": true, |
| 55 | + "svgoConfig": null, |
| 56 | + "template": null, |
| 57 | + "titleProp": false, |
| 58 | +} |
| 59 | +`) |
| 60 | + }) |
| 61 | + |
| 62 | + it('should load config using filePath', async () => { |
| 63 | + const config = await loadConfig( |
| 64 | + {}, |
| 65 | + { filePath: path.join(__dirname, '__fixtures__/svgr/icon.svg') }, |
| 66 | + ) |
| 67 | + expect(config).toMatchInlineSnapshot(` |
| 68 | +Object { |
| 69 | + "dimensions": true, |
| 70 | + "expandProps": true, |
| 71 | + "h2xConfig": null, |
| 72 | + "icon": true, |
| 73 | + "native": false, |
| 74 | + "noSemi": true, |
| 75 | + "prettier": true, |
| 76 | + "prettierConfig": null, |
| 77 | + "ref": false, |
| 78 | + "replaceAttrValues": Array [ |
| 79 | + Array [ |
| 80 | + "#063855", |
| 81 | + "currentColor", |
| 82 | + ], |
| 83 | + ], |
| 84 | + "runtimeConfig": true, |
| 85 | + "svgAttributes": null, |
| 86 | + "svgProps": null, |
| 87 | + "svgo": true, |
| 88 | + "svgoConfig": null, |
| 89 | + "template": null, |
| 90 | + "titleProp": false, |
| 91 | +} |
| 92 | +`) |
| 93 | + }) |
| 94 | + |
| 95 | + it('should not load config with "runtimeConfig: false', async () => { |
| 96 | + const config = await loadConfig( |
| 97 | + { useRuntimeConfig: false }, |
| 98 | + { filePath: path.join(__dirname, '__fixtures__/svgr/icon.svg') }, |
| 99 | + ) |
| 100 | + expect(config).toMatchInlineSnapshot(` |
| 101 | +Object { |
| 102 | + "dimensions": true, |
| 103 | + "expandProps": true, |
| 104 | + "h2xConfig": null, |
| 105 | + "icon": true, |
| 106 | + "native": false, |
| 107 | + "noSemi": true, |
| 108 | + "prettier": true, |
| 109 | + "prettierConfig": null, |
| 110 | + "ref": false, |
| 111 | + "replaceAttrValues": Array [ |
| 112 | + Array [ |
| 113 | + "#063855", |
| 114 | + "currentColor", |
| 115 | + ], |
| 116 | + ], |
| 117 | + "runtimeConfig": true, |
| 118 | + "svgAttributes": null, |
| 119 | + "svgProps": null, |
| 120 | + "svgo": true, |
| 121 | + "svgoConfig": null, |
| 122 | + "template": null, |
| 123 | + "titleProp": false, |
| 124 | + "useRuntimeConfig": false, |
| 125 | +} |
| 126 | +`) |
| 127 | + }) |
| 128 | + |
| 129 | + it('should work with custom config path', async () => { |
| 130 | + const config = await loadConfig( |
| 131 | + { configFile: path.join(__dirname, '__fixtures__/svgr/.svgrrc') }, |
| 132 | + { filePath: __dirname }, |
| 133 | + ) |
| 134 | + expect(config).toMatchInlineSnapshot(` |
| 135 | +Object { |
| 136 | + "dimensions": true, |
| 137 | + "expandProps": true, |
| 138 | + "h2xConfig": null, |
| 139 | + "icon": true, |
| 140 | + "native": false, |
| 141 | + "noSemi": true, |
| 142 | + "prettier": true, |
| 143 | + "prettierConfig": null, |
| 144 | + "ref": false, |
| 145 | + "replaceAttrValues": Array [ |
| 146 | + Array [ |
| 147 | + "#063855", |
| 148 | + "currentColor", |
| 149 | + ], |
| 150 | + ], |
| 151 | + "runtimeConfig": true, |
| 152 | + "svgAttributes": null, |
| 153 | + "svgProps": null, |
| 154 | + "svgo": true, |
| 155 | + "svgoConfig": null, |
| 156 | + "template": null, |
| 157 | + "titleProp": false, |
| 158 | +} |
| 159 | +`) |
| 160 | + }) |
| 161 | + }) |
36 | 162 | }) |
0 commit comments