-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
framework-preset-react-docs.test.ts
165 lines (150 loc) · 4.37 KB
/
framework-preset-react-docs.test.ts
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import ReactDocgenTypescriptPlugin from '@storybook/react-docgen-typescript-plugin';
import type { TypescriptConfig } from '@storybook/core-common';
import * as preset from './framework-preset-react-docs';
describe('framework-preset-react-docgen', () => {
const babelPluginReactDocgenPath = require.resolve('babel-plugin-react-docgen');
const presetsListWithDocs = [{ name: '@storybook/addon-docs', options: {}, preset: null }];
describe('react-docgen', () => {
it('should return the babel config with the extra plugin', async () => {
const babelConfig = {
babelrc: false,
presets: ['env', 'foo-preset'],
plugins: ['foo-plugin'],
};
const config = await preset.babel(babelConfig, {
presets: {
// @ts-ignore
apply: async () =>
({
check: false,
reactDocgen: 'react-docgen',
} as TypescriptConfig),
},
presetsList: presetsListWithDocs,
} as any);
expect(config).toEqual({
babelrc: false,
plugins: ['foo-plugin'],
presets: ['env', 'foo-preset'],
overrides: [
{
test: /\.(cjs|mjs|tsx?|jsx?)$/,
plugins: [
[
babelPluginReactDocgenPath,
{
DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES',
},
],
],
},
],
});
});
});
describe('react-docgen-typescript', () => {
it('should return the webpack config with the extra plugin', async () => {
const webpackConfig = {
plugins: [],
};
const config = await preset.webpackFinal(webpackConfig, {
presets: {
// @ts-ignore
apply: async () =>
({
check: false,
reactDocgen: 'react-docgen-typescript',
} as TypescriptConfig),
},
presetsList: presetsListWithDocs,
});
expect(config).toEqual({
plugins: [expect.any(ReactDocgenTypescriptPlugin)],
});
});
});
describe('no docgen', () => {
it('should not add any extra plugins', async () => {
const babelConfig = {
babelrc: false,
presets: ['env', 'foo-preset'],
plugins: ['foo-plugin'],
};
const webpackConfig = {
plugins: [],
};
const outputBabelconfig = await preset.babel(babelConfig, {
presets: {
// @ts-ignore
apply: async () =>
({
check: false,
reactDocgen: false,
} as TypescriptConfig),
},
presetsList: presetsListWithDocs,
});
const outputWebpackconfig = await preset.webpackFinal(webpackConfig, {
presets: {
// @ts-ignore
apply: async () =>
({
check: false,
reactDocgen: false,
} as TypescriptConfig),
},
presetsList: presetsListWithDocs,
});
expect(outputBabelconfig).toEqual({
babelrc: false,
presets: ['env', 'foo-preset'],
plugins: ['foo-plugin'],
});
expect(outputWebpackconfig).toEqual({
plugins: [],
});
});
});
describe('no docs or controls addon used', () => {
it('should not add any extra plugins', async () => {
const babelConfig = {
babelrc: false,
presets: ['env', 'foo-preset'],
plugins: ['foo-plugin'],
};
const webpackConfig = {
plugins: [],
};
const outputBabelconfig = await preset.babel(babelConfig, {
presets: {
// @ts-ignore
apply: async () =>
({
check: false,
reactDocgen: 'react-docgen-typescript',
} as TypescriptConfig),
},
presetsList: [],
});
const outputWebpackconfig = await preset.webpackFinal(webpackConfig, {
presets: {
// @ts-ignore
apply: async () =>
({
check: false,
reactDocgen: 'react-docgen-typescript',
} as TypescriptConfig),
},
presetsList: [],
});
expect(outputBabelconfig).toEqual({
babelrc: false,
presets: ['env', 'foo-preset'],
plugins: ['foo-plugin'],
});
expect(outputWebpackconfig).toEqual({
plugins: [],
});
});
});
});