@storybook/csf 0.0.2--canary.51.768ca23.0 → 0.0.2--canary.51.26e6539.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.
- package/dist/index.d.ts +325 -9
- package/dist/index.js +88 -117
- package/dist/index.mjs +73 -0
- package/package.json +25 -12
- package/.babelrc.js +0 -6
- package/dist/SBType.d.ts +0 -33
- package/dist/SBType.js +0 -1
- package/dist/includeConditionalArg.d.ts +0 -3
- package/dist/includeConditionalArg.js +0 -74
- package/dist/includeConditionalArg.test.js +0 -325
- package/dist/index.test.js +0 -142
- package/dist/story.d.ts +0 -164
- package/dist/story.js +0 -17
- package/dist/story.test.js +0 -236
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@storybook/csf",
|
3
|
-
"version": "0.0.2--canary.51.
|
3
|
+
"version": "0.0.2--canary.51.26e6539.0",
|
4
4
|
"description": "Component Story Format (CSF) utilities",
|
5
5
|
"keywords": [
|
6
6
|
"storybook",
|
@@ -24,45 +24,58 @@
|
|
24
24
|
"*.d.ts"
|
25
25
|
],
|
26
26
|
"main": "dist/index.js",
|
27
|
+
"module": "dist/index.mjs",
|
27
28
|
"types": "dist/index.d.ts",
|
28
29
|
"scripts": {
|
29
|
-
"build": "
|
30
|
-
"
|
30
|
+
"build": "tsup ./src/index.ts --format esm,cjs --dts",
|
31
|
+
"check": "tsc",
|
32
|
+
"lint": "eslint src --ext .ts",
|
31
33
|
"test": "jest",
|
32
34
|
"release": "yarn build && auto shipit"
|
33
35
|
},
|
34
36
|
"eslintConfig": {
|
35
37
|
"extends": [
|
36
38
|
"@storybook/eslint-config-storybook"
|
37
|
-
]
|
39
|
+
],
|
40
|
+
"rules": {
|
41
|
+
"jest/expect-expect": [
|
42
|
+
"warn",
|
43
|
+
{
|
44
|
+
"assertFunctionNames": [
|
45
|
+
"expect",
|
46
|
+
"expectTypeOf"
|
47
|
+
]
|
48
|
+
}
|
49
|
+
]
|
50
|
+
}
|
38
51
|
},
|
39
52
|
"prettier": "@storybook/linter-config/prettier.config",
|
40
53
|
"jest": {
|
54
|
+
"preset": "ts-jest",
|
41
55
|
"testEnvironment": "node",
|
42
56
|
"roots": [
|
43
57
|
"<rootDir>/src"
|
44
58
|
]
|
45
59
|
},
|
46
60
|
"dependencies": {
|
61
|
+
"expect-type": "^0.14.2",
|
47
62
|
"lodash": "^4.17.15",
|
48
63
|
"type-fest": "^2.19.0"
|
49
64
|
},
|
50
65
|
"devDependencies": {
|
51
66
|
"@auto-it/released": "^10.37.1",
|
52
|
-
"@babel/cli": "^7.8.4",
|
53
|
-
"@babel/core": "^7.9.0",
|
54
|
-
"@babel/preset-env": "^7.9.5",
|
55
|
-
"@babel/preset-typescript": "^7.9.0",
|
56
67
|
"@storybook/eslint-config-storybook": "^2.1.0",
|
57
|
-
"@types/jest": "^
|
68
|
+
"@types/jest": "^29.2.0",
|
58
69
|
"@types/lodash": "^4.14.149",
|
70
|
+
"@types/node": "^18.11.0",
|
71
|
+
"@typescript-eslint/parser": "^4.33.0",
|
59
72
|
"auto": "^10.31.0",
|
60
|
-
"babel-core": "7.0.0-bridge.0",
|
61
|
-
"babel-jest": "^24.9.0",
|
62
73
|
"common-tags": "^1.8.0",
|
63
74
|
"eslint": "^6.7.1",
|
64
|
-
"jest": "^
|
75
|
+
"jest": "^29.2.0",
|
65
76
|
"prettier": "^2.7.1",
|
77
|
+
"ts-jest": "^29.0.3",
|
78
|
+
"tsup": "^6.3.0",
|
66
79
|
"typescript": "^4.8.4"
|
67
80
|
},
|
68
81
|
"auto": {
|
package/.babelrc.js
DELETED
package/dist/SBType.d.ts
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
interface SBBaseType {
|
2
|
-
required?: boolean;
|
3
|
-
raw?: string;
|
4
|
-
}
|
5
|
-
export declare type SBScalarType = SBBaseType & {
|
6
|
-
name: 'boolean' | 'string' | 'number' | 'function' | 'symbol';
|
7
|
-
};
|
8
|
-
export declare type SBArrayType = SBBaseType & {
|
9
|
-
name: 'array';
|
10
|
-
value: SBType;
|
11
|
-
};
|
12
|
-
export declare type SBObjectType = SBBaseType & {
|
13
|
-
name: 'object';
|
14
|
-
value: Record<string, SBType>;
|
15
|
-
};
|
16
|
-
export declare type SBEnumType = SBBaseType & {
|
17
|
-
name: 'enum';
|
18
|
-
value: (string | number)[];
|
19
|
-
};
|
20
|
-
export declare type SBIntersectionType = SBBaseType & {
|
21
|
-
name: 'intersection';
|
22
|
-
value: SBType[];
|
23
|
-
};
|
24
|
-
export declare type SBUnionType = SBBaseType & {
|
25
|
-
name: 'union';
|
26
|
-
value: SBType[];
|
27
|
-
};
|
28
|
-
export declare type SBOtherType = SBBaseType & {
|
29
|
-
name: 'other';
|
30
|
-
value: string;
|
31
|
-
};
|
32
|
-
export declare type SBType = SBScalarType | SBEnumType | SBArrayType | SBObjectType | SBIntersectionType | SBUnionType | SBOtherType;
|
33
|
-
export {};
|
package/dist/SBType.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
"use strict";
|
@@ -1,74 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.includeConditionalArg = exports.testValue = void 0;
|
7
|
-
|
8
|
-
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
9
|
-
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
11
|
-
|
12
|
-
var count = function count(vals) {
|
13
|
-
return vals.map(function (v) {
|
14
|
-
return typeof v !== 'undefined';
|
15
|
-
}).filter(Boolean).length;
|
16
|
-
};
|
17
|
-
|
18
|
-
var testValue = function testValue(cond, value) {
|
19
|
-
var _ref = cond,
|
20
|
-
exists = _ref.exists,
|
21
|
-
eq = _ref.eq,
|
22
|
-
neq = _ref.neq,
|
23
|
-
truthy = _ref.truthy;
|
24
|
-
|
25
|
-
if (count([exists, eq, neq, truthy]) > 1) {
|
26
|
-
throw new Error("Invalid conditional test ".concat(JSON.stringify({
|
27
|
-
exists: exists,
|
28
|
-
eq: eq,
|
29
|
-
neq: neq
|
30
|
-
})));
|
31
|
-
}
|
32
|
-
|
33
|
-
if (typeof eq !== 'undefined') {
|
34
|
-
return (0, _isEqual["default"])(value, eq);
|
35
|
-
}
|
36
|
-
|
37
|
-
if (typeof neq !== 'undefined') {
|
38
|
-
return !(0, _isEqual["default"])(value, neq);
|
39
|
-
}
|
40
|
-
|
41
|
-
if (typeof exists !== 'undefined') {
|
42
|
-
var valueExists = typeof value !== 'undefined';
|
43
|
-
return exists ? valueExists : !valueExists;
|
44
|
-
}
|
45
|
-
|
46
|
-
var shouldBeTruthy = typeof truthy === 'undefined' ? true : truthy;
|
47
|
-
return shouldBeTruthy ? !!value : !value;
|
48
|
-
};
|
49
|
-
/**
|
50
|
-
* Helper function to include/exclude an arg based on the value of other other args
|
51
|
-
* aka "conditional args"
|
52
|
-
*/
|
53
|
-
|
54
|
-
|
55
|
-
exports.testValue = testValue;
|
56
|
-
|
57
|
-
var includeConditionalArg = function includeConditionalArg(argType, args, globals) {
|
58
|
-
if (!argType["if"]) return true;
|
59
|
-
var _ref2 = argType["if"],
|
60
|
-
arg = _ref2.arg,
|
61
|
-
global = _ref2.global;
|
62
|
-
|
63
|
-
if (count([arg, global]) !== 1) {
|
64
|
-
throw new Error("Invalid conditional value ".concat(JSON.stringify({
|
65
|
-
arg: arg,
|
66
|
-
global: global
|
67
|
-
})));
|
68
|
-
}
|
69
|
-
|
70
|
-
var value = arg ? args[arg] : globals[global];
|
71
|
-
return testValue(argType["if"], value);
|
72
|
-
};
|
73
|
-
|
74
|
-
exports.includeConditionalArg = includeConditionalArg;
|
@@ -1,325 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _includeConditionalArg = require("./includeConditionalArg");
|
4
|
-
|
5
|
-
/* eslint-disable @typescript-eslint/ban-ts-ignore */
|
6
|
-
describe('testValue', function () {
|
7
|
-
describe('truthy', function () {
|
8
|
-
it.each([['implicit true', {}, true, true], ['implicit truthy', {}, 1, true], ['implicit falsey', {}, 0, false], ['truthy true', {
|
9
|
-
truthy: true
|
10
|
-
}, true, true], ['truthy truthy', {
|
11
|
-
truthy: true
|
12
|
-
}, 1, true], ['truthy falsey', {
|
13
|
-
truthy: true
|
14
|
-
}, 0, false], ['falsey true', {
|
15
|
-
truthy: false
|
16
|
-
}, true, false], ['falsey truthy', {
|
17
|
-
truthy: false
|
18
|
-
}, 1, false], ['falsey falsey', {
|
19
|
-
truthy: false
|
20
|
-
}, 0, true]])('%s', function (_name, cond, value, expected) {
|
21
|
-
// @ts-ignore
|
22
|
-
expect((0, _includeConditionalArg.testValue)(cond, value)).toBe(expected);
|
23
|
-
});
|
24
|
-
});
|
25
|
-
describe('exists', function () {
|
26
|
-
it.each([['exist', {
|
27
|
-
exists: true
|
28
|
-
}, 1, true], ['exist false', {
|
29
|
-
exists: true
|
30
|
-
}, undefined, false], ['nexist', {
|
31
|
-
exists: false
|
32
|
-
}, undefined, true], ['nexist false', {
|
33
|
-
exists: false
|
34
|
-
}, 1, false]])('%s', function (_name, cond, value, expected) {
|
35
|
-
// @ts-ignore
|
36
|
-
expect((0, _includeConditionalArg.testValue)(cond, value)).toBe(expected);
|
37
|
-
});
|
38
|
-
});
|
39
|
-
describe('eq', function () {
|
40
|
-
it.each([['true', {
|
41
|
-
eq: 1
|
42
|
-
}, 1, true], ['false', {
|
43
|
-
eq: 1
|
44
|
-
}, 2, false], ['undefined', {
|
45
|
-
eq: undefined
|
46
|
-
}, undefined, false], ['undefined false', {
|
47
|
-
eq: 1
|
48
|
-
}, undefined, false], ['object true', {
|
49
|
-
eq: {
|
50
|
-
x: 1
|
51
|
-
}
|
52
|
-
}, {
|
53
|
-
x: 1
|
54
|
-
}, true], ['object true', {
|
55
|
-
eq: {
|
56
|
-
x: 1
|
57
|
-
}
|
58
|
-
}, {
|
59
|
-
x: 2
|
60
|
-
}, false]])('%s', function (_name, cond, value, expected) {
|
61
|
-
// @ts-ignore
|
62
|
-
expect((0, _includeConditionalArg.testValue)(cond, value)).toBe(expected);
|
63
|
-
});
|
64
|
-
});
|
65
|
-
describe('neq', function () {
|
66
|
-
it.each([['true', {
|
67
|
-
neq: 1
|
68
|
-
}, 2, true], ['false', {
|
69
|
-
neq: 1
|
70
|
-
}, 1, false], ['undefined true', {
|
71
|
-
neq: 1
|
72
|
-
}, undefined, true], ['undefined false', {
|
73
|
-
neq: undefined
|
74
|
-
}, undefined, false], ['object true', {
|
75
|
-
neq: {
|
76
|
-
x: 1
|
77
|
-
}
|
78
|
-
}, {
|
79
|
-
x: 2
|
80
|
-
}, true], ['object false', {
|
81
|
-
neq: {
|
82
|
-
x: 1
|
83
|
-
}
|
84
|
-
}, {
|
85
|
-
x: 1
|
86
|
-
}, false]])('%s', function (_name, cond, value, expected) {
|
87
|
-
// @ts-ignore
|
88
|
-
expect((0, _includeConditionalArg.testValue)(cond, value)).toBe(expected);
|
89
|
-
});
|
90
|
-
});
|
91
|
-
});
|
92
|
-
describe('includeConditionalArg', function () {
|
93
|
-
describe('errors', function () {
|
94
|
-
it('should throw if neither arg nor global is specified', function () {
|
95
|
-
expect(function () {
|
96
|
-
return (0, _includeConditionalArg.includeConditionalArg)({
|
97
|
-
"if": {}
|
98
|
-
}, {}, {});
|
99
|
-
}).toThrowErrorMatchingInlineSnapshot("\"Invalid conditional value {}\"");
|
100
|
-
});
|
101
|
-
it('should throw if arg and global are both specified', function () {
|
102
|
-
expect(function () {
|
103
|
-
return (0, _includeConditionalArg.includeConditionalArg)({
|
104
|
-
"if": {
|
105
|
-
arg: 'a',
|
106
|
-
global: 'b'
|
107
|
-
}
|
108
|
-
}, {}, {});
|
109
|
-
}).toThrowErrorMatchingInlineSnapshot("\"Invalid conditional value {\\\"arg\\\":\\\"a\\\",\\\"global\\\":\\\"b\\\"}\"");
|
110
|
-
});
|
111
|
-
it('should throw if mulitiple exists / eq / neq are specified', function () {
|
112
|
-
expect(function () {
|
113
|
-
return (0, _includeConditionalArg.includeConditionalArg)({
|
114
|
-
"if": {
|
115
|
-
arg: 'a',
|
116
|
-
exists: true,
|
117
|
-
eq: 1
|
118
|
-
}
|
119
|
-
}, {}, {});
|
120
|
-
}).toThrowErrorMatchingInlineSnapshot("\"Invalid conditional test {\\\"exists\\\":true,\\\"eq\\\":1}\"");
|
121
|
-
expect(function () {
|
122
|
-
return (0, _includeConditionalArg.includeConditionalArg)({
|
123
|
-
"if": {
|
124
|
-
arg: 'a',
|
125
|
-
exists: false,
|
126
|
-
neq: 0
|
127
|
-
}
|
128
|
-
}, {}, {});
|
129
|
-
}).toThrowErrorMatchingInlineSnapshot("\"Invalid conditional test {\\\"exists\\\":false,\\\"neq\\\":0}\"");
|
130
|
-
expect(function () {
|
131
|
-
return (0, _includeConditionalArg.includeConditionalArg)({
|
132
|
-
"if": {
|
133
|
-
arg: 'a',
|
134
|
-
eq: 1,
|
135
|
-
neq: 0
|
136
|
-
}
|
137
|
-
}, {}, {});
|
138
|
-
}).toThrowErrorMatchingInlineSnapshot("\"Invalid conditional test {\\\"eq\\\":1,\\\"neq\\\":0}\"");
|
139
|
-
});
|
140
|
-
});
|
141
|
-
describe('args', function () {
|
142
|
-
describe('implicit', function () {
|
143
|
-
it.each([['implicit true', {
|
144
|
-
"if": {
|
145
|
-
arg: 'a'
|
146
|
-
}
|
147
|
-
}, {
|
148
|
-
a: 1
|
149
|
-
}, {}, true], ['truthy true', {
|
150
|
-
"if": {
|
151
|
-
arg: 'a',
|
152
|
-
truthy: true
|
153
|
-
}
|
154
|
-
}, {
|
155
|
-
a: 0
|
156
|
-
}, {}, false], ['truthy false', {
|
157
|
-
"if": {
|
158
|
-
arg: 'a',
|
159
|
-
truthy: false
|
160
|
-
}
|
161
|
-
}, {}, {}, true]])('%s', function (_name, argType, args, globals, expected) {
|
162
|
-
// @ts-ignore
|
163
|
-
expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
|
164
|
-
});
|
165
|
-
});
|
166
|
-
describe('exists', function () {
|
167
|
-
it.each([['exist', {
|
168
|
-
"if": {
|
169
|
-
arg: 'a',
|
170
|
-
exists: true
|
171
|
-
}
|
172
|
-
}, {
|
173
|
-
a: 1
|
174
|
-
}, {}, true], ['exist false', {
|
175
|
-
"if": {
|
176
|
-
arg: 'a',
|
177
|
-
exists: true
|
178
|
-
}
|
179
|
-
}, {}, {}, false]])('%s', function (_name, argType, args, globals, expected) {
|
180
|
-
// @ts-ignore
|
181
|
-
expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
|
182
|
-
});
|
183
|
-
});
|
184
|
-
describe('eq', function () {
|
185
|
-
it.each([['scalar true', {
|
186
|
-
"if": {
|
187
|
-
arg: 'a',
|
188
|
-
eq: 1
|
189
|
-
}
|
190
|
-
}, {
|
191
|
-
a: 1
|
192
|
-
}, {}, true], ['scalar false', {
|
193
|
-
"if": {
|
194
|
-
arg: 'a',
|
195
|
-
eq: 1
|
196
|
-
}
|
197
|
-
}, {
|
198
|
-
a: 2
|
199
|
-
}, {
|
200
|
-
a: 1
|
201
|
-
}, false]])('%s', function (_name, argType, args, globals, expected) {
|
202
|
-
// @ts-ignore
|
203
|
-
expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
|
204
|
-
});
|
205
|
-
});
|
206
|
-
describe('neq', function () {
|
207
|
-
it.each([['scalar true', {
|
208
|
-
"if": {
|
209
|
-
arg: 'a',
|
210
|
-
neq: 1
|
211
|
-
}
|
212
|
-
}, {
|
213
|
-
a: 2
|
214
|
-
}, {}, true], ['scalar false', {
|
215
|
-
"if": {
|
216
|
-
arg: 'a',
|
217
|
-
neq: 1
|
218
|
-
}
|
219
|
-
}, {
|
220
|
-
a: 1
|
221
|
-
}, {
|
222
|
-
a: 2
|
223
|
-
}, false]])('%s', function (_name, argType, args, globals, expected) {
|
224
|
-
// @ts-ignore
|
225
|
-
expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
|
226
|
-
});
|
227
|
-
});
|
228
|
-
});
|
229
|
-
describe('globals', function () {
|
230
|
-
describe('truthy', function () {
|
231
|
-
it.each([['implicit true', {
|
232
|
-
"if": {
|
233
|
-
global: 'a'
|
234
|
-
}
|
235
|
-
}, {}, {
|
236
|
-
a: 1
|
237
|
-
}, true], ['implicit undefined', {
|
238
|
-
"if": {
|
239
|
-
global: 'a'
|
240
|
-
}
|
241
|
-
}, {}, {}, false], ['truthy true', {
|
242
|
-
"if": {
|
243
|
-
global: 'a',
|
244
|
-
truthy: true
|
245
|
-
}
|
246
|
-
}, {}, {
|
247
|
-
a: 0
|
248
|
-
}, false], ['truthy false', {
|
249
|
-
"if": {
|
250
|
-
global: 'a',
|
251
|
-
truthy: false
|
252
|
-
}
|
253
|
-
}, {}, {
|
254
|
-
a: 0
|
255
|
-
}, true]])('%s', function (_name, argType, args, globals, expected) {
|
256
|
-
// @ts-ignore
|
257
|
-
expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
|
258
|
-
});
|
259
|
-
});
|
260
|
-
describe('exists', function () {
|
261
|
-
it.each([['implicit exist true', {
|
262
|
-
"if": {
|
263
|
-
global: 'a',
|
264
|
-
exists: true
|
265
|
-
}
|
266
|
-
}, {}, {
|
267
|
-
a: 1
|
268
|
-
}, true], ['implicit exist false', {
|
269
|
-
"if": {
|
270
|
-
global: 'a',
|
271
|
-
exists: true
|
272
|
-
}
|
273
|
-
}, {
|
274
|
-
a: 1
|
275
|
-
}, {}, false]])('%s', function (_name, argType, args, globals, expected) {
|
276
|
-
// @ts-ignore
|
277
|
-
expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
|
278
|
-
});
|
279
|
-
});
|
280
|
-
describe('eq', function () {
|
281
|
-
it.each([['scalar true', {
|
282
|
-
"if": {
|
283
|
-
global: 'a',
|
284
|
-
eq: 1
|
285
|
-
}
|
286
|
-
}, {}, {
|
287
|
-
a: 1
|
288
|
-
}, true], ['scalar false', {
|
289
|
-
"if": {
|
290
|
-
arg: 'a',
|
291
|
-
eq: 1
|
292
|
-
}
|
293
|
-
}, {
|
294
|
-
a: 2
|
295
|
-
}, {
|
296
|
-
a: 1
|
297
|
-
}, false]])('%s', function (_name, argType, args, globals, expected) {
|
298
|
-
// @ts-ignore
|
299
|
-
expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
|
300
|
-
});
|
301
|
-
});
|
302
|
-
describe('neq', function () {
|
303
|
-
it.each([['scalar true', {
|
304
|
-
"if": {
|
305
|
-
global: 'a',
|
306
|
-
neq: 1
|
307
|
-
}
|
308
|
-
}, {}, {
|
309
|
-
a: 2
|
310
|
-
}, true], ['scalar false', {
|
311
|
-
"if": {
|
312
|
-
global: 'a',
|
313
|
-
neq: 1
|
314
|
-
}
|
315
|
-
}, {
|
316
|
-
a: 2
|
317
|
-
}, {
|
318
|
-
a: 1
|
319
|
-
}, false]])('%s', function (_name, argType, args, globals, expected) {
|
320
|
-
// @ts-ignore
|
321
|
-
expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
|
322
|
-
});
|
323
|
-
});
|
324
|
-
});
|
325
|
-
});
|
package/dist/index.test.js
DELETED
@@ -1,142 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _ = require(".");
|
4
|
-
|
5
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
6
|
-
|
7
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
8
|
-
|
9
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
10
|
-
|
11
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
12
|
-
|
13
|
-
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
14
|
-
|
15
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
16
|
-
|
17
|
-
describe('toId', function () {
|
18
|
-
var testCases = [// name, kind, story, output
|
19
|
-
['handles simple cases', 'kind', 'story', 'kind--story'], ['handles kind without story', 'kind', undefined, 'kind'], ['handles basic substitution', 'a b$c?d😀e', '1-2:3', 'a-b-c-d😀e--1-2-3'], ['handles runs of non-url chars', 'a?&*b', 'story', 'a-b--story'], ['removes non-url chars from start and end', '?ab-', 'story', 'ab--story'], ['downcases', 'KIND', 'STORY', 'kind--story'], ['non-latin', 'Кнопки', 'нормальный', 'кнопки--нормальный'], ['korean', 'kind', '바보 (babo)', 'kind--바보-babo'], ['all punctuation', 'kind', 'unicorns,’–—―′¿`"<>()!.!!!{}[]%^&$*#&', 'kind--unicorns']];
|
20
|
-
testCases.forEach(function (_ref) {
|
21
|
-
var _ref2 = _slicedToArray(_ref, 4),
|
22
|
-
name = _ref2[0],
|
23
|
-
kind = _ref2[1],
|
24
|
-
story = _ref2[2],
|
25
|
-
output = _ref2[3];
|
26
|
-
|
27
|
-
it(name, function () {
|
28
|
-
expect((0, _.toId)(kind, story)).toBe(output);
|
29
|
-
});
|
30
|
-
});
|
31
|
-
it('does not allow kind with *no* url chars', function () {
|
32
|
-
expect(function () {
|
33
|
-
return (0, _.toId)('?', 'asdf');
|
34
|
-
}).toThrow("Invalid kind '?', must include alphanumeric characters");
|
35
|
-
});
|
36
|
-
it('does not allow empty kind', function () {
|
37
|
-
expect(function () {
|
38
|
-
return (0, _.toId)('', 'asdf');
|
39
|
-
}).toThrow("Invalid kind '', must include alphanumeric characters");
|
40
|
-
});
|
41
|
-
it('does not allow story with *no* url chars', function () {
|
42
|
-
expect(function () {
|
43
|
-
return (0, _.toId)('kind', '?');
|
44
|
-
}).toThrow("Invalid name '?', must include alphanumeric characters");
|
45
|
-
});
|
46
|
-
it('allows empty story', function () {
|
47
|
-
expect(function () {
|
48
|
-
return (0, _.toId)('kind', '');
|
49
|
-
}).not.toThrow();
|
50
|
-
});
|
51
|
-
});
|
52
|
-
describe('storyNameFromExport', function () {
|
53
|
-
it('should format CSF exports with sensible defaults', function () {
|
54
|
-
var testCases = {
|
55
|
-
name: 'Name',
|
56
|
-
someName: 'Some Name',
|
57
|
-
someNAME: 'Some NAME',
|
58
|
-
some_custom_NAME: 'Some Custom NAME',
|
59
|
-
someName1234: 'Some Name 1234',
|
60
|
-
someName1_2_3_4: 'Some Name 1 2 3 4'
|
61
|
-
};
|
62
|
-
Object.entries(testCases).forEach(function (_ref3) {
|
63
|
-
var _ref4 = _slicedToArray(_ref3, 2),
|
64
|
-
key = _ref4[0],
|
65
|
-
val = _ref4[1];
|
66
|
-
|
67
|
-
return expect((0, _.storyNameFromExport)(key)).toBe(val);
|
68
|
-
});
|
69
|
-
});
|
70
|
-
});
|
71
|
-
describe('isExportStory', function () {
|
72
|
-
it('should exclude __esModule', function () {
|
73
|
-
expect((0, _.isExportStory)('__esModule', {})).toBeFalsy();
|
74
|
-
});
|
75
|
-
it('should include all stories when there are no filters', function () {
|
76
|
-
expect((0, _.isExportStory)('a', {})).toBeTruthy();
|
77
|
-
});
|
78
|
-
it('should filter stories by arrays', function () {
|
79
|
-
expect((0, _.isExportStory)('a', {
|
80
|
-
includeStories: ['a']
|
81
|
-
})).toBeTruthy();
|
82
|
-
expect((0, _.isExportStory)('a', {
|
83
|
-
includeStories: []
|
84
|
-
})).toBeFalsy();
|
85
|
-
expect((0, _.isExportStory)('a', {
|
86
|
-
includeStories: ['b']
|
87
|
-
})).toBeFalsy();
|
88
|
-
expect((0, _.isExportStory)('a', {
|
89
|
-
excludeStories: ['a']
|
90
|
-
})).toBeFalsy();
|
91
|
-
expect((0, _.isExportStory)('a', {
|
92
|
-
excludeStories: []
|
93
|
-
})).toBeTruthy();
|
94
|
-
expect((0, _.isExportStory)('a', {
|
95
|
-
excludeStories: ['b']
|
96
|
-
})).toBeTruthy();
|
97
|
-
expect((0, _.isExportStory)('a', {
|
98
|
-
includeStories: ['a'],
|
99
|
-
excludeStories: ['a']
|
100
|
-
})).toBeFalsy();
|
101
|
-
expect((0, _.isExportStory)('a', {
|
102
|
-
includeStories: [],
|
103
|
-
excludeStories: []
|
104
|
-
})).toBeFalsy();
|
105
|
-
expect((0, _.isExportStory)('a', {
|
106
|
-
includeStories: ['a'],
|
107
|
-
excludeStories: ['b']
|
108
|
-
})).toBeTruthy();
|
109
|
-
});
|
110
|
-
it('should filter stories by regex', function () {
|
111
|
-
expect((0, _.isExportStory)('a', {
|
112
|
-
includeStories: /a/
|
113
|
-
})).toBeTruthy();
|
114
|
-
expect((0, _.isExportStory)('a', {
|
115
|
-
includeStories: /.*/
|
116
|
-
})).toBeTruthy();
|
117
|
-
expect((0, _.isExportStory)('a', {
|
118
|
-
includeStories: /b/
|
119
|
-
})).toBeFalsy();
|
120
|
-
expect((0, _.isExportStory)('a', {
|
121
|
-
excludeStories: /a/
|
122
|
-
})).toBeFalsy();
|
123
|
-
expect((0, _.isExportStory)('a', {
|
124
|
-
excludeStories: /.*/
|
125
|
-
})).toBeFalsy();
|
126
|
-
expect((0, _.isExportStory)('a', {
|
127
|
-
excludeStories: /b/
|
128
|
-
})).toBeTruthy();
|
129
|
-
expect((0, _.isExportStory)('a', {
|
130
|
-
includeStories: /a/,
|
131
|
-
excludeStories: ['a']
|
132
|
-
})).toBeFalsy();
|
133
|
-
expect((0, _.isExportStory)('a', {
|
134
|
-
includeStories: /.*/,
|
135
|
-
excludeStories: /.*/
|
136
|
-
})).toBeFalsy();
|
137
|
-
expect((0, _.isExportStory)('a', {
|
138
|
-
includeStories: /a/,
|
139
|
-
excludeStories: /b/
|
140
|
-
})).toBeTruthy();
|
141
|
-
});
|
142
|
-
});
|