|
1 | 1 | import { mkdtempSync, readFileSync } from 'node:fs'; |
2 | 2 | import { tmpdir } from 'node:os'; |
3 | 3 | import { join } from 'node:path'; |
| 4 | +import react from '@vitejs/plugin-react'; |
4 | 5 | import { createServer } from 'vite'; |
5 | 6 | import { afterEach, beforeEach, describe, expect, it } from 'vitest'; |
6 | 7 | import Symfony from '../../src/vite'; |
@@ -36,9 +37,29 @@ describe('vite serve writes a dev entrypoints.json', () => { |
36 | 37 | expect(origin).toMatch(/^http:\/\/127\.0\.0\.1:\d+$/); |
37 | 38 | // The HMR client is served under `base` (our publicPath), so its URL carries `/build/`. |
38 | 39 | expect(entry.devServer.client).toBe(`${origin}/build/@vite/client`); |
| 40 | + // No React plugin in this fixture, so no Fast Refresh preamble URL. |
| 41 | + expect(entry.devServer.reactRefresh ?? null).toBe(null); |
39 | 42 |
|
40 | 43 | expect(Object.keys(entry.entryPoints).sort()).toEqual(['admin', 'app']); |
41 | 44 | expect(entry.entryPoints.app.js).toEqual([`${origin}/build/app.js`]); |
42 | 45 | expect(entry.entryPoints.app.css).toEqual([]); |
43 | 46 | }); |
| 47 | + |
| 48 | + it('exposes the React Fast Refresh URL when a React plugin is present', async () => { |
| 49 | + const reactOut = mkdtempSync(join(tmpdir(), 'ups-dev-react-')); |
| 50 | + const reactServer = await createServer({ |
| 51 | + root: fixture, |
| 52 | + logLevel: 'silent', |
| 53 | + server: { port: 0, host: '127.0.0.1' }, |
| 54 | + build: { rollupOptions: { input: { app: join(fixture, 'app.js') } } }, |
| 55 | + plugins: [react(), Symfony({ outputPath: reactOut, publicPath: '/build/' })], |
| 56 | + }); |
| 57 | + await reactServer.listen(); |
| 58 | + try { |
| 59 | + const entry = JSON.parse(readFileSync(join(reactOut, 'entrypoints.json'), 'utf8')); |
| 60 | + expect(entry.devServer.reactRefresh).toBe(`${entry.devServer.origin}/build/@react-refresh`); |
| 61 | + } finally { |
| 62 | + await reactServer.close(); |
| 63 | + } |
| 64 | + }); |
44 | 65 | }); |
0 commit comments