|
1 | 1 | import webpack, { Configuration } from "webpack"; |
2 | 2 | import { createFsFromVolume, IFs, Volume } from "memfs"; |
3 | 3 | import ReactDocgenTypeScriptPlugin from ".."; |
| 4 | +import { LoaderOptions } from "../types"; |
4 | 5 |
|
5 | 6 | // eslint-disable-next-line |
6 | 7 | const joinPath = require("memory-fs/lib/join"); |
@@ -84,3 +85,34 @@ test("default options", async () => { |
84 | 85 |
|
85 | 86 | expect(result).toContain("STORYBOOK_REACT_CLASSES"); |
86 | 87 | }); |
| 88 | + |
| 89 | +describe("custom options", () => { |
| 90 | + describe("loader options", () => { |
| 91 | + const options: Record< |
| 92 | + keyof LoaderOptions, |
| 93 | + Array<LoaderOptions[keyof LoaderOptions]> |
| 94 | + > = { |
| 95 | + setDisplayName: [true, false, undefined], |
| 96 | + typePropName: ["customValue", undefined], |
| 97 | + docgenCollectionName: ["customValue", null, undefined], |
| 98 | + }; |
| 99 | + const { defaultOptions } = ReactDocgenTypeScriptPlugin; |
| 100 | + |
| 101 | + (Object.keys(options) as Array<keyof LoaderOptions>).forEach( |
| 102 | + (optionName) => { |
| 103 | + const values = options[optionName]; |
| 104 | + |
| 105 | + test.each(values)(`${optionName}: %p`, (value) => { |
| 106 | + const plugin = new ReactDocgenTypeScriptPlugin({ |
| 107 | + [optionName]: value, |
| 108 | + }); |
| 109 | + const { generateOptions: resultOptions } = plugin.getOptions(); |
| 110 | + |
| 111 | + expect(resultOptions[optionName]).toBe( |
| 112 | + value === undefined ? defaultOptions[optionName] : value |
| 113 | + ); |
| 114 | + }); |
| 115 | + } |
| 116 | + ); |
| 117 | + }); |
| 118 | +}); |
0 commit comments