creevey 0.9.0-beta.13 → 0.9.0-beta.14

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.
Files changed (216) hide show
  1. package/.yarn/install-state.gz +0 -0
  2. package/.yarnrc.yml +1 -0
  3. package/lib/cjs/cli.js +1 -0
  4. package/lib/cjs/client/addon/Manager.js +151 -223
  5. package/lib/cjs/client/addon/components/Addon.js +2 -9
  6. package/lib/cjs/client/addon/components/Icons.js +1 -7
  7. package/lib/cjs/client/addon/components/Panel.js +5 -18
  8. package/lib/cjs/client/addon/components/TestSelect.js +12 -25
  9. package/lib/cjs/client/addon/components/Tools.js +17 -28
  10. package/lib/cjs/client/addon/decorator.js +1 -4
  11. package/lib/cjs/client/addon/index.js +0 -4
  12. package/lib/cjs/client/addon/preset.js +3 -12
  13. package/lib/cjs/client/addon/preview.js +1 -4
  14. package/lib/cjs/client/addon/readyForCapture.js +1 -4
  15. package/lib/cjs/client/addon/register.js +11 -26
  16. package/lib/cjs/client/addon/utils.js +1 -9
  17. package/lib/cjs/client/addon/withCreevey.js +55 -134
  18. package/lib/cjs/client/shared/components/ImagesView/BlendView.js +5 -17
  19. package/lib/cjs/client/shared/components/ImagesView/ImagesView.js +8 -24
  20. package/lib/cjs/client/shared/components/ImagesView/SideBySideView.js +7 -23
  21. package/lib/cjs/client/shared/components/ImagesView/SlideView.js +7 -22
  22. package/lib/cjs/client/shared/components/ImagesView/SwapView.js +5 -17
  23. package/lib/cjs/client/shared/components/ImagesView/index.js +0 -5
  24. package/lib/cjs/client/shared/components/PageFooter/PageFooter.js +1 -8
  25. package/lib/cjs/client/shared/components/PageFooter/Paging.js +2 -19
  26. package/lib/cjs/client/shared/components/PageHeader/ImagePreview.js +21 -17
  27. package/lib/cjs/client/shared/components/PageHeader/PageHeader.js +5 -24
  28. package/lib/cjs/client/shared/components/ResultsPage.js +9 -37
  29. package/lib/cjs/client/shared/creeveyClientApi.js +3 -13
  30. package/lib/cjs/client/shared/helpers.js +21 -75
  31. package/lib/cjs/client/shared/viewMode.js +2 -6
  32. package/lib/cjs/client/web/192.js +1 -0
  33. package/lib/cjs/client/web/632.js +43 -0
  34. package/lib/cjs/client/web/794.js +1 -0
  35. package/lib/cjs/client/web/main.js +78 -1
  36. package/lib/cjs/client/web/main.js.LICENSE.txt +0 -15
  37. package/lib/cjs/creevey.js +5 -21
  38. package/lib/cjs/index.js +0 -15
  39. package/lib/cjs/server/config.js +13 -33
  40. package/lib/cjs/server/docker.js +5 -27
  41. package/lib/cjs/server/index.js +8 -33
  42. package/lib/cjs/server/logger.js +5 -19
  43. package/lib/cjs/server/master/api.js +1 -14
  44. package/lib/cjs/server/master/index.js +15 -46
  45. package/lib/cjs/server/master/master.js +6 -21
  46. package/lib/cjs/server/master/pool.js +2 -37
  47. package/lib/cjs/server/master/runner.js +15 -42
  48. package/lib/cjs/server/master/server.js +5 -27
  49. package/lib/cjs/server/messages.js +7 -53
  50. package/lib/cjs/server/selenium/browser.js +51 -136
  51. package/lib/cjs/server/selenium/index.js +0 -4
  52. package/lib/cjs/server/selenium/selenoid.js +7 -33
  53. package/lib/cjs/server/stories.js +25 -30
  54. package/lib/cjs/server/storybook/providers/browser.js +5 -18
  55. package/lib/cjs/server/storybook/providers/hybrid.js +9 -29
  56. package/lib/cjs/server/testsFiles/parser.js +3 -19
  57. package/lib/cjs/server/testsFiles/register.js +7 -9
  58. package/lib/cjs/server/update.js +3 -20
  59. package/lib/cjs/server/utils.js +9 -41
  60. package/lib/cjs/server/worker/chai-image.js +1 -27
  61. package/lib/cjs/server/worker/helpers.js +2 -12
  62. package/lib/cjs/server/worker/index.js +1 -3
  63. package/lib/cjs/server/worker/reporter.js +8 -24
  64. package/lib/cjs/server/worker/worker.js +5 -49
  65. package/lib/cjs/shared/index.js +22 -36
  66. package/lib/cjs/shared/serializeRegExp.js +0 -8
  67. package/lib/cjs/types.js +4 -14
  68. package/lib/esm/cli.js +1 -1
  69. package/lib/esm/client/addon/Manager.js +151 -214
  70. package/lib/esm/client/addon/components/Panel.js +4 -6
  71. package/lib/esm/client/addon/components/TestSelect.js +11 -17
  72. package/lib/esm/client/addon/components/Tools.js +15 -14
  73. package/lib/esm/client/addon/preset.js +2 -8
  74. package/lib/esm/client/addon/readyForCapture.js +1 -3
  75. package/lib/esm/client/addon/register.js +6 -8
  76. package/lib/esm/client/addon/utils.js +0 -5
  77. package/lib/esm/client/addon/withCreevey.js +54 -116
  78. package/lib/esm/client/shared/components/ImagesView/BlendView.js +1 -1
  79. package/lib/esm/client/shared/components/ImagesView/ImagesView.js +6 -8
  80. package/lib/esm/client/shared/components/ImagesView/SideBySideView.js +3 -4
  81. package/lib/esm/client/shared/components/ImagesView/SlideView.js +3 -3
  82. package/lib/esm/client/shared/components/ImagesView/SwapView.js +1 -1
  83. package/lib/esm/client/shared/components/PageFooter/Paging.js +1 -11
  84. package/lib/esm/client/shared/components/PageHeader/ImagePreview.js +18 -7
  85. package/lib/esm/client/shared/components/PageHeader/PageHeader.js +3 -8
  86. package/lib/esm/client/shared/components/ResultsPage.js +6 -15
  87. package/lib/esm/client/shared/creeveyClientApi.js +3 -10
  88. package/lib/esm/client/shared/helpers.js +21 -47
  89. package/lib/esm/client/web/192.js +1 -0
  90. package/lib/esm/client/web/632.js +43 -0
  91. package/lib/esm/client/web/794.js +1 -0
  92. package/lib/esm/client/web/index.html +19 -0
  93. package/lib/esm/client/web/main.js +79 -0
  94. package/lib/esm/client/web/main.js.LICENSE.txt +34 -0
  95. package/lib/esm/creevey.js +4 -8
  96. package/lib/esm/index.js +0 -1
  97. package/lib/esm/server/config.js +7 -14
  98. package/lib/esm/server/docker.js +4 -12
  99. package/lib/esm/server/index.js +7 -21
  100. package/lib/esm/server/logger.js +0 -1
  101. package/lib/esm/server/master/api.js +0 -9
  102. package/lib/esm/server/master/index.js +15 -32
  103. package/lib/esm/server/master/master.js +2 -7
  104. package/lib/esm/server/master/pool.js +0 -23
  105. package/lib/esm/server/master/runner.js +14 -27
  106. package/lib/esm/server/master/server.js +4 -9
  107. package/lib/esm/server/messages.js +6 -38
  108. package/lib/esm/server/selenium/browser.js +50 -114
  109. package/lib/esm/server/selenium/selenoid.js +6 -17
  110. package/lib/esm/server/stories.js +24 -20
  111. package/lib/esm/server/storybook/providers/browser.js +4 -8
  112. package/lib/esm/server/storybook/providers/hybrid.js +6 -14
  113. package/lib/esm/server/testsFiles/parser.js +0 -6
  114. package/lib/esm/server/testsFiles/register.js +5 -2
  115. package/lib/esm/server/update.js +0 -8
  116. package/lib/esm/server/utils.js +3 -11
  117. package/lib/esm/server/worker/chai-image.js +0 -21
  118. package/lib/esm/server/worker/helpers.js +2 -9
  119. package/lib/esm/server/worker/reporter.js +7 -10
  120. package/lib/esm/server/worker/worker.js +4 -25
  121. package/lib/esm/shared/index.js +24 -25
  122. package/lib/esm/types.js +4 -1
  123. package/lib/types/client/addon/Manager.d.ts +1 -1
  124. package/lib/types/client/addon/components/Addon.d.ts +1 -0
  125. package/lib/types/client/addon/components/Icons.d.ts +1 -0
  126. package/lib/types/client/addon/components/Panel.d.ts +1 -0
  127. package/lib/types/client/addon/components/TestSelect.d.ts +1 -0
  128. package/lib/types/client/addon/components/Tools.d.ts +1 -0
  129. package/lib/types/client/addon/decorator.d.ts +1 -1
  130. package/lib/types/client/addon/preset.d.ts +2 -2
  131. package/lib/types/client/addon/preview.d.ts +1 -1
  132. package/lib/types/client/addon/withCreevey.d.ts +3 -2
  133. package/lib/types/client/shared/components/ImagesView/BlendView.d.ts +3 -1
  134. package/lib/types/client/shared/components/ImagesView/ImagesView.d.ts +1 -0
  135. package/lib/types/client/shared/components/ImagesView/SideBySideView.d.ts +3 -1
  136. package/lib/types/client/shared/components/ImagesView/SlideView.d.ts +3 -1
  137. package/lib/types/client/shared/components/ImagesView/SwapView.d.ts +3 -1
  138. package/lib/types/client/shared/components/PageFooter/PageFooter.d.ts +1 -0
  139. package/lib/types/client/shared/components/PageFooter/Paging.d.ts +1 -0
  140. package/lib/types/client/shared/components/PageHeader/ImagePreview.d.ts +3 -1
  141. package/lib/types/client/shared/components/PageHeader/PageHeader.d.ts +1 -0
  142. package/lib/types/client/shared/components/ResultsPage.d.ts +3 -1
  143. package/lib/types/client/web/CreeveyApp.d.ts +1 -0
  144. package/lib/types/client/web/CreeveyLoader.d.ts +2 -1
  145. package/lib/types/client/web/CreeveyView/SideBar/Checkbox.d.ts +4 -1
  146. package/lib/types/client/web/CreeveyView/SideBar/Search.d.ts +1 -0
  147. package/lib/types/client/web/CreeveyView/SideBar/SideBarHeader.d.ts +1 -0
  148. package/lib/types/client/web/CreeveyView/SideBar/SuiteLink.d.ts +19 -14
  149. package/lib/types/client/web/CreeveyView/SideBar/TestLink.d.ts +1 -0
  150. package/lib/types/client/web/CreeveyView/SideBar/TestStatusIcon.d.ts +3 -1
  151. package/lib/types/client/web/CreeveyView/SideBar/TestsStatus.d.ts +3 -1
  152. package/lib/types/client/web/CreeveyView/SideBar/Toggle.d.ts +1 -0
  153. package/lib/types/shared/index.d.ts +1 -1
  154. package/lib/types/types.d.ts +7 -28
  155. package/package.json +60 -78
  156. package/lib/cjs/client/addon/preset.ie11.js +0 -74
  157. package/lib/cjs/client/addon/preset.sb7.js +0 -19
  158. package/lib/cjs/client/web/142.js +0 -2
  159. package/lib/cjs/client/web/142.js.LICENSE.txt +0 -12
  160. package/lib/cjs/client/web/32.js +0 -1
  161. package/lib/cjs/client/web/551.js +0 -1
  162. package/lib/cjs/client/web/566.js +0 -2
  163. package/lib/cjs/client/web/566.js.LICENSE.txt +0 -31
  164. package/lib/cjs/client/web/691.js +0 -2
  165. package/lib/cjs/client/web/691.js.LICENSE.txt +0 -8
  166. package/lib/cjs/client/web/725.js +0 -1
  167. package/lib/cjs/server/extract.js +0 -46
  168. package/lib/cjs/server/loaders/babel/creevey-plugin.js +0 -86
  169. package/lib/cjs/server/loaders/babel/helpers.js +0 -469
  170. package/lib/cjs/server/loaders/babel/register.js +0 -124
  171. package/lib/cjs/server/loaders/hooks/mdx.js +0 -30
  172. package/lib/cjs/server/loaders/hooks/svelte.js +0 -65
  173. package/lib/cjs/server/loaders/webpack/compile.js +0 -269
  174. package/lib/cjs/server/loaders/webpack/creevey-loader.js +0 -172
  175. package/lib/cjs/server/loaders/webpack/dummy-hmr.js +0 -39
  176. package/lib/cjs/server/loaders/webpack/mdx-loader.js +0 -72
  177. package/lib/cjs/server/loaders/webpack/start.js +0 -41
  178. package/lib/cjs/server/storybook/entry.js +0 -53
  179. package/lib/cjs/server/storybook/helpers.js +0 -158
  180. package/lib/cjs/server/storybook/providers/nodejs.js +0 -239
  181. package/lib/esm/client/addon/preset.ie11.js +0 -59
  182. package/lib/esm/client/addon/preset.sb7.js +0 -8
  183. package/lib/esm/server/extract.js +0 -32
  184. package/lib/esm/server/loaders/babel/creevey-plugin.js +0 -72
  185. package/lib/esm/server/loaders/babel/helpers.js +0 -452
  186. package/lib/esm/server/loaders/babel/register.js +0 -103
  187. package/lib/esm/server/loaders/hooks/mdx.js +0 -15
  188. package/lib/esm/server/loaders/hooks/svelte.js +0 -49
  189. package/lib/esm/server/loaders/webpack/compile.js +0 -246
  190. package/lib/esm/server/loaders/webpack/creevey-loader.js +0 -152
  191. package/lib/esm/server/loaders/webpack/dummy-hmr.js +0 -32
  192. package/lib/esm/server/loaders/webpack/mdx-loader.js +0 -58
  193. package/lib/esm/server/loaders/webpack/start.js +0 -27
  194. package/lib/esm/server/storybook/entry.js +0 -27
  195. package/lib/esm/server/storybook/helpers.js +0 -97
  196. package/lib/esm/server/storybook/providers/nodejs.js +0 -216
  197. package/lib/types/client/addon/preset.ie11.d.ts +0 -10
  198. package/lib/types/client/addon/preset.sb7.d.ts +0 -2
  199. package/lib/types/server/extract.d.ts +0 -2
  200. package/lib/types/server/loaders/babel/creevey-plugin.d.ts +0 -1
  201. package/lib/types/server/loaders/babel/helpers.d.ts +0 -19
  202. package/lib/types/server/loaders/babel/register.d.ts +0 -5
  203. package/lib/types/server/loaders/hooks/mdx.d.ts +0 -1
  204. package/lib/types/server/loaders/hooks/svelte.d.ts +0 -1
  205. package/lib/types/server/loaders/webpack/compile.d.ts +0 -2
  206. package/lib/types/server/loaders/webpack/creevey-loader.d.ts +0 -4
  207. package/lib/types/server/loaders/webpack/dummy-hmr.d.ts +0 -10
  208. package/lib/types/server/loaders/webpack/mdx-loader.d.ts +0 -6
  209. package/lib/types/server/loaders/webpack/start.d.ts +0 -1
  210. package/lib/types/server/storybook/entry.d.ts +0 -17
  211. package/lib/types/server/storybook/helpers.d.ts +0 -24
  212. package/lib/types/server/storybook/providers/nodejs.d.ts +0 -9
  213. package/preset/ie11.js +0 -5
  214. package/preset/index.js +0 -9
  215. package/preset/sb7.js +0 -5
  216. package/types/mdx.d.ts +0 -7
