creevey 0.9.0-beta.2 → 0.9.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.yarn/install-state.gz +0 -0
- package/.yarnrc.yml +1 -0
- package/CHANGELOG.md +51 -0
- package/README.md +9 -1
- package/addon/README.md +3 -0
- package/addon/package.json +5 -0
- package/docs/config.md +29 -26
- package/jest.config.js +6 -0
- package/lib/cjs/cli.js +1 -0
- package/lib/cjs/client/addon/Manager.js +170 -390
- package/lib/cjs/client/addon/components/Addon.js +17 -45
- package/lib/cjs/client/addon/components/Icons.js +12 -14
- package/lib/cjs/client/addon/components/Panel.js +21 -30
- package/lib/cjs/client/addon/components/TestSelect.js +20 -31
- package/lib/cjs/client/addon/components/Tools.js +35 -65
- package/lib/cjs/client/addon/decorator.js +1 -4
- package/lib/cjs/client/addon/index.js +27 -0
- package/lib/cjs/client/addon/preset.js +3 -76
- package/lib/cjs/client/addon/preview.js +11 -0
- package/lib/cjs/client/addon/readyForCapture.js +1 -4
- package/lib/cjs/client/addon/register.js +43 -82
- package/lib/cjs/client/addon/utils.js +4 -8
- package/lib/cjs/client/addon/withCreevey.js +145 -404
- package/lib/cjs/client/shared/components/ImagesView/BlendView.js +25 -35
- package/lib/cjs/client/shared/components/ImagesView/ImagesView.js +29 -41
- package/lib/cjs/client/shared/components/ImagesView/SideBySideView.js +46 -83
- package/lib/cjs/client/shared/components/ImagesView/SlideView.js +39 -67
- package/lib/cjs/client/shared/components/ImagesView/SwapView.js +26 -57
- package/lib/cjs/client/shared/components/ImagesView/index.js +9 -14
- package/lib/cjs/client/shared/components/PageFooter/PageFooter.js +13 -16
- package/lib/cjs/client/shared/components/PageFooter/Paging.js +16 -37
- package/lib/cjs/client/shared/components/PageHeader/ImagePreview.js +42 -34
- package/lib/cjs/client/shared/components/PageHeader/PageHeader.js +40 -84
- package/lib/cjs/client/shared/components/ResultsPage.js +42 -99
- package/lib/cjs/client/shared/creeveyClientApi.js +56 -93
- package/lib/cjs/client/shared/helpers.js +149 -274
- package/lib/cjs/client/shared/viewMode.js +5 -9
- package/lib/cjs/client/web/192.js +1 -0
- package/lib/cjs/client/web/632.js +43 -0
- package/lib/cjs/client/web/794.js +1 -0
- package/lib/cjs/client/web/main.js +79 -38
- package/lib/cjs/client/web/main.js.LICENSE.txt +34 -0
- package/lib/cjs/creevey.js +15 -30
- package/lib/cjs/index.js +0 -15
- package/lib/cjs/server/config.js +16 -36
- package/lib/cjs/server/docker.js +8 -34
- package/lib/cjs/server/index.js +9 -34
- package/lib/cjs/server/logger.js +7 -20
- package/lib/cjs/server/master/api.js +1 -14
- package/lib/cjs/server/master/index.js +25 -49
- package/lib/cjs/server/master/master.js +6 -21
- package/lib/cjs/server/master/pool.js +10 -53
- package/lib/cjs/server/master/runner.js +65 -105
- package/lib/cjs/server/master/server.js +10 -29
- package/lib/cjs/server/messages.js +14 -62
- package/lib/cjs/server/selenium/browser.js +149 -185
- package/lib/cjs/server/selenium/index.js +0 -4
- package/lib/cjs/server/selenium/selenoid.js +18 -44
- package/lib/cjs/server/stories.js +35 -57
- package/lib/cjs/server/storybook/providers/browser.js +15 -29
- package/lib/cjs/server/storybook/providers/hybrid.js +16 -37
- package/lib/cjs/server/telemetry.js +167 -0
- package/lib/cjs/server/testsFiles/parser.js +3 -19
- package/lib/cjs/server/testsFiles/register.js +8 -14
- package/lib/cjs/server/update.js +4 -25
- package/lib/cjs/server/utils.js +35 -76
- package/lib/cjs/server/worker/chai-image.js +1 -27
- package/lib/cjs/server/worker/helpers.js +2 -12
- package/lib/cjs/server/worker/index.js +1 -3
- package/lib/cjs/server/worker/reporter.js +16 -43
- package/lib/cjs/server/worker/worker.js +32 -72
- package/lib/cjs/shared/index.js +87 -0
- package/lib/cjs/shared/serializeRegExp.js +34 -0
- package/lib/cjs/types.js +11 -20
- package/lib/esm/cli.js +1 -1
- package/lib/esm/client/addon/Manager.js +170 -381
- package/lib/esm/client/addon/components/Addon.js +15 -34
- package/lib/esm/client/addon/components/Icons.js +10 -6
- package/lib/esm/client/addon/components/Panel.js +20 -18
- package/lib/esm/client/addon/components/TestSelect.js +19 -23
- package/lib/esm/client/addon/components/Tools.js +33 -49
- package/lib/esm/client/addon/decorator.js +1 -1
- package/lib/esm/client/addon/index.js +2 -0
- package/lib/esm/client/addon/preset.js +2 -56
- package/lib/esm/client/addon/preview.js +5 -0
- package/lib/esm/client/addon/readyForCapture.js +1 -3
- package/lib/esm/client/addon/register.js +41 -67
- package/lib/esm/client/addon/utils.js +3 -7
- package/lib/esm/client/addon/withCreevey.js +142 -388
- package/lib/esm/client/shared/components/ImagesView/BlendView.js +22 -18
- package/lib/esm/client/shared/components/ImagesView/ImagesView.js +27 -25
- package/lib/esm/client/shared/components/ImagesView/SideBySideView.js +43 -63
- package/lib/esm/client/shared/components/ImagesView/SlideView.js +36 -47
- package/lib/esm/client/shared/components/ImagesView/SwapView.js +23 -40
- package/lib/esm/client/shared/components/PageFooter/PageFooter.js +12 -8
- package/lib/esm/client/shared/components/PageFooter/Paging.js +15 -29
- package/lib/esm/client/shared/components/PageHeader/ImagePreview.js +40 -25
- package/lib/esm/client/shared/components/PageHeader/PageHeader.js +38 -66
- package/lib/esm/client/shared/components/ResultsPage.js +39 -75
- package/lib/esm/client/shared/creeveyClientApi.js +56 -90
- package/lib/esm/client/shared/helpers.js +133 -230
- package/lib/esm/client/shared/viewMode.js +4 -4
- package/lib/esm/client/web/192.js +1 -0
- package/lib/esm/client/web/632.js +43 -0
- package/lib/esm/client/web/794.js +1 -0
- package/lib/esm/client/web/index.html +19 -0
- package/lib/esm/client/web/main.js +79 -0
- package/lib/esm/client/web/main.js.LICENSE.txt +34 -0
- package/lib/esm/creevey.js +13 -16
- package/lib/esm/index.js +1 -4
- package/lib/esm/server/config.js +9 -16
- package/lib/esm/server/docker.js +6 -14
- package/lib/esm/server/index.js +8 -22
- package/lib/esm/server/logger.js +0 -1
- package/lib/esm/server/master/api.js +0 -9
- package/lib/esm/server/master/index.js +25 -35
- package/lib/esm/server/master/master.js +2 -7
- package/lib/esm/server/master/pool.js +8 -41
- package/lib/esm/server/master/runner.js +64 -90
- package/lib/esm/server/master/server.js +9 -11
- package/lib/esm/server/messages.js +8 -42
- package/lib/esm/server/selenium/browser.js +147 -163
- package/lib/esm/server/selenium/selenoid.js +16 -27
- package/lib/esm/server/stories.js +34 -46
- package/lib/esm/server/storybook/providers/browser.js +12 -17
- package/lib/esm/server/storybook/providers/hybrid.js +11 -22
- package/lib/esm/server/telemetry.js +160 -0
- package/lib/esm/server/testsFiles/parser.js +0 -6
- package/lib/esm/server/testsFiles/register.js +6 -7
- package/lib/esm/server/update.js +1 -13
- package/lib/esm/server/utils.js +20 -41
- package/lib/esm/server/worker/chai-image.js +0 -21
- package/lib/esm/server/worker/helpers.js +2 -9
- package/lib/esm/server/worker/reporter.js +15 -29
- package/lib/esm/server/worker/worker.js +31 -48
- package/lib/esm/shared/index.js +77 -0
- package/lib/esm/shared/serializeRegExp.js +24 -0
- package/lib/esm/types.js +5 -1
- package/lib/types/client/addon/Manager.d.ts +3 -3
- package/lib/types/client/addon/components/Addon.d.ts +1 -0
- package/lib/types/client/addon/components/Icons.d.ts +1 -0
- package/lib/types/client/addon/components/Panel.d.ts +1 -0
- package/lib/types/client/addon/components/Tools.d.ts +1 -0
- package/lib/types/client/addon/decorator.d.ts +1 -1
- package/lib/types/client/addon/index.d.ts +2 -0
- package/lib/types/client/addon/preset.d.ts +2 -24
- package/lib/types/client/addon/preview.d.ts +4 -0
- package/lib/types/client/addon/utils.d.ts +1 -0
- package/lib/types/client/addon/withCreevey.d.ts +4 -3
- package/lib/types/client/shared/components/ImagesView/BlendView.d.ts +3 -1
- package/lib/types/client/shared/components/ImagesView/SideBySideView.d.ts +3 -1
- package/lib/types/client/shared/components/ImagesView/SlideView.d.ts +3 -1
- package/lib/types/client/shared/components/ImagesView/SwapView.d.ts +3 -1
- package/lib/types/client/shared/components/PageHeader/ImagePreview.d.ts +3 -1
- package/lib/types/client/shared/components/ResultsPage.d.ts +3 -1
- package/lib/types/client/web/CreeveyLoader.d.ts +1 -1
- package/lib/types/client/web/CreeveyView/SideBar/Checkbox.d.ts +6 -3
- package/lib/types/client/web/CreeveyView/SideBar/Search.d.ts +1 -0
- package/lib/types/client/web/CreeveyView/SideBar/SuiteLink.d.ts +19 -14
- package/lib/types/client/web/CreeveyView/SideBar/TestStatusIcon.d.ts +3 -1
- package/lib/types/client/web/CreeveyView/SideBar/TestsStatus.d.ts +3 -1
- package/lib/types/client/web/CreeveyView/SideBar/Toggle.d.ts +1 -0
- package/lib/types/client/web/KeyboardEventsContext.d.ts +4 -2
- package/lib/types/index.d.ts +4 -1
- package/lib/types/server/logger.d.ts +6 -2
- package/lib/types/server/messages.d.ts +14 -12
- package/lib/types/server/selenium/browser.d.ts +5 -3
- package/lib/types/server/storybook/providers/browser.d.ts +2 -4
- package/lib/types/server/storybook/providers/hybrid.d.ts +2 -4
- package/lib/types/server/telemetry.d.ts +2 -0
- package/lib/types/server/utils.d.ts +5 -1
- package/lib/types/shared/index.d.ts +7 -0
- package/lib/types/shared/serializeRegExp.d.ts +9 -0
- package/lib/types/types.d.ts +29 -36
- package/package.json +132 -133
- package/types/global.d.ts +5 -0
- package/lib/cjs/client/web/1.js +0 -13
- package/lib/cjs/client/web/2.js +0 -1
- package/lib/cjs/server/extract.js +0 -50
- package/lib/cjs/server/loaders/babel/creevey-plugin.js +0 -88
- package/lib/cjs/server/loaders/babel/helpers.js +0 -479
- package/lib/cjs/server/loaders/babel/register.js +0 -126
- package/lib/cjs/server/loaders/hooks/mdx.js +0 -30
- package/lib/cjs/server/loaders/hooks/svelte.js +0 -65
- package/lib/cjs/server/loaders/webpack/compile.js +0 -286
- package/lib/cjs/server/loaders/webpack/creevey-loader.js +0 -174
- package/lib/cjs/server/loaders/webpack/dummy-hmr.js +0 -44
- package/lib/cjs/server/loaders/webpack/mdx-loader.js +0 -72
- package/lib/cjs/server/loaders/webpack/start.js +0 -41
- package/lib/cjs/server/storybook/entry.js +0 -68
- package/lib/cjs/server/storybook/helpers.js +0 -165
- package/lib/cjs/server/storybook/providers/nodejs.js +0 -239
- package/lib/cjs/shared.js +0 -124
- package/lib/esm/server/extract.js +0 -34
- package/lib/esm/server/loaders/babel/creevey-plugin.js +0 -74
- package/lib/esm/server/loaders/babel/helpers.js +0 -462
- package/lib/esm/server/loaders/babel/register.js +0 -105
- package/lib/esm/server/loaders/hooks/mdx.js +0 -15
- package/lib/esm/server/loaders/hooks/svelte.js +0 -49
- package/lib/esm/server/loaders/webpack/compile.js +0 -263
- package/lib/esm/server/loaders/webpack/creevey-loader.js +0 -153
- package/lib/esm/server/loaders/webpack/dummy-hmr.js +0 -36
- package/lib/esm/server/loaders/webpack/mdx-loader.js +0 -58
- package/lib/esm/server/loaders/webpack/start.js +0 -27
- package/lib/esm/server/storybook/entry.js +0 -44
- package/lib/esm/server/storybook/helpers.js +0 -106
- package/lib/esm/server/storybook/providers/nodejs.js +0 -217
- package/lib/esm/shared.js +0 -93
- package/lib/types/server/extract.d.ts +0 -2
- package/lib/types/server/loaders/babel/creevey-plugin.d.ts +0 -1
- package/lib/types/server/loaders/babel/helpers.d.ts +0 -19
- package/lib/types/server/loaders/babel/register.d.ts +0 -5
- package/lib/types/server/loaders/hooks/mdx.d.ts +0 -1
- package/lib/types/server/loaders/hooks/svelte.d.ts +0 -1
- package/lib/types/server/loaders/webpack/compile.d.ts +0 -2
- package/lib/types/server/loaders/webpack/creevey-loader.d.ts +0 -2
- package/lib/types/server/loaders/webpack/dummy-hmr.d.ts +0 -10
- package/lib/types/server/loaders/webpack/mdx-loader.d.ts +0 -6
- package/lib/types/server/loaders/webpack/start.d.ts +0 -1
- package/lib/types/server/storybook/entry.d.ts +0 -18
- package/lib/types/server/storybook/helpers.d.ts +0 -24
- package/lib/types/server/storybook/providers/nodejs.d.ts +0 -9
- package/lib/types/shared.d.ts +0 -16
- package/preset.js +0 -9
- package/storybook-static/stories.json +0 -21
- package/types/mdx.d.ts +0 -6
@@ -1,453 +1,238 @@
|
|
1
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
2
|
-
|
3
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
4
|
-
|
5
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
6
|
-
|
7
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
8
|
-
|
9
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
10
|
-
|
11
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
12
|
-
|
13
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
14
|
-
|
15
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
16
|
-
|
17
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
18
|
-
|
19
1
|
import * as Events from '@storybook/core-events';
|
20
|
-
import
|
21
|
-
// import { buildQueries, within } from '@storybook/testing-library';
|
22
|
-
import { addons, makeDecorator } from '@storybook/addons';
|
2
|
+
import { makeDecorator } from '@storybook/preview-api';
|
23
3
|
import { isObject, noop } from '../../types';
|
24
|
-
import {
|
4
|
+
import { serializeRawStories } from '../../shared';
|
25
5
|
import { getConnectionUrl } from '../shared/helpers';
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
6
|
+
const disableAnimationsStyles = `
|
7
|
+
*,
|
8
|
+
*:hover,
|
9
|
+
*::before,
|
10
|
+
*::after {
|
11
|
+
animation-delay: -0.0001ms !important;
|
12
|
+
animation-duration: 0s !important;
|
13
|
+
animation-play-state: paused !important;
|
14
|
+
cursor: none !important;
|
15
|
+
caret-color: transparent !important;
|
16
|
+
transition: 0s !important;
|
36
17
|
}
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
18
|
+
`;
|
19
|
+
async function resetCurrentStory(channel) {
|
20
|
+
setTimeout(() => channel.emit(Events.SET_CURRENT_STORY, {
|
21
|
+
storyId: true,
|
22
|
+
name: '',
|
23
|
+
kind: ''
|
24
|
+
}), 0);
|
25
|
+
return new Promise(resolve => channel.once(Events.STORY_MISSING, resolve));
|
42
26
|
}
|
43
|
-
|
44
|
-
function _resetCurrentStory() {
|
45
|
-
_resetCurrentStory = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(channel) {
|
46
|
-
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
47
|
-
while (1) {
|
48
|
-
switch (_context4.prev = _context4.next) {
|
49
|
-
case 0:
|
50
|
-
setTimeout(function () {
|
51
|
-
return channel.emit(Events.SET_CURRENT_STORY, {
|
52
|
-
storyId: true,
|
53
|
-
name: '',
|
54
|
-
kind: ''
|
55
|
-
});
|
56
|
-
}, 0);
|
57
|
-
return _context4.abrupt("return", new Promise(function (resolve) {
|
58
|
-
return channel.once(Events.STORY_MISSING, resolve);
|
59
|
-
}));
|
60
|
-
|
61
|
-
case 2:
|
62
|
-
case "end":
|
63
|
-
return _context4.stop();
|
64
|
-
}
|
65
|
-
}
|
66
|
-
}, _callee4);
|
67
|
-
}));
|
68
|
-
return _resetCurrentStory.apply(this, arguments);
|
69
|
-
}
|
70
|
-
|
71
27
|
function catchRenderError(channel) {
|
72
|
-
|
73
|
-
|
74
|
-
return rejectCallback = reject;
|
75
|
-
});
|
76
|
-
|
28
|
+
let rejectCallback;
|
29
|
+
const promise = new Promise((_resolve, reject) => rejectCallback = reject);
|
77
30
|
function errorHandler(_ref) {
|
78
|
-
|
79
|
-
|
31
|
+
let {
|
32
|
+
title,
|
33
|
+
description
|
34
|
+
} = _ref;
|
80
35
|
rejectCallback({
|
81
36
|
message: title,
|
82
37
|
stack: description
|
83
38
|
});
|
84
39
|
}
|
85
|
-
|
86
40
|
function exceptionHandler(exception) {
|
87
41
|
rejectCallback(exception);
|
88
42
|
}
|
89
|
-
|
90
43
|
function removeHandlers() {
|
91
44
|
channel.off(Events.STORY_ERRORED, errorHandler);
|
92
45
|
channel.off(Events.STORY_THREW_EXCEPTION, errorHandler);
|
93
46
|
}
|
94
|
-
|
95
47
|
channel.once(Events.STORY_ERRORED, errorHandler);
|
96
48
|
channel.once(Events.STORY_THREW_EXCEPTION, exceptionHandler);
|
97
49
|
return Object.assign(promise, {
|
98
50
|
cancel: removeHandlers
|
99
51
|
});
|
100
52
|
}
|
101
|
-
|
102
53
|
function waitForStoryRendered(channel) {
|
103
|
-
|
104
|
-
|
105
|
-
return resolveCallback = resolve;
|
106
|
-
});
|
107
|
-
|
54
|
+
let resolveCallback;
|
55
|
+
const promise = new Promise(resolve => resolveCallback = resolve);
|
108
56
|
function renderHandler() {
|
109
57
|
resolveCallback();
|
110
58
|
}
|
111
|
-
|
112
59
|
function removeHandlers() {
|
113
60
|
channel.off(Events.STORY_RENDERED, renderHandler);
|
114
61
|
}
|
115
|
-
|
116
62
|
channel.once(Events.STORY_RENDERED, renderHandler);
|
117
63
|
return Object.assign(promise, {
|
118
64
|
cancel: removeHandlers
|
119
65
|
});
|
120
66
|
}
|
121
|
-
|
122
67
|
function waitForFontsLoaded() {
|
123
68
|
if (!document.fonts) return;
|
124
|
-
|
125
|
-
return font.status == 'loading';
|
126
|
-
});
|
127
|
-
|
69
|
+
const areFontsLoading = Array.from(document.fonts).some(font => font.status == 'loading');
|
128
70
|
if (areFontsLoading) {
|
129
|
-
return new Promise(
|
130
|
-
|
71
|
+
return new Promise(resolve => {
|
72
|
+
const fontsLoadedHandler = () => {
|
131
73
|
document.fonts.removeEventListener('loadingdone', fontsLoadedHandler);
|
132
74
|
resolve();
|
133
75
|
};
|
134
|
-
|
135
76
|
document.fonts.addEventListener('loadingdone', fontsLoadedHandler);
|
136
77
|
});
|
137
78
|
}
|
138
79
|
}
|
139
|
-
|
140
80
|
function waitForCaptureCall() {
|
141
|
-
return new Promise(
|
142
|
-
return captureResolver = resolve;
|
143
|
-
});
|
81
|
+
return new Promise(resolve => captureResolver = resolve);
|
144
82
|
}
|
145
|
-
|
146
83
|
function initCreeveyState() {
|
147
|
-
|
148
|
-
|
149
|
-
var prevState = JSON.parse((_window$localStorage$ = window.localStorage.getItem('Creevey_Tests')) !== null && _window$localStorage$ !== void 0 ? _window$localStorage$ : '{}');
|
84
|
+
const prevState = JSON.parse(window.localStorage.getItem('Creevey_Tests') ?? '{}');
|
150
85
|
if (prevState.creeveyHost) window.__CREEVEY_SERVER_HOST__ = prevState.creeveyHost;
|
151
86
|
if (prevState.creeveyPort) window.__CREEVEY_SERVER_PORT__ = prevState.creeveyPort;
|
152
87
|
if (prevState.setStoriesCounter) setStoriesCounter = prevState.setStoriesCounter;
|
153
88
|
if (prevState.isTestBrowser) isTestBrowser = prevState.isTestBrowser;
|
154
|
-
window.addEventListener('beforeunload',
|
89
|
+
window.addEventListener('beforeunload', () => {
|
155
90
|
window.localStorage.setItem('Creevey_Tests', JSON.stringify({
|
156
91
|
creeveyHost: window.__CREEVEY_SERVER_HOST__,
|
157
92
|
creeveyPort: window.__CREEVEY_SERVER_PORT__,
|
158
|
-
setStoriesCounter
|
159
|
-
isTestBrowser
|
93
|
+
setStoriesCounter,
|
94
|
+
isTestBrowser
|
160
95
|
}));
|
161
96
|
});
|
162
97
|
}
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
var setStoriesCounter = 0;
|
98
|
+
let isTestBrowser = false;
|
99
|
+
let captureResolver;
|
100
|
+
let waitForCreevey;
|
101
|
+
let creeveyReady;
|
102
|
+
let setStoriesCounter = 0;
|
169
103
|
export function withCreevey() {
|
170
|
-
|
171
|
-
|
104
|
+
const addonsChannel = () => window.__STORYBOOK_ADDONS_CHANNEL__;
|
105
|
+
let currentStory = '';
|
106
|
+
let isAnimationDisabled = false;
|
172
107
|
initCreeveyState();
|
173
|
-
|
174
108
|
function disableAnimation() {
|
175
109
|
isAnimationDisabled = true;
|
176
|
-
|
177
|
-
|
110
|
+
const style = document.createElement('style');
|
111
|
+
const textNode = document.createTextNode(disableAnimationsStyles);
|
178
112
|
style.setAttribute('type', 'text/css');
|
179
113
|
style.appendChild(textNode);
|
180
114
|
document.head.appendChild(style);
|
181
115
|
}
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
store = (_window$__STORYBOOK_S = window.__STORYBOOK_STORY_STORE__) !== null && _window$__STORYBOOK_S !== void 0 ? _window$__STORYBOOK_S : {}; // @ts-expect-error `pushToManager` exists only in Storybook 6.0 - 6.3
|
202
|
-
|
203
|
-
if (!store.pushToManager) {
|
204
|
-
_context.next = 6;
|
205
|
-
break;
|
206
|
-
}
|
207
|
-
|
208
|
-
// @ts-expect-error `pushToManager` exists only in Storybook 6.0 - 6.3
|
209
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
210
|
-
store.pushToManager();
|
211
|
-
_context.next = 13;
|
212
|
-
break;
|
213
|
-
|
214
|
-
case 6:
|
215
|
-
if (!store.cacheAllCSFFiles) {
|
216
|
-
_context.next = 12;
|
217
|
-
break;
|
218
|
-
}
|
219
|
-
|
220
|
-
_context.next = 9;
|
221
|
-
return store.cacheAllCSFFiles();
|
222
|
-
|
223
|
-
case 9:
|
224
|
-
addons.getChannel().emit(Events.SET_STORIES, store.getSetStoriesPayload());
|
225
|
-
_context.next = 13;
|
226
|
-
break;
|
227
|
-
|
228
|
-
case 12:
|
229
|
-
return _context.abrupt("return");
|
230
|
-
|
231
|
-
case 13:
|
232
|
-
addons.getChannel().on(Events.SET_STORIES, function (data) {
|
233
|
-
// TODO Figure out how to get only updated stories
|
234
|
-
// TODO Subscribe on hmr? like use dummy-hmr
|
235
|
-
setStoriesCounter += 1;
|
236
|
-
var stories = serializeRawStories(denormalizeStoryParameters(data));
|
237
|
-
var storiesByFiles = new Map();
|
238
|
-
Object.values(stories).forEach(function (story) {
|
239
|
-
var storiesFromFile = storiesByFiles.get(story.parameters.fileName);
|
240
|
-
if (storiesFromFile) storiesFromFile.push(story);else storiesByFiles.set(story.parameters.fileName, [story]);
|
241
|
-
});
|
242
|
-
void fetch("http://".concat(getConnectionUrl(), "/stories"), {
|
243
|
-
method: 'POST',
|
244
|
-
headers: {
|
245
|
-
'Content-Type': 'application/json'
|
246
|
-
},
|
247
|
-
body: JSON.stringify({
|
248
|
-
setStoriesCounter: setStoriesCounter,
|
249
|
-
stories: _toConsumableArray(storiesByFiles.entries())
|
250
|
-
})
|
251
|
-
});
|
252
|
-
});
|
253
|
-
return _context.abrupt("return", storiesPromise);
|
254
|
-
|
255
|
-
case 15:
|
256
|
-
case "end":
|
257
|
-
return _context.stop();
|
258
|
-
}
|
259
|
-
}
|
260
|
-
}, _callee);
|
261
|
-
}));
|
262
|
-
return _getStories.apply(this, arguments);
|
263
|
-
}
|
264
|
-
|
265
|
-
function selectStory(_x2, _x3, _x4, _x5, _x6) {
|
266
|
-
return _selectStory.apply(this, arguments);
|
116
|
+
async function getStories() {
|
117
|
+
const stories = serializeRawStories(await window.__STORYBOOK_PREVIEW__.extract());
|
118
|
+
const storiesByFiles = new Map();
|
119
|
+
Object.values(stories).forEach(story => {
|
120
|
+
const fileName = story.parameters.fileName;
|
121
|
+
const storiesFromFile = storiesByFiles.get(fileName);
|
122
|
+
if (storiesFromFile) storiesFromFile.push(story);else storiesByFiles.set(fileName, [story]);
|
123
|
+
});
|
124
|
+
void fetch(`http://${getConnectionUrl()}/stories`, {
|
125
|
+
method: 'POST',
|
126
|
+
headers: {
|
127
|
+
'Content-Type': 'application/json'
|
128
|
+
},
|
129
|
+
body: JSON.stringify({
|
130
|
+
setStoriesCounter,
|
131
|
+
stories: [...storiesByFiles.entries()]
|
132
|
+
})
|
133
|
+
});
|
134
|
+
return stories;
|
267
135
|
}
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
case 10:
|
300
|
-
isCaptureCalled = false;
|
301
|
-
renderPromise = waitForStoryRendered(channel);
|
302
|
-
errorPromise = catchRenderError(channel);
|
303
|
-
capturePromise = waitForCaptureCall().then(function () {
|
304
|
-
return isCaptureCalled = true;
|
305
|
-
});
|
306
|
-
setTimeout(function () {
|
307
|
-
return channel.emit(Events.SET_CURRENT_STORY, {
|
308
|
-
storyId: storyId,
|
309
|
-
name: name,
|
310
|
-
kind: kind
|
311
|
-
});
|
312
|
-
}, 0);
|
313
|
-
_context3.prev = 15;
|
314
|
-
_context3.next = 18;
|
315
|
-
return Promise.race([_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
316
|
-
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
317
|
-
while (1) {
|
318
|
-
switch (_context2.prev = _context2.next) {
|
319
|
-
case 0:
|
320
|
-
_context2.next = 2;
|
321
|
-
return Promise.race([renderPromise, capturePromise]);
|
322
|
-
|
323
|
-
case 2:
|
324
|
-
_context2.next = 4;
|
325
|
-
return waitForFontsLoaded();
|
326
|
-
|
327
|
-
case 4:
|
328
|
-
_context2.next = 6;
|
329
|
-
return waitForReady;
|
330
|
-
|
331
|
-
case 6:
|
332
|
-
case "end":
|
333
|
-
return _context2.stop();
|
334
|
-
}
|
335
|
-
}
|
336
|
-
}, _callee2);
|
337
|
-
}))(), errorPromise]);
|
338
|
-
|
339
|
-
case 18:
|
340
|
-
callback([null, isCaptureCalled]);
|
341
|
-
_context3.next = 25;
|
342
|
-
break;
|
343
|
-
|
344
|
-
case 21:
|
345
|
-
_context3.prev = 21;
|
346
|
-
_context3.t0 = _context3["catch"](15);
|
347
|
-
// NOTE Event `STORY_THREW_EXCEPTION` triggered only in react and vue frameworks and return Error instance
|
348
|
-
// NOTE Event `STORY_ERRORED` return error-like object without `name` field
|
349
|
-
errorMessage = _context3.t0 instanceof Error ? (_reason$stack = _context3.t0.stack) !== null && _reason$stack !== void 0 ? _reason$stack : _context3.t0.message : isObject(_context3.t0) ? "".concat(_context3.t0.message, "\n ").concat(_context3.t0.stack) : _context3.t0;
|
350
|
-
callback([errorMessage]);
|
351
|
-
|
352
|
-
case 25:
|
353
|
-
_context3.prev = 25;
|
354
|
-
renderPromise.cancel();
|
355
|
-
errorPromise.cancel();
|
356
|
-
return _context3.finish(25);
|
357
|
-
|
358
|
-
case 29:
|
359
|
-
case "end":
|
360
|
-
return _context3.stop();
|
361
|
-
}
|
362
|
-
}
|
363
|
-
}, _callee3, null, [[15, 21, 25, 29]]);
|
364
|
-
}));
|
365
|
-
return _selectStory.apply(this, arguments);
|
136
|
+
async function selectStory(storyId, kind, name, shouldWaitForReady, callback) {
|
137
|
+
if (!isAnimationDisabled) disableAnimation();
|
138
|
+
isTestBrowser = true;
|
139
|
+
const channel = addonsChannel();
|
140
|
+
const waitForReady = shouldWaitForReady ? new Promise(resolve => window.__CREEVEY_SET_READY_FOR_CAPTURE__ = resolve) : Promise.resolve();
|
141
|
+
if (storyId == currentStory) await resetCurrentStory(channel);else currentStory = storyId;
|
142
|
+
let isCaptureCalled = false;
|
143
|
+
const renderPromise = waitForStoryRendered(channel);
|
144
|
+
const errorPromise = catchRenderError(channel);
|
145
|
+
const capturePromise = waitForCaptureCall().then(() => isCaptureCalled = true);
|
146
|
+
setTimeout(() => channel.emit(Events.SET_CURRENT_STORY, {
|
147
|
+
storyId,
|
148
|
+
name,
|
149
|
+
kind
|
150
|
+
}), 0);
|
151
|
+
try {
|
152
|
+
await Promise.race([(async () => {
|
153
|
+
await Promise.race([renderPromise, capturePromise]);
|
154
|
+
await waitForFontsLoaded();
|
155
|
+
await waitForReady;
|
156
|
+
})(), errorPromise]);
|
157
|
+
callback([null, isCaptureCalled]);
|
158
|
+
} catch (reason) {
|
159
|
+
// NOTE Event `STORY_THREW_EXCEPTION` triggered only in react and vue frameworks and return Error instance
|
160
|
+
// NOTE Event `STORY_ERRORED` return error-like object without `name` field
|
161
|
+
const errorMessage = reason instanceof Error ? reason.stack ?? reason.message : isObject(reason) ? `${reason.message}\n ${reason.stack}` : reason;
|
162
|
+
callback([errorMessage]);
|
163
|
+
} finally {
|
164
|
+
renderPromise.cancel();
|
165
|
+
errorPromise.cancel();
|
166
|
+
}
|
366
167
|
}
|
367
|
-
|
368
168
|
function updateGlobals(globals) {
|
369
|
-
|
370
|
-
globals
|
169
|
+
addonsChannel().emit(Events.UPDATE_GLOBALS, {
|
170
|
+
globals
|
371
171
|
});
|
372
172
|
}
|
373
|
-
|
374
173
|
function insertIgnoreStyles(ignoreSelectors) {
|
375
|
-
|
174
|
+
const stylesElement = document.createElement('style');
|
376
175
|
stylesElement.setAttribute('type', 'text/css');
|
377
176
|
document.head.appendChild(stylesElement);
|
378
|
-
ignoreSelectors.forEach(
|
379
|
-
stylesElement.innerHTML +=
|
177
|
+
ignoreSelectors.forEach(selector => {
|
178
|
+
stylesElement.innerHTML += `
|
179
|
+
${selector} {
|
180
|
+
background: #000 !important;
|
181
|
+
box-shadow: none !important;
|
182
|
+
text-shadow: none !important;
|
183
|
+
outline: 0 !important;
|
184
|
+
color: rgba(0,0,0,0) !important;
|
185
|
+
}
|
186
|
+
${selector} *, ${selector}::before, ${selector}::after {
|
187
|
+
visibility: hidden !important;
|
188
|
+
}
|
189
|
+
`;
|
380
190
|
});
|
381
191
|
return stylesElement;
|
382
192
|
}
|
383
|
-
|
384
193
|
function removeIgnoreStyles(ignoreStyles) {
|
385
|
-
|
386
|
-
|
387
|
-
(_ignoreStyles$parentN = ignoreStyles.parentNode) === null || _ignoreStyles$parentN === void 0 ? void 0 : _ignoreStyles$parentN.removeChild(ignoreStyles);
|
194
|
+
ignoreStyles.parentNode?.removeChild(ignoreStyles);
|
388
195
|
}
|
389
|
-
|
390
196
|
function hasPlayCompletedYet(callback) {
|
391
197
|
creeveyReady();
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
void waitForStoryRendered(channel).then(
|
198
|
+
let isCaptureCalled = false;
|
199
|
+
let isPlayCompleted = false;
|
200
|
+
const channel = addonsChannel();
|
201
|
+
void waitForStoryRendered(channel).then(() => {
|
396
202
|
if (isCaptureCalled) return;
|
397
203
|
isPlayCompleted = true;
|
398
204
|
callback(true);
|
399
205
|
});
|
400
|
-
void waitForCaptureCall().then(
|
206
|
+
void waitForCaptureCall().then(() => {
|
401
207
|
if (isPlayCompleted) return;
|
402
208
|
isCaptureCalled = true;
|
403
209
|
callback(false);
|
404
210
|
});
|
405
211
|
}
|
406
|
-
|
407
212
|
window.__CREEVEY_GET_STORIES__ = getStories;
|
408
213
|
window.__CREEVEY_SELECT_STORY__ = selectStory;
|
409
214
|
window.__CREEVEY_UPDATE_GLOBALS__ = updateGlobals;
|
410
215
|
window.__CREEVEY_INSERT_IGNORE_STYLES__ = insertIgnoreStyles;
|
411
216
|
window.__CREEVEY_REMOVE_IGNORE_STYLES__ = removeIgnoreStyles;
|
412
217
|
window.__CREEVEY_HAS_PLAY_COMPLETED_YET__ = hasPlayCompletedYet;
|
413
|
-
window.__CREEVEY_SET_READY_FOR_CAPTURE__ = noop;
|
414
|
-
// [...container.querySelectorAll(query)].filter((e) => e instanceof HTMLElement) as HTMLElement[];
|
415
|
-
// const getMultipleError = (_: Element | null, query: string): string => `Found multiple elements by query: ${query}`;
|
416
|
-
// const getMissingError = (_: Element | null, query: string): string => `Unable to find an element by query: ${query}`;
|
417
|
-
// const [queryByQuery, getAllByQuery, getByQuery, findAllByQuery, findByQuery] = buildQueries(
|
418
|
-
// queryAllByQuery,
|
419
|
-
// getMultipleError,
|
420
|
-
// getMissingError,
|
421
|
-
// );
|
422
|
-
// const queries = {
|
423
|
-
// queryByQuery,
|
424
|
-
// getAllByQuery,
|
425
|
-
// getByQuery,
|
426
|
-
// findAllByQuery,
|
427
|
-
// findByQuery,
|
428
|
-
// };
|
429
|
-
|
218
|
+
window.__CREEVEY_SET_READY_FOR_CAPTURE__ = noop;
|
430
219
|
return makeDecorator({
|
431
220
|
name: 'withCreevey',
|
432
221
|
parameterName: 'creevey',
|
433
|
-
wrapper:
|
434
|
-
var _ref2;
|
435
|
-
|
222
|
+
wrapper: (getStory, context) => {
|
436
223
|
// TODO Define proper types, like captureElement is a promise
|
437
|
-
|
438
|
-
|
439
|
-
|
224
|
+
const {
|
225
|
+
captureElement
|
226
|
+
} = context.parameters.creevey = context.parameters.creevey ?? {};
|
440
227
|
Object.defineProperty(context.parameters.creevey, 'captureElement', {
|
441
|
-
get
|
228
|
+
get() {
|
442
229
|
switch (true) {
|
443
230
|
case captureElement === undefined:
|
444
231
|
return Promise.resolve(context.canvasElement);
|
445
|
-
|
446
232
|
case captureElement === null:
|
447
233
|
return Promise.resolve(document.documentElement);
|
448
|
-
|
449
|
-
|
450
|
-
|
234
|
+
case typeof captureElement == 'string':
|
235
|
+
return Promise.resolve(context.canvasElement.querySelector(captureElement));
|
451
236
|
case typeof captureElement == 'function':
|
452
237
|
// TODO Define type for it
|
453
238
|
return Promise.resolve(captureElement(context));
|
@@ -460,50 +245,19 @@ export function withCreevey() {
|
|
460
245
|
}
|
461
246
|
});
|
462
247
|
}
|
463
|
-
export function capture(
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
return _context5.abrupt("return");
|
479
|
-
|
480
|
-
case 2:
|
481
|
-
captureResolver();
|
482
|
-
waitForCreevey = new Promise(function (resolve) {
|
483
|
-
return creeveyReady = resolve;
|
484
|
-
});
|
485
|
-
_context5.next = 6;
|
486
|
-
return fetch("http://".concat(getConnectionUrl(), "/capture"), {
|
487
|
-
method: 'POST',
|
488
|
-
headers: {
|
489
|
-
'Content-Type': 'application/json'
|
490
|
-
},
|
491
|
-
body: JSON.stringify({
|
492
|
-
workerId: window.__CREEVEY_WORKER_ID__,
|
493
|
-
options: options
|
494
|
-
})
|
495
|
-
});
|
496
|
-
|
497
|
-
case 6:
|
498
|
-
_context5.next = 8;
|
499
|
-
return waitForCreevey;
|
500
|
-
|
501
|
-
case 8:
|
502
|
-
case "end":
|
503
|
-
return _context5.stop();
|
504
|
-
}
|
505
|
-
}
|
506
|
-
}, _callee5);
|
507
|
-
}));
|
508
|
-
return _capture.apply(this, arguments);
|
248
|
+
export async function capture(options) {
|
249
|
+
if (!isTestBrowser) return;
|
250
|
+
captureResolver();
|
251
|
+
waitForCreevey = new Promise(resolve => creeveyReady = resolve);
|
252
|
+
await fetch(`http://${getConnectionUrl()}/capture`, {
|
253
|
+
method: 'POST',
|
254
|
+
headers: {
|
255
|
+
'Content-Type': 'application/json'
|
256
|
+
},
|
257
|
+
body: JSON.stringify({
|
258
|
+
workerId: window.__CREEVEY_WORKER_ID__,
|
259
|
+
options
|
260
|
+
})
|
261
|
+
});
|
262
|
+
await waitForCreevey;
|
509
263
|
}
|