Skip to content

Commit de619c1

Browse files
authored
Merge pull request #33277 from storybookjs/disable-ecosystem-ci-test-runner
CI: Fix ecosystem CI resolution handling
2 parents 8edd8c5 + e0a00da commit de619c1

File tree

7 files changed

+115
-18
lines changed

7 files changed

+115
-18
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@
2626
"nx": "nx",
2727
"pretty-docs": "cd scripts; yarn install >/dev/null; yarn docs:prettier:write",
2828
"start": "yarn task --task dev --template react-vite/default-ts --start-from=install",
29-
"svelte-ecosystem-ci:before-test": "STORYBOOK_SANDBOX_ROOT=./storybook-sandboxes node ./scripts/ecosystem-ci/before-test.js svelte-kit/skeleton-ts && cd ./storybook-sandboxes/svelte-kit-skeleton-ts && STORYBOOK_SANDBOX_ROOT=./storybook-sandboxes yarn install",
30-
"svelte-ecosystem-ci:build": "yarn task --task install && yarn --cwd code build svelte && STORYBOOK_SANDBOX_ROOT=./storybook-sandboxes yarn task --task sandbox --template svelte-kit/skeleton-ts --start-from=compile --no-link --skip-cache",
31-
"svelte-ecosystem-ci:test": "STORYBOOK_SANDBOX_ROOT=./storybook-sandboxes yarn task --task test-runner --template svelte-kit/skeleton-ts --start-from=build --no-link --skip-cache && STORYBOOK_SANDBOX_ROOT=./storybook-sandboxes yarn task --task vitest-integration --template svelte-kit/skeleton-ts --start-from=vitest-integration --no-link --skip-cache",
29+
"svelte-ecosystem-ci:before-test": "./scripts/ecosystem-ci/before-test.sh svelte-kit/skeleton-ts",
30+
"svelte-ecosystem-ci:build": "./scripts/ecosystem-ci/build.sh svelte-kit/skeleton-ts svelte",
31+
"svelte-ecosystem-ci:test": "./scripts/ecosystem-ci/test.sh svelte-kit/skeleton-ts",
3232
"task": "yarn --cwd=./scripts task",
3333
"test": "cd code; yarn test",
3434
"test:watch": "cd code; yarn test:watch",
3535
"upload-bench": "cd scripts; yarn upload-bench",
36-
"vite-ecosystem-ci:before-test": "STORYBOOK_SANDBOX_ROOT=./storybook-sandboxes node ./scripts/ecosystem-ci/before-test.js react-vite/default-ts && cd ./storybook-sandboxes/react-vite-default-ts && yarn install",
37-
"vite-ecosystem-ci:build": "STORYBOOK_SANDBOX_ROOT=./storybook-sandboxes yarn task --task sandbox --template react-vite/default-ts --start-from=install --skip-cache",
38-
"vite-ecosystem-ci:test": "STORYBOOK_SANDBOX_ROOT=./storybook-sandboxes yarn task --task test-runner-dev --template react-vite/default-ts --start-from=dev && yarn task --task test-runner --template react-vite/default-ts --start-from=build && yarn task --task vitest-integration --template react-vite/default-ts --start-from=vitest-integration"
36+
"vite-ecosystem-ci:before-test": "./scripts/ecosystem-ci/before-test.sh react-vite/default-ts",
37+
"vite-ecosystem-ci:build": "./scripts/ecosystem-ci/build.sh react-vite/default-ts",
38+
"vite-ecosystem-ci:test": "./scripts/ecosystem-ci/test.sh react-vite/default-ts"
3939
},
4040
"packageManager": "[email protected]",
4141
"engines": {

scripts/ecosystem-ci/before-test.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,45 @@
44
* resolutions are needed to run the tests. The vite-ecosystem-ci, though, sets the resolutions in
55
* the root package.json.
66
*/
7-
import { readFile, writeFile } from 'node:fs/promises';
7+
import { writeFile } from 'node:fs/promises';
88
import { dirname, resolve } from 'node:path';
99
import { fileURLToPath } from 'node:url';
1010

1111
// eslint-disable-next-line depend/ban-dependencies
1212
import { execaCommand } from 'execa';
1313

14+
import { EXISTING_RESOLUTIONS } from './existing-resolutions.js';
15+
1416
const filename = fileURLToPath(import.meta.url);
1517
const __dirname = dirname(filename);
1618

1719
const sandbox = process.argv[2] ?? 'react-vite/default-ts';
1820

19-
const rootPackageJsonPath = resolve(__dirname, '../../package.json');
2021
const sandboxPackageJsonPath = resolve(
2122
__dirname,
22-
`../../storybook-sandboxes/${sandbox.replace('/', '-')}/package.json`
23+
`../../../storybook-sandboxes/${sandbox.replace('/', '-')}/package.json`
2324
);
2425

25-
const rootPackageJson = JSON.parse(await readFile(rootPackageJsonPath, 'utf-8'));
26-
const sandboxPackageJson = JSON.parse(await readFile(sandboxPackageJsonPath, 'utf-8'));
26+
const { default: rootPkgJson } = await import('../../package.json', { with: { type: 'json' } });
27+
const { default: sandboxPkgJson } = await import(sandboxPackageJsonPath, {
28+
with: { type: 'json' },
29+
});
2730

28-
const resolutions = rootPackageJson.resolutions
31+
// copy resolutions from root package.json to sandbox package.json, excluding the known resolutions we have internally in our repo
32+
// ecosystem-ci will add resolutions to the root package.json, and we want to propagate ONLY those to the sandbox package.json
33+
const resolutionsToCopy = rootPkgJson.resolutions
2934
? Object.fromEntries(
30-
Object.entries(rootPackageJson.resolutions).filter(([_, v]) => !v.includes('patch:'))
35+
Object.entries(rootPkgJson.resolutions).filter(([pkg]) => !EXISTING_RESOLUTIONS.has(pkg))
3136
)
3237
: {};
3338

34-
sandboxPackageJson.resolutions = {
35-
...(sandboxPackageJson.resolutions ?? {}),
36-
...resolutions,
39+
sandboxPkgJson.resolutions = {
40+
...(sandboxPkgJson.resolutions ?? {}),
41+
...resolutionsToCopy,
3742
};
3843

39-
await writeFile(sandboxPackageJsonPath, JSON.stringify(sandboxPackageJson, null, 2));
40-
const sandboxDir = dirname(sandboxPackageJsonPath);
44+
await writeFile(sandboxPackageJsonPath, JSON.stringify(sandboxPkgJson, null, 2));
4145

46+
const sandboxDir = dirname(sandboxPackageJsonPath);
4247
await execaCommand('yarn add playwright', { cwd: sandboxDir, shell: true });
4348
await execaCommand('yarn playwright install', { cwd: sandboxDir, shell: true });
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
set -e
3+
4+
TEMPLATE=${1:?Usage: $0 <template>}
5+
SANDBOX_NAME=${TEMPLATE//\//-}
6+
7+
# Run the before-test script to copy resolutions and set up Playwright
8+
node ./scripts/ecosystem-ci/before-test.js "$TEMPLATE"
9+
10+
# Install dependencies in the sandbox
11+
cd "../storybook-sandboxes/$SANDBOX_NAME"
12+
yarn install

scripts/ecosystem-ci/build.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
set -e
3+
4+
TEMPLATE=${1:?Usage: $0 <template> [renderer]}
5+
RENDERER=${2:-}
6+
7+
# Install all dependencies
8+
yarn task --task install
9+
10+
# If a renderer is specified, build it so it uses the resolution set by the ecosystem-ci
11+
if [ -n "$RENDERER" ]; then
12+
yarn --cwd code build "$RENDERER"
13+
fi
14+
15+
# Create the storybook-sandboxes directory with a package.json that specifies Yarn as the package manager.
16+
# This is required because the ecosystem-ci repo uses pnpm, and yarn refuses to install in the sandbox dir
17+
# if it sees a different packageManager field higher up in the directory tree.
18+
mkdir -p ../storybook-sandboxes
19+
echo "{ \"packageManager\": \"yarn@$(yarn -v)\" }" > ../storybook-sandboxes/package.json
20+
21+
yarn task build --template "$TEMPLATE" --start-from=compile --no-link --skip-cache
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Set of resolutions from the root package.json that should NOT be copied to sandbox package.json.
3+
* These are the "existing" resolutions that Storybook maintains, as opposed to resolutions that
4+
* might be injected by ecosystem-ci repos.
5+
*
6+
* This set must stay in sync with the resolutions in the root package.json. Run the test in
7+
* before-test.test.ts to verify they match.
8+
*/
9+
export const EXISTING_RESOLUTIONS = new Set([
10+
'@babel/runtime',
11+
'@babel/traverse',
12+
'@babel/types',
13+
'@playwright/test',
14+
'@testing-library/user-event@npm:^14.4.0',
15+
'@testing-library/user-event@npm:^14.6.1',
16+
'@types/babel__traverse@npm:*',
17+
'@types/babel__traverse@npm:^7.18.0',
18+
'@types/node',
19+
'@types/react',
20+
'@vitest/expect@npm:3.2.4',
21+
22+
'esbuild',
23+
'playwright',
24+
'playwright-core',
25+
'react',
26+
'serialize-javascript',
27+
'type-fest',
28+
'typescript',
29+
]);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
import rootPkgJson from '../../package.json';
4+
import { EXISTING_RESOLUTIONS } from './existing-resolutions';
5+
6+
/*
7+
If this test is failing for you, it means that you have changed the list of resolutions
8+
in the root package.json, but you have not updated the EXISTING_RESOLUTIONS set in
9+
scripts/ecosystem-ci/existing-resolutions.ts.
10+
11+
The purpose of this test is to ensure that any changes to the resolutions in package.json
12+
are reflected in the EXISTING_RESOLUTIONS set, which is used by the ecosystem-ci before-test
13+
script to copy the resolutions into the sandbox package.json files.
14+
*/
15+
16+
describe('ecosystem-ci', () => {
17+
it('EXISTING_RESOLUTIONS should match all keys in package.json resolutions', () => {
18+
const actualKeys = new Set(Object.keys(rootPkgJson.resolutions));
19+
const difference = actualKeys.symmetricDifference(EXISTING_RESOLUTIONS);
20+
21+
expect(difference.size).toBe(0);
22+
});
23+
});

scripts/ecosystem-ci/test.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
set -e
3+
4+
TEMPLATE=${1:?Usage: $0 <template>}
5+
6+
# Run Vitest integration tests
7+
yarn task --task vitest-integration --template "$TEMPLATE" --start-from=vitest-integration --no-link --skip-cache

0 commit comments

Comments
 (0)