@@ -4,98 +4,84 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.serializeRawStories = exports.deserializeStory = exports.deserializeRawStories = exports.denormalizeStoryParameters = exports.combineParameters = void 0;
7
-
8
7
  var _lodash = require("lodash");
9
-
10
8
  var _serializeRegExp = require("./serializeRegExp");
11
-
12
9
  // NOTE: Copy-paste from storybook/api
13
10
  const combineParameters = function () {
14
11
  for (var _len = arguments.length, parameterSets = new Array(_len), _key = 0; _key < _len; _key++) {
15
12
  parameterSets[_key] = arguments[_key];
16
13
  }
17
-
18
- return (// eslint-disable-next-line @typescript-eslint/no-unsafe-return
14
+ return (
15
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
19
16
  (0, _lodash.mergeWith)({}, ...parameterSets, (_, srcValue) => {
20
17
  // Treat arrays as scalars:
21
18
  if (Array.isArray(srcValue)) return srcValue;
22
19
  return undefined;
23
20
  })
24
21
  );
25
- }; // NOTE: Copy-paste from storybook/api
26
-
22
+ };
27
23
 
24
+ // NOTE: Copy-paste from storybook/api
28
25
  exports.combineParameters = combineParameters;
29
-
30
26
  const denormalizeStoryParameters = _ref => {
31
27
  let {
32
28
  globalParameters,
33
29
  kindParameters,
34
30
  stories
35
31
  } = _ref;
36
- return (0, _lodash.mapValues)(stories, storyData => {
37
- var _kindParameters$story;
38
-
39
- return { ...storyData,
40
- parameters: combineParameters(globalParameters, (_kindParameters$story = kindParameters[storyData.kind]) !== null && _kindParameters$story !== void 0 ? _kindParameters$story : {}, storyData.parameters)
41
- };
42
- });
32
+ return (0, _lodash.mapValues)(stories, storyData => ({
33
+ ...storyData,
34
+ parameters: combineParameters(globalParameters, kindParameters[storyData.kind] ?? {}, storyData.parameters)
35
+ }));
43
36
  };
