creevey 0.8.1-sb7.1 → 0.8.1-sb7.2

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 (235) hide show
  1. package/lib/cjs/cli.js +5 -0
  2. package/lib/cjs/client/addon/Manager.js +264 -0
  3. package/lib/cjs/client/addon/components/Addon.js +55 -0
  4. package/lib/cjs/client/addon/components/Icons.js +46 -0
  5. package/lib/cjs/client/addon/components/Panel.js +72 -0
  6. package/lib/cjs/client/addon/components/TestSelect.js +65 -0
  7. package/lib/cjs/client/addon/components/Tools.js +97 -0
  8. package/lib/cjs/client/addon/decorator.js +11 -0
  9. package/lib/cjs/client/addon/index.js +31 -0
  10. package/lib/cjs/client/addon/preset.ie11.js +74 -0
  11. package/lib/cjs/client/addon/preset.js +62 -0
  12. package/lib/cjs/client/addon/readyForCapture.js +12 -0
  13. package/lib/cjs/client/addon/register.js +74 -0
  14. package/lib/cjs/client/addon/utils.js +42 -0
  15. package/lib/cjs/client/addon/withCreevey.js +354 -0
  16. package/lib/cjs/client/shared/components/ImagesView/BlendView.js +87 -0
  17. package/lib/cjs/client/shared/components/ImagesView/ImagesView.js +92 -0
  18. package/lib/cjs/client/shared/components/ImagesView/SideBySideView.js +154 -0
  19. package/lib/cjs/client/shared/components/ImagesView/SlideView.js +166 -0
  20. package/lib/cjs/client/shared/components/ImagesView/SwapView.js +91 -0
  21. package/lib/cjs/client/shared/components/ImagesView/index.js +45 -0
  22. package/lib/cjs/client/shared/components/PageFooter/PageFooter.js +50 -0
  23. package/lib/cjs/client/shared/components/PageFooter/Paging.js +94 -0
  24. package/lib/cjs/client/shared/components/PageHeader/ImagePreview.js +82 -0
  25. package/lib/cjs/client/shared/components/PageHeader/PageHeader.js +119 -0
  26. package/lib/cjs/client/shared/components/ResultsPage.js +143 -0
  27. package/lib/cjs/client/shared/creeveyClientApi.js +76 -0
  28. package/lib/cjs/client/shared/helpers.js +411 -0
  29. package/lib/cjs/client/shared/viewMode.js +17 -0
  30. package/lib/cjs/client/web/19.js +1 -0
  31. package/lib/cjs/client/web/632.js +43 -0
  32. package/lib/cjs/client/web/794.js +1 -0
  33. package/lib/cjs/client/web/index.html +19 -0
  34. package/lib/cjs/client/web/main.js +79 -0
  35. package/lib/cjs/client/web/main.js.LICENSE.txt +34 -0
  36. package/lib/cjs/creevey.js +69 -0
  37. package/lib/cjs/index.js +39 -0
  38. package/lib/cjs/server/config.js +93 -0
  39. package/lib/cjs/server/docker.js +146 -0
  40. package/lib/cjs/server/extract.js +46 -0
  41. package/lib/cjs/server/index.js +83 -0
  42. package/lib/cjs/server/loaders/babel/creevey-plugin.js +86 -0
  43. package/lib/cjs/server/loaders/babel/helpers.js +469 -0
  44. package/lib/cjs/server/loaders/babel/register.js +124 -0
  45. package/lib/cjs/server/loaders/hooks/mdx.js +30 -0
  46. package/lib/cjs/server/loaders/hooks/svelte.js +65 -0
  47. package/lib/cjs/server/loaders/webpack/compile.js +269 -0
  48. package/lib/cjs/server/loaders/webpack/creevey-loader.js +172 -0
  49. package/lib/cjs/server/loaders/webpack/dummy-hmr.js +39 -0
  50. package/lib/cjs/server/loaders/webpack/mdx-loader.js +72 -0
  51. package/lib/cjs/server/loaders/webpack/start.js +41 -0
  52. package/lib/cjs/server/logger.js +48 -0
  53. package/lib/cjs/server/master/api.js +71 -0
  54. package/lib/cjs/server/master/index.js +152 -0
  55. package/lib/cjs/server/master/master.js +57 -0
  56. package/lib/cjs/server/master/pool.js +197 -0
  57. package/lib/cjs/server/master/runner.js +281 -0
  58. package/lib/cjs/server/master/server.js +131 -0
  59. package/lib/cjs/server/messages.js +264 -0
  60. package/lib/cjs/server/selenium/browser.js +667 -0
  61. package/lib/cjs/server/selenium/index.js +31 -0
  62. package/lib/cjs/server/selenium/selenoid.js +172 -0
  63. package/lib/cjs/server/stories.js +155 -0
  64. package/lib/cjs/server/storybook/entry.js +55 -0
  65. package/lib/cjs/server/storybook/helpers.js +158 -0
  66. package/lib/cjs/server/storybook/providers/browser.js +76 -0
  67. package/lib/cjs/server/storybook/providers/nodejs.js +239 -0
  68. package/lib/cjs/server/update.js +79 -0
  69. package/lib/cjs/server/utils.js +169 -0
  70. package/lib/cjs/server/worker/chai-image.js +142 -0
  71. package/lib/cjs/server/worker/helpers.js +69 -0
  72. package/lib/cjs/server/worker/index.js +15 -0
  73. package/lib/cjs/server/worker/reporter.js +108 -0
  74. package/lib/cjs/server/worker/worker.js +268 -0
  75. package/lib/cjs/shared/index.js +103 -0
  76. package/lib/cjs/shared/serializeRegExp.js +42 -0
  77. package/lib/cjs/types.js +77 -0
  78. package/lib/esm/cli.js +4 -0
  79. package/lib/esm/client/addon/Manager.js +252 -0
  80. package/lib/esm/client/addon/components/Addon.js +39 -0
  81. package/lib/esm/client/addon/components/Icons.js +31 -0
  82. package/lib/esm/client/addon/components/Panel.js +53 -0
  83. package/lib/esm/client/addon/components/TestSelect.js +51 -0
  84. package/lib/esm/client/addon/components/Tools.js +76 -0
  85. package/lib/esm/client/addon/decorator.js +2 -0
  86. package/lib/esm/client/addon/index.js +2 -0
  87. package/lib/esm/client/addon/preset.ie11.js +59 -0
  88. package/lib/esm/client/addon/preset.js +41 -0
  89. package/lib/esm/client/addon/readyForCapture.js +5 -0
  90. package/lib/esm/client/addon/register.js +53 -0
  91. package/lib/esm/client/addon/utils.js +32 -0
  92. package/lib/esm/client/addon/withCreevey.js +327 -0
  93. package/lib/esm/client/shared/components/ImagesView/BlendView.js +67 -0
  94. package/lib/esm/client/shared/components/ImagesView/ImagesView.js +69 -0
  95. package/lib/esm/client/shared/components/ImagesView/SideBySideView.js +131 -0
  96. package/lib/esm/client/shared/components/ImagesView/SlideView.js +143 -0
  97. package/lib/esm/client/shared/components/ImagesView/SwapView.js +71 -0
  98. package/lib/esm/client/shared/components/ImagesView/index.js +5 -0
  99. package/lib/esm/client/shared/components/PageFooter/PageFooter.js +36 -0
  100. package/lib/esm/client/shared/components/PageFooter/Paging.js +80 -0
  101. package/lib/esm/client/shared/components/PageHeader/ImagePreview.js +68 -0
  102. package/lib/esm/client/shared/components/PageHeader/PageHeader.js +97 -0
  103. package/lib/esm/client/shared/components/ResultsPage.js +115 -0
  104. package/lib/esm/client/shared/creeveyClientApi.js +67 -0
  105. package/lib/esm/client/shared/helpers.js +353 -0
  106. package/lib/esm/client/shared/viewMode.js +6 -0
  107. package/lib/esm/creevey.js +54 -0
  108. package/lib/esm/index.js +3 -0
  109. package/lib/esm/server/config.js +70 -0
  110. package/lib/esm/server/docker.js +123 -0
  111. package/lib/esm/server/extract.js +32 -0
  112. package/lib/esm/server/index.js +64 -0
  113. package/lib/esm/server/loaders/babel/creevey-plugin.js +72 -0
  114. package/lib/esm/server/loaders/babel/helpers.js +452 -0
  115. package/lib/esm/server/loaders/babel/register.js +103 -0
  116. package/lib/esm/server/loaders/hooks/mdx.js +15 -0
  117. package/lib/esm/server/loaders/hooks/svelte.js +49 -0
  118. package/lib/esm/server/loaders/webpack/compile.js +246 -0
  119. package/lib/esm/server/loaders/webpack/creevey-loader.js +152 -0
  120. package/lib/esm/server/loaders/webpack/dummy-hmr.js +32 -0
  121. package/lib/esm/server/loaders/webpack/mdx-loader.js +58 -0
  122. package/lib/esm/server/loaders/webpack/start.js +27 -0
  123. package/lib/esm/server/logger.js +20 -0
  124. package/lib/esm/server/master/api.js +60 -0
  125. package/lib/esm/server/master/index.js +131 -0
  126. package/lib/esm/server/master/master.js +38 -0
  127. package/lib/esm/server/master/pool.js +176 -0
  128. package/lib/esm/server/master/runner.js +259 -0
  129. package/lib/esm/server/master/server.js +107 -0
  130. package/lib/esm/server/messages.js +232 -0
  131. package/lib/esm/server/selenium/browser.js +634 -0
  132. package/lib/esm/server/selenium/index.js +2 -0
  133. package/lib/esm/server/selenium/selenoid.js +149 -0
  134. package/lib/esm/server/stories.js +137 -0
  135. package/lib/esm/server/storybook/entry.js +29 -0
  136. package/lib/esm/server/storybook/helpers.js +99 -0
  137. package/lib/esm/server/storybook/providers/browser.js +60 -0
  138. package/lib/esm/server/storybook/providers/nodejs.js +219 -0
  139. package/lib/esm/server/update.js +61 -0
  140. package/lib/esm/server/utils.js +128 -0
  141. package/lib/esm/server/worker/chai-image.js +130 -0
  142. package/lib/esm/server/worker/helpers.js +60 -0
  143. package/lib/esm/server/worker/index.js +1 -0
  144. package/lib/esm/server/worker/reporter.js +86 -0
  145. package/lib/esm/server/worker/worker.js +238 -0
  146. package/lib/esm/shared/index.js +80 -0
  147. package/lib/esm/shared/serializeRegExp.js +24 -0
  148. package/lib/esm/types.js +46 -0
  149. package/lib/types/cli.d.ts +1 -0
  150. package/lib/types/client/addon/Manager.d.ts +37 -0
  151. package/lib/types/client/addon/components/Addon.d.ts +9 -0
  152. package/lib/types/client/addon/components/Icons.d.ts +8 -0
  153. package/lib/types/client/addon/components/Panel.d.ts +10 -0
  154. package/lib/types/client/addon/components/TestSelect.d.ts +9 -0
  155. package/lib/types/client/addon/components/Tools.d.ts +7 -0
  156. package/lib/types/client/addon/decorator.d.ts +1 -0
  157. package/lib/types/client/addon/index.d.ts +2 -0
  158. package/lib/types/client/addon/preset.d.ts +23 -0
  159. package/lib/types/client/addon/preset.ie11.d.ts +10 -0
  160. package/lib/types/client/addon/readyForCapture.d.ts +6 -0
  161. package/lib/types/client/addon/register.d.ts +3 -0
  162. package/lib/types/client/addon/utils.d.ts +3 -0
  163. package/lib/types/client/addon/withCreevey.d.ts +24 -0
  164. package/lib/types/client/shared/components/ImagesView/BlendView.d.ts +5 -0
  165. package/lib/types/client/shared/components/ImagesView/ImagesView.d.ts +25 -0
  166. package/lib/types/client/shared/components/ImagesView/SideBySideView.d.ts +5 -0
  167. package/lib/types/client/shared/components/ImagesView/SlideView.d.ts +5 -0
  168. package/lib/types/client/shared/components/ImagesView/SwapView.d.ts +5 -0
  169. package/lib/types/client/shared/components/ImagesView/index.d.ts +5 -0
  170. package/lib/types/client/shared/components/PageFooter/PageFooter.d.ts +9 -0
  171. package/lib/types/client/shared/components/PageFooter/Paging.d.ts +8 -0
  172. package/lib/types/client/shared/components/PageHeader/ImagePreview.d.ts +14 -0
  173. package/lib/types/client/shared/components/PageHeader/PageHeader.d.ts +17 -0
  174. package/lib/types/client/shared/components/ResultsPage.d.ts +20 -0
  175. package/lib/types/client/shared/creeveyClientApi.d.ts +9 -0
  176. package/lib/types/client/shared/helpers.d.ts +46 -0
  177. package/lib/types/client/shared/viewMode.d.ts +4 -0
  178. package/lib/types/client/web/CreeveyApp.d.ts +12 -0
  179. package/lib/types/client/web/CreeveyContext.d.ts +11 -0
  180. package/lib/types/client/web/CreeveyLoader.d.ts +3 -0
  181. package/lib/types/client/web/CreeveyView/SideBar/Checkbox.d.ts +22 -0
  182. package/lib/types/client/web/CreeveyView/SideBar/Search.d.ts +7 -0
  183. package/lib/types/client/web/CreeveyView/SideBar/SideBar.d.ts +14 -0
  184. package/lib/types/client/web/CreeveyView/SideBar/SideBarHeader.d.ts +13 -0
  185. package/lib/types/client/web/CreeveyView/SideBar/SuiteLink.d.ts +38 -0
  186. package/lib/types/client/web/CreeveyView/SideBar/TestLink.d.ts +8 -0
  187. package/lib/types/client/web/CreeveyView/SideBar/TestStatusIcon.d.ts +12 -0
  188. package/lib/types/client/web/CreeveyView/SideBar/TestsStatus.d.ts +11 -0
  189. package/lib/types/client/web/CreeveyView/SideBar/Toggle.d.ts +7 -0
  190. package/lib/types/client/web/CreeveyView/SideBar/index.d.ts +1 -0
  191. package/lib/types/client/web/KeyboardEventsContext.d.ts +13 -0
  192. package/lib/types/client/web/index.d.ts +4 -0
  193. package/lib/types/creevey.d.ts +1 -0
  194. package/lib/types/index.d.ts +2 -0
  195. package/lib/types/server/config.d.ts +4 -0
  196. package/lib/types/server/docker.d.ts +7 -0
  197. package/lib/types/server/extract.d.ts +2 -0
  198. package/lib/types/server/index.d.ts +2 -0
  199. package/lib/types/server/loaders/babel/creevey-plugin.d.ts +1 -0
  200. package/lib/types/server/loaders/babel/helpers.d.ts +19 -0
  201. package/lib/types/server/loaders/babel/register.d.ts +5 -0
  202. package/lib/types/server/loaders/hooks/mdx.d.ts +1 -0
  203. package/lib/types/server/loaders/hooks/svelte.d.ts +1 -0
  204. package/lib/types/server/loaders/webpack/compile.d.ts +2 -0
  205. package/lib/types/server/loaders/webpack/creevey-loader.d.ts +4 -0
  206. package/lib/types/server/loaders/webpack/dummy-hmr.d.ts +10 -0
  207. package/lib/types/server/loaders/webpack/mdx-loader.d.ts +6 -0
  208. package/lib/types/server/loaders/webpack/start.d.ts +1 -0
  209. package/lib/types/server/logger.d.ts +10 -0
  210. package/lib/types/server/master/api.d.ts +7 -0
  211. package/lib/types/server/master/index.d.ts +3 -0
  212. package/lib/types/server/master/master.d.ts +7 -0
  213. package/lib/types/server/master/pool.d.ts +31 -0
  214. package/lib/types/server/master/runner.d.ts +26 -0
  215. package/lib/types/server/master/server.d.ts +2 -0
  216. package/lib/types/server/messages.d.ts +29 -0
  217. package/lib/types/server/selenium/browser.d.ts +19 -0
  218. package/lib/types/server/selenium/index.d.ts +2 -0
  219. package/lib/types/server/selenium/selenoid.d.ts +3 -0
  220. package/lib/types/server/stories.d.ts +8 -0
  221. package/lib/types/server/storybook/entry.d.ts +16 -0
  222. package/lib/types/server/storybook/helpers.d.ts +24 -0
  223. package/lib/types/server/storybook/providers/browser.d.ts +2 -0
  224. package/lib/types/server/storybook/providers/nodejs.d.ts +6 -0
  225. package/lib/types/server/update.d.ts +2 -0
  226. package/lib/types/server/utils.d.ts +23 -0
  227. package/lib/types/server/worker/chai-image.d.ts +6 -0
  228. package/lib/types/server/worker/helpers.d.ts +8 -0
  229. package/lib/types/server/worker/index.d.ts +1 -0
  230. package/lib/types/server/worker/reporter.d.ts +8 -0
  231. package/lib/types/server/worker/worker.d.ts +4 -0
  232. package/lib/types/shared/index.d.ts +7 -0
  233. package/lib/types/shared/serializeRegExp.d.ts +9 -0
  234. package/lib/types/types.d.ts +486 -0
  235. package/package.json +1 -1
