creevey 0.9.0-beta.1 → 0.9.0-beta.10.timeouts.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.
Files changed (221) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +9 -1
  3. package/addon/README.md +3 -0
  4. package/addon/package.json +5 -0
  5. package/docs/config.md +29 -26
  6. package/jest.config.js +6 -0
  7. package/lib/cjs/cli.js +5 -0
  8. package/lib/cjs/client/addon/Manager.js +264 -0
  9. package/lib/cjs/client/addon/components/Addon.js +55 -0
  10. package/lib/cjs/client/addon/components/Icons.js +46 -0
  11. package/lib/cjs/client/addon/components/Panel.js +72 -0
  12. package/lib/cjs/client/addon/components/TestSelect.js +65 -0
  13. package/lib/cjs/client/addon/components/Tools.js +95 -0
  14. package/lib/cjs/client/addon/decorator.js +11 -0
  15. package/lib/cjs/client/addon/index.js +31 -0
  16. package/lib/cjs/client/addon/preset.ie11.js +74 -0
  17. package/lib/cjs/client/addon/preset.js +17 -0
  18. package/lib/cjs/client/addon/preset.sb7.js +19 -0
  19. package/lib/cjs/client/addon/preview.js +14 -0
  20. package/lib/cjs/client/addon/readyForCapture.js +12 -0
  21. package/lib/cjs/client/addon/register.js +72 -0
  22. package/lib/cjs/client/addon/utils.js +42 -0
  23. package/lib/cjs/client/addon/withCreevey.js +351 -0
  24. package/lib/cjs/client/shared/components/ImagesView/BlendView.js +87 -0
  25. package/lib/cjs/client/shared/components/ImagesView/ImagesView.js +92 -0
  26. package/lib/cjs/client/shared/components/ImagesView/SideBySideView.js +154 -0
  27. package/lib/cjs/client/shared/components/ImagesView/SlideView.js +166 -0
  28. package/lib/cjs/client/shared/components/ImagesView/SwapView.js +91 -0
  29. package/lib/cjs/client/shared/components/ImagesView/index.js +45 -0
  30. package/lib/cjs/client/shared/components/PageFooter/PageFooter.js +50 -0
  31. package/lib/cjs/client/shared/components/PageFooter/Paging.js +94 -0
  32. package/lib/cjs/client/shared/components/PageHeader/ImagePreview.js +82 -0
  33. package/lib/cjs/client/shared/components/PageHeader/PageHeader.js +119 -0
  34. package/lib/cjs/client/shared/components/ResultsPage.js +143 -0
  35. package/lib/cjs/client/shared/creeveyClientApi.js +76 -0
  36. package/lib/cjs/client/shared/helpers.js +411 -0
  37. package/lib/cjs/client/shared/viewMode.js +17 -0
  38. package/lib/cjs/client/web/142.js +2 -0
  39. package/lib/cjs/client/web/142.js.LICENSE.txt +12 -0
  40. package/lib/cjs/client/web/32.js +1 -0
  41. package/lib/cjs/client/web/551.js +1 -0
  42. package/lib/cjs/client/web/566.js +2 -0
  43. package/lib/cjs/client/web/566.js.LICENSE.txt +31 -0
  44. package/lib/cjs/client/web/691.js +2 -0
  45. package/lib/cjs/client/web/691.js.LICENSE.txt +8 -0
  46. package/lib/cjs/client/web/725.js +1 -0
  47. package/lib/cjs/client/web/index.html +19 -0
  48. package/lib/cjs/client/web/main.js +2 -38
  49. package/lib/cjs/client/web/main.js.LICENSE.txt +49 -0
  50. package/lib/cjs/creevey.js +69 -0
  51. package/lib/cjs/index.js +62 -0
  52. package/lib/cjs/server/config.js +94 -0
  53. package/lib/cjs/server/docker.js +146 -0
  54. package/lib/cjs/server/extract.js +46 -0
  55. package/lib/cjs/server/index.js +83 -0
  56. package/lib/cjs/server/loaders/babel/creevey-plugin.js +86 -0
  57. package/lib/cjs/server/loaders/babel/helpers.js +469 -0
  58. package/lib/cjs/server/loaders/babel/register.js +124 -0
  59. package/lib/cjs/server/loaders/hooks/mdx.js +30 -0
  60. package/lib/cjs/server/loaders/hooks/svelte.js +65 -0
  61. package/lib/cjs/server/loaders/webpack/compile.js +269 -0
  62. package/lib/cjs/server/loaders/webpack/creevey-loader.js +172 -0
  63. package/lib/cjs/server/loaders/webpack/dummy-hmr.js +39 -0
  64. package/lib/cjs/server/loaders/webpack/mdx-loader.js +72 -0
  65. package/lib/cjs/server/loaders/webpack/start.js +41 -0
  66. package/lib/cjs/server/logger.js +48 -0
  67. package/lib/cjs/server/master/api.js +71 -0
  68. package/lib/cjs/server/master/index.js +146 -0
  69. package/lib/cjs/server/master/master.js +57 -0
  70. package/lib/cjs/server/master/pool.js +197 -0
  71. package/lib/cjs/server/master/runner.js +281 -0
  72. package/lib/cjs/server/master/server.js +131 -0
  73. package/lib/cjs/server/messages.js +264 -0
  74. package/lib/cjs/server/selenium/browser.js +671 -0
  75. package/lib/cjs/server/selenium/index.js +31 -0
  76. package/lib/cjs/server/selenium/selenoid.js +172 -0
  77. package/lib/cjs/server/stories.js +153 -0
  78. package/lib/cjs/server/storybook/entry.js +53 -0
  79. package/lib/cjs/server/storybook/helpers.js +158 -0
  80. package/lib/cjs/server/storybook/providers/browser.js +74 -0
  81. package/lib/cjs/server/storybook/providers/hybrid.js +82 -0
  82. package/lib/cjs/server/storybook/providers/nodejs.js +239 -0
  83. package/lib/cjs/server/testsFiles/parser.js +72 -0
  84. package/lib/cjs/server/testsFiles/register.js +44 -0
  85. package/lib/cjs/server/update.js +79 -0
  86. package/lib/cjs/server/utils.js +176 -0
  87. package/lib/cjs/server/worker/chai-image.js +142 -0
  88. package/lib/cjs/server/worker/helpers.js +69 -0
  89. package/lib/cjs/server/worker/index.js +15 -0
  90. package/lib/cjs/server/worker/reporter.js +108 -0
  91. package/lib/cjs/server/worker/worker.js +268 -0
  92. package/lib/cjs/shared/index.js +101 -0
  93. package/lib/cjs/shared/serializeRegExp.js +42 -0
  94. package/lib/cjs/types.js +75 -0
  95. package/lib/esm/cli.js +4 -0
  96. package/lib/esm/client/addon/Manager.js +248 -0
  97. package/lib/esm/client/addon/components/Addon.js +39 -0
  98. package/lib/esm/client/addon/components/Icons.js +31 -0
  99. package/lib/esm/client/addon/components/Panel.js +53 -0
  100. package/lib/esm/client/addon/components/TestSelect.js +51 -0
  101. package/lib/esm/client/addon/components/Tools.js +74 -0
  102. package/lib/esm/client/addon/decorator.js +2 -0
  103. package/lib/esm/client/addon/index.js +2 -0
  104. package/lib/esm/client/addon/preset.ie11.js +59 -0
  105. package/lib/esm/client/addon/preset.js +8 -0
  106. package/lib/esm/client/addon/preset.sb7.js +8 -0
  107. package/lib/esm/client/addon/preview.js +5 -0
  108. package/lib/esm/client/addon/readyForCapture.js +5 -0
  109. package/lib/esm/client/addon/register.js +51 -0
  110. package/lib/esm/client/addon/utils.js +32 -0
  111. package/lib/esm/client/addon/withCreevey.js +325 -0
  112. package/lib/esm/client/shared/components/ImagesView/BlendView.js +67 -0
  113. package/lib/esm/client/shared/components/ImagesView/ImagesView.js +69 -0
  114. package/lib/esm/client/shared/components/ImagesView/SideBySideView.js +131 -0
  115. package/lib/esm/client/shared/components/ImagesView/SlideView.js +143 -0
  116. package/lib/esm/client/shared/components/ImagesView/SwapView.js +71 -0
  117. package/lib/esm/client/shared/components/ImagesView/index.js +5 -0
  118. package/lib/esm/client/shared/components/PageFooter/PageFooter.js +36 -0
  119. package/lib/esm/client/shared/components/PageFooter/Paging.js +80 -0
  120. package/lib/esm/client/shared/components/PageHeader/ImagePreview.js +68 -0
  121. package/lib/esm/client/shared/components/PageHeader/PageHeader.js +97 -0
  122. package/lib/esm/client/shared/components/ResultsPage.js +115 -0
  123. package/lib/esm/client/shared/creeveyClientApi.js +67 -0
  124. package/lib/esm/client/shared/helpers.js +353 -0
  125. package/lib/esm/client/shared/viewMode.js +6 -0
  126. package/lib/esm/creevey.js +54 -0
  127. package/lib/esm/index.js +5 -0
  128. package/lib/esm/server/config.js +71 -0
  129. package/lib/esm/server/docker.js +123 -0
  130. package/lib/esm/server/extract.js +32 -0
  131. package/lib/esm/server/index.js +64 -0
  132. package/lib/esm/server/loaders/babel/creevey-plugin.js +72 -0
  133. package/lib/esm/server/loaders/babel/helpers.js +452 -0
  134. package/lib/esm/server/loaders/babel/register.js +103 -0
  135. package/lib/esm/server/loaders/hooks/mdx.js +15 -0
  136. package/lib/esm/server/loaders/hooks/svelte.js +49 -0
  137. package/lib/esm/server/loaders/webpack/compile.js +246 -0
  138. package/lib/esm/server/loaders/webpack/creevey-loader.js +152 -0
  139. package/lib/esm/server/loaders/webpack/dummy-hmr.js +32 -0
  140. package/lib/esm/server/loaders/webpack/mdx-loader.js +58 -0
  141. package/lib/esm/server/loaders/webpack/start.js +27 -0
  142. package/lib/esm/server/logger.js +20 -0
  143. package/lib/esm/server/master/api.js +60 -0
  144. package/lib/esm/server/master/index.js +125 -0
  145. package/lib/esm/server/master/master.js +38 -0
  146. package/lib/esm/server/master/pool.js +176 -0
  147. package/lib/esm/server/master/runner.js +259 -0
  148. package/lib/esm/server/master/server.js +107 -0
  149. package/lib/esm/server/messages.js +232 -0
  150. package/lib/esm/server/selenium/browser.js +638 -0
  151. package/lib/esm/server/selenium/index.js +2 -0
  152. package/lib/esm/server/selenium/selenoid.js +149 -0
  153. package/lib/esm/server/stories.js +135 -0
  154. package/lib/esm/server/storybook/entry.js +27 -0
  155. package/lib/esm/server/storybook/helpers.js +97 -0
  156. package/lib/esm/server/storybook/providers/browser.js +58 -0
  157. package/lib/esm/server/storybook/providers/hybrid.js +60 -0
  158. package/lib/esm/server/storybook/providers/nodejs.js +216 -0
  159. package/lib/esm/server/testsFiles/parser.js +50 -0
  160. package/lib/esm/server/testsFiles/register.js +31 -0
  161. package/lib/esm/server/update.js +61 -0
  162. package/lib/esm/server/utils.js +133 -0
  163. package/lib/esm/server/worker/chai-image.js +130 -0
  164. package/lib/esm/server/worker/helpers.js +60 -0
  165. package/lib/esm/server/worker/index.js +1 -0
  166. package/lib/esm/server/worker/reporter.js +86 -0
  167. package/lib/esm/server/worker/worker.js +238 -0
  168. package/lib/esm/shared/index.js +78 -0
  169. package/lib/esm/shared/serializeRegExp.js +24 -0
  170. package/lib/esm/types.js +44 -0
  171. package/lib/types/client/addon/Manager.d.ts +2 -2
  172. package/lib/types/client/addon/components/TestSelect.d.ts +0 -1
  173. package/lib/types/client/addon/index.d.ts +2 -0
  174. package/lib/types/client/addon/preset.d.ts +0 -22
  175. package/lib/types/client/addon/preset.ie11.d.ts +10 -0
  176. package/lib/types/client/addon/preset.sb7.d.ts +2 -0
  177. package/lib/types/client/addon/preview.d.ts +4 -0
  178. package/lib/types/client/addon/utils.d.ts +1 -0
  179. package/lib/types/client/addon/withCreevey.d.ts +1 -1
  180. package/lib/types/client/shared/components/ImagesView/BlendView.d.ts +1 -1
  181. package/lib/types/client/shared/components/ImagesView/ImagesView.d.ts +0 -1
  182. package/lib/types/client/shared/components/ImagesView/SideBySideView.d.ts +1 -1
  183. package/lib/types/client/shared/components/ImagesView/SlideView.d.ts +1 -1
  184. package/lib/types/client/shared/components/ImagesView/SwapView.d.ts +1 -1
  185. package/lib/types/client/shared/components/PageFooter/PageFooter.d.ts +0 -1
  186. package/lib/types/client/shared/components/PageFooter/Paging.d.ts +0 -1
  187. package/lib/types/client/shared/components/PageHeader/ImagePreview.d.ts +1 -1
  188. package/lib/types/client/shared/components/PageHeader/PageHeader.d.ts +0 -1
  189. package/lib/types/client/shared/components/ResultsPage.d.ts +1 -1
  190. package/lib/types/client/web/CreeveyApp.d.ts +0 -1
  191. package/lib/types/client/web/CreeveyLoader.d.ts +1 -2
  192. package/lib/types/client/web/CreeveyView/SideBar/Checkbox.d.ts +1 -1
  193. package/lib/types/client/web/CreeveyView/SideBar/SideBarHeader.d.ts +0 -1
  194. package/lib/types/client/web/CreeveyView/SideBar/SuiteLink.d.ts +4 -4
  195. package/lib/types/client/web/CreeveyView/SideBar/TestLink.d.ts +0 -1
  196. package/lib/types/client/web/CreeveyView/SideBar/TestStatusIcon.d.ts +1 -1
  197. package/lib/types/client/web/CreeveyView/SideBar/TestsStatus.d.ts +1 -1
  198. package/lib/types/index.d.ts +1 -0
  199. package/lib/types/server/loaders/babel/register.d.ts +1 -1
  200. package/lib/types/server/loaders/webpack/creevey-loader.d.ts +4 -2
  201. package/lib/types/server/logger.d.ts +6 -2
  202. package/lib/types/server/messages.d.ts +14 -12
  203. package/lib/types/server/selenium/browser.d.ts +5 -3
  204. package/lib/types/server/storybook/entry.d.ts +2 -3
  205. package/lib/types/server/storybook/helpers.d.ts +1 -1
  206. package/lib/types/server/storybook/providers/browser.d.ts +2 -4
  207. package/lib/types/server/storybook/providers/hybrid.d.ts +2 -4
  208. package/lib/types/server/storybook/providers/nodejs.d.ts +3 -3
  209. package/lib/types/server/utils.d.ts +5 -1
  210. package/lib/types/{shared.d.ts → shared/index.d.ts} +1 -10
  211. package/lib/types/shared/serializeRegExp.d.ts +9 -0
  212. package/lib/types/types.d.ts +4 -7
  213. package/package.json +117 -103
  214. package/preset/ie11.js +5 -0
  215. package/{preset.js → preset/index.js} +2 -2
  216. package/preset/sb7.js +5 -0
  217. package/types/global.d.ts +5 -0
  218. package/types/mdx.d.ts +3 -2
  219. package/lib/cjs/client/web/1.js +0 -13
  220. package/lib/cjs/client/web/2.js +0 -1
  221. package/storybook-static/stories.json +0 -21
