@applitools/eyes-storybook 3.34.2 → 3.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,91 @@
3
3
  ## Unreleased
4
4
 
5
5
 
6
+
7
+ ## [3.36.0](https://github.com/applitools/eyes.sdk.javascript1/compare/js/eyes-storybook-v3.35.1...js/eyes-storybook@3.36.0) (2023-07-05)
8
+
9
+
10
+ ### Features
11
+
12
+ * added support for storybook installed in parent module ([#1060](https://github.com/applitools/eyes.sdk.javascript1/issues/1060)) ([e2b9fbb](https://github.com/applitools/eyes.sdk.javascript1/commit/e2b9fbbb41938b2363a2c675874ad28e41859076))
13
+ * support dns caching ([#1680](https://github.com/applitools/eyes.sdk.javascript1/issues/1680)) ([9bbff34](https://github.com/applitools/eyes.sdk.javascript1/commit/9bbff34f50c9d18758b55a6bcb45571ca1148180))
14
+
15
+
16
+ ### Dependencies
17
+
18
+ * @applitools/core bumped from 3.4.0 to 3.5.0
19
+ #### Features
20
+
21
+ * added auto applitools lib detection ([#1707](https://github.com/applitools/eyes.sdk.javascript1/issues/1707)) ([7d439b5](https://github.com/applitools/eyes.sdk.javascript1/commit/7d439b52af55f3b0596c9d35d6ba85c717448023))
22
+ * support dns caching ([#1680](https://github.com/applitools/eyes.sdk.javascript1/issues/1680)) ([9bbff34](https://github.com/applitools/eyes.sdk.javascript1/commit/9bbff34f50c9d18758b55a6bcb45571ca1148180))
23
+
24
+
25
+ #### Bug Fixes
26
+
27
+ * some fix ([660a137](https://github.com/applitools/eyes.sdk.javascript1/commit/660a1376a49dd28f8f399690502cd3d1f77665fa))
28
+
29
+
30
+
31
+ * @applitools/core-base bumped from 1.2.1 to 1.3.0
32
+ #### Features
33
+
34
+ * support dns caching ([#1680](https://github.com/applitools/eyes.sdk.javascript1/issues/1680)) ([9bbff34](https://github.com/applitools/eyes.sdk.javascript1/commit/9bbff34f50c9d18758b55a6bcb45571ca1148180))
35
+
36
+
37
+
38
+ * @applitools/req bumped from 1.3.3 to 1.4.0
39
+ #### Features
40
+
41
+ * support dns caching ([#1680](https://github.com/applitools/eyes.sdk.javascript1/issues/1680)) ([9bbff34](https://github.com/applitools/eyes.sdk.javascript1/commit/9bbff34f50c9d18758b55a6bcb45571ca1148180))
42
+ * @applitools/driver bumped from 1.12.4 to 1.13.0
43
+ #### Features
44
+
45
+ * added auto applitools lib detection ([#1707](https://github.com/applitools/eyes.sdk.javascript1/issues/1707)) ([7d439b5](https://github.com/applitools/eyes.sdk.javascript1/commit/7d439b52af55f3b0596c9d35d6ba85c717448023))
46
+ * @applitools/ec-client bumped from 1.5.0 to 1.6.0
47
+ #### Features
48
+
49
+ * added support of regional execution cloud servers ([#1711](https://github.com/applitools/eyes.sdk.javascript1/issues/1711)) ([2e26c69](https://github.com/applitools/eyes.sdk.javascript1/commit/2e26c6944bb15f6121fb37c1dba95aba162c1f6a))
50
+ * support dns caching ([#1680](https://github.com/applitools/eyes.sdk.javascript1/issues/1680)) ([9bbff34](https://github.com/applitools/eyes.sdk.javascript1/commit/9bbff34f50c9d18758b55a6bcb45571ca1148180))
51
+
52
+
53
+ #### Bug Fixes
54
+
55
+ * fixed auto tunnel cleanup after unexpected end of the process ([3c1ad08](https://github.com/applitools/eyes.sdk.javascript1/commit/3c1ad0837d2d3560becc6d89370aa878becb3270))
56
+
57
+
58
+
59
+ * @applitools/tunnel-client bumped from 0.1.1 to 1.0.0
60
+ #### Features
61
+
62
+ * added binaries and made them available in jfrog ([92033fe](https://github.com/applitools/eyes.sdk.javascript1/commit/92033fed7edc58bbc4a4e37269068418fe3afc3d))
63
+ * release as 1.0.0 ([93bf312](https://github.com/applitools/eyes.sdk.javascript1/commit/93bf31205b07d19bc2cb4f50b974c7bad0f49cea))
64
+
65
+
66
+
67
+ * @applitools/ufg-client bumped from 1.2.22 to 1.3.0
68
+ #### Features
69
+
70
+ * support dns caching ([#1680](https://github.com/applitools/eyes.sdk.javascript1/issues/1680)) ([9bbff34](https://github.com/applitools/eyes.sdk.javascript1/commit/9bbff34f50c9d18758b55a6bcb45571ca1148180))
71
+
72
+
73
+
74
+ * @applitools/spec-driver-webdriver bumped from 1.0.36 to 1.0.37
75
+
76
+ * @applitools/nml-client bumped from 1.5.0 to 1.5.1
77
+
78
+ * @applitools/screenshoter bumped from 3.8.1 to 3.8.2
79
+
80
+ * @applitools/spec-driver-puppeteer bumped from 1.1.67 to 1.1.68
81
+
82
+
83
+ ## 3.35.0 - 2023/6/13
84
+
85
+ ### Features
86
+ ### Bug fixes
87
+ - Add support for variations in storybook 7
88
+ - Increase timeout for rendering results polling
89
+ - Add the option to not fail on visual differences using exitcode `nodiffs`
90
+
6
91
  ## 3.34.2 - 2023/5/16
7
92
 
8
93
  ### Features
package/README.md CHANGED
@@ -154,7 +154,7 @@ In addition to command-line arguments, it's possible to define the following con
154
154
  | `storybookStaticDir` | undefined | Path to Storybook's static files folder (also available as command-line argument). |
155
155
  | `showStorybookOutput` | undefined | Whether or not you want to see Storybook output (also available as command-line argument). |
156
156
  | `viewportSize` | { width: 1024, height: 600} | The size of the puppeteer browser's window. This is the browser window which renders the stories originally (and opens at the size provided in the `viewportSize` parameter), and then a DOM snapshot is uploaded to the server, which renders this snapshot on all the browsers and sizes provided in the `browser` parameter.|
157
- | `exitcode` | true | If tests failed or has visual differences close with non-zero exit code (also available as command-line argument).|
157
+ | `exitcode` | true | When set to `true` - if there were visual differences or other errors, close with non-zero exit code. When set to `false` - always close with zero exit code (i.e. never fail the build). When set to `nodiffs` - close with non-zero exit code only for errors and **not** for visual differences. (also available as command-line argument: `--exitcode true/false/nodiffs`) |
158
158
  | `browser` | { width: 1024, height: 768, name: 'chrome' } | The size and browser of the generated screenshots. For more info and possible values, see the [browser section below](#configuring-the-browser).|
159
159
  | `showLogs` | false | Whether or not you want to see logs of the Eyes-Storybook plugin. |
160
160
  | `batch` | undefined | An object which describes different aspects of the batch. The following lines in this table depict the various ways to configure the batch. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applitools/eyes-storybook",
3
- "version": "3.34.2",
3
+ "version": "3.36.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "applitools",
@@ -18,12 +18,7 @@
18
18
  },
19
19
  "license": "SEE LICENSE IN LICENSE",
20
20
  "author": "Applitools Team <team@applitools.com>",
21
- "aliases": [
22
- "storybook"
23
- ],
24
- "bin": {
25
- "eyes-storybook": "./bin/eyes-storybook.js"
26
- },
21
+ "bin": "./bin/eyes-storybook.js",
27
22
  "files": [
28
23
  "src",
29
24
  "bin",
@@ -34,14 +29,14 @@
34
29
  "build": "rollup -c rollup.config.js",
35
30
  "build:heavy": "node scripts/bitmap.js",
36
31
  "test": "yarn build && yarn test:mocha && yarn lint",
37
- "test:sanity": "yarn test:unit && yarn test:it",
38
32
  "test:mocha": "mocha --no-timeouts --trace-warnings 'test/{unit,it,e2e}/*.test.js'",
39
33
  "test:unit": "mocha --no-timeouts --trace-warnings 'test/unit/*.test.js'",
40
34
  "test:it": "mocha --no-timeouts --trace-warnings 'test/it/*.test.js'",
41
35
  "test:versions": "yarn build && yarn test:e2e:versions && yarn lint",
42
36
  "test:e2e": "mocha --no-timeouts --trace-warnings 'test/e2e/*.e2e.test.js'",
43
37
  "test:e2e:versions": "npx mocha --no-timeouts --trace-warnings --require test/fixtures/storybook-versions/mochaHooks.js test/versions/*.e2e.versions.test.js",
44
- "test:e2e:versions_local": "STORYBOOK_VERSION=latest npx mocha --no-timeouts --trace-warnings --require test/fixtures/storybook-versions/mochaHooks.js test/versions/*.e2e.versions.test.js",
38
+ "test:e2e:versions_local": "APPLITOOLS_FRAMEWORK_VERSION=latest npx mocha --no-timeouts --trace-warnings --require test/fixtures/storybook-versions/mochaHooks.js test/versions/*.e2e.versions.test.js",
39
+ "test:heavy": "node bin/eyes-storybook.js -f test/fixtures/heavyStorybook/applitools.config.js",
45
40
  "storybook": "start-storybook -c test/fixtures/appWithStorybook -p 9001 -s test/fixtures",
46
41
  "storybook:httpHeaders": "start-storybook -c test/fixtures/appWithCustomHttpHeaders -p 9007",
47
42
  "storybook:jslayout": "start-storybook -c test/fixtures/jsLayoutStorybookLocal -p 9001 -s test/fixtures",
@@ -59,44 +54,33 @@
59
54
  "changelog": "git changelog -x -p -f v$npm_package_version > History.md && git add ./History.md && git commit -am 'changelog'",
60
55
  "changelog:init": "git config changelog.format \"* %s [[%h]($(echo $npm_package_repository_url|cut -d+ -f2|cut -d. -f1-2)/commit/%H)]\"",
61
56
  "changelog:install": "sudo apt-get install git-extras",
62
- "gh:publish": "gh workflow run publish-storybook.yml --ref $(git rev-parse --abbrev-ref HEAD)",
63
- "prepublish:setup": "echo 'setup is a no-op. Move along, nothing to see here.'",
64
- "deps": "bongo deps",
65
- "postinstall": "node src/postinstall",
66
- "preversion": "bongo preversion --verifyPendingChanges",
67
- "version": "bongo version --withPendingChanges",
68
- "postversion": "bongo postversion"
69
- },
70
- "husky": {
71
- "hooks": {
72
- "pre-push": "yarn bongo lint"
73
- }
57
+ "postinstall": "node src/postinstall"
74
58
  },
75
59
  "dependencies": {
76
- "@applitools/core": "3.0.1",
77
- "@applitools/driver": "1.11.51",
60
+ "@applitools/core": "3.5.0",
61
+ "@applitools/driver": "1.13.0",
78
62
  "@applitools/functional-commons": "1.6.0",
79
- "@applitools/logger": "2.0.0",
63
+ "@applitools/logger": "2.0.5",
80
64
  "@applitools/monitoring-commons": "1.0.19",
81
- "@applitools/spec-driver-puppeteer": "1.1.62",
82
- "@applitools/test-server": "1.2.0",
83
- "@applitools/ufg-client": "1.2.13",
84
- "@applitools/utils": "1.3.36",
65
+ "@applitools/spec-driver-puppeteer": "1.1.68",
66
+ "@applitools/ufg-client": "1.3.0",
67
+ "@applitools/utils": "1.5.0",
85
68
  "boxen": "4.2.0",
86
69
  "chalk": "3.0.0",
87
70
  "detect-port": "1.3.0",
88
71
  "lodash.flatten": "4.4.0",
89
72
  "lodash.pick": "4.4.0",
90
73
  "ora": "3.4.0",
91
- "puppeteer": "19.5.0",
74
+ "puppeteer": "19.8.0",
92
75
  "strip-ansi": "6.0.0",
93
76
  "throat": "6.0.1",
94
- "yargs": "15.4.1"
77
+ "yargs": "^17.7.2"
95
78
  },
96
79
  "devDependencies": {
97
- "@applitools/bongo": "^3.0.3",
80
+ "@applitools/bongo": "^4.0.0",
98
81
  "@applitools/sdk-shared": "0.9.15",
99
82
  "@applitools/snaptdout": "^1.0.1",
83
+ "@applitools/test-server": "^1.2.2",
100
84
  "@storybook/addon-interactions": "^6.4.18",
101
85
  "@storybook/react": "^6.4.18",
102
86
  "@storybook/testing-library": "^0.0.9",
@@ -115,8 +99,7 @@
115
99
  "eslint-plugin-prettier": "^3.1.1",
116
100
  "express": "^4.17.1",
117
101
  "filenamify": "^4.1.0",
118
- "husky": "^4.3.8",
119
- "mocha": "^8.0.1",
102
+ "mocha": "^10.2.0",
120
103
  "node-fetch": "^2.6.0",
121
104
  "prettier": "^1.19.1",
122
105
  "react": "^16.12.0",
@@ -126,6 +109,9 @@
126
109
  "ua-parser-js": "^0.7.21"
127
110
  },
128
111
  "engines": {
129
- "node": ">=12.13.0"
112
+ "node": ">=14.15.0"
113
+ },
114
+ "publishConfig": {
115
+ "access": "public"
130
116
  }
131
- }
117
+ }
package/src/cli.js CHANGED
@@ -32,14 +32,20 @@ const {performance, timeItAsync} = makeTiming();
32
32
  console.log(`Using @applitools/eyes-storybook version ${VERSION}.\n`);
33
33
  const config = generateConfig({argv, defaultConfig, externalConfigParams});
34
34
  const logger = makeLogger({level: config.showLogs ? 'info' : 'silent', label: 'eyes'});
35
- await validateAndPopulateConfig({config, logger, packagePath: process.cwd()});
35
+ const isVersion7 = await validateAndPopulateConfig({
36
+ config,
37
+ logger,
38
+ packagePath: process.cwd(),
39
+ });
36
40
  logger.log(`Running with the following config:\n${configDigest(config)}`);
37
41
  const [err, results] = await presult(
38
- timeItAsync('eyesStorybook', () => eyesStorybook({config, logger, performance, timeItAsync})),
42
+ timeItAsync('eyesStorybook', () =>
43
+ eyesStorybook({config, logger, performance, timeItAsync, isVersion7}),
44
+ ),
39
45
  );
40
46
  if (err) {
41
47
  console.log(chalk.red(err.message));
42
- process.exit(config.exitcode ? config.exitcode : 0);
48
+ process.exit(config.exitcode ? 1 : 0);
43
49
  } else {
44
50
  const totalTime = performance['eyesStorybook'];
45
51
  const {exitCode, summary, outputStr} = processResults({
@@ -47,6 +53,7 @@ const {performance, timeItAsync} = makeTiming();
47
53
  totalTime,
48
54
  testConcurrency: config.testConcurrency,
49
55
  saveNewTests: config.saveNewTests,
56
+ configExitCode: config.exitcode,
50
57
  });
51
58
  console.log(outputStr);
52
59
  if (config.jsonFilePath) {
@@ -58,7 +65,7 @@ const {performance, timeItAsync} = makeTiming();
58
65
  if (config.xmlFilePath) {
59
66
  handleXmlFile(config.xmlFilePath, summary, {totalTime});
60
67
  }
61
- process.exit(config.exitcode ? exitCode : 0);
68
+ process.exit(exitCode);
62
69
  }
63
70
  } catch (ex) {
64
71
  console.log(ex);
@@ -34,6 +34,7 @@ async function eyesStorybook({
34
34
  performance,
35
35
  timeItAsync,
36
36
  outputStream = process.stderr,
37
+ isVersion7,
37
38
  }) {
38
39
  let memoryTimeout;
39
40
  let renderIE = false;
@@ -46,7 +47,14 @@ async function eyesStorybook({
46
47
  : Number(process.env.APPLITOOLS_CONCURRENT_TABS);
47
48
  logger.log(`Running with ${CONCURRENT_TABS} concurrent tabs`);
48
49
 
49
- const {storybookUrl, readStoriesTimeout, reloadPagePerStory, proxy, testConcurrency} = config;
50
+ const {
51
+ storybookUrl,
52
+ readStoriesTimeout,
53
+ reloadPagePerStory,
54
+ proxy,
55
+ testConcurrency,
56
+ useDnsCache,
57
+ } = config;
50
58
 
51
59
  let iframeUrl;
52
60
  try {
@@ -56,6 +64,7 @@ async function eyesStorybook({
56
64
  throw new Error(`Storybook URL is not valid: ${storybookUrl}`);
57
65
  }
58
66
  const agentId = `eyes-storybook/${require('../package.json').version}`;
67
+ process.env.PUPPETEER_DISABLE_HEADLESS_WARNING = true;
59
68
  const browser = await puppeteer.launch(config.puppeteerOptions);
60
69
  logger.log('browser launched');
61
70
  const page = await browser.newPage();
@@ -77,6 +86,7 @@ async function eyesStorybook({
77
86
  serverUrl: config.serverUrl,
78
87
  apiKey: config.apiKey,
79
88
  agentId,
89
+ useDnsCache,
80
90
  };
81
91
  const [error, account] = await presult(core.getAccountInfo({settings, logger}));
82
92
 
@@ -95,6 +105,7 @@ async function eyesStorybook({
95
105
  ...account,
96
106
  proxy,
97
107
  concurrency: testConcurrency,
108
+ useDnsCache,
98
109
  },
99
110
  logger,
100
111
  });
@@ -213,6 +224,7 @@ async function eyesStorybook({
213
224
  logger,
214
225
  stream: outputStream,
215
226
  pagePool,
227
+ isVersion7,
216
228
  });
217
229
 
218
230
  logger.log('finished creating functions');
@@ -0,0 +1,46 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ /**
5
+ * Find the path to the given npm command.
6
+ * It goes recursively up the directory tree until it finds the command, like npm itself does.
7
+ * @param {string} npmModuleCommand - The npm command to find.
8
+ * @param {string} packageJsonDirPath - the directory in which to start searching for the command.
9
+ * @returns {Promise<string|null>} The path to the command.
10
+ */
11
+ module.exports = async function findNpmModuleCommandPath(npmModuleCommand, packageJsonDirPath) {
12
+ const isWindows = process.platform.startsWith('win');
13
+
14
+ let checkRootPath = path.resolve(packageJsonDirPath);
15
+ while (checkRootPath !== '') {
16
+ const commandPath = path.join(
17
+ checkRootPath,
18
+ 'node_modules',
19
+ '.bin',
20
+ npmModuleCommand + (isWindows ? '.cmd' : ''),
21
+ );
22
+ if (await doesFileExist(commandPath)) return commandPath;
23
+
24
+ const nextPath = path.dirname(checkRootPath);
25
+ if (nextPath === checkRootPath) break; // the top of the file tree is reached
26
+
27
+ checkRootPath = nextPath;
28
+ }
29
+
30
+ return null;
31
+ };
32
+
33
+ /**
34
+ * Check whether a file exists asynchronously.
35
+ * @param {string} filePath
36
+ * @returns {Promise<boolean>}
37
+ */
38
+ function doesFileExist(filePath) {
39
+ return new Promise(resolve => {
40
+ fs.stat(filePath, (err, stats) => {
41
+ if (err) resolve(false);
42
+ else if (stats != null && stats.isFile()) resolve(true);
43
+ else resolve(false);
44
+ });
45
+ });
46
+ }
@@ -1,10 +1,14 @@
1
1
  'use strict';
2
2
  const getIframeUrl = require('./getIframeUrl');
3
3
 
4
- function getStoryUrl({name, kind, parameters}, baseUrl) {
4
+ function getStoryUrl({name, kind, parameters, id}, baseUrl, isVersion7) {
5
5
  let storyUrl = getIframeUrl(baseUrl);
6
- storyUrl += `&selectedKind=${encodeURIComponent(kind)}`;
7
- storyUrl += `&selectedStory=${encodeURIComponent(name)}`;
6
+ if (!isVersion7) {
7
+ storyUrl += `&selectedKind=${encodeURIComponent(kind)}`;
8
+ storyUrl += `&selectedStory=${encodeURIComponent(name)}`;
9
+ } else {
10
+ storyUrl += `&path=/story/${encodeURIComponent(id)}`;
11
+ }
8
12
 
9
13
  const queryParams = parameters && parameters.eyes && parameters.eyes.queryParams;
10
14
  if (queryParams) {
@@ -5,7 +5,13 @@ const utils = require('@applitools/utils');
5
5
  const uniq = require('./uniq');
6
6
  const concurrencyMsg = require('./concurrencyMsg');
7
7
 
8
- function processResults({results, totalTime, testConcurrency, saveNewTests = true}) {
8
+ function processResults({
9
+ results,
10
+ totalTime,
11
+ testConcurrency,
12
+ saveNewTests = true,
13
+ configExitCode,
14
+ }) {
9
15
  let outputStr = '\n';
10
16
  const pluralize = utils.general.pluralize;
11
17
  let testResults = flatten(results.summary.results);
@@ -101,8 +107,16 @@ function processResults({results, totalTime, testConcurrency, saveNewTests = tru
101
107
  // TODO require from core
102
108
  outputStr += `\n${concurrencyMsg}\n`;
103
109
  }
104
- const exitCode =
105
- !warnForUnsavedNewTests && passedOrNew.length && !errors.length && !unresolved.length ? 0 : 1;
110
+
111
+ let exitCode;
112
+ if (!configExitCode) {
113
+ exitCode = 0;
114
+ } else if (configExitCode === 'nodiffs') {
115
+ exitCode = errors.length ? 1 : 0;
116
+ } else {
117
+ exitCode =
118
+ !warnForUnsavedNewTests && passedOrNew.length && !errors.length && !unresolved.length ? 0 : 1;
119
+ }
106
120
  return {
107
121
  outputStr,
108
122
  summary: results.summary,
@@ -13,6 +13,7 @@ function makeRenderStories({
13
13
  stream,
14
14
  getClientAPI,
15
15
  maxPageTTL = 60000,
16
+ isVersion7,
16
17
  }) {
17
18
  let newPageIdToAdd;
18
19
 
@@ -56,7 +57,7 @@ function makeRenderStories({
56
57
 
57
58
  async function processStory() {
58
59
  const story = stories[currIndex++];
59
- const storyUrl = getStoryUrl(story, storybookUrl);
60
+ const storyUrl = getStoryUrl(story, storybookUrl, isVersion7);
60
61
  const title = getStoryBaselineName(story);
61
62
  try {
62
63
  let [error, storyData] = await presult(
@@ -1,16 +1,8 @@
1
1
  'use strict';
2
- const {resolve} = require('path');
3
2
  const ora = require('ora');
4
3
  const StorybookConnector = require('./storybookConnector');
5
- const fs = require('fs');
6
- const {exec} = require('child_process');
7
- const {promisify: p} = require('util');
8
- const pexec = p(exec);
9
- // eslint-disable-next-line
10
- const semver = require('semver');
11
4
 
12
5
  async function startStorybookServer({
13
- packagePath,
14
6
  storybookPort,
15
7
  storybookHost,
16
8
  storybookConfigDir,
@@ -18,22 +10,10 @@ async function startStorybookServer({
18
10
  showStorybookOutput,
19
11
  logger,
20
12
  startStorybookServerTimeout,
13
+ storybookPath,
14
+ sbArg,
21
15
  }) {
22
16
  const isWindows = process.platform.startsWith('win');
23
- let storybookPath, sbArg;
24
- const storybookPathV6 = resolve(packagePath, 'node_modules/.bin/start-storybook');
25
- const storybookPathV7 = resolve(packagePath, 'node_modules/.bin/sb');
26
- if (fs.existsSync(storybookPathV7)) {
27
- const version = await pexec(`${storybookPathV7} --version`);
28
- if (semver.satisfies(version.stdout, '<7.0.0')) {
29
- storybookPath = storybookPathV6;
30
- } else {
31
- storybookPath = storybookPathV7;
32
- sbArg = 'dev';
33
- }
34
- } else {
35
- storybookPath = storybookPathV6;
36
- }
37
17
 
38
18
  const storybookConnector = new StorybookConnector({
39
19
  storybookPath,
@@ -15,7 +15,7 @@ class StorybookConnector extends EventEmitter {
15
15
  sbArg,
16
16
  }) {
17
17
  super();
18
- this._storybookPath = `${storybookPath}${isWindows ? '.cmd' : ''}`;
18
+ this._storybookPath = storybookPath;
19
19
  this._storybookPort = storybookPort;
20
20
  this._storybookHost = storybookHost;
21
21
  this._storybookConfigDir = storybookConfigDir;
@@ -11,14 +11,21 @@ const {
11
11
  } = require('./errMessages');
12
12
  const startStorybookServer = require('./startStorybookServer');
13
13
  const {isIE} = require('./shouldRenderIE');
14
+ const {makeLogger} = require('@applitools/logger');
15
+ const findNpmModuleCommandPath = require('./findNpmModuleCommandPath');
16
+ const {resolve} = require('path');
14
17
 
15
- async function validateAndPopulateConfig({config, packagePath, logger}) {
18
+ async function validateAndPopulateConfig({config, packagePath = '', logger = makeLogger()}) {
16
19
  if (!config.apiKey) {
17
20
  throw new Error(missingApiKeyFailMsg);
18
21
  }
19
22
 
20
23
  const packageJsonPath = `${packagePath}/package.json`;
21
24
  const packageJson = fs.existsSync(packageJsonPath) ? require(packageJsonPath) : undefined;
25
+ const {storybookPath, isVersion7, sbArg} = await determineStorybookVersion(packagePath);
26
+ logger.log(
27
+ `[validateAndPopulateConfig] storybookPath=${storybookPath} isVersion7=${isVersion7} sbArg=${sbArg}`,
28
+ );
22
29
 
23
30
  if (!config.appName) {
24
31
  if (!packageJson) {
@@ -39,7 +46,9 @@ async function validateAndPopulateConfig({config, packagePath, logger}) {
39
46
  console.log(chalk.red(`couldn't find available port around`, config.storybookPort));
40
47
  }
41
48
 
42
- config.storybookUrl = await startStorybookServer(Object.assign({packagePath, logger}, config));
49
+ config.storybookUrl = await startStorybookServer(
50
+ Object.assign({packagePath, logger, storybookPath, sbArg}, config),
51
+ );
43
52
 
44
53
  // NOTE (Amit): I don't understand why this condition is here. It shouldn't happen. I might have been the one to put it here, but it seems like a mistake. We should take a thorough look and remove it.
45
54
  if (!config.storybookUrl) {
@@ -65,6 +74,36 @@ async function validateAndPopulateConfig({config, packagePath, logger}) {
65
74
  ),
66
75
  );
67
76
  }
77
+ return isVersion7;
68
78
  }
69
79
 
80
+ async function determineStorybookVersion(packagePath) {
81
+ let sbArg,
82
+ storybookPath,
83
+ isVersion7 = false;
84
+
85
+ const storybookPathV6 = resolve(packagePath, 'node_modules/.bin/start-storybook');
86
+ const storybookPathV7 = resolve(packagePath, 'node_modules/.bin/sb');
87
+
88
+ // first we look for the binaries in the local node_modules/.bin folder in case there are multiple versions of storybook installed
89
+ if (fs.existsSync(storybookPathV6)) {
90
+ storybookPath = storybookPathV6;
91
+ } else if (fs.existsSync(storybookPathV7)) {
92
+ storybookPath = storybookPathV7;
93
+ isVersion7 = true;
94
+ sbArg = 'dev';
95
+ } else {
96
+ // the binary is not in the local node_modules/.bin folder, so we need to find it
97
+ storybookPath = await findNpmModuleCommandPath('start-storybook', packagePath);
98
+ if (!storybookPath) {
99
+ storybookPath = await findNpmModuleCommandPath('sb', packagePath);
100
+ isVersion7 = true;
101
+ sbArg = 'dev';
102
+ } else {
103
+ isVersion7 = false;
104
+ }
105
+ }
106
+
107
+ return {storybookPath, isVersion7, sbArg};
108
+ }
70
109
  module.exports = validateAndPopulateConfig;