|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import { setupTest } from '../_setup/suite.ts'; |
| 3 | +import devtoolsJson from '../../devtools-json/index.ts'; |
| 4 | +import fs from 'node:fs'; |
| 5 | +import path from 'node:path'; |
| 6 | + |
| 7 | +const { test, variants, prepareServer } = setupTest({ devtoolsJson } as { |
| 8 | + devtoolsJson?: typeof devtoolsJson; |
| 9 | +}); |
| 10 | + |
| 11 | +test.concurrent.for(variants)('default - %s', async (variant, { page, ...ctx }) => { |
| 12 | + const cwd = await ctx.run(variant, { devtoolsJson: {} }); |
| 13 | + |
| 14 | + const { close } = await prepareServer({ cwd, page }); |
| 15 | + // kill server process when we're done |
| 16 | + ctx.onTestFinished(async () => await close()); |
| 17 | + |
| 18 | + const ext = variant.includes('ts') ? 'ts' : 'js'; |
| 19 | + const viteFile = path.resolve(cwd, `vite.config.${ext}`); |
| 20 | + const viteContent = fs.readFileSync(viteFile, 'utf8'); |
| 21 | + |
| 22 | + // Check if we have the import part |
| 23 | + expect(viteContent).toContain(`import devtoolsJson from`); |
| 24 | + expect(viteContent).toContain(`vite-plugin-devtools-json`); |
| 25 | + |
| 26 | + // Check if it's called |
| 27 | + expect(viteContent).toContain(`devtoolsJson()`); |
| 28 | +}); |
| 29 | + |
| 30 | +test.concurrent.for(variants)( |
| 31 | + 'without selecting the addon specifically - %s', |
| 32 | + async (variant, { page, ...ctx }) => { |
| 33 | + const cwd = await ctx.run(variant, {}); |
| 34 | + |
| 35 | + const { close } = await prepareServer({ cwd, page }); |
| 36 | + // kill server process when we're done |
| 37 | + ctx.onTestFinished(async () => await close()); |
| 38 | + |
| 39 | + const ext = variant.includes('ts') ? 'ts' : 'js'; |
| 40 | + const viteFile = path.resolve(cwd, `vite.config.${ext}`); |
| 41 | + const viteContent = fs.readFileSync(viteFile, 'utf8'); |
| 42 | + |
| 43 | + // Check if we have the import part |
| 44 | + expect(viteContent).toContain(`import devtoolsJson from`); |
| 45 | + expect(viteContent).toContain(`vite-plugin-devtools-json`); |
| 46 | + |
| 47 | + // Check if it's called |
| 48 | + expect(viteContent).toContain(`devtoolsJson()`); |
| 49 | + } |
| 50 | +); |
0 commit comments