Skip to content
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/addons/_tests/_setup/global.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import { fileURLToPath } from 'node:url';
import { setup, type ProjectVariant } from 'sv/testing';
import type { TestProject } from 'vitest/node';
import process from 'node:process';
import { exec } from 'tinyexec';

import { STORYBOOK_VERSION } from '../../storybook/index.ts';

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

export default async function ({ provide }: TestProject) {
if (CI) {
// prefetch the storybook cli during ci to reduce fetching errors in tests
const { stdout } = await exec('pnpm', [
'dlx',
`create-storybook@${STORYBOOK_VERSION}`,
'--version'
]);
console.info('storybook version:', stdout);
}

// downloads different project configurations (sveltekit, js/ts, vite-only, etc)
const { templatesDir } = await setup({ cwd: TEST_DIR, variants });

Expand Down
41 changes: 13 additions & 28 deletions packages/addons/_tests/storybook/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import process from 'node:process';
import { execSync } from 'node:child_process';
import { expect } from '@playwright/test';
import { beforeAll } from 'vitest';
import { setupTest } from '../_setup/suite.ts';
import storybook from '../../storybook/index.ts';
import eslint from '../../eslint/index.ts';
Expand All @@ -13,31 +10,19 @@ const { test, testCases, prepareServer } = setupTest(
);

let port = 6006;
const CI = Boolean(process.env.CI);

beforeAll(() => {
if (CI) {
// prefetch the storybook cli during ci to reduce fetching errors in tests
execSync('pnpm dlx create-storybook@latest --version');
}
});

test.for(testCases)(
'storybook $variant',
{ concurrent: !CI },
async (testCase, { page, ...ctx }) => {
const cwd = ctx.cwd(testCase);
test.concurrent.for(testCases)('storybook $variant', async (testCase, { page, ...ctx }) => {
const cwd = ctx.cwd(testCase);

const { close } = await prepareServer({
cwd,
page,
previewCommand: `pnpm storybook -p ${++port} --ci`,
buildCommand: ''
});
// kill server process when we're done
ctx.onTestFinished(async () => await close());
const { close } = await prepareServer({
cwd,
page,
previewCommand: `pnpm storybook -p ${++port} --ci`,
buildCommand: ''
});
// kill server process when we're done
ctx.onTestFinished(async () => await close());

expect(page.locator('main .sb-bar')).toBeTruthy();
expect(page.locator('#storybook-preview-wrapper')).toBeTruthy();
}
);
expect(page.locator('main .sb-bar')).toBeTruthy();
expect(page.locator('#storybook-preview-wrapper')).toBeTruthy();
});
3 changes: 2 additions & 1 deletion packages/addons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@sveltejs/cli-core": "workspace:*"
},
"devDependencies": {
"package-manager-detector": "^0.2.11"
"package-manager-detector": "^0.2.11",
"tinyexec": "^0.3.2"
}
}
10 changes: 9 additions & 1 deletion packages/addons/storybook/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import process from 'node:process';
import { defineAddon } from '@sveltejs/cli-core';
import { getNodeTypesVersion } from '../common.ts';

export const STORYBOOK_VERSION = '0.0.0-pr-32717-sha-f340a68b';

export default defineAddon({
id: 'storybook',
shortDescription: 'frontend workshop',
Expand All @@ -12,7 +14,13 @@ export default defineAddon({
runsAfter('eslint');
},
run: async ({ sv }) => {
const args = ['create-storybook@latest', '--skip-install', '--no-dev'];
const args = [
`create-storybook@${STORYBOOK_VERSION}`,
'--skip-install',
'--no-dev',
'--features',
'docs'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be --no-features in the future according to Jeppe

];

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