From 10b34eea56ed2bc7105bb9f206d3ef21c1d62b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Maisse?= Date: Fri, 29 May 2020 17:07:35 +0200 Subject: [PATCH 1/4] fix(cli): fix `init` command when run in a Yarn workspace env Add `--ignore-workspace-root-check` to avoid Yarn error when adding dependencies to the workspace root. --- lib/cli/src/helpers.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/cli/src/helpers.ts b/lib/cli/src/helpers.ts index 4e345911d346..0f7994ee6b43 100644 --- a/lib/cli/src/helpers.ts +++ b/lib/cli/src/helpers.ts @@ -255,6 +255,10 @@ export function installDependencies( installArgs.push('-D'); } + if (options.useYarn) { + installArgs.push('--ignore-workspace-root-check'); + } + const dependencyResult = spawnSync(spawnCommand, installArgs, { stdio: 'inherit', }); From df737246d7d1cbd6aae9c3d6f9ea971c7b324b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Maisse?= Date: Fri, 29 May 2020 17:38:30 +0200 Subject: [PATCH 2/4] fix(e2e): remove `skip-install` option from sb init command Removed this option because it can hide some issues with dependency installation process of @storybook/cli. For instance, missing Yarn flags needed to have the CLI working in Yarn workspaces. Also, as `sb init` is now running `yarn/npm install` the resolution step has to be made before init Storybook. --- scripts/run-e2e.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/run-e2e.ts b/scripts/run-e2e.ts index 40e510297d6b..e4b4322f0445 100644 --- a/scripts/run-e2e.ts +++ b/scripts/run-e2e.ts @@ -85,7 +85,7 @@ const initStorybook = async ({ cwd, autoDetect = true, name }: Options) => { logger.info(`🎨 Initializing Storybook with @storybook/cli`); try { const type = autoDetect ? '' : `--type ${name}`; - await exec(`npx -p @storybook/cli sb init --skip-install --yes ${type}`, { cwd }); + await exec(`npx -p @storybook/cli sb init --yes ${type}`, { cwd }); } catch (e) { logger.error(`🚨 Storybook initialization failed`); throw e; @@ -187,10 +187,10 @@ const runTests = async ({ name, version, ...rest }: Parameters) => { await generate({ ...options, cwd: siblingDir }); logger.log(); - await initStorybook(options); + await setResolutions(options); logger.log(); - await setResolutions(options); + await initStorybook(options); logger.log(); await addRequiredDeps(options); From 0e0006e39b2beb19beadde0f93641746350698e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Maisse?= Date: Fri, 29 May 2020 17:39:50 +0200 Subject: [PATCH 3/4] test(e2e): add a E2E test config for Yarn workspace env (based on React) --- scripts/run-e2e-config.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scripts/run-e2e-config.ts b/scripts/run-e2e-config.ts index 8713d37ba9da..40184b9128de 100644 --- a/scripts/run-e2e-config.ts +++ b/scripts/run-e2e-config.ts @@ -152,3 +152,13 @@ export const yarn2Cra: Parameters = { `yarn dlx create-react-app@{{version}} {{name}}-v{{version}}`, ].join(' && '), }; + +export const reactInYarnWorkspace: Parameters = { + name: 'reactInYarnWorkspace', + version: 'latest', + generator: [ + 'cd {{name}}-v{{version}}', + 'echo "{ \\"name\\": \\"workspace-root\\", \\"private\\": true, \\"workspaces\\": [] }" > package.json', + `yarn add react react-dom --silent -W`, + ].join(' && '), +}; From 23459576b8b25480fc6f0fa01b28f8da7bb22f81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Maisse?= Date: Fri, 29 May 2020 19:02:21 +0200 Subject: [PATCH 4/4] test(e2e): improve jobs assignment on CI nodes With the previous algorithm, some nodes have no jobs assigned to them due to rounding consideration. For example with 10 nodes and 13 jobs to assign: 13 jobs / 10 nodes -> 1.3 jobs per node -> rounded to 2 -> only the 1st 6 nodes run 2 jobs, the 7th 1 job and the other 0 job. Using a modulo ensures that each node will at least run 1 job. --- scripts/run-e2e.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/scripts/run-e2e.ts b/scripts/run-e2e.ts index e4b4322f0445..6c484e258ea7 100644 --- a/scripts/run-e2e.ts +++ b/scripts/run-e2e.ts @@ -274,13 +274,18 @@ if (frameworkArgs.length > 0) { const perform = () => { const limit = pLimit(1); const narrowedConfigs = Object.values(e2eConfigs); - const [a, b] = [+process.env.CIRCLE_NODE_INDEX || 0, +process.env.CIRCLE_NODE_TOTAL || 1]; - const step = Math.ceil(narrowedConfigs.length / b); - const offset = step * a; - - const list = narrowedConfigs.slice().splice(offset, step); - - logger.info(`📑 Assigning jobs ${list.map((c) => c.name).join(', ')} to node ${a} (on ${b})`); + const nodeIndex = +process.env.CIRCLE_NODE_INDEX || 0; + const numberOfNodes = +process.env.CIRCLE_NODE_TOTAL || 1; + + const list = narrowedConfigs.filter((_, index) => { + return index % numberOfNodes === nodeIndex; + }); + + logger.info( + `📑 Assigning jobs ${list + .map((c) => c.name) + .join(', ')} to node ${nodeIndex} (on ${numberOfNodes})` + ); return Promise.all(list.map((config) => limit(() => runE2E(config)))); };