Skip to content

Commit c0d9e99

Browse files
manuel3108jycouetJReinhold
authored
chore: storybook new cli ux (#781)
* chore: storybook new cli ux * Update packages/addons/storybook/index.ts Co-authored-by: Jeppe Reinhold <jeppe@reinhold.is> * link storybook versions * with this syntax! * --features docs * prefetch storybook ONCE in the global setup. (for all-addons + storybook + others...) * let's see if now in // t's possible in CI * --no-features * storybook 10.1.0 --------- Co-authored-by: jyc.dev <jycouet@gmail.com> Co-authored-by: Jeppe Reinhold <jeppe@reinhold.is>
1 parent c6c721a commit c0d9e99

File tree

5 files changed

+41
-30
lines changed

5 files changed

+41
-30
lines changed

packages/addons/_tests/_setup/global.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
import { fileURLToPath } from 'node:url';
22
import { setup, type ProjectVariant } from 'sv/testing';
33
import type { TestProject } from 'vitest/node';
4+
import process from 'node:process';
5+
import { exec } from 'tinyexec';
6+
7+
import { STORYBOOK_VERSION } from '../../storybook/index.ts';
48

59
const TEST_DIR = fileURLToPath(new URL('../../../../.test-output/addons/', import.meta.url));
610
const variants: ProjectVariant[] = ['kit-js', 'kit-ts', 'vite-js', 'vite-ts'];
11+
const CI = Boolean(process.env.CI);
712

813
export default async function ({ provide }: TestProject) {
14+
if (CI) {
15+
// prefetch the storybook cli during ci to reduce fetching errors in tests
16+
const { stdout } = await exec('pnpm', [
17+
'dlx',
18+
`create-storybook@${STORYBOOK_VERSION}`,
19+
'--version'
20+
]);
21+
console.info('storybook version:', stdout);
22+
}
23+
924
// downloads different project configurations (sveltekit, js/ts, vite-only, etc)
1025
const { templatesDir } = await setup({ cwd: TEST_DIR, variants });
1126

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import process from 'node:process';
2-
import { execSync } from 'node:child_process';
31
import { expect } from '@playwright/test';
4-
import { beforeAll } from 'vitest';
52
import { setupTest } from '../_setup/suite.ts';
63
import storybook from '../../storybook/index.ts';
74
import eslint from '../../eslint/index.ts';
@@ -13,31 +10,19 @@ const { test, testCases, prepareServer } = setupTest(
1310
);
1411

1512
let port = 6006;
16-
const CI = Boolean(process.env.CI);
1713

18-
beforeAll(() => {
19-
if (CI) {
20-
// prefetch the storybook cli during ci to reduce fetching errors in tests
21-
execSync('pnpm dlx create-storybook@latest --version');
22-
}
23-
});
24-
25-
test.for(testCases)(
26-
'storybook $variant',
27-
{ concurrent: !CI },
28-
async (testCase, { page, ...ctx }) => {
29-
const cwd = ctx.cwd(testCase);
14+
test.concurrent.for(testCases)('storybook $variant', async (testCase, { page, ...ctx }) => {
15+
const cwd = ctx.cwd(testCase);
3016

31-
const { close } = await prepareServer({
32-
cwd,
33-
page,
34-
previewCommand: `pnpm storybook -p ${++port} --ci`,
35-
buildCommand: ''
36-
});
37-
// kill server process when we're done
38-
ctx.onTestFinished(async () => await close());
17+
const { close } = await prepareServer({
18+
cwd,
19+
page,
20+
previewCommand: `pnpm storybook -p ${++port} --ci`,
21+
buildCommand: ''
22+
});
23+
// kill server process when we're done
24+
ctx.onTestFinished(async () => await close());
3925

40-
expect(page.locator('main .sb-bar')).toBeTruthy();
41-
expect(page.locator('#storybook-preview-wrapper')).toBeTruthy();
42-
}
43-
);
26+
expect(page.locator('main .sb-bar')).toBeTruthy();
27+
expect(page.locator('#storybook-preview-wrapper')).toBeTruthy();
28+
});

packages/addons/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@sveltejs/cli-core": "workspace:*"
1616
},
1717
"devDependencies": {
18-
"package-manager-detector": "^0.2.11"
18+
"package-manager-detector": "^0.2.11",
19+
"tinyexec": "^0.3.2"
1920
}
2021
}

packages/addons/storybook/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import process from 'node:process';
22
import { defineAddon } from '@sveltejs/cli-core';
33
import { getNodeTypesVersion } from '../common.ts';
44

5+
export const STORYBOOK_VERSION = '10.1.0';
6+
57
export default defineAddon({
68
id: 'storybook',
79
shortDescription: 'frontend workshop',
@@ -12,7 +14,12 @@ export default defineAddon({
1214
runsAfter('eslint');
1315
},
1416
run: async ({ sv }) => {
15-
const args = ['create-storybook@latest', '--skip-install', '--no-dev'];
17+
const args = [
18+
`create-storybook@${STORYBOOK_VERSION}`,
19+
'--skip-install',
20+
'--no-dev',
21+
'--no-features'
22+
];
1623

1724
// skips the onboarding prompt during tests
1825
if (process.env.NODE_ENV?.toLowerCase() === 'test') args.push('--yes');

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)