@ornikar/kitt-universal 13.3.2 → 13.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,10 @@ module.exports = function babelPluginStorybookCSFToJest({ types }, opts) {
6
6
  const storybookImportName = 'BabelPluginStorybookCSFToJest_StorybookReact';
7
7
  const storiesOfName = 'BabelPluginStorybookCSFToJest_stories';
8
8
 
9
- const isStory = (file) => file.opts && file.opts.filename && file.opts.filename.endsWith('.stories.tsx');
9
+ const isStory = (file) =>
10
+ file.opts &&
11
+ file.opts.filename &&
12
+ (file.opts.filename.endsWith('.stories.tsx') || file.opts.filename.endsWith('/stories.tsx'));
10
13
 
11
14
  return {
12
15
  name: 'plugin-storybook-csf-to-jest',
@@ -134,6 +137,7 @@ module.exports = function babelPluginStorybookCSFToJest({ types }, opts) {
134
137
 
135
138
  const binding = path.scope.getBinding(declaration.id.name);
136
139
  let storyName = declaration.id.name;
140
+ let parameters;
137
141
 
138
142
  binding.referencePaths.forEach((refPath) => {
139
143
  if (refPath === path) return; // skip named export
@@ -154,28 +158,44 @@ module.exports = function babelPluginStorybookCSFToJest({ types }, opts) {
154
158
  }
155
159
 
156
160
  const prop = refPath.parent.property;
157
- if (types.isIdentifier(prop) && prop.name === 'args') {
158
- foundArgs = true;
159
- path.scope.push({
160
- id: types.identifier('args'),
161
- init: assignmentExpression.right,
162
- });
163
- }
161
+ if (types.isIdentifier(prop)) {
162
+ if (prop.name === 'args') {
163
+ foundArgs = true;
164
164
 
165
- if (
166
- types.isIdentifier(prop) &&
167
- prop.name === 'story' &&
168
- types.isObjectExpression(assignmentExpression.right)
169
- ) {
170
- const objectExpression = assignmentExpression.right;
171
- objectExpression.properties.forEach((property) => {
172
- if (types.isIdentifier(property.key) && property.key.name === 'name') {
173
- storyName = property.value.value;
165
+ if (declaration.init.body.type !== 'BlockStatement') {
166
+ declaration.init.body = types.blockStatement([types.returnStatement(declaration.init.body)]);
174
167
  }
175
- });
176
- }
177
168
 
178
- // Need to add decorators and parameters
169
+ declaration.init.body.body.unshift(
170
+ types.variableDeclaration('const', [
171
+ types.variableDeclarator(types.identifier('args'), assignmentExpression.right),
172
+ ]),
173
+ );
174
+ }
175
+
176
+ if (prop.name === 'storyName') {
177
+ if (!types.isStringLiteral(assignmentExpression.right)) {
178
+ throw path.buildCodeFrameError(
179
+ `Invalid storyName, expecting StringLiteral, got "${assignmentExpression.right.type}"`,
180
+ );
181
+ }
182
+ storyName = assignmentExpression.right.value;
183
+ }
184
+
185
+ if (prop.name === 'story' && types.isObjectExpression(assignmentExpression.right)) {
186
+ throw path.buildCodeFrameError('story.name is deprecated, use storyName instead');
187
+ }
188
+
189
+ if (prop.name === 'parameters') {
190
+ parameters = assignmentExpression.right;
191
+ }
192
+
193
+ if (prop.name === 'decorators') {
194
+ throw path.buildCodeFrameError(
195
+ 'Story-specific decorators are not supported, use global decorators instead (in export default).',
196
+ );
197
+ }
198
+ }
179
199
 
180
200
  memberExpressionPath.parentPath.remove();
181
201
  });
@@ -188,6 +208,7 @@ module.exports = function babelPluginStorybookCSFToJest({ types }, opts) {
188
208
  types.callExpression(types.memberExpression(types.identifier(storiesOfName), types.identifier('add')), [
189
209
  types.stringLiteral(storyName),
190
210
  declaration.init,
211
+ ...(parameters ? [parameters] : []),
191
212
  ]),
192
213
  );
193
214
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ornikar/kitt-universal",
3
- "version": "13.3.2",
3
+ "version": "13.4.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "directory": "@ornikar/kitt-universal",
@@ -46,6 +46,7 @@
46
46
  "./translations/fr-FR.json": "./translations/fr-FR.json",
47
47
  "./translations/es-ES.json": "./translations/es-ES.json",
48
48
  "./dist/linaria-themes-node-14.17.cjs.web.js": "./dist/linaria-themes-node-14.17.cjs.web.js",
49
+ "./babel-plugin-csf-to-jest": "./babel-plugin-csf-to-jest.js",
49
50
  "./package.json": "./package.json"
50
51
  },
51
52
  "engines": {
@@ -140,5 +141,5 @@
140
141
  "react-native-svg": "13.4.0",
141
142
  "react-native-web": "0.18.12"
142
143
  },
143
- "gitHead": "6139cb5f4f8e94300f6ea8a61bf179276cff9fff"
144
+ "gitHead": "05c075b21a5cef0f923a40b983569a517afb9997"
144
145
  }