@@ -0,0 +1,248 @@
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
+ import { SET_STORIES, STORY_RENDERED } from '@storybook/core-events';
4
+ import { denormalizeStoryParameters } from '../../shared';
5
+ import { isDefined } from '../../types';
6
+ import { initCreeveyClientApi } from '../shared/creeveyClientApi';
7
+ import { calcStatus } from '../shared/helpers';
8
+ import { ADDON_ID } from './register';
9
+ import { getEmojiByTestStatus } from './utils';
10
+ export class CreeveyManager {
11
+ constructor(storybookApi) {
12
+ 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
+ this.storybookApi = storybookApi;
218
+ }
219
+
220
+ onUpdateStatus(listener) {
221
+ this.updateStatusListeners.push(listener);
222
+ return () => void (this.updateStatusListeners = this.updateStatusListeners.filter(x => x != listener));
223
+ }
224
+
225
+ onChangeTest(listener) {
226
+ this.changeTestListeners.push(listener);
227
+ return () => void (this.changeTestListeners = this.changeTestListeners.filter(x => x != listener));
228
+ }
229
+
230
+ async addStatusesToSideBar() {
231
+ if (!Object.keys(this.stories).length) return;
232
+ const stories = this.stories;
233
+ Object.keys(this.stories).forEach(storyId => {
234
+ const storyStatus = this.getStoryTests(storyId);
235
+ const status = storyStatus.map(x => x.status).reduce((oldStatus, newStatus) => calcStatus(oldStatus, newStatus), undefined);
236
+ const skip = storyStatus.length > 0 ? storyStatus.every(x => x.skip) : false;
237
+ this.stories[storyId].name = this.addStatusToStoryName(stories[storyId].name, status, skip);
238
+ });
239
+ await this.storybookApi.setStories(this.stories);
240
+ }
241
+
242
+ addStatusToStoryName(name, status, skip) {
243
+ name = name.replace(/^(❌|✔|🟡|🕗|⏸) /, '');
244
+ const emojiStatus = getEmojiByTestStatus(status, skip);
245
+ return "".concat(emojiStatus ? "".concat(emojiStatus, " ") : '', " ").concat(name);
246
+ }
247
+
248
+ }
@@ -0,0 +1,39 @@
1
+ import { Placeholder } from '@storybook/components';
2
+ import React, { useEffect, useState } from 'react';
3
+ import { Panel } from './Panel';
4
+ export const Addon = _ref => {
5
+ let {
6
+ active,
7
+ browser,
8
+ manager
9
+ } = _ref;
10
+ const [tests, setTests] = useState([]);
11
+ const [selectedTestId, setSelectedTestId] = useState(manager.selectedTestId);
12
+ useEffect(() => {
13
+ if (active) {
14
+ manager.setActiveBrowser(browser);
15
+ const browserTests = manager.getTestsByStoryIdAndBrowser(manager.activeBrowser);
16
+ setTests(browserTests);
17
+ }
18
+ }, [active, browser, manager]);
19
+ useEffect(() => {
20
+ const unsubscribe = manager.onChangeTest(testId => {
21
+ setSelectedTestId(testId);
22
+ const status = manager.getTestsByStoryIdAndBrowser(manager.activeBrowser);
23
+ setTests(status);
24
+ });
25
+ return unsubscribe;
26
+ }, [manager]);
27
+ useEffect(() => {
28
+ const unsubscribe = manager.onUpdateStatus(() => {
29
+ setTests(manager.getTestsByStoryIdAndBrowser(manager.activeBrowser));
30
+ });
31
+ return unsubscribe;
32
+ }, [manager, browser]);
33
+ return active ? tests.length ? /*#__PURE__*/React.createElement(Panel, {
34
+ tests: tests,
35
+ selectedTestId: selectedTestId,
36
+ onChangeTest: manager.setSelectedTestId,
37
+ onImageApprove: manager.onImageApprove
38
+ }) : /*#__PURE__*/React.createElement(Placeholder, null, "No test results") : null;
39
+ };
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ export const NextIcon = _ref => {
3
+ let {
4
+ width,
5
+ height
6
+ } = _ref;
7
+ return /*#__PURE__*/React.createElement("svg", {
8
+ version: "1.1",
9
+ width: width,
10
+ height: height,
11
+ viewBox: "0 0 306 306"
12
+ }, /*#__PURE__*/React.createElement("path", {
13
+ d: "M0,306l216.75-153L0,0V306z M255,0v306h51V0H255z",
14
+ fill: "currentColor"
15
+ }));
16
+ };
17
+ export const ForwardIcon = _ref2 => {
18
+ let {
19
+ width,
20
+ height
21
+ } = _ref2;
22
+ return /*#__PURE__*/React.createElement("svg", {
23
+ version: "1.1",
24
+ width: width,
25
+ height: height,
26
+ viewBox: "0 0 512 512"
27
+ }, /*#__PURE__*/React.createElement("path", {
28
+ fill: "currentColor",
29
+ d: "M460.9,246.8l-209-164.2c-7.8-6.1-19.2-0.6-19.2,9.2v328.4c0,9.8,11.4,15.3,19.2,9.2l209-164.2c5.1-4,6-11.4,2-16.5 C462.4,248,461.7,247.3,460.9,246.8L460.9,246.8z M228.2,246.8L19.2,82.5C11.4,76.4,0,82,0,91.8v328.4c0,9.8,11.4,15.3,19.2,9.2 l209-164.2c3-2.3,4.5-5.8,4.5-9.2C232.7,252.6,231.2,249.1,228.2,246.8z M507.3,64h-37.2c-2.5,0-4.7,2-4.7,4.4v375.3 c0,2.4,2.1,4.4,4.7,4.4h37.2c2.5,0,4.7-2,4.7-4.4V68.4C512,66,509.9,64,507.3,64z"
30
+ }));
31
+ };
@@ -0,0 +1,53 @@
1
+ import React from 'react';
2
+ import { Loader } from '@storybook/components';
3
+ import { ResultsPage } from '../../shared/components/ResultsPage';
4
+ import { styled } from '@storybook/theming';
5
+ import { getTestPath } from '../../shared/helpers';
6
+ import TestSelect from './TestSelect';
7
+ const Wrapper = styled.div(_ref => {
8
+ let {
9
+ isRunning
10
+ } = _ref;
11
+ return {
12
+ opacity: isRunning ? 0.5 : 1,
13
+ height: '100%'
14
+ };
15
+ });
16
+ const TestSelectContainer = styled.div(_ref2 => {
17
+ let {
18
+ theme
19
+ } = _ref2;
20
+ return {
21
+ padding: '8px',
22
+ border: "1px solid ".concat(theme.appBorderColor)
23
+ };
24
+ });
25
+ export const Panel = _ref3 => {
26
+ var _result$results, _result$results$lengt, _result$results2;
27
+
28
+ let {
29
+ tests,
30
+ selectedTestId,
31
+ onChangeTest,
32
+ onImageApprove
33
+ } = _ref3;
34
+ const result = tests.find(x => x.id === selectedTestId);
35
+ const isRunning = (result === null || result === void 0 ? void 0 : result.status) === 'running';
36
+ return /*#__PURE__*/React.createElement("div", null, tests.length > 1 && /*#__PURE__*/React.createElement(TestSelectContainer, null, /*#__PURE__*/React.createElement(TestSelect, {
37
+ tests: tests,
38
+ selectedTestId: selectedTestId,
39
+ 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, {
41
+ isRunning: isRunning
42
+ }, /*#__PURE__*/React.createElement(ResultsPage, {
43
+ 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
45
+ ,
46
+ id: result.id,
47
+ path: getTestPath(result) // TODO Memo?
48
+ ,
49
+ results: result.results,
50
+ approved: result.approved,
51
+ onImageApprove: onImageApprove
52
+ })) : null);
53
+ };
@@ -0,0 +1,51 @@
1
+ import { Button, Icons, TooltipLinkList, WithTooltip } from '@storybook/components';
2
+ import { styled } from '@storybook/theming';
3
+ import React from 'react';
4
+ import { getEmojiByTestStatus } from '../utils';
5
+ const LinkIconContainer = styled.span(_ref => {
6
+ let {
7
+ theme
8
+ } = _ref;
9
+ return {
10
+ display: 'inline-block',
11
+ width: '20px',
12
+ color: theme.color.defaultText,
13
+ textAlign: 'center'
14
+ };
15
+ });
16
+ export default function TestSelect(props) {
17
+ var _props$tests$find$tes, _props$tests$find;
18
+
19
+ const testName = (_props$tests$find$tes = (_props$tests$find = props.tests.find(x => x.id === props.selectedTestId)) === null || _props$tests$find === void 0 ? void 0 : _props$tests$find.testName) !== null && _props$tests$find$tes !== void 0 ? _props$tests$find$tes : '';
20
+ return /*#__PURE__*/React.createElement(WithTooltip, {
21
+ trigger: "click",
22
+ placement: "bottom",
23
+ closeOnClick: true,
24
+ tooltip: _ref2 => {
25
+ let {
26
+ onHide
27
+ } = _ref2;
28
+ return /*#__PURE__*/React.createElement(TooltipLinkList, {
29
+ links: props.tests.map(x => {
30
+ var _x$testName;
31
+
32
+ return {
33
+ id: x.id,
34
+ title: (_x$testName = x.testName) !== null && _x$testName !== void 0 ? _x$testName : '',
35
+ active: props.selectedTestId === x.id,
36
+ onClick: () => {
37
+ props.onChangeTest(x.id);
38
+ onHide();
39
+ },
40
+ left: /*#__PURE__*/React.createElement(LinkIconContainer, null, getEmojiByTestStatus(x.status, x.skip))
41
+ };
42
+ })
43
+ });
44
+ }
45
+ }, /*#__PURE__*/React.createElement(Button, {
46
+ outline: true,
47
+ small: true
48
+ }, /*#__PURE__*/React.createElement(Icons, {
49
+ icon: "menu"
50
+ }), testName));
51
+ }
@@ -0,0 +1,74 @@
1
+ import React, { Fragment, useState, useEffect } from 'react';
2
+ import { IconButton, Icons, Separator } from '@storybook/components';
3
+ import { ForwardIcon, NextIcon } from './Icons';
4
+ import { stringify } from 'qs';
5
+ import { styled } from '@storybook/theming';
6
+ import { isDefined } from '../../../types';
7
+ import { getTestPath, useForceUpdate } from '../../shared/helpers';
8
+ const Button = styled(IconButton)({
9
+ '&:disabled': {
10
+ opacity: 0.5,
11
+ cursor: 'default'
12
+ },
13
+ '&:disabled:hover': {
14
+ color: 'inherit'
15
+ }
16
+ });
17
+ export const Tools = _ref => {
18
+ let {
19
+ manager
20
+ } = _ref;
21
+ const [buttonClicked, setButtonClicked] = useState();
22
+ const [isRunning, setRunning] = useState(manager.status.isRunning);
23
+ const forceUpdate = useForceUpdate();
24
+ const test = manager.getCurrentTest();
25
+ useEffect(() => {
26
+ const unsubscribe = manager.onChangeTest(() => {
27
+ forceUpdate();
28
+ });
29
+ return unsubscribe;
30
+ }, [manager, forceUpdate]);
31
+ useEffect(() => {
32
+ const unsubscribe = manager.onUpdateStatus(_ref2 => {
33
+ let {
34
+ isRunning
35
+ } = _ref2;
36
+ if (isDefined(isRunning)) setRunning(isRunning);
37
+ });
38
+ return unsubscribe;
39
+ }, [manager]);
40
+ if (!test) return null;
41
+
42
+ function renderButton(type, title, onClick, icon) {
43
+ const handleClick = () => {
44
+ setButtonClicked(type);
45
+ onClick();
46
+ };
47
+
48
+ const disabled = isRunning && buttonClicked != null && buttonClicked !== type;
49
+ return /*#__PURE__*/React.createElement(Button, {
50
+ onClick: () => {
51
+ isRunning ? manager.onStop() : handleClick();
52
+ },
53
+ title: disabled ? '' : title,
54
+ disabled: disabled
55
+ }, buttonClicked === type && isRunning ? /*#__PURE__*/React.createElement(Icons, {
56
+ icon: 'stop'
57
+ }) : icon);
58
+ }
59
+
60
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(IconButton, {
61
+ href: "http://localhost:".concat(__CREEVEY_CLIENT_PORT__ || __CREEVEY_SERVER_PORT__ || 3000, "/?").concat(stringify({
62
+ testPath: getTestPath(test)
63
+ })),
64
+ target: "_blank",
65
+ title: "Show in Creevey UI"
66
+ }, /*#__PURE__*/React.createElement(Icons, {
67
+ icon: "sharealt"
68
+ })), /*#__PURE__*/React.createElement(Separator, null), renderButton('RunAll', 'Run all', manager.onStartAllTests, /*#__PURE__*/React.createElement(ForwardIcon, null)), renderButton('RunStoryTests', 'Run all story tests', manager.onStartAllStoryTests, /*#__PURE__*/React.createElement(NextIcon, {
69
+ width: 15,
70
+ height: 11
71
+ })), renderButton('RunTest', 'Run', manager.onStart, /*#__PURE__*/React.createElement(Icons, {
72
+ icon: "play"
73
+ })));
74
+ };
@@ -0,0 +1,2 @@
1
+ import { withCreevey } from './withCreevey';
2
+ export const decorators = [withCreevey()];
@@ -0,0 +1,2 @@
1
+ export * from './withCreevey';
2
+ export * from './readyForCapture';
@@ -0,0 +1,59 @@
1
+ const ie11Preset = ['@babel/preset-env', {
2
+ targets: {
3
+ ie: '11'
4
+ }
5
+ }];
6
+ export const babel = config => {
7
+ const {
8
+ presets = []
9
+ } = config;
10
+ return { ...config,
11
+ presets: [...(presets || []), ie11Preset]
12
+ };
13
+ };
14
+ const nodeModulesThatNeedToBeParsedBecauseTheyExposeES6 = ['creevey', '@testing-library'];
15
+ const include = new RegExp("[\\\\/](".concat(nodeModulesThatNeedToBeParsedBecauseTheyExposeES6.join('|'), ")"));
16
+ const es6Loader = {
17
+ test: /\.js$/,
18
+ use: [{
19
+ loader: require.resolve('babel-loader'),
20
+ options: {
21
+ presets: [ie11Preset]
22
+ }
23
+ }],
24
+ include
25
+ };
26
+ export const managerWebpack = function () {
27
+ var _webpackConfig$module, _webpackConfig$module2;
28
+
29
+ let webpackConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
30
+ return { ...webpackConfig,
31
+ module: { ...webpackConfig.module,
32
+ rules: [...((_webpackConfig$module = (_webpackConfig$module2 = webpackConfig.module) === null || _webpackConfig$module2 === void 0 ? void 0 : _webpackConfig$module2.rules) !== null && _webpackConfig$module !== void 0 ? _webpackConfig$module : []), es6Loader]
33
+ }
34
+ };
35
+ };
36
+ export const webpack = function () {
37
+ var _webpackConfig$module3, _webpackConfig$module4;
38
+
39
+ let webpackConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
40
+ const {
41
+ entry
42
+ } = webpackConfig;
43
+ const polyfills = [require.resolve('whatwg-fetch')];
44
+
45
+ if (Array.isArray(entry)) {
46
+ polyfills.forEach(polyfill => {
47
+ if (!entry.includes(polyfill)) {
48
+ entry.unshift(polyfill);
49
+ }
50
+ });
51
+ }
52
+
53
+ return { ...webpackConfig,
54
+ entry,
55
+ module: { ...webpackConfig.module,
56
+ rules: [...((_webpackConfig$module3 = (_webpackConfig$module4 = webpackConfig.module) === null || _webpackConfig$module4 === void 0 ? void 0 : _webpackConfig$module4.rules) !== null && _webpackConfig$module3 !== void 0 ? _webpackConfig$module3 : []), es6Loader]
57
+ }
58
+ };
59
+ };
@@ -0,0 +1,8 @@
1
+ export function config() {
2
+ let entry = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
3
+ return [...entry, require.resolve('./decorator')];
4
+ }
5
+ export function managerEntries() {
6
+ let entry = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
7
+ return [...entry, require.resolve('./register')];
8
+ }
@@ -0,0 +1,8 @@
1
+ export const previewAnnotations = function () {
2
+ let entry = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
3
+ return [...entry, require.resolve('./preview')];
4
+ };
5
+ export function managerEntries() {
6
+ let entry = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
7
+ return [...entry, require.resolve('./register')];
8
+ }
@@ -0,0 +1,5 @@
1
+ import { withCreevey } from './withCreevey';
2
+ const preview = {
3
+ decorators: [withCreevey()]
4
+ };
5
+ export default preview;
@@ -0,0 +1,5 @@
1
+ export function readyForCapture() {
2
+ var _window$__CREEVEY_SET, _window;
3
+
4
+ (_window$__CREEVEY_SET = (_window = window).__CREEVEY_SET_READY_FOR_CAPTURE__) === null || _window$__CREEVEY_SET === void 0 ? void 0 : _window$__CREEVEY_SET.call(_window);
5
+ }
@@ -0,0 +1,51 @@
1
+ import { addons, types } from '@storybook/addons';
2
+ import React from 'react';
3
+ import { Addon } from './components/Addon';
4
+ import { Tools } from './components/Tools';
5
+ import { CreeveyManager } from './Manager';
6
+ export const ADDON_ID = 'creevey';
7
+ addons.register(ADDON_ID, api => {
8
+ void registerCreeveyPanels(api);
9
+ });
10
+ export async function registerCreeveyPanels(storybookApi) {
11
+ const manager = new CreeveyManager(storybookApi);
12
+ addons.addPanel("".concat(ADDON_ID, "/panel/run"), {
13
+ title: "Creevey/Run",
14
+ match: _ref => {
15
+ let {
16
+ viewMode
17
+ } = _ref;
18
+ return !!(viewMode && /^story$/.exec(viewMode));
19
+ },
20
+ type: types.TOOL,
21
+ // eslint-disable-next-line react/display-name
22
+ render: () => /*#__PURE__*/React.createElement(Tools, {
23
+ manager
24
+ })
25
+ });
26
+ await manager.initAll();
27
+ const browsers = manager.getBrowsers();
28
+ browsers.forEach(browser => {
29
+ const panelId = "".concat(ADDON_ID, "/panel/").concat(browser);
30
+ const title = manager.getTabTitle(browser);
31
+ addons.addPanel(panelId, {
32
+ title,
33
+ type: types.PANEL,
34
+ paramKey: browser,
35
+ // NOTE key = PANEL_ID needs to correct render button in addons panel
36
+ // eslint-disable-next-line react/display-name
37
+ render: _ref2 => {
38
+ let {
39
+ active,
40
+ key
41
+ } = _ref2;
42
+ return /*#__PURE__*/React.createElement(Addon, {
43
+ active,
44
+ key,
45
+ manager,
46
+ browser
47
+ });
48
+ }
49
+ });
50
+ });
51
+ }
@@ -0,0 +1,32 @@
1
+ export function getEmojiByTestStatus(status) {
2
+ let skip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
3
+
4
+ switch (status) {
5
+ case 'failed':
6
+ {
7
+ return '❌';
8
+ }
9
+
10
+ case 'success':
11
+ {
12
+ return '✔';
13
+ }
14
+
15
+ case 'running':
16
+ {
17
+ return '🟡';
18
+ }
19
+
20
+ case 'pending':
21
+ {
22
+ return '🕗';
23
+ }
24
+
25
+ default:
26
+ {
27
+ if (skip) return '⏸';
28
+ return '';
29
+ }
30
+ }
31
+ }
32
+ export const isInternetExplorer = navigator.userAgent.includes('Trident/');