44
-
45
37
  exports.denormalizeStoryParameters = denormalizeStoryParameters;
46
-
47
38
  const serializeRawStories = stories => {
48
39
  return (0, _lodash.mapValues)(stories, storyData => {
49
40
  const creevey = storyData.parameters.creevey;
50
-
51
- if (creevey !== null && creevey !== void 0 && creevey.skip) {
52
- return { ...storyData,
53
- parameters: { ...storyData.parameters,
54
- creevey: { ...creevey,
41
+ if (creevey?.skip) {
42
+ return {
43
+ ...storyData,
44
+ parameters: {
45
+ ...storyData.parameters,
46
+ creevey: {
47
+ ...creevey,
55
48
  skip: (0, _lodash.cloneDeepWith)(creevey.skip, value => {
56
49
  if ((0, _serializeRegExp.isRegExp)(value)) {
57
50
  return (0, _serializeRegExp.serializeRegExp)(value);
58
51
  }
59
-
60
52
  return undefined;
61
53
  })
62
54
  }
63
55
  }
64
56
  };
65
57
  }
66
-
67
58
  return storyData;
68
59
  });
69
60
  };
70
-
71
61
  exports.serializeRawStories = serializeRawStories;
72
-
73
62
  const deserializeRawStories = stories => {
74
63
  return (0, _lodash.mapValues)(stories, deserializeStory);
75
64
  };
76
-
77
65
  exports.deserializeRawStories = deserializeRawStories;
78
-
79
66
  const deserializeStory = story => {
80
67
  const creevey = story.parameters.creevey;
81
-
82
- if (creevey !== null && creevey !== void 0 && creevey.skip) {
83
- return { ...story,
84
- parameters: { ...story.parameters,
85
- creevey: { ...creevey,
68
+ if (creevey?.skip) {
69
+ return {
70
+ ...story,
71
+ parameters: {
72
+ ...story.parameters,
73
+ creevey: {
74
+ ...creevey,
86
75
  skip: (0, _lodash.cloneDeepWith)(creevey.skip, value => {
87
76
  if ((0, _serializeRegExp.isSerializedRegExp)(value)) {
88
77
  return (0, _serializeRegExp.deserializeRegExp)(value);
89
78
  }
90
-
91
79
  return undefined;
92
80
  })
93
81
  }
94
82
  }
95
83
  };
96
84
  }
97
-
98
85
  return story;
99
86
  };
100
-
101
87
  exports.deserializeStory = deserializeStory;
@@ -4,19 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.serializeRegExp = exports.isSerializedRegExp = exports.isRegExp = exports.deserializeRegExp = void 0;
7
-
8
7
  const isRegExp = exp => {
9
8
  return exp instanceof RegExp;
10
9
  };
11
-
12
10
  exports.isRegExp = isRegExp;
13
-
14
11
  const isSerializedRegExp = exp => {
15
12
  return typeof exp === 'object' && exp !== null && Reflect.get(exp, '__regexp') === true;
16
13
  };
17
-
18
14
  exports.isSerializedRegExp = isSerializedRegExp;
19
-
20
15
  const serializeRegExp = exp => {
21
16
  const {
22
17
  source,
@@ -28,9 +23,7 @@ const serializeRegExp = exp => {
28
23
  flags
29
24
  };
30
25
  };
31
-
32
26
  exports.serializeRegExp = serializeRegExp;
33
-
34
27
  const deserializeRegExp = _ref => {
35
28
  let {
36
29
  source,
@@ -38,5 +31,4 @@ const deserializeRegExp = _ref => {
38
31
  } = _ref;
39
32
  return new RegExp(source, flags);
40
33
  };
41
-
42
34
  exports.deserializeRegExp = deserializeRegExp;
package/lib/cjs/types.js CHANGED
@@ -16,60 +16,50 @@ exports.isTestMessage = isTestMessage;
16
16
  exports.isWebpackMessage = isWebpackMessage;
17
17
  exports.isWorkerMessage = isWorkerMessage;
18
18
  exports.noop = noop;
19
-
20
19
  /* eslint-disable @typescript-eslint/no-explicit-any */
21
20
 
22
21
  /* eslint-enable @typescript-eslint/no-explicit-any */
22
+
23
23
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
+
24
25
  function noop() {
25
26
  /* noop */
26
27
  }
27
-
28
28
  function isDefined(value) {
29
29
  return value !== null && value !== undefined;
30
30
  }
31
-
32
31
  function isTest(x) {
33
32
  return isDefined(x) && 'id' in x && 'storyId' in x && typeof x.id == 'string' && typeof x.storyId == 'string';
34
33
  }
35
-
36
34
  function isObject(x) {
37
35
  return typeof x == 'object' && x != null;
38
36
  }
39
-
40
37
  function isString(x) {
41
38
  return typeof x == 'string';
42
- } // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
-
39
+ }
44
40
 
41
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
42
  function isFunction(x) {
46
43
  return typeof x == 'function';
47
44
  }
48
-
49
45
  function isImageError(error) {
50
46
  return error instanceof Error && 'images' in error;
51
47
  }
52
-
53
48
  function isProcessMessage(message) {
54
49
  return isObject(message) && 'scope' in message;
55
50
  }
56
-
57
51
  function isWorkerMessage(message) {
58
52
  return isProcessMessage(message) && message.scope == 'worker';
59
53
  }
60
-
61
54
  function isStoriesMessage(message) {
62
55
  return isProcessMessage(message) && message.scope == 'stories';
63
56
  }
64
-
65
57
  function isTestMessage(message) {
66
58
  return isProcessMessage(message) && message.scope == 'test';
67
59
  }
68
-
69
60
  function isWebpackMessage(message) {
70
61
  return isProcessMessage(message) && message.scope == 'webpack';
71
62
  }
72
-
73
63
  function isDockerMessage(message) {
74
64
  return isProcessMessage(message) && message.scope == 'docker';
75
65
  }
package/lib/esm/cli.js CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- // eslint-disable-next-line node/shebang
3
2
 
3
+ // eslint-disable-next-line node/shebang
4
4
  require('./creevey');
@@ -1,5 +1,3 @@
1
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
-
3
1
  import { SET_STORIES, STORY_RENDERED } from '@storybook/core-events';
4
2
  import { denormalizeStoryParameters } from '../../shared';
5
3
  import { isDefined } from '../../types';
@@ -8,226 +6,165 @@ import { calcStatus } from '../shared/helpers';
8
6
  import { ADDON_ID } from './register';
9
7
  import { getEmojiByTestStatus } from './utils';
10
8
  export class CreeveyManager {
9
+ storyId = '';
10
+ activeBrowser = '';
11
+ selectedTestId = '';
12
+ status = {
13
+ isRunning: false,
14
+ tests: {},
15
+ browsers: []
16
+ };
17
+ creeveyApi = null;
18
+ stories = {};
19
+ updateStatusListeners = [];
20
+ changeTestListeners = [];
11
21
  constructor(storybookApi) {
12
22
  this.storybookApi = storybookApi;
13
-
14
- _defineProperty(this, "storyId", '');
15
-
16
- _defineProperty(this, "activeBrowser", '');
17
-
18
- _defineProperty(this, "selectedTestId", '');
19
-
20
- _defineProperty(this, "status", {
21
- isRunning: false,
22
- tests: {},
23
- browsers: []
24
- });
25
-
26
- _defineProperty(this, "creeveyApi", null);
27
-
28
- _defineProperty(this, "stories", {});
29
-
30
- _defineProperty(this, "updateStatusListeners", []);
31
-
32
- _defineProperty(this, "changeTestListeners", []);
33
-
34
- _defineProperty(this, "initAll", async () => {
35
- this.storybookApi.on(STORY_RENDERED, this.onStoryRendered);
36
- this.storybookApi.on(SET_STORIES, this.onSetStories);
37
- this.creeveyApi = await initCreeveyClientApi();
38
- this.creeveyApi.onUpdate(this.handleCreeveyUpdate);
39
- this.status = await this.creeveyApi.status;
40
- });
41
-
42
- _defineProperty(this, "handleCreeveyUpdate", update => {
43
- const {
44
- tests,
45
- removedTests = [],
46
- isRunning
47
- } = update;
48
-
49
- if (isDefined(isRunning)) {
50
- this.status.isRunning = isRunning;
51
- }
52
-
53
- if (isDefined(tests)) {
54
- const prevTests = this.status.tests;
55
- const prevStories = this.stories || {};
56
- Object.values(tests).filter(isDefined).forEach(update => {
57
- const {
58
- id,
59
- skip,
60
- status,
61
- results,
62
- approved,
63
- storyId
64
- } = update;
65
- const test = prevTests[id];
66
-
67
- if (!test) {
68
- return prevTests[id] = update;
69
- }
70
-
71
- if (isDefined(skip)) test.skip = skip;
72
-
73
- if (isDefined(status)) {
74
- test.status = status;
75
-
76
- if (isDefined(storyId) && isDefined(prevStories[storyId])) {
77
- const story = prevStories[storyId];
78
- const storyStatus = this.getStoryTests(storyId);
79
- const oldStatus = storyStatus.map(x => x.id === id ? status : x.status).reduce((oldStatus, newStatus) => calcStatus(oldStatus, newStatus), undefined);
80
- story.name = this.addStatusToStoryName(story.name, calcStatus(oldStatus, status), skip || false);
81
- }
82
- }
83
-
84
- if (isDefined(results)) test.results ? test.results.push(...results) : test.results = results;
85
-
86
- if (isDefined(approved)) {
87
- Object.entries(approved).forEach(_ref => {
88
- let [image, retry] = _ref;
89
- return retry !== undefined && test && ((test.approved = (test === null || test === void 0 ? void 0 : test.approved) || {})[image] = retry);
90
- });
91
- }
92
- });
93
- removedTests.forEach(_ref2 => {
94
- let {
95
- id
96
- } = _ref2;
97
- return delete prevTests[id];
98
- });
99
- this.status.tests = prevTests;
100
- this.stories = prevStories;
101
- this.setPanelsTitle();
102
- void this.storybookApi.setStories(this.stories);
103
- }
104
-
105
- this.updateStatusListeners.forEach(x => x(update));
106
- });
107
-
108
- _defineProperty(this, "getCurrentTest", () => {
109
- return this.status.tests[this.selectedTestId];
110
- });
111
-
112
- _defineProperty(this, "onStoryRendered", storyId => {
113
- if (this.storyId === '') void this.addStatusesToSideBar();
114
-
115
- if (this.storyId !== storyId) {
116
- var _this$getTestsByStory, _this$getTestsByStory2;
117
-
118
- this.storyId = storyId;
119
- this.selectedTestId = (_this$getTestsByStory = (_this$getTestsByStory2 = this.getTestsByStoryIdAndBrowser(this.activeBrowser)[0]) === null || _this$getTestsByStory2 === void 0 ? void 0 : _this$getTestsByStory2.id) !== null && _this$getTestsByStory !== void 0 ? _this$getTestsByStory : '';
120
- this.setPanelsTitle();
121
- this.changeTestListeners.forEach(x => x(this.selectedTestId));
122
- }
123
- });
124
-
125
- _defineProperty(this, "onStart", () => {
126
- var _this$creeveyApi;
127
-
128
- (_this$creeveyApi = this.creeveyApi) === null || _this$creeveyApi === void 0 ? void 0 : _this$creeveyApi.start([this.selectedTestId]);
129
- });
130
-
131
- _defineProperty(this, "onStop", () => {
132
- var _this$creeveyApi2;
133
-
134
- (_this$creeveyApi2 = this.creeveyApi) === null || _this$creeveyApi2 === void 0 ? void 0 : _this$creeveyApi2.stop();
135
- });
136
-
137
- _defineProperty(this, "onImageApprove", (id, retry, image) => {
138
- var _this$creeveyApi3;
139
-
140
- return (_this$creeveyApi3 = this.creeveyApi) === null || _this$creeveyApi3 === void 0 ? void 0 : _this$creeveyApi3.approve(id, retry, image);
141
- });
142
-
143
- _defineProperty(this, "onStartAllStoryTests", () => {
144
- var _this$creeveyApi4;
145
-
146
- const ids = Object.values(this.status.tests).filter(isDefined).filter(x => x.storyId === this.storyId).map(x => x.id);
147
- (_this$creeveyApi4 = this.creeveyApi) === null || _this$creeveyApi4 === void 0 ? void 0 : _this$creeveyApi4.start(ids);
148
- });
149
-
150
- _defineProperty(this, "onStartAllTests", () => {
151
- var _this$creeveyApi5;
152
-
153
- const ids = Object.values(this.status.tests).filter(isDefined).map(x => x.id);
154
- (_this$creeveyApi5 = this.creeveyApi) === null || _this$creeveyApi5 === void 0 ? void 0 : _this$creeveyApi5.start(ids);
155
- });
156
-
157
- _defineProperty(this, "onSetStories", data => {
158
- const stories = data.v ? denormalizeStoryParameters(data) : data.stories;
159
- this.stories = stories;
160
- });
161
-
162
- _defineProperty(this, "setActiveBrowser", browser => {
163
- var _this$getTestsByStory3, _this$getTestsByStory4;
164
-
165
- this.activeBrowser = browser;
166
- this.selectedTestId = (_this$getTestsByStory3 = (_this$getTestsByStory4 = this.getTestsByStoryIdAndBrowser(this.activeBrowser)[0]) === null || _this$getTestsByStory4 === void 0 ? void 0 : _this$getTestsByStory4.id) !== null && _this$getTestsByStory3 !== void 0 ? _this$getTestsByStory3 : '';
167
- this.changeTestListeners.forEach(x => x(this.selectedTestId));
168
- });
169
-
170
- _defineProperty(this, "setSelectedTestId", testId => {
171
- this.selectedTestId = testId;
172
- this.changeTestListeners.forEach(x => x(this.selectedTestId));
173
- });
174
-
175
- _defineProperty(this, "getStoryTests", storyId => {
176
- if (!this.status || !this.status.tests) return [];
177
- return Object.values(this.status.tests).filter(result => (result === null || result === void 0 ? void 0 : result.storyId) === storyId).filter(isDefined);
178
- });
179
-
180
- _defineProperty(this, "getBrowsers", () => {
181
- return this.status.browsers;
182
- });
183
-
184
- _defineProperty(this, "getTestsByStoryIdAndBrowser", browser => {
185
- return Object.values(this.status.tests).filter(x => (x === null || x === void 0 ? void 0 : x.browser) === browser && x.storyId === this.storyId).filter(isDefined);
186
- });
187
-
188
- _defineProperty(this, "getTabTitle", browser => {
189
- const tests = this.getTestsByStoryIdAndBrowser(browser);
190
- const browserStatus = tests.map(x => x && x.status).reduce((oldStatus, newStatus) => calcStatus(oldStatus, newStatus), undefined);
191
- const browserSkip = tests.length > 0 ? tests.every(x => x && x.skip) : false;
192
- const emojiStatus = getEmojiByTestStatus(browserStatus, browserSkip);
193
- return "".concat(emojiStatus ? "".concat(emojiStatus, " ") : '', "Creevey/").concat(browser);
194
- });
195
-
196
- _defineProperty(this, "setPanelsTitle", () => {
197
- var _this$storybookApi;
198
-
199
- const panels = (_this$storybookApi = this.storybookApi) === null || _this$storybookApi === void 0 ? void 0 : _this$storybookApi.getPanels();
200
- if (!panels) return;
201
- let firstPanelBrowser = this.activeBrowser;
202
-
203
- for (const p in panels) {
204
- var _panel$id;
205
-
206
- const panel = panels[p];
207
-
208
- if (((_panel$id = panel.id) === null || _panel$id === void 0 ? void 0 : _panel$id.indexOf(ADDON_ID)) === 0 && panel.paramKey) {
209
- panel.title = this.getTabTitle(panel.paramKey);
210
- if (!firstPanelBrowser) firstPanelBrowser = panel.paramKey;
211
- }
212
- }
213
-
214
- this.storybookApi.setSelectedPanel("".concat(ADDON_ID, "/panel/").concat(firstPanelBrowser));
215
- });
216
-
217
23
  this.storybookApi = storybookApi;
218
24
  }
219
-
25
+ initAll = async () => {
26
+ this.storybookApi.on(STORY_RENDERED, this.onStoryRendered);
27
+ this.storybookApi.on(SET_STORIES, this.onSetStories);
28
+ this.creeveyApi = await initCreeveyClientApi();
29
+ this.creeveyApi.onUpdate(this.handleCreeveyUpdate);
30
+ this.status = await this.creeveyApi.status;
31
+ };
220
32
  onUpdateStatus(listener) {
221
33
  this.updateStatusListeners.push(listener);
222
34
  return () => void (this.updateStatusListeners = this.updateStatusListeners.filter(x => x != listener));
223
35
  }
224
-
225
36
  onChangeTest(listener) {
226
37
  this.changeTestListeners.push(listener);
227
38
  return () => void (this.changeTestListeners = this.changeTestListeners.filter(x => x != listener));
228
39
  }
229
-
230
- async addStatusesToSideBar() {
40
+ handleCreeveyUpdate = update => {
41
+ const {
42
+ tests,
43
+ removedTests = [],
44
+ isRunning
45
+ } = update;
46
+ if (isDefined(isRunning)) {
47
+ this.status.isRunning = isRunning;
48
+ }
49
+ if (isDefined(tests)) {
50
+ const prevTests = this.status.tests;
51
+ const prevStories = this.stories || {};
52
+ Object.values(tests).filter(isDefined).forEach(update => {
53
+ const {
54
+ id,
55
+ skip,
56
+ status,
57
+ results,
58
+ approved,
59
+ storyId
60
+ } = update;
61
+ const test = prevTests[id];
62
+ if (!test) {
63
+ return prevTests[id] = update;
64
+ }
65
+ if (isDefined(skip)) test.skip = skip;
66
+ if (isDefined(status)) {
67
+ test.status = status;
68
+ if (isDefined(storyId) && isDefined(prevStories[storyId])) {
69
+ const story = prevStories[storyId];
70
+ const storyStatus = this.getStoryTests(storyId);
71
+ const oldStatus = storyStatus.map(x => x.id === id ? status : x.status).reduce((oldStatus, newStatus) => calcStatus(oldStatus, newStatus), undefined);
72
+ story.name = this.addStatusToStoryName(story.name, calcStatus(oldStatus, status), skip || false);
73
+ }
74
+ }
75
+ if (isDefined(results)) test.results ? test.results.push(...results) : test.results = results;
76
+ if (isDefined(approved)) {
77
+ Object.entries(approved).forEach(_ref => {
78
+ let [image, retry] = _ref;
79
+ return retry !== undefined && test && ((test.approved = test?.approved || {})[image] = retry);
80
+ });
81
+ }
82
+ });
83
+ removedTests.forEach(_ref2 => {
84
+ let {
85
+ id
86
+ } = _ref2;
87
+ return delete prevTests[id];
88
+ });
89
+ this.status.tests = prevTests;
90
+ this.stories = prevStories;
91
+ this.setPanelsTitle();
92
+ // TODO Check setStories method in 6.x and migrate properly
93
+ this.storybookApi.emit(SET_STORIES, this.stories);
94
+ }
95
+ this.updateStatusListeners.forEach(x => x(update));
96
+ };
97
+ getCurrentTest = () => {
98
+ return this.status.tests[this.selectedTestId];
99
+ };
100
+ onStoryRendered = storyId => {
101
+ if (this.storyId === '') this.addStatusesToSideBar();
102
+ if (this.storyId !== storyId) {
103
+ this.storyId = storyId;
104
+ this.selectedTestId = this.getTestsByStoryIdAndBrowser(this.activeBrowser)[0]?.id ?? '';
105
+ this.setPanelsTitle();
106
+ this.changeTestListeners.forEach(x => x(this.selectedTestId));
107
+ }
108
+ };
109
+ onStart = () => {
110
+ this.creeveyApi?.start([this.selectedTestId]);
111
+ };
112
+ onStop = () => {
113
+ this.creeveyApi?.stop();
114
+ };
115
+ onImageApprove = (id, retry, image) => this.creeveyApi?.approve(id, retry, image);
116
+ onStartAllStoryTests = () => {
117
+ const ids = Object.values(this.status.tests).filter(isDefined).filter(x => x.storyId === this.storyId).map(x => x.id);
118
+ this.creeveyApi?.start(ids);
119
+ };
120
+ onStartAllTests = () => {
121
+ const ids = Object.values(this.status.tests).filter(isDefined).map(x => x.id);
122
+ this.creeveyApi?.start(ids);
123
+ };
124
+ onSetStories = data => {
125
+ const stories = data.v ? denormalizeStoryParameters(data) : data.stories;
126
+ this.stories = stories;
127
+ };
128
+ setActiveBrowser = browser => {
129
+ this.activeBrowser = browser;
130
+ this.selectedTestId = this.getTestsByStoryIdAndBrowser(this.activeBrowser)[0]?.id ?? '';
131
+ this.changeTestListeners.forEach(x => x(this.selectedTestId));
132
+ };
133
+ setSelectedTestId = testId => {
134
+ this.selectedTestId = testId;
135
+ this.changeTestListeners.forEach(x => x(this.selectedTestId));
136
+ };
137
+ getStoryTests = storyId => {
138
+ if (!this.status || !this.status.tests) return [];
139
+ return Object.values(this.status.tests).filter(result => result?.storyId === storyId).filter(isDefined);
140
+ };
141
+ getBrowsers = () => {
142
+ return this.status.browsers;
143
+ };
144
+ getTestsByStoryIdAndBrowser = browser => {
145
+ return Object.values(this.status.tests).filter(x => x?.browser === browser && x.storyId === this.storyId).filter(isDefined);
146
+ };
147
+ getTabTitle = browser => {
148
+ const tests = this.getTestsByStoryIdAndBrowser(browser);
149
+ const browserStatus = tests.map(x => x && x.status).reduce((oldStatus, newStatus) => calcStatus(oldStatus, newStatus), undefined);
150
+ const browserSkip = tests.length > 0 ? tests.every(x => x && x.skip) : false;
151
+ const emojiStatus = getEmojiByTestStatus(browserStatus, browserSkip);
152
+ return `${emojiStatus ? `${emojiStatus} ` : ''}Creevey/${browser}`;
153
+ };
154
+ setPanelsTitle = () => {
155
+ const panels = this.storybookApi?.getPanels();
156
+ if (!panels) return;
157
+ let firstPanelBrowser = this.activeBrowser;
158
+ for (const p in panels) {
159
+ const panel = panels[p];
160
+ if (panel.id?.indexOf(ADDON_ID) === 0 && panel.paramKey) {
161
+ panel.title = this.getTabTitle(panel.paramKey);
162
+ if (!firstPanelBrowser) firstPanelBrowser = panel.paramKey;
163
+ }
164
+ }
165
+ this.storybookApi.setSelectedPanel(`${ADDON_ID}/panel/${firstPanelBrowser}`);
166
+ };
167
+ addStatusesToSideBar() {
231
168
  if (!Object.keys(this.stories).length) return;
232
169
  const stories = this.stories;
233
170
  Object.keys(this.stories).forEach(storyId => {
@@ -236,13 +173,13 @@ export class CreeveyManager {
236
173
  const skip = storyStatus.length > 0 ? storyStatus.every(x => x.skip) : false;
237
174
  this.stories[storyId].name = this.addStatusToStoryName(stories[storyId].name, status, skip);
238
175
  });
239
- await this.storybookApi.setStories(this.stories);
240
- }
241
176
 
177
+ // TODO Check setStories method in 6.x and migrate properly
178
+ this.storybookApi.emit(SET_STORIES, this.stories);
179
+ }
242
180
  addStatusToStoryName(name, status, skip) {
243
181
  name = name.replace(/^(❌|✔|🟡|🕗|⏸) /, '');
244
182
  const emojiStatus = getEmojiByTestStatus(status, skip);
245
- return "".concat(emojiStatus ? "".concat(emojiStatus, " ") : '', " ").concat(name);
183
+ return `${emojiStatus ? `${emojiStatus} ` : ''} ${name}`;
246
184
  }
247
-
248
185
  }
@@ -19,12 +19,10 @@ const TestSelectContainer = styled.div(_ref2 => {
19
19
  } = _ref2;
20
20
  return {
21
21
  padding: '8px',
22
- border: "1px solid ".concat(theme.appBorderColor)
22
+ border: `1px solid ${theme.appBorderColor}`
23
23
  };
24
24
  });
25
25
  export const Panel = _ref3 => {
26
- var _result$results, _result$results$lengt, _result$results2;
27
-
28
26
  let {
29
27
  tests,
30
28
  selectedTestId,
@@ -32,16 +30,16 @@ export const Panel = _ref3 => {
32
30
  onImageApprove
33
31
  } = _ref3;
34
32
  const result = tests.find(x => x.id === selectedTestId);
35
- const isRunning = (result === null || result === void 0 ? void 0 : result.status) === 'running';
33
+ const isRunning = result?.status === 'running';
36
34
  return /*#__PURE__*/React.createElement("div", null, tests.length > 1 && /*#__PURE__*/React.createElement(TestSelectContainer, null, /*#__PURE__*/React.createElement(TestSelect, {
37
35
  tests: tests,
38
36
  selectedTestId: selectedTestId,
39
37
  onChangeTest: onChangeTest
40
- })), isRunning && /*#__PURE__*/React.createElement(Loader, null), result !== null && result !== void 0 && (_result$results = result.results) !== null && _result$results !== void 0 && _result$results.length ? /*#__PURE__*/React.createElement(Wrapper, {
38
+ })), isRunning && /*#__PURE__*/React.createElement(Loader, null), result?.results?.length ? /*#__PURE__*/React.createElement(Wrapper, {
41
39
  isRunning: isRunning
42
40
  }, /*#__PURE__*/React.createElement(ResultsPage, {
43
41
  height: '100%',
44
- key: "".concat(result.id, "_").concat((_result$results$lengt = (_result$results2 = result.results) === null || _result$results2 === void 0 ? void 0 : _result$results2.length) !== null && _result$results$lengt !== void 0 ? _result$results$lengt : 0) // TODO
42
+ key: `${result.id}_${result.results?.length ?? 0}` // TODO
45
43
  ,
46
44
  id: result.id,
47
45
  path: getTestPath(result) // TODO Memo?