creevey 0.9.0-beta.1 → 0.9.0-beta.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 (145) hide show
  1. package/lib/cjs/cli.js +5 -0
  2. package/lib/cjs/client/addon/Manager.js +412 -0
  3. package/lib/cjs/client/addon/components/Addon.js +76 -0
  4. package/lib/cjs/client/addon/components/Icons.js +42 -0
  5. package/lib/cjs/client/addon/components/Panel.js +68 -0
  6. package/lib/cjs/client/addon/components/TestSelect.js +63 -0
  7. package/lib/cjs/client/addon/components/Tools.js +114 -0
  8. package/lib/cjs/client/addon/decorator.js +11 -0
  9. package/lib/cjs/client/addon/preset.js +81 -0
  10. package/lib/cjs/client/addon/readyForCapture.js +12 -0
  11. package/lib/cjs/client/addon/register.js +96 -0
  12. package/lib/cjs/client/addon/utils.js +38 -0
  13. package/lib/cjs/client/addon/withCreevey.js +531 -0
  14. package/lib/cjs/client/shared/components/ImagesView/BlendView.js +85 -0
  15. package/lib/cjs/client/shared/components/ImagesView/ImagesView.js +88 -0
  16. package/lib/cjs/client/shared/components/ImagesView/SideBySideView.js +176 -0
  17. package/lib/cjs/client/shared/components/ImagesView/SlideView.js +179 -0
  18. package/lib/cjs/client/shared/components/ImagesView/SwapView.js +110 -0
  19. package/lib/cjs/client/shared/components/ImagesView/index.js +45 -0
  20. package/lib/cjs/client/shared/components/PageFooter/PageFooter.js +46 -0
  21. package/lib/cjs/client/shared/components/PageFooter/Paging.js +98 -0
  22. package/lib/cjs/client/shared/components/PageHeader/ImagePreview.js +78 -0
  23. package/lib/cjs/client/shared/components/PageHeader/PageHeader.js +144 -0
  24. package/lib/cjs/client/shared/components/ResultsPage.js +173 -0
  25. package/lib/cjs/client/shared/creeveyClientApi.js +103 -0
  26. package/lib/cjs/client/shared/helpers.js +482 -0
  27. package/lib/cjs/client/shared/viewMode.js +17 -0
  28. package/lib/cjs/client/web/index.html +19 -0
  29. package/lib/cjs/creevey.js +71 -0
  30. package/lib/cjs/index.js +62 -0
  31. package/lib/cjs/server/config.js +96 -0
  32. package/lib/cjs/server/docker.js +150 -0
  33. package/lib/cjs/server/extract.js +50 -0
  34. package/lib/cjs/server/index.js +83 -0
  35. package/lib/cjs/server/loaders/babel/creevey-plugin.js +88 -0
  36. package/lib/cjs/server/loaders/babel/helpers.js +479 -0
  37. package/lib/cjs/server/loaders/babel/register.js +126 -0
  38. package/lib/cjs/server/loaders/hooks/mdx.js +30 -0
  39. package/lib/cjs/server/loaders/hooks/svelte.js +65 -0
  40. package/lib/cjs/server/loaders/webpack/compile.js +286 -0
  41. package/lib/cjs/server/loaders/webpack/creevey-loader.js +174 -0
  42. package/lib/cjs/server/loaders/webpack/dummy-hmr.js +44 -0
  43. package/lib/cjs/server/loaders/webpack/mdx-loader.js +72 -0
  44. package/lib/cjs/server/loaders/webpack/start.js +41 -0
  45. package/lib/cjs/server/logger.js +47 -0
  46. package/lib/cjs/server/master/api.js +71 -0
  47. package/lib/cjs/server/master/index.js +146 -0
  48. package/lib/cjs/server/master/master.js +57 -0
  49. package/lib/cjs/server/master/pool.js +206 -0
  50. package/lib/cjs/server/master/runner.js +294 -0
  51. package/lib/cjs/server/master/server.js +129 -0
  52. package/lib/cjs/server/messages.js +266 -0
  53. package/lib/cjs/server/selenium/browser.js +680 -0
  54. package/lib/cjs/server/selenium/index.js +31 -0
  55. package/lib/cjs/server/selenium/selenoid.js +174 -0
  56. package/lib/cjs/server/stories.js +170 -0
  57. package/lib/cjs/server/storybook/entry.js +68 -0
  58. package/lib/cjs/server/storybook/helpers.js +165 -0
  59. package/lib/cjs/server/storybook/providers/browser.js +78 -0
  60. package/lib/cjs/server/storybook/providers/hybrid.js +84 -0
  61. package/lib/cjs/server/storybook/providers/nodejs.js +239 -0
  62. package/lib/cjs/server/testsFiles/parser.js +72 -0
  63. package/lib/cjs/server/testsFiles/register.js +48 -0
  64. package/lib/cjs/server/update.js +83 -0
  65. package/lib/cjs/server/utils.js +185 -0
  66. package/lib/cjs/server/worker/chai-image.js +142 -0
  67. package/lib/cjs/server/worker/helpers.js +69 -0
  68. package/lib/cjs/server/worker/index.js +15 -0
  69. package/lib/cjs/server/worker/reporter.js +120 -0
  70. package/lib/cjs/server/worker/worker.js +278 -0
  71. package/lib/cjs/shared.js +124 -0
  72. package/lib/cjs/types.js +74 -0
  73. package/lib/esm/cli.js +4 -0
  74. package/lib/esm/client/addon/Manager.js +396 -0
  75. package/lib/esm/client/addon/components/Addon.js +58 -0
  76. package/lib/esm/client/addon/components/Icons.js +27 -0
  77. package/lib/esm/client/addon/components/Panel.js +49 -0
  78. package/lib/esm/client/addon/components/TestSelect.js +49 -0
  79. package/lib/esm/client/addon/components/Tools.js +91 -0
  80. package/lib/esm/client/addon/decorator.js +2 -0
  81. package/lib/esm/client/addon/preset.js +56 -0
  82. package/lib/esm/client/addon/readyForCapture.js +5 -0
  83. package/lib/esm/client/addon/register.js +75 -0
  84. package/lib/esm/client/addon/utils.js +31 -0
  85. package/lib/esm/client/addon/withCreevey.js +509 -0
  86. package/lib/esm/client/shared/components/ImagesView/BlendView.js +63 -0
  87. package/lib/esm/client/shared/components/ImagesView/ImagesView.js +65 -0
  88. package/lib/esm/client/shared/components/ImagesView/SideBySideView.js +151 -0
  89. package/lib/esm/client/shared/components/ImagesView/SlideView.js +154 -0
  90. package/lib/esm/client/shared/components/ImagesView/SwapView.js +88 -0
  91. package/lib/esm/client/shared/components/ImagesView/index.js +5 -0
  92. package/lib/esm/client/shared/components/PageFooter/PageFooter.js +32 -0
  93. package/lib/esm/client/shared/components/PageFooter/Paging.js +84 -0
  94. package/lib/esm/client/shared/components/PageHeader/ImagePreview.js +64 -0
  95. package/lib/esm/client/shared/components/PageHeader/PageHeader.js +120 -0
  96. package/lib/esm/client/shared/components/ResultsPage.js +143 -0
  97. package/lib/esm/client/shared/creeveyClientApi.js +94 -0
  98. package/lib/esm/client/shared/helpers.js +424 -0
  99. package/lib/esm/client/shared/viewMode.js +6 -0
  100. package/lib/esm/creevey.js +56 -0
  101. package/lib/esm/index.js +7 -0
  102. package/lib/esm/server/config.js +73 -0
  103. package/lib/esm/server/docker.js +123 -0
  104. package/lib/esm/server/extract.js +34 -0
  105. package/lib/esm/server/index.js +64 -0
  106. package/lib/esm/server/loaders/babel/creevey-plugin.js +74 -0
  107. package/lib/esm/server/loaders/babel/helpers.js +462 -0
  108. package/lib/esm/server/loaders/babel/register.js +105 -0
  109. package/lib/esm/server/loaders/hooks/mdx.js +15 -0
  110. package/lib/esm/server/loaders/hooks/svelte.js +49 -0
  111. package/lib/esm/server/loaders/webpack/compile.js +263 -0
  112. package/lib/esm/server/loaders/webpack/creevey-loader.js +153 -0
  113. package/lib/esm/server/loaders/webpack/dummy-hmr.js +36 -0
  114. package/lib/esm/server/loaders/webpack/mdx-loader.js +58 -0
  115. package/lib/esm/server/loaders/webpack/start.js +27 -0
  116. package/lib/esm/server/logger.js +20 -0
  117. package/lib/esm/server/master/api.js +60 -0
  118. package/lib/esm/server/master/index.js +125 -0
  119. package/lib/esm/server/master/master.js +38 -0
  120. package/lib/esm/server/master/pool.js +187 -0
  121. package/lib/esm/server/master/runner.js +272 -0
  122. package/lib/esm/server/master/server.js +105 -0
  123. package/lib/esm/server/messages.js +234 -0
  124. package/lib/esm/server/selenium/browser.js +647 -0
  125. package/lib/esm/server/selenium/index.js +2 -0
  126. package/lib/esm/server/selenium/selenoid.js +151 -0
  127. package/lib/esm/server/stories.js +151 -0
  128. package/lib/esm/server/storybook/entry.js +44 -0
  129. package/lib/esm/server/storybook/helpers.js +106 -0
  130. package/lib/esm/server/storybook/providers/browser.js +61 -0
  131. package/lib/esm/server/storybook/providers/hybrid.js +64 -0
  132. package/lib/esm/server/storybook/providers/nodejs.js +217 -0
  133. package/lib/esm/server/testsFiles/parser.js +50 -0
  134. package/lib/esm/server/testsFiles/register.js +35 -0
  135. package/lib/esm/server/update.js +65 -0
  136. package/lib/esm/server/utils.js +146 -0
  137. package/lib/esm/server/worker/chai-image.js +130 -0
  138. package/lib/esm/server/worker/helpers.js +60 -0
  139. package/lib/esm/server/worker/index.js +1 -0
  140. package/lib/esm/server/worker/reporter.js +98 -0
  141. package/lib/esm/server/worker/worker.js +248 -0
  142. package/lib/esm/shared.js +93 -0
  143. package/lib/esm/types.js +43 -0
  144. package/lib/types/index.d.ts +2 -4
  145. package/package.json +1 -1