@@ -0,0 +1,219 @@
1
+ /* eslint-disable */
2
+ //@ts-nocheck
3
+
4
+ /* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/ban-ts-comment */
5
+ import path from 'path';
6
+ import cluster from 'cluster';
7
+ import chokidar from 'chokidar';
8
+ import { noop } from '../../../types';
9
+ import { getCreeveyCache } from '../../utils';
10
+ import { subscribeOn } from '../../messages';
11
+ import { importStorybookClientLogger, importStorybookConfig, importStorybookCoreCommon, importStorybookCoreEvents } from '../helpers';
12
+ import { logger } from '../../logger';
13
+
14
+ async function initStorybookEnvironment() {
15
+ // @ts-expect-error There is no @types/global-jsdom package
16
+ (await import('global-jsdom')).default(undefined, {
17
+ url: 'http://localhost'
18
+ }); // NOTE Cutoff `jsdom` part from userAgent, because storybook check enviroment and create events channel if runs in browser
19
+ // https://github.com/storybookjs/storybook/blob/v5.2.8/lib/core/src/client/preview/start.js#L98
20
+ // Example: "Mozilla/5.0 (linux) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/15.2.1"
21
+
22
+ Object.defineProperty(window.navigator, 'userAgent', {
23
+ value: window.navigator.userAgent.split(' ').filter(token => !token.startsWith('jsdom')).join(' ')
24
+ }); // TODO Look at creevey debug flag
25
+
26
+ const {
27
+ logger
28
+ } = await importStorybookClientLogger(); // NOTE: Disable duplication warnings for >=6.2 storybook
29
+
30
+ if (cluster.isWorker) logger.warn = noop; // NOTE: disable logger for 5.x storybook
31
+
32
+ logger.debug = noop;
33
+ return import('../entry');
34
+ }
35
+
36
+ function watchStories(channel, watcher, initialFiles) {
37
+ const watchingFiles = initialFiles;
38
+ let storiesByFiles = new Map();
39
+ subscribeOn('shutdown', () => void watcher.close());
40
+ watcher.add(Array.from(watchingFiles));
41
+ watcher.on('change', filePath => storiesByFiles.set(path.isAbsolute(filePath) ? filePath : `./${filePath.replace(/\\/g, '/')}`, []));
42
+ watcher.on('unlink', filePath => storiesByFiles.set(path.isAbsolute(filePath) ? filePath : `./${filePath.replace(/\\/g, '/')}`, []));
43
+ return data => {
44
+ const stories = data.stories;
45
+ const files = new Set(Object.values(stories).map(story => story.parameters.fileName));
46
+ const addedFiles = Array.from(files).filter(filePath => !watchingFiles.has(filePath));
47
+ const removedFiles = Array.from(watchingFiles).filter(filePath => !files.has(filePath));
48
+ watcher.add(addedFiles);
49
+ addedFiles.forEach(filePath => {
50
+ watchingFiles.add(filePath);
51
+ storiesByFiles.set(filePath, []);
52
+ });
53
+ removedFiles.forEach(filePath => watchingFiles.delete(filePath));
54
+ Object.values(stories).forEach(story => {
55
+ var _storiesByFiles$get;
56
+
57
+ return (_storiesByFiles$get = storiesByFiles.get(story.parameters.fileName)) === null || _storiesByFiles$get === void 0 ? void 0 : _storiesByFiles$get.push(story);
58
+ });
59
+ channel.emit('storiesUpdated', storiesByFiles);
60
+ storiesByFiles = new Map();
61
+ };
62
+ }
63
+
64
+ function loadStoriesFromBundle(watch) {
65
+ const bundlePath = path.join(getCreeveyCache(), 'storybook/main.js');
66
+
67
+ if (watch) {
68
+ subscribeOn('webpack', message => {
69
+ if (message.type != 'rebuild succeeded') return;
70
+ Object.values(global.__CREEVEY_HMR_DATA__).filter(({
71
+ callback
72
+ }) => callback).forEach(({
73
+ data,
74
+ callback
75
+ }) => callback(data));
76
+ delete require.cache[bundlePath];
77
+ import(bundlePath);
78
+ });
79
+ }
80
+
81
+ import(bundlePath);
82
+ }
83
+
84
+ async function loadStoriesDirectly(config, {
85
+ watcher,
86
+ debug
87
+ }) {
88
+ const {
89
+ toRequireContext,
90
+ normalizeStoriesEntry
91
+ } = await importStorybookCoreCommon();
92
+ const {
93
+ addParameters,
94
+ configure
95
+ } = await import('../entry');
96
+ const requireContext = await (await import('../../loaders/babel/register')).default(config, debug);
97
+
98
+ const preview = (() => {
99
+ try {
100
+ return require.resolve(`${config.storybookDir}/preview`);
101
+ } catch (_) {
102
+ /* noop */
103
+ }
104
+ })();
105
+
106
+ const {
107
+ stories
108
+ } = await importStorybookConfig();
109
+ const contexts = stories.map(entry => {
110
+ const normalizedEntry = normalizeStoriesEntry(entry, {
111
+ configDir: config.storybookDir,
112
+ workingDir: process.cwd()
113
+ });
114
+ const {
115
+ path: storiesPath,
116
+ recursive,
117
+ match
118
+ } = toRequireContext(normalizedEntry);
119
+ watcher === null || watcher === void 0 ? void 0 : watcher.add(path.resolve(config.storybookDir, storiesPath));
120
+ return () => requireContext(storiesPath, recursive, new RegExp(match));
121
+ });
122
+
123
+ let disposeCallback = data => void data;
124
+
125
+ Object.assign(module, {
126
+ hot: {
127
+ data: {},
128
+
129
+ accept() {
130
+ /* noop */
131
+ },
132
+
133
+ dispose(callback) {
134
+ disposeCallback = callback;
135
+ }
136
+
137
+ }
138
+ });
139
+
140
+ async function startStorybook() {
141
+ if (preview) {
142
+ const {
143
+ parameters,
144
+ globals,
145
+ globalTypes
146
+ } = await import(preview);
147
+ if (parameters) addParameters(parameters);
148
+ if (globals) addParameters({
149
+ globals
150
+ });
151
+ if (globalTypes) addParameters({
152
+ globalTypes
153
+ });
154
+ }
155
+
156
+ try {
157
+ configure(contexts.map(ctx => ctx()), module, false);
158
+ } catch (error) {
159
+ if (cluster.isPrimary) logger.error(error);
160
+ }
161
+ }
162
+
163
+ watcher === null || watcher === void 0 ? void 0 : watcher.add(config.storybookDir);
164
+ watcher === null || watcher === void 0 ? void 0 : watcher.on('all', (_event, filename) => {
165
+ var _module$hot;
166
+
167
+ disposeCallback((_module$hot = module.hot) === null || _module$hot === void 0 ? void 0 : _module$hot.data);
168
+ delete require.cache[filename];
169
+ void startStorybook();
170
+ });
171
+ void startStorybook();
172
+ } // TODO Do we need to support multiple storybooks here?
173
+
174
+
175
+ export const loadStories = async (config, {
176
+ watch,
177
+ debug
178
+ }, storiesListener) => {
179
+ const storybookApi = await initStorybookEnvironment();
180
+ const Events = await importStorybookCoreEvents();
181
+ const {
182
+ channel
183
+ } = storybookApi;
184
+ channel.removeAllListeners(Events.CURRENT_STORY_WAS_SET);
185
+ channel.on('storiesUpdated', storiesListener);
186
+ let watcher;
187
+ if (watch) watcher = chokidar.watch([], {
188
+ ignoreInitial: true
189
+ });
190
+ const loadPromise = new Promise(resolve => {
191
+ channel.once(Events.SET_STORIES, data => {
192
+ const stories = data.stories;
193
+ const files = new Set(Object.values(stories).map(story => story.parameters.fileName));
194
+ if (watcher) channel.on(Events.SET_STORIES, watchStories(channel, watcher, files));
195
+ resolve(stories);
196
+ });
197
+ });
198
+ if (config.useWebpackToExtractTests) loadStoriesFromBundle(watch);else void loadStoriesDirectly(config, {
199
+ watcher,
200
+ debug
201
+ });
202
+ return loadPromise;
203
+ };
204
+ export async function extractStoriesData(config, {
205
+ watch,
206
+ debug
207
+ }) {
208
+ const storybookApi = await initStorybookEnvironment();
209
+ const Events = await importStorybookCoreEvents();
210
+ const {
211
+ channel
212
+ } = storybookApi;
213
+ channel.removeAllListeners(Events.CURRENT_STORY_WAS_SET);
214
+ const loadPromise = new Promise(resolve => channel.once(Events.SET_STORIES, resolve));
215
+ if (config.useWebpackToExtractTests) loadStoriesFromBundle(watch);else void loadStoriesDirectly(config, {
216
+ debug
217
+ });
218
+ return loadPromise;
219
+ }
@@ -0,0 +1,61 @@
1
+ import path from 'path';
2
+ import fs, { mkdirSync } from 'fs';
3
+ import micromatch from 'micromatch';
4
+ import { isDefined } from '../types';
5
+
6
+ function tryToLoadTestsData(filename) {
7
+ try {
8
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
9
+ return require(filename);
10
+ } catch (_) {
11
+ /* noop */
12
+ }
13
+ }
14
+
15
+ const actualRegex = /^(.*)-actual-(\d+)\.png$/i;
16
+
17
+ function approve(dirents, srcPath, dstPath, testPaths, isMatch) {
18
+ dirents.filter(dirent => dirent.isFile()).map(dirent => actualRegex.exec(dirent.name)).filter(isDefined).filter(([fileName, imageName]) => !testPaths || testPaths.find(([token]) => token == imageName) && isMatch(path.join(srcPath, fileName))).reduce((images, [, imageName, retry]) => Number(retry) > (images.get(imageName) ?? -1) ? images.set(imageName, Number(retry)) : images, new Map()).forEach((retry, imageName) => {
19
+ mkdirSync(dstPath, {
20
+ recursive: true
21
+ });
22
+ fs.copyFileSync(path.join(srcPath, `${imageName}-actual-${retry}.png`), path.join(dstPath, `${imageName}.png`));
23
+ });
24
+ }
25
+
26
+ function traverse(srcPath, dstPath, testPaths, isMatch) {
27
+ const dirents = fs.readdirSync(srcPath, {
28
+ withFileTypes: true
29
+ });
30
+ approve(dirents, srcPath, dstPath, testPaths, isMatch);
31
+ dirents.filter(dirent => dirent.isDirectory()).map(dirent => [dirent.name, testPaths === null || testPaths === void 0 ? void 0 : testPaths.map(([token, ...restPath]) => token == dirent.name ? restPath : null).filter(isDefined)]).filter(([, paths]) => !paths || paths.length > 0).forEach(([dirname, paths]) => traverse(path.join(srcPath, dirname), path.join(dstPath, dirname), paths, isMatch));
32
+ }
33
+
34
+ export default function update(config, grepPattern) {
35
+ const {
36
+ reportDir,
37
+ screenDir
38
+ } = config;
39
+ const isMatch = grepPattern ? micromatch.matcher(grepPattern, {
40
+ contains: true
41
+ }) : () => true;
42
+ const testsMeta = tryToLoadTestsData(`${reportDir}/tests.json`);
43
+ const testsReport = tryToLoadTestsData(`${reportDir}/data`);
44
+ let testPaths = null;
45
+
46
+ if (testsMeta && testsReport) {
47
+ testPaths = Object.values(testsMeta).filter(isDefined).filter(({
48
+ id
49
+ }) => {
50
+ var _testsReport$id;
51
+
52
+ return ((_testsReport$id = testsReport[id]) === null || _testsReport$id === void 0 ? void 0 : _testsReport$id.status) == 'failed';
53
+ }).map(({
54
+ storyPath,
55
+ testName,
56
+ browser
57
+ }) => [...storyPath, ...(testName ? [testName] : []), browser]);
58
+ }
59
+
60
+ traverse(reportDir, screenDir, testPaths, value => isMatch(path.relative(reportDir, value)));
61
+ }
@@ -0,0 +1,128 @@
1
+ import { createWriteStream, existsSync, readFileSync, unlink } from 'fs';
2
+ import cluster from 'cluster';
3
+ import { isDefined, noop, isFunction } from '../types';
4
+ import { emitShutdownMessage, sendShutdownMessage } from './messages';
5
+ import findCacheDir from 'find-cache-dir';
6
+ import { get } from 'https';
7
+ export const isShuttingDown = {
8
+ current: false
9
+ };
10
+ export const LOCALHOST_REGEXP = /(localhost|127\.0\.0\.1)/i;
11
+ export const extensions = ['.js', '.jsx', '.ts', '.tsx'];
12
+ export const skipOptionKeys = ['in', 'kinds', 'stories', 'tests', 'reason'];
13
+
14
+ function matchBy(pattern, value) {
15
+ return typeof pattern == 'string' && pattern == value || Array.isArray(pattern) && pattern.includes(value) || pattern instanceof RegExp && pattern.test(value) || !isDefined(pattern);
16
+ }
17
+
18
+ export function shouldSkip(browser, meta, skipOptions, test) {
19
+ if (typeof skipOptions != 'object') {
20
+ return skipOptions;
21
+ }
22
+
23
+ for (const skipKey in skipOptions) {
24
+ const reason = shouldSkipByOption(browser, meta, skipOptions[skipKey], skipKey, test);
25
+ if (reason) return reason;
26
+ }
27
+
28
+ return false;
29
+ }
30
+ export function shouldSkipByOption(browser, meta, skipOption, reason, test) {
31
+ if (Array.isArray(skipOption)) {
32
+ for (const skip of skipOption) {
33
+ const result = shouldSkipByOption(browser, meta, skip, reason, test);
34
+ if (result) return result;
35
+ }
36
+
37
+ return false;
38
+ }
39
+
40
+ const {
41
+ in: browsers,
42
+ kinds,
43
+ stories,
44
+ tests
45
+ } = skipOption;
46
+ const {
47
+ kind,
48
+ story
49
+ } = meta;
50
+ const skipByBrowser = matchBy(browsers, browser);
51
+ const skipByKind = matchBy(kinds, kind);
52
+ const skipByStory = matchBy(stories, story);
53
+ const skipByTest = !isDefined(test) || matchBy(tests, test);
54
+ return skipByBrowser && skipByKind && skipByStory && skipByTest && reason;
55
+ }
56
+ export async function shutdownWorkers() {
57
+ isShuttingDown.current = true;
58
+ await Promise.all(Object.values(cluster.workers ?? {}).filter(isDefined).filter(worker => worker.isConnected()).map(worker => new Promise(resolve => {
59
+ const timeout = setTimeout(() => worker.kill(), 10000);
60
+ worker.on('exit', () => {
61
+ clearTimeout(timeout);
62
+ resolve();
63
+ });
64
+ sendShutdownMessage(worker);
65
+ })));
66
+ emitShutdownMessage();
67
+ }
68
+ export function shutdown() {
69
+ // eslint-disable-next-line no-process-exit
70
+ process.exit();
71
+ }
72
+ export function getCreeveyCache() {
73
+ return findCacheDir({
74
+ name: 'creevey',
75
+ cwd: __dirname
76
+ });
77
+ }
78
+ export async function runSequence(seq, predicate) {
79
+ for (const fn of seq) {
80
+ if (predicate()) await fn();
81
+ }
82
+ }
83
+ export function testsToImages(tests) {
84
+ return new Set([].concat(...tests.filter(isDefined).map(({
85
+ browser,
86
+ testName,
87
+ storyPath,
88
+ results
89
+ }) => {
90
+ var _results$slice$;
91
+
92
+ return Object.keys((results === null || results === void 0 ? void 0 : (_results$slice$ = results.slice(-1)[0]) === null || _results$slice$ === void 0 ? void 0 : _results$slice$.images) ?? {}).map(image => `${[...storyPath, testName, browser, browser == image ? undefined : image].filter(isDefined).join('/')}.png`);
93
+ })));
94
+ } // https://tuhrig.de/how-to-know-you-are-inside-a-docker-container/
95
+
96
+ export const isInsideDocker = existsSync('/proc/1/cgroup') && /docker/.test(readFileSync('/proc/1/cgroup', 'utf8'));
97
+ export const downloadBinary = (downloadUrl, destination) => new Promise((resolve, reject) => get(downloadUrl, response => {
98
+ if (response.statusCode == 302) {
99
+ const {
100
+ location
101
+ } = response.headers;
102
+ if (!location) return reject(new Error(`Couldn't download selenoid. Status code: ${response.statusCode ?? 'UNKNOWN'}`));
103
+ return resolve(downloadBinary(location, destination));
104
+ }
105
+
106
+ if (response.statusCode != 200) return reject(new Error(`Couldn't download selenoid. Status code: ${response.statusCode ?? 'UNKNOWN'}`));
107
+ const fileStream = createWriteStream(destination);
108
+ response.pipe(fileStream);
109
+ fileStream.on('finish', () => {
110
+ fileStream.close();
111
+ resolve();
112
+ });
113
+ fileStream.on('error', error => {
114
+ unlink(destination, noop);
115
+ reject(error);
116
+ });
117
+ }));
118
+ export function removeProps(obj, propPath) {
119
+ const [prop, ...restPath] = propPath;
120
+
121
+ if (restPath.length > 0) {
122
+ if (typeof prop == 'string') obj[prop] && removeProps(obj[prop], restPath);
123
+ if (isFunction(prop)) Object.keys(obj).filter(prop).forEach(key => obj[key] && removeProps(obj[key], restPath));
124
+ } else {
125
+ if (typeof prop == 'string') delete obj[prop];
126
+ if (isFunction(prop)) Object.keys(obj).filter(prop).forEach(key => delete obj[key]);
127
+ }
128
+ }
@@ -0,0 +1,130 @@
1
+ import { PNG } from 'pngjs';
2
+ import pixelmatch from 'pixelmatch';
3
+
4
+ function normalizeImageSize(image, width, height) {
5
+ const normalizedImage = Buffer.alloc(4 * width * height);
6
+
7
+ for (let y = 0; y < height; y++) {
8
+ for (let x = 0; x < width; x++) {
9
+ const i = (y * width + x) * 4;
10
+
11
+ if (x < image.width && y < image.height) {
12
+ const j = (y * image.width + x) * 4;
13
+ normalizedImage[i + 0] = image.data[j + 0];
14
+ normalizedImage[i + 1] = image.data[j + 1];
15
+ normalizedImage[i + 2] = image.data[j + 2];
16
+ normalizedImage[i + 3] = image.data[j + 3];
17
+ } else {
18
+ normalizedImage[i + 0] = 0;
19
+ normalizedImage[i + 1] = 0;
20
+ normalizedImage[i + 2] = 0;
21
+ normalizedImage[i + 3] = 0;
22
+ }
23
+ }
24
+ }
25
+
26
+ return normalizedImage;
27
+ }
28
+
29
+ function hasDiffPixels(diff) {
30
+ for (let i = 0; i < diff.length; i += 4) {
31
+ if (diff[i + 0] == 255 && diff[i + 1] == 0 && diff[i + 2] == 0 && diff[i + 3] == 255) return true;
32
+ }
33
+
34
+ return false;
35
+ }
36
+
37
+ function compareImages(expect, actual, diffOptions) {
38
+ const expectImage = PNG.sync.read(expect);
39
+ const actualImage = PNG.sync.read(actual);
40
+ const width = Math.max(actualImage.width, expectImage.width);
41
+ const height = Math.max(actualImage.height, expectImage.height);
42
+ const diffImage = new PNG({
43
+ width,
44
+ height
45
+ });
46
+ let actualImageData = actualImage.data;
47
+
48
+ if (actualImage.width < width || actualImage.height < height) {
49
+ actualImageData = normalizeImageSize(actualImage, width, height);
50
+ }
51
+
52
+ let expectImageData = expectImage.data;
53
+
54
+ if (expectImage.width < width || expectImage.height < height) {
55
+ expectImageData = normalizeImageSize(expectImage, width, height);
56
+ }
57
+
58
+ pixelmatch(expectImageData, actualImageData, diffImage.data, width, height, diffOptions);
59
+ return {
60
+ isEqual: !hasDiffPixels(diffImage.data),
61
+ diff: PNG.sync.write(diffImage)
62
+ };
63
+ }
64
+
65
+ export default function (getExpected, diffOptions) {
66
+ return function chaiImage({
67
+ Assertion
68
+ }, utils) {
69
+ async function assertImage(actual, imageName) {
70
+ let onCompare = () => Promise.resolve();
71
+
72
+ let expected = await getExpected(imageName);
73
+ if (!(expected instanceof Buffer) && expected != null) ({
74
+ expected,
75
+ onCompare
76
+ } = expected);
77
+
78
+ if (expected == null) {
79
+ await onCompare(actual);
80
+ return imageName ? `Expected image '${imageName}' does not exists` : 'Expected image does not exists';
81
+ }
82
+
83
+ if (actual.equals(expected)) return await onCompare(actual);
84
+ const {
85
+ isEqual,
86
+ diff
87
+ } = compareImages(expected, actual, diffOptions);
88
+ if (isEqual) return await onCompare(actual);
89
+ await onCompare(actual, expected, diff);
90
+ return imageName ? `Expected image '${imageName}' to match` : 'Expected image to match';
91
+ }
92
+
93
+ utils.addMethod(Assertion.prototype, 'matchImage', async function matchImage(imageName) {
94
+ const actual = utils.flag(this, 'object');
95
+ const errorMessage = await assertImage(typeof actual == 'string' ? Buffer.from(actual, 'base64') : actual, imageName);
96
+
97
+ if (errorMessage) {
98
+ throw createImageError(imageName ? {
99
+ [imageName]: errorMessage
100
+ } : errorMessage);
101
+ }
102
+ });
103
+ utils.addMethod(Assertion.prototype, 'matchImages', async function matchImages() {
104
+ const errors = {};
105
+ await Promise.all(Object.entries(utils.flag(this, 'object')).map(async ([imageName, imageOrBase64]) => {
106
+ let errorMessage;
107
+
108
+ try {
109
+ errorMessage = await assertImage(typeof imageOrBase64 == 'string' ? Buffer.from(imageOrBase64, 'base64') : imageOrBase64, imageName);
110
+ } catch (error) {
111
+ errorMessage = error.stack;
112
+ }
113
+
114
+ if (errorMessage) {
115
+ errors[imageName] = errorMessage;
116
+ }
117
+ }));
118
+
119
+ if (Object.keys(errors).length > 0) {
120
+ throw createImageError(errors);
121
+ }
122
+ });
123
+ };
124
+ }
125
+
126
+ function createImageError(imageErrors) {
127
+ const error = new Error('Expected image to match');
128
+ error.images = imageErrors;
129
+ return error;
130
+ }
@@ -0,0 +1,60 @@
1
+ import { Suite, Test } from 'mocha';
2
+ import { isDefined } from '../../types';
3
+ import { loadTestsFromStories } from '../stories';
4
+
5
+ function findOrCreateSuite(name, parent) {
6
+ const suite = parent.suites.find(({
7
+ title
8
+ }) => title == name) || new Suite(name, parent.ctx);
9
+
10
+ if (!suite.parent) {
11
+ suite.parent = parent;
12
+ parent.addSuite(suite);
13
+ }
14
+
15
+ return suite;
16
+ }
17
+
18
+ function createTest(name, fn, skip = false) {
19
+ const test = new Test(name, skip ? undefined : fn);
20
+ test.pending = Boolean(skip); // NOTE Can't define skip reason in mocha https://github.com/mochajs/mocha/issues/2026
21
+
22
+ test.skipReason = skip;
23
+ return test;
24
+ }
25
+
26
+ function addTest(rootSuite, test) {
27
+ const [testName, ...suitePath] = [...test.storyPath, test.testName].reverse().filter(isDefined);
28
+ const suite = suitePath.reduceRight((subSuite, suiteName) => findOrCreateSuite(suiteName, subSuite), rootSuite);
29
+ const mochaTest = createTest(testName, test.fn, test.skip);
30
+ suite.addTest(mochaTest);
31
+ mochaTest.ctx = Object.setPrototypeOf({
32
+ id: test.id,
33
+ story: test.story
34
+ }, suite.ctx);
35
+ return mochaTest;
36
+ }
37
+
38
+ function removeTestOrSuite(testOrSuite) {
39
+ const {
40
+ parent
41
+ } = testOrSuite;
42
+ if (!parent) return;
43
+ if (testOrSuite instanceof Test) parent.tests = parent.tests.filter(test => test != testOrSuite);
44
+ if (testOrSuite instanceof Suite) parent.suites = parent.suites.filter(suite => suite != testOrSuite);
45
+ if (parent.tests.length == 0 && parent.suites.length == 0) removeTestOrSuite(parent);
46
+ }
47
+
48
+ export async function addTestsFromStories(rootSuite, config, {
49
+ browser,
50
+ ...options
51
+ }) {
52
+ const mochaTestsById = new Map();
53
+ const tests = await loadTestsFromStories([browser], listener => config.storiesProvider(config, options, listener), testsDiff => Object.entries(testsDiff).forEach(([id, newTest]) => {
54
+ const oldTest = mochaTestsById.get(id);
55
+ mochaTestsById.delete(id);
56
+ if (oldTest) removeTestOrSuite(oldTest);
57
+ if (newTest) mochaTestsById.set(id, addTest(rootSuite, newTest));
58
+ }));
59
+ Object.values(tests).filter(isDefined).forEach(test => mochaTestsById.set(test.id, addTest(rootSuite, test)));
60
+ }
@@ -0,0 +1 @@
1
+ export { default } from './worker';
@@ -0,0 +1,86 @@
1
+ import chalk from 'chalk';
2
+ import { reporters } from 'mocha';
3
+ import prefix from 'loglevel-plugin-prefix';
4
+ import { isDefined, isImageError } from '../../types';
5
+ import { getLogger } from '../logger';
6
+ const testLevels = {
7
+ INFO: chalk.green('PASS'),
8
+ WARN: chalk.yellow('START'),
9
+ ERROR: chalk.red('FAIL')
10
+ };
11
+ export class CreeveyReporter extends reporters.Base {
12
+ constructor(runner, options) {
13
+ super(runner);
14
+ const {
15
+ sessionId,
16
+ topLevelSuite
17
+ } = options.reporterOptions;
18
+ const testLogger = getLogger(topLevelSuite);
19
+ prefix.apply(testLogger, {
20
+ format(level) {
21
+ return `${testLevels[level]} => (${topLevelSuite}:${chalk.gray(sessionId)})`;
22
+ }
23
+
24
+ });
25
+ runner.on('test', test => testLogger.warn(chalk.cyan(test.titlePath().join('/'))));
26
+ runner.on('pass', test => testLogger.info(chalk.cyan(test.titlePath().join('/'))));
27
+ runner.on('fail', (test, error) => testLogger.error(chalk.cyan(test.titlePath().join('/')), '\n ', getErrors(error, (error, imageName) => `${chalk.bold(imageName ?? topLevelSuite)}:${error}`, error => `${error.stack ?? error.message}`).join('\n ')));
28
+ }
29
+
30
+ }
31
+ export class TeamcityReporter extends reporters.Base {
32
+ constructor(runner, options) {
33
+ super(runner);
34
+ const topLevelSuite = this.escape(options.reporterOptions.topLevelSuite);
35
+ const reporterOptions = options.reporterOptions;
36
+ runner.on('suite', suite => suite.root ? console.log(`##teamcity[testSuiteStarted name='${topLevelSuite}' flowId='${process.pid}']`) : console.log(`##teamcity[testSuiteStarted name='${this.escape(suite.title)}' flowId='${process.pid}']`));
37
+ runner.on('test', test => console.log(`##teamcity[testStarted name='${this.escape(test.title)}' flowId='${process.pid}']`));
38
+ runner.on('fail', (test, error) => {
39
+ Object.entries(reporterOptions.images).forEach(([name, image]) => {
40
+ if (!image) return;
41
+ const filePath = test.titlePath().concat(name == topLevelSuite ? [] : [topLevelSuite]).map(this.escape).join('/'); // eslint-disable-next-line @typescript-eslint/no-unused-vars
42
+
43
+ const {
44
+ error,
45
+ ...rest
46
+ } = image;
47
+ Object.values(rest).filter(isDefined).forEach(fileName => {
48
+ console.log(`##teamcity[publishArtifacts '${reporterOptions.reportDir}/${filePath}/${fileName} => report/${filePath}']`);
49
+ console.log(`##teamcity[testMetadata testName='${this.escape(test.title)}' type='image' value='report/${filePath}/${fileName}' flowId='${process.pid}']`);
50
+ });
51
+ }); // Output failed test as passed due TC don't support retry mechanic
52
+ // https://teamcity-support.jetbrains.com/hc/en-us/community/posts/207216829-Count-test-as-successful-if-at-least-one-try-is-successful?page=1#community_comment_207394125
53
+
54
+ reporterOptions.willRetry ? console.log(`##teamcity[testFinished name='${this.escape(test.title)}' flowId='${process.pid}']`) : console.log(`##teamcity[testFailed name='${this.escape(test.title)}' message='${this.escape(error.message)}' details='${this.escape(error.stack ?? '')}' flowId='${process.pid}']`);
55
+ });
56
+ runner.on('pending', test => console.log(`##teamcity[testIgnored name='${this.escape(test.title)}' message='${this.escape(typeof test.skipReason == 'boolean' ? test.title : test.skipReason)}' flowId='${process.pid}']`));
57
+ runner.on('test end', test => console.log(`##teamcity[testFinished name='${this.escape(test.title)}' flowId='${process.pid}']`));
58
+ runner.on('suite end', suite => suite.root || console.log(`##teamcity[testSuiteFinished name='${this.escape(suite.title)}' flowId='${process.pid}']`));
59
+ runner.on('end', () => console.log(`##teamcity[testSuiteFinished name='${topLevelSuite}' flowId='${process.pid}']`));
60
+ }
61
+
62
+ escape = str => {
63
+ if (!str) return '';
64
+ return str.toString() // eslint-disable-next-line no-control-regex
65
+ .replace(/\x1B.*?m/g, '').replace(/\|/g, '||').replace(/\n/g, '|n').replace(/\r/g, '|r').replace(/\[/g, '|[').replace(/\]/g, '|]').replace(/\u0085/g, '|x').replace(/\u2028/g, '|l').replace(/\u2029/g, '|p').replace(/'/g, "|'");
66
+ };
67
+ }
68
+
69
+ function getErrors(error, imageErrorToString, errorToString) {
70
+ const errors = [];
71
+
72
+ if (!(error instanceof Error)) {
73
+ errors.push(error);
74
+ } else if (!isImageError(error)) {
75
+ errors.push(errorToString(error));
76
+ } else if (typeof error.images == 'string') {
77
+ errors.push(imageErrorToString(error.images));
78
+ } else {
79
+ const imageErrors = error.images;
80
+ Object.keys(imageErrors).forEach(imageName => {
81
+ errors.push(imageErrorToString(imageErrors[imageName] ?? '', imageName));
82
+ });
83
+ }
84
+
85
+ return errors;
86
+ }