diff --git a/packages/sv/src/cli/tests/snapshots/@my-org/sv/tests/addon.test.js b/packages/sv/src/cli/tests/snapshots/@my-org/sv/tests/addon.test.js index dc2b8c3cb..9d8704974 100644 --- a/packages/sv/src/cli/tests/snapshots/@my-org/sv/tests/addon.test.js +++ b/packages/sv/src/cli/tests/snapshots/@my-org/sv/tests/addon.test.js @@ -10,7 +10,7 @@ const browser = false; const { test, prepareServer, testCases } = setupTest( { addon }, { - kinds: [{ type: 'default', options: { addon: { who: 'you' } } }], + kinds: [{ type: 'default', options: { [addon.id]: { who: 'you' } } }], filter: (testCase) => testCase.variant.includes('kit'), browser } @@ -21,15 +21,18 @@ test.concurrent.for(testCases)( async (testCase, { page, ...ctx }) => { const cwd = ctx.cwd(testCase); - const msg = - "This is a text file made by the Community Addon Template demo for the add-on: '@my-org/sv'!"; + const msg = "Community Addon Template demo for the add-on: '@my-org/sv'!"; const contentPath = path.resolve(cwd, `src/lib/@my-org/sv/content.txt`); const contentContent = fs.readFileSync(contentPath, 'utf8'); - // Check if we have the imports expect(contentContent).toContain(msg); + const helloPath = path.resolve(cwd, `src/lib/@my-org/sv/HelloComponent.svelte`); + const helloContent = fs.readFileSync(helloPath, 'utf8'); + // Check if we have the imports + expect(helloContent).toContain('you'); + // For browser testing if (browser) { const { close } = await prepareServer({ cwd, page }); diff --git a/packages/sv/src/create/templates/addon/tests/addon.test.js b/packages/sv/src/create/templates/addon/tests/addon.test.js index e525062c5..6ff085500 100644 --- a/packages/sv/src/create/templates/addon/tests/addon.test.js +++ b/packages/sv/src/create/templates/addon/tests/addon.test.js @@ -10,7 +10,7 @@ const browser = false; const { test, prepareServer, testCases } = setupTest( { addon }, { - kinds: [{ type: 'default', options: { addon: { who: 'you' } } }], + kinds: [{ type: 'default', options: { [addon.id]: { who: 'you' } } }], filter: (testCase) => testCase.variant.includes('kit'), browser } @@ -21,15 +21,18 @@ test.concurrent.for(testCases)( async (testCase, { page, ...ctx }) => { const cwd = ctx.cwd(testCase); - const msg = - "This is a text file made by the Community Addon Template demo for the add-on: '~SV-NAME-TODO~'!"; + const msg = "Community Addon Template demo for the add-on: '~SV-NAME-TODO~'!"; const contentPath = path.resolve(cwd, `src/lib/~SV-NAME-TODO~/content.txt`); const contentContent = fs.readFileSync(contentPath, 'utf8'); - // Check if we have the imports expect(contentContent).toContain(msg); + const helloPath = path.resolve(cwd, `src/lib/~SV-NAME-TODO~/HelloComponent.svelte`); + const helloContent = fs.readFileSync(helloPath, 'utf8'); + // Check if we have the imports + expect(helloContent).toContain('you'); + // For browser testing if (browser) { const { close } = await prepareServer({ cwd, page }); diff --git a/packages/sv/src/testing.ts b/packages/sv/src/testing.ts index 14bfb309a..285592dd5 100644 --- a/packages/sv/src/testing.ts +++ b/packages/sv/src/testing.ts @@ -239,12 +239,17 @@ export async function prepareServer({ return { url, close }; } +export type PlaywrightContext = Pick; + export type VitestContext = Pick< typeof import('vitest'), 'inject' | 'test' | 'beforeAll' | 'beforeEach' >; -export function createSetupTest(vitest: VitestContext): ( +export function createSetupTest( + vitest: VitestContext, + playwright?: PlaywrightContext +): ( addons: Addons, options?: SetupTestOptions ) => { @@ -272,12 +277,16 @@ export function createSetupTest(vitest: VitestContext): { let chromium: Awaited['chromium']; - try { - ({ chromium } = await import('@playwright/test')); - } catch { - throw new Error( - 'Browser testing requires @playwright/test. Install it with: pnpm add -D @playwright/test' - ); + if (playwright) { + chromium = playwright.chromium; + } else { + try { + ({ chromium } = await import('@playwright/test')); + } catch { + throw new Error( + 'Browser testing requires @playwright/test. Install it with: pnpm add -D @playwright/test' + ); + } } browser = await chromium.launch(); return async () => {