@@ -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,98 @@
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 chalk from 'chalk';
4
+ import { reporters } from 'mocha';
5
+ import prefix from 'loglevel-plugin-prefix';
6
+ import { isDefined, isImageError } from '../../types';
7
+ import { getLogger } from '../logger';
8
+ const testLevels = {
9
+ INFO: chalk.green('PASS'),
10
+ WARN: chalk.yellow('START'),
11
+ ERROR: chalk.red('FAIL')
12
+ };
13
+ export class CreeveyReporter extends reporters.Base {
14
+ constructor(runner, options) {
15
+ super(runner);
16
+ const {
17
+ sessionId,
18
+ topLevelSuite
19
+ } = options.reporterOptions;
20
+ const testLogger = getLogger(topLevelSuite);
21
+ prefix.apply(testLogger, {
22
+ format(level) {
23
+ return `${testLevels[level]} => (${topLevelSuite}:${chalk.gray(sessionId)})`;
24
+ }
25
+
26
+ });
27
+ runner.on('test', test => testLogger.warn(chalk.cyan(test.titlePath().join('/'))));
28
+ runner.on('pass', test => testLogger.info(chalk.cyan(test.titlePath().join('/'))));
29
+ runner.on('fail', (test, error) => testLogger.error(chalk.cyan(test.titlePath().join('/')), '\n ', getErrors(error, (error, imageName) => `${chalk.bold(imageName !== null && imageName !== void 0 ? imageName : topLevelSuite)}:${error}`, error => {
30
+ var _error$stack;
31
+
32
+ return `${(_error$stack = error.stack) !== null && _error$stack !== void 0 ? _error$stack : error.message}`;
33
+ }).join('\n ')));
34
+ }
35
+
36
+ }
37
+ export class TeamcityReporter extends reporters.Base {
38
+ constructor(runner, options) {
39
+ super(runner);
40
+
41
+ _defineProperty(this, "escape", str => {
42
+ if (!str) return '';
43
+ return str.toString() // eslint-disable-next-line no-control-regex
44
+ .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, "|'");
45
+ });
46
+
47
+ const topLevelSuite = this.escape(options.reporterOptions.topLevelSuite);
48
+ const reporterOptions = options.reporterOptions;
49
+ 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}']`));
50
+ runner.on('test', test => console.log(`##teamcity[testStarted name='${this.escape(test.title)}' flowId='${process.pid}']`));
51
+ runner.on('fail', (test, error) => {
52
+ var _error$stack2;
53
+
54
+ Object.entries(reporterOptions.images).forEach(([name, image]) => {
55
+ if (!image) return;
56
+ const filePath = test.titlePath().concat(name == topLevelSuite ? [] : [topLevelSuite]).map(this.escape).join('/'); // eslint-disable-next-line @typescript-eslint/no-unused-vars
57
+
58
+ const {
59
+ error,
60
+ ...rest
61
+ } = image;
62
+ Object.values(rest).filter(isDefined).forEach(fileName => {
63
+ console.log(`##teamcity[publishArtifacts '${reporterOptions.reportDir}/${filePath}/${fileName} => report/${filePath}']`);
64
+ console.log(`##teamcity[testMetadata testName='${this.escape(test.title)}' type='image' value='report/${filePath}/${fileName}' flowId='${process.pid}']`);
65
+ });
66
+ }); // Output failed test as passed due TC don't support retry mechanic
67
+ // 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
68
+
69
+ 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$stack2 = error.stack) !== null && _error$stack2 !== void 0 ? _error$stack2 : '')}' flowId='${process.pid}']`);
70
+ });
71
+ 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}']`));
72
+ runner.on('test end', test => console.log(`##teamcity[testFinished name='${this.escape(test.title)}' flowId='${process.pid}']`));
73
+ runner.on('suite end', suite => suite.root || console.log(`##teamcity[testSuiteFinished name='${this.escape(suite.title)}' flowId='${process.pid}']`));
74
+ runner.on('end', () => console.log(`##teamcity[testSuiteFinished name='${topLevelSuite}' flowId='${process.pid}']`));
75
+ }
76
+
77
+ }
78
+
79
+ function getErrors(error, imageErrorToString, errorToString) {
80
+ const errors = [];
81
+
82
+ if (!(error instanceof Error)) {
83
+ errors.push(error);
84
+ } else if (!isImageError(error)) {
85
+ errors.push(errorToString(error));
86
+ } else if (typeof error.images == 'string') {
87
+ errors.push(imageErrorToString(error.images));
88
+ } else {
89
+ const imageErrors = error.images;
90
+ Object.keys(imageErrors).forEach(imageName => {
91
+ var _imageErrors$imageNam;
92
+
93
+ errors.push(imageErrorToString((_imageErrors$imageNam = imageErrors[imageName]) !== null && _imageErrors$imageNam !== void 0 ? _imageErrors$imageNam : '', imageName));
94
+ });
95
+ }
96
+
97
+ return errors;
98
+ }
@@ -0,0 +1,248 @@
1
+ import { promisify } from 'util';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import chai from 'chai';
5
+ import chalk from 'chalk';
6
+ import Mocha from 'mocha';
7
+ import { Key, until } from 'selenium-webdriver';
8
+ import { isImageError } from '../../types';
9
+ import { subscribeOn, emitTestMessage, emitWorkerMessage } from '../messages';
10
+ import chaiImage from './chai-image';
11
+ import { closeBrowser, getBrowser, switchStory } from '../selenium';
12
+ import { CreeveyReporter, TeamcityReporter } from './reporter';
13
+ import { addTestsFromStories } from './helpers';
14
+ import { logger } from '../logger';
15
+ const statAsync = promisify(fs.stat);
16
+ const readdirAsync = promisify(fs.readdir);
17
+ const readFileAsync = promisify(fs.readFile);
18
+ const writeFileAsync = promisify(fs.writeFile);
19
+ const mkdirAsync = promisify(fs.mkdir);
20
+
21
+ async function getStat(filePath) {
22
+ try {
23
+ return await statAsync(filePath);
24
+ } catch (error) {
25
+ if (typeof error == 'object' && error && error.code === 'ENOENT') {
26
+ return null;
27
+ }
28
+
29
+ throw error;
30
+ }
31
+ }
32
+
33
+ async function getLastImageNumber(imageDir, imageName) {
34
+ const actualImagesRegexp = new RegExp(`${imageName}-actual-(\\d+)\\.png`);
35
+
36
+ try {
37
+ var _await$readdirAsync$m;
38
+
39
+ return (_await$readdirAsync$m = (await readdirAsync(imageDir)).map(filename => filename.replace(actualImagesRegexp, '$1')).map(Number).filter(x => !isNaN(x)).sort((a, b) => b - a)[0]) !== null && _await$readdirAsync$m !== void 0 ? _await$readdirAsync$m : 0;
40
+ } catch (_error) {
41
+ return 0;
42
+ }
43
+ } // FIXME browser options hotfix
44
+
45
+
46
+ export default async function worker(config, options) {
47
+ var _await$browser$getSes;
48
+
49
+ let retries = 0;
50
+ let images = {};
51
+ let error = undefined;
52
+ const screenshots = [];
53
+ const testScope = [];
54
+
55
+ function runHandler(failures) {
56
+ if (failures > 0 && (error || Object.values(images).some(image => (image === null || image === void 0 ? void 0 : image.error) != null))) {
57
+ var _error2;
58
+
59
+ const isTimeout = hasTimeout(error) || Object.values(images).some(image => hasTimeout(image === null || image === void 0 ? void 0 : image.error));
60
+ const payload = {
61
+ status: 'failed',
62
+ images,
63
+ error
64
+ };
65
+ isTimeout ? emitWorkerMessage({
66
+ type: 'error',
67
+ payload: {
68
+ error: (_error2 = error) !== null && _error2 !== void 0 ? _error2 : 'Unknown error'
69
+ }
70
+ }) : emitTestMessage({
71
+ type: 'end',
72
+ payload
73
+ });
74
+ } else {
75
+ emitTestMessage({
76
+ type: 'end',
77
+ payload: {
78
+ status: 'success',
79
+ images
80
+ }
81
+ });
82
+ }
83
+ }
84
+
85
+ async function saveImages(imageDir, images) {
86
+ await mkdirAsync(imageDir, {
87
+ recursive: true
88
+ });
89
+
90
+ for (const {
91
+ name,
92
+ data
93
+ } of images) {
94
+ await writeFileAsync(path.join(imageDir, name), data);
95
+ }
96
+ }
97
+
98
+ async function getExpected(assertImageName) {
99
+ var _images$imageName;
100
+
101
+ // context => [kind, story, test, browser]
102
+ // rootSuite -> kindSuite -> storyTest -> [browsers.png]
103
+ // rootSuite -> kindSuite -> storySuite -> test -> [browsers.png]
104
+ const testPath = [...testScope];
105
+ const imageName = assertImageName !== null && assertImageName !== void 0 ? assertImageName : testPath.pop();
106
+ const imagesMeta = [];
107
+ const reportImageDir = path.join(config.reportDir, ...testPath);
108
+ const imageNumber = (await getLastImageNumber(reportImageDir, imageName)) + 1;
109
+ const actualImageName = `${imageName}-actual-${imageNumber}.png`;
110
+ const image = images[imageName] = (_images$imageName = images[imageName]) !== null && _images$imageName !== void 0 ? _images$imageName : {
111
+ actual: actualImageName
112
+ };
113
+
114
+ const onCompare = async (actual, expect, diff) => {
115
+ imagesMeta.push({
116
+ name: image.actual,
117
+ data: actual
118
+ });
119
+
120
+ if (diff && expect) {
121
+ image.expect = `${imageName}-expect-${imageNumber}.png`;
122
+ image.diff = `${imageName}-diff-${imageNumber}.png`;
123
+ imagesMeta.push({
124
+ name: image.expect,
125
+ data: expect
126
+ });
127
+ imagesMeta.push({
128
+ name: image.diff,
129
+ data: diff
130
+ });
131
+ }
132
+
133
+ if (options.saveReport) {
134
+ await saveImages(reportImageDir, imagesMeta);
135
+ }
136
+ };
137
+
138
+ const expectImageDir = path.join(config.screenDir, ...testPath);
139
+ const expectImageStat = await getStat(path.join(expectImageDir, `${imageName}.png`));
140
+ if (!expectImageStat) return {
141
+ expected: null,
142
+ onCompare
143
+ };
144
+ const expected = await readFileAsync(path.join(expectImageDir, `${imageName}.png`));
145
+ return {
146
+ expected,
147
+ onCompare
148
+ };
149
+ }
150
+
151
+ const mochaOptions = {
152
+ timeout: 30000,
153
+ reporter: process.env.TEAMCITY_VERSION ? TeamcityReporter : options.reporter || CreeveyReporter,
154
+ reporterOptions: {
155
+ reportDir: config.reportDir,
156
+ topLevelSuite: options.browser,
157
+
158
+ get willRetry() {
159
+ return retries < config.maxRetries;
160
+ },
161
+
162
+ get images() {
163
+ return images;
164
+ },
165
+
166
+ get sessionId() {
167
+ return sessionId;
168
+ }
169
+
170
+ }
171
+ };
172
+ const mocha = new Mocha(mochaOptions); // @ts-expect-error: @types/mocha has out-dated types
173
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
174
+
175
+ mocha.cleanReferencesAfterRun(false);
176
+ chai.use(chaiImage(getExpected, config.diffOptions));
177
+ if ((await getBrowser(config, options.browser)) == null) return;
178
+ await addTestsFromStories(mocha.suite, config, {
179
+ browser: options.browser,
180
+ watch: options.ui,
181
+ debug: options.debug,
182
+ port: options.port
183
+ });
184
+
185
+ try {
186
+ var _await$getBrowser;
187
+
188
+ await ((_await$getBrowser = await getBrowser(config, options.browser)) === null || _await$getBrowser === void 0 ? void 0 : _await$getBrowser.getCurrentUrl());
189
+ } catch (_) {
190
+ await closeBrowser();
191
+ }
192
+
193
+ const browser = await getBrowser(config, options.browser);
194
+ const sessionId = (_await$browser$getSes = await (browser === null || browser === void 0 ? void 0 : browser.getSession())) === null || _await$browser$getSes === void 0 ? void 0 : _await$browser$getSes.getId();
195
+ if (browser == null) return;
196
+ const interval = setInterval(() => void browser.getCurrentUrl().then(url => {
197
+ if (options.debug) logger.debug(`${options.browser}:${chalk.gray(sessionId)}`, 'current url', chalk.magenta(url));
198
+ }), 10 * 1000);
199
+ subscribeOn('shutdown', () => clearInterval(interval));
200
+ mocha.suite.beforeAll(function () {
201
+ this.config = config;
202
+ this.browser = browser;
203
+ this.until = until;
204
+ this.keys = Key;
205
+ this.expect = chai.expect;
206
+ this.browserName = options.browser;
207
+ this.testScope = testScope;
208
+ this.screenshots = screenshots;
209
+ });
210
+ mocha.suite.beforeEach(switchStory);
211
+ subscribeOn('test', message => {
212
+ if (message.type != 'start') return;
213
+ const test = message.payload;
214
+ const testPath = test.path.join(' ').replace(/[|\\{}()[\]^$+*?.-]/g, '\\$&');
215
+ images = {};
216
+ error = undefined;
217
+ retries = test.retries;
218
+ mocha.grep(new RegExp(`^${testPath}$`));
219
+ const runner = mocha.run(runHandler); // TODO How handle browser corruption?
220
+
221
+ runner.on('fail', (_test, reason) => {
222
+ if (!(reason instanceof Error)) {
223
+ error = reason;
224
+ } else if (!isImageError(reason)) {
225
+ var _reason$stack;
226
+
227
+ error = (_reason$stack = reason.stack) !== null && _reason$stack !== void 0 ? _reason$stack : reason.message;
228
+ } else if (typeof reason.images == 'string') {
229
+ const image = images[testScope.slice(-1)[0]];
230
+ if (image) image.error = reason.images;
231
+ } else {
232
+ const imageErrors = reason.images;
233
+ Object.keys(imageErrors).forEach(imageName => {
234
+ const image = images[imageName];
235
+ if (image) image.error = imageErrors[imageName];
236
+ });
237
+ }
238
+ });
239
+ });
240
+ logger.info(`${options.browser}:${chalk.gray(sessionId)} is ready`);
241
+ emitWorkerMessage({
242
+ type: 'ready'
243
+ });
244
+ }
245
+
246
+ function hasTimeout(str) {
247
+ return str != null && str.toLowerCase().includes('timeout');
248
+ }
@@ -0,0 +1,93 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
2
+
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4
+
5
+ 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; }
6
+
7
+ 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); }
8
+
9
+ import { mapValues, mergeWith, cloneDeepWith } from 'lodash';
10
+ // NOTE: Copy-paste from storybook/api
11
+ export var combineParameters = function combineParameters() {
12
+ for (var _len = arguments.length, parameterSets = new Array(_len), _key = 0; _key < _len; _key++) {
13
+ parameterSets[_key] = arguments[_key];
14
+ }
15
+
16
+ return (// eslint-disable-next-line @typescript-eslint/no-unsafe-return
17
+ mergeWith.apply(void 0, [{}].concat(parameterSets, [function (_, srcValue) {
18
+ // Treat arrays as scalars:
19
+ if (Array.isArray(srcValue)) return srcValue;
20
+ return undefined;
21
+ }]))
22
+ );
23
+ }; // NOTE: Copy-paste from storybook/api
24
+
25
+ export var denormalizeStoryParameters = function denormalizeStoryParameters(_ref) {
26
+ var globalParameters = _ref.globalParameters,
27
+ kindParameters = _ref.kindParameters,
28
+ stories = _ref.stories;
29
+ return mapValues(stories, function (storyData) {
30
+ var _globalParameters$cre, _kindParameters$story, _kindParameters$story2;
31
+
32
+ storyData.parameters.creevey = combineParameters((_globalParameters$cre = globalParameters.creevey) !== null && _globalParameters$cre !== void 0 ? _globalParameters$cre : {}, (_kindParameters$story = (_kindParameters$story2 = kindParameters[storyData.kind]) === null || _kindParameters$story2 === void 0 ? void 0 : _kindParameters$story2.creevey) !== null && _kindParameters$story !== void 0 ? _kindParameters$story : {}, storyData.parameters.creevey);
33
+ return storyData;
34
+ });
35
+ };
36
+ export var isSerializedRegExp = function isSerializedRegExp(exp) {
37
+ return _typeof(exp) === 'object' && exp !== null && Reflect.get(exp, '__regexp') === true;
38
+ };
39
+ export var serializeRegExp = function serializeRegExp(exp) {
40
+ var source = exp.source,
41
+ flags = exp.flags;
42
+ return {
43
+ __regexp: true,
44
+ source: source,
45
+ flags: flags
46
+ };
47
+ };
48
+ export var deserializeRegExp = function deserializeRegExp(_ref2) {
49
+ var source = _ref2.source,
50
+ flags = _ref2.flags;
51
+ return new RegExp(source, flags);
52
+ };
53
+ export var serializeRawStories = function serializeRawStories(stories) {
54
+ return mapValues(stories, function (storyData) {
55
+ var creevey = storyData.parameters.creevey;
56
+
57
+ if (creevey !== null && creevey !== void 0 && creevey.skip) {
58
+ creevey.skip = cloneDeepWith(creevey.skip, function (value) {
59
+ if (value instanceof RegExp) {
60
+ return serializeRegExp(value);
61
+ }
62
+
63
+ return undefined;
64
+ });
65
+ }
66
+
67
+ return storyData;
68
+ });
69
+ };
70
+ export var deserializeRawStories = function deserializeRawStories(stories) {
71
+ return mapValues(stories, deserializeStory);
72
+ };
73
+ export var deserializeStory = function deserializeStory(story) {
74
+ var creevey = story.parameters.creevey;
75
+
76
+ if (creevey !== null && creevey !== void 0 && creevey.skip) {
77
+ return _objectSpread(_objectSpread({}, story), {}, {
78
+ parameters: _objectSpread(_objectSpread({}, story.parameters), {}, {
79
+ creevey: _objectSpread(_objectSpread({}, creevey), {}, {
80
+ skip: cloneDeepWith(creevey.skip, function (value) {
81
+ if (isSerializedRegExp(value)) {
82
+ return deserializeRegExp(value);
83
+ }
84
+
85
+ return undefined;
86
+ })
87
+ })
88
+ })
89
+ });
90
+ }
91
+
92
+ return story;
93
+ };
@@ -0,0 +1,43 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
3
+ /* eslint-enable @typescript-eslint/no-explicit-any */
4
+ export function noop() {
5
+ /* noop */
6
+ }
7
+ export function isDefined(value) {
8
+ return value !== null && value !== undefined;
9
+ }
10
+ export function isTest(x) {
11
+ return isDefined(x) && 'id' in x && 'storyId' in x && typeof x.id == 'string' && typeof x.storyId == 'string';
12
+ }
13
+ export function isObject(x) {
14
+ return typeof x == 'object' && x != null;
15
+ }
16
+ export function isString(x) {
17
+ return typeof x == 'string';
18
+ } // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+
20
+ export function isFunction(x) {
21
+ return typeof x == 'function';
22
+ }
23
+ export function isImageError(error) {
24
+ return error instanceof Error && 'images' in error;
25
+ }
26
+ export function isProcessMessage(message) {
27
+ return isObject(message) && 'scope' in message;
28
+ }
29
+ export function isWorkerMessage(message) {
30
+ return isProcessMessage(message) && message.scope == 'worker';
31
+ }
32
+ export function isStoriesMessage(message) {
33
+ return isProcessMessage(message) && message.scope == 'stories';
34
+ }
35
+ export function isTestMessage(message) {
36
+ return isProcessMessage(message) && message.scope == 'test';
37
+ }
38
+ export function isWebpackMessage(message) {
39
+ return isProcessMessage(message) && message.scope == 'webpack';
40
+ }
41
+ export function isDockerMessage(message) {
42
+ return isProcessMessage(message) && message.scope == 'docker';
43
+ }
@@ -1,5 +1,3 @@
1
+ /// <reference types="../../types/chai" />
1
2
  export * from './types';
2
- export { loadStories as browserStoriesProvider } from './server/storybook/providers/browser';
3
- export { loadStories as nodejsStoriesProvider } from './server/storybook/providers/nodejs';
4
- export { loadStories as hybridStoriesProvider } from './server/storybook/providers/hybrid';
5
- export * from './server/testsFiles/parser';
3
+ // export * from './client/addon/withCreevey';
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "addon",
14
14
  "test"
15
15
  ],
16
- "version": "0.9.0-beta.1",
16
+ "version": "0.9.0-beta.2",
17
17
  "bin": {
18
18
  "creevey": "./lib/cjs/cli.js"
19
19
  },