Skip to content
Draft
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"
}
}
9 changes: 8 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 { 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,12 +14,17 @@
runsAfter('eslint');
},
run: async ({ sv }) => {
const args = ['create-storybook@latest', '--skip-install', '--no-dev'];
const args = [
`create-storybook@${STORYBOOK_VERSION}`,
'--skip-install',
'--no-dev',
'--no-features'
];

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

await sv.execute(args, 'inherit');

Check failure on line 27 in packages/addons/storybook/index.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

_tests/storybook/test.ts

Error: Failed to execute scripts 'pnpm dlx [email protected] --skip-install --no-dev --no-features --yes': Process exited with non-zero status (1) ❯ Object.run storybook/index.ts:27:3 ❯ _tests/_setup/suite.ts:103:38

Check failure on line 27 in packages/addons/storybook/index.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

_tests/all-addons/test.ts

Error: Failed to execute scripts 'pnpm dlx [email protected] --skip-install --no-dev --no-features --yes': Process exited with non-zero status (1) ❯ Object.run storybook/index.ts:27:3 ❯ _tests/_setup/suite.ts:103:38
sv.devDependency(`@types/node`, getNodeTypesVersion());
}
});
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading