From 59ccf12935d7cd066ef31a09fc1364333676c207 Mon Sep 17 00:00:00 2001 From: Dominik G Date: Mon, 18 Sep 2023 11:08:52 +0200 Subject: [PATCH] chore: remove cjs-ssr test as vite5 no longer supports it (#754) * chore: remove cjs-ssr test as vite5 no longer supports it * fix: changesets writes pre.json with spaces --- .prettierrc.js | 2 +- .../vite-ssr/__tests__/vite-ssr.spec.ts | 75 ------------ packages/e2e-tests/vite-ssr/index.html | 13 -- packages/e2e-tests/vite-ssr/package.json | 23 ---- packages/e2e-tests/vite-ssr/server.js | 111 ------------------ packages/e2e-tests/vite-ssr/src/App.svelte | 30 ----- .../e2e-tests/vite-ssr/src/assets/logo.png | Bin 3127 -> 0 bytes .../vite-ssr/src/components/Foo.svelte | 12 -- .../e2e-tests/vite-ssr/src/entry-client.mjs | 14 --- .../e2e-tests/vite-ssr/src/entry-server.mjs | 10 -- packages/e2e-tests/vite-ssr/vite.config.js | 30 ----- 11 files changed, 1 insertion(+), 319 deletions(-) delete mode 100644 packages/e2e-tests/vite-ssr/__tests__/vite-ssr.spec.ts delete mode 100644 packages/e2e-tests/vite-ssr/index.html delete mode 100644 packages/e2e-tests/vite-ssr/package.json delete mode 100644 packages/e2e-tests/vite-ssr/server.js delete mode 100644 packages/e2e-tests/vite-ssr/src/App.svelte delete mode 100644 packages/e2e-tests/vite-ssr/src/assets/logo.png delete mode 100644 packages/e2e-tests/vite-ssr/src/components/Foo.svelte delete mode 100644 packages/e2e-tests/vite-ssr/src/entry-client.mjs delete mode 100644 packages/e2e-tests/vite-ssr/src/entry-server.mjs delete mode 100644 packages/e2e-tests/vite-ssr/vite.config.js diff --git a/.prettierrc.js b/.prettierrc.js index 81cdfcd4d..384f65f42 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -20,7 +20,7 @@ module.exports = { } }, { - files: ['**/package.json', '**/README.md', 'docs/**/*.md'], + files: ['**/package.json', '**/README.md', 'docs/**/*.md', '.changeset/pre.json'], options: { useTabs: false, tabWidth: 2 diff --git a/packages/e2e-tests/vite-ssr/__tests__/vite-ssr.spec.ts b/packages/e2e-tests/vite-ssr/__tests__/vite-ssr.spec.ts deleted file mode 100644 index 1617d626f..000000000 --- a/packages/e2e-tests/vite-ssr/__tests__/vite-ssr.spec.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { - editFileAndWaitForHmrComplete, - getColor, - getEl, - getText, - isBuild, - untilMatches, - page, - e2eServer, - browserLogs, - fetchPageText -} from '~utils'; - -test('/', async () => { - expect(await page.textContent('h1')).toMatch('Hello svelte world'); // after hydration - - const html = await fetchPageText(); - expect(html).toMatch('Hello world'); // before hydration - if (isBuild) { - // TODO expect preload links - } -}); - -test('css', async () => { - if (isBuild) { - expect(await getColor('h1')).toBe('green'); - } else { - // During dev, the CSS is loaded from async chunk and we may have to wait - // when the test runs concurrently. - await untilMatches(() => getColor('h1'), 'green', 'h1 has color green'); - } -}); - -test('loaded esm only package', async () => { - expect(await page.textContent('#esm')).toMatch('esm'); - expect(browserLogs).toContain('esm'); - expect(e2eServer.logs.server.out).toContain('esm'); -}); - -test('asset', async () => { - // should have no 404s - browserLogs.forEach((msg) => { - expect(msg).not.toMatch('404'); - }); - const img = await page.$('img'); - expect(await img.getAttribute('src')).toMatch( - isBuild ? /\/assets\/logo-\w{8}\.png/ : '/src/assets/logo.png' - ); -}); - -if (!isBuild) { - describe('hmr', () => { - const updateApp = editFileAndWaitForHmrComplete.bind(null, 'src/App.svelte'); - test('should render additional html', async () => { - expect(await getEl('#hmr-test')).toBe(null); - await updateApp((content) => - content.replace( - '', - '
foo
\n' - ) - ); - await untilMatches(() => getText('#hmr-test'), 'foo', '#hmr-test contains text foo'); - }); - test('should apply style update', async () => { - expect(await getColor('h1')).toBe('green'); - await updateApp((content) => content.replace('color: green', 'color: red')); - await untilMatches(() => getColor('h1'), 'red', 'h1 has color red'); - }); - test('should not preserve state of updated props', async () => { - expect(await getText('#foo')).toBe('foo'); - await updateApp((content) => content.replace("foo = 'foo'", "foo = 'bar'")); - await untilMatches(() => getText('#foo'), 'bar', '#foo contains text bar'); - }); - }); -} diff --git a/packages/e2e-tests/vite-ssr/index.html b/packages/e2e-tests/vite-ssr/index.html deleted file mode 100644 index 7ef3ed135..000000000 --- a/packages/e2e-tests/vite-ssr/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - Svelte App - - - -
- - - diff --git a/packages/e2e-tests/vite-ssr/package.json b/packages/e2e-tests/vite-ssr/package.json deleted file mode 100644 index bb3f3b5a8..000000000 --- a/packages/e2e-tests/vite-ssr/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "e2e-tests-vite-ssr", - "private": true, - "version": "0.0.0", - "scripts": { - "dev": "node server", - "build": "pnpm build:client && pnpm build:server", - "build:client": "vite build --ssrManifest --outDir dist/client", - "build:server": "vite build --ssr src/entry-server.mjs --outDir dist/server", - "preview": "cross-env NODE_ENV=production node server", - "debug": "node --inspect-brk server" - }, - "devDependencies": { - "@sveltejs/vite-plugin-svelte": "workspace:^", - "compression": "^1.7.4", - "cross-env": "^7.0.3", - "e2e-test-dep-esm-only": "file:../_test_dependencies/esm-only", - "express": "^4.18.2", - "serve-static": "^1.15.0", - "svelte": "^4.2.0", - "vite": "^5.0.0-beta.1" - } -} diff --git a/packages/e2e-tests/vite-ssr/server.js b/packages/e2e-tests/vite-ssr/server.js deleted file mode 100644 index ef3192368..000000000 --- a/packages/e2e-tests/vite-ssr/server.js +++ /dev/null @@ -1,111 +0,0 @@ -// @ts-check -const fs = require('node:fs'); -const path = require('node:path'); -const express = require('express'); - -let port = 3000; -const args = process.argv.slice(2); -const portArgPos = args.indexOf('--port') + 1; -if (portArgPos > 0) { - port = parseInt(args[portArgPos], 10); -} - -async function createServer(root = process.cwd(), isProd = process.env.NODE_ENV === 'production') { - const resolve = (p) => path.resolve(__dirname, p); - - const indexProd = isProd ? fs.readFileSync(resolve('dist/client/index.html'), 'utf-8') : ''; - - const manifest = isProd - ? // @ts-ignore - // eslint-disable-next-line n/no-missing-require - require('./dist/client/ssr-manifest.json') - : {}; - - const app = express(); - - /** - * @type {import('vite').ViteDevServer} - */ - let vite; - if (!isProd) { - const inlineCfg = { - root, - appType: 'custom', - server: { - middlewareMode: true, - port, - strictPort: true, - hmr: { - port: port + 25000 - } - } - }; - // @ts-ignore - vite = await require('vite').createServer(inlineCfg); - // use vite's connect instance as middleware - app.use(vite.middlewares); - } else { - app.use(require('compression')()); - app.use( - require('serve-static')(resolve('dist/client'), { - index: false - }) - ); - } - - app.use('*', async (req, res) => { - try { - const url = req.originalUrl; - - let template, render; - if (!isProd) { - // always read fresh template in dev - template = fs.readFileSync(resolve('index.html'), 'utf-8'); - template = await vite.transformIndexHtml(url, template); - render = (await vite.ssrLoadModule('/src/entry-server.mjs')).render; - } else { - template = indexProd; - // @ts-ignore - // eslint-disable-next-line n/no-missing-require - render = require('./dist/server/entry-server.js').render; - } - const rendered = await render(req.originalUrl, manifest); - const appHtml = rendered.html; - const headElements = rendered.head || ''; - // TODO what do we do with rendered.css here. find out if emitCss was used and vite took care of it - const html = template - .replace('', headElements) - .replace('', appHtml); - - res.status(200).set({ 'Content-Type': 'text/html' }).end(html); - } catch (e) { - vite && vite.ssrFixStacktrace(e); - console.log(e.stack); - res.status(500).end(e.stack); - } - }); - - return { app, vite }; -} - -createServer().then(({ app }) => { - const server = app.listen(port, () => { - console.log('http://localhost:' + port); - }); - const exitProcess = async () => { - process.off('SIGTERM', exitProcess); - process.off('SIGINT', exitProcess); - process.stdin.off('end', exitProcess); - try { - await server.close(() => { - console.log('ssr server closed'); - }); - } finally { - // eslint-disable-next-line n/no-process-exit - process.exit(0); - } - }; - process.once('SIGTERM', exitProcess); - process.once('SIGINT', exitProcess); - process.stdin.on('end', exitProcess); -}); diff --git a/packages/e2e-tests/vite-ssr/src/App.svelte b/packages/e2e-tests/vite-ssr/src/App.svelte deleted file mode 100644 index 999941b80..000000000 --- a/packages/e2e-tests/vite-ssr/src/App.svelte +++ /dev/null @@ -1,30 +0,0 @@ - - -

Hello {world}

-

Open App.svelte in your editor and change something to see HMR in action

- -logo -
{foo}
-
{esm()}
- - - - - - - diff --git a/packages/e2e-tests/vite-ssr/src/assets/logo.png b/packages/e2e-tests/vite-ssr/src/assets/logo.png deleted file mode 100644 index 7e6f5eb5a2f1f1c882d265cf479de25caa925645..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3127 zcmV-749N3|P)i z7)}s4L53SJCkR}iVi00SFk;`MXX*#X*kkwKs@nFGS}c;=?XFjU|G$3t^5sjIVS2G+ zw)WGF83CpoGXhLGW(1gW%uV|X7>1P6VhCX=Ux)Lb!*DZ%@I3!{Gsf7d?gtIQ%nQiK z3%(LUSkBji;C5Rfgd6$VsF@H`Pk@xtY6t<>FNR-pD}=C~$?)9pdm3XZ36N5PNWYjb z$xd$yNQR9N!dfj-Vd@BwQo^FIIWPPmT&sZyQ$v81(sCBV=PGy{0wltEjB%~h157*t zvbe_!{=I_783x!0t1-r#-d{Y?ae$Q4N_Nd^Ui^@y(%)Gjou6y<3^XJdu{rmUf-Me?)zZ>9OR&6U5H*cK; z$gUlB{g0O4gN0sLSO|Of?hU(l?;h(jA3uH!Z{EBKuV23ouU@^Y6#%v+QG;>e*E}%?wlu-NT4DG zs)z)7WbLr)vGAu(ohrKc^em@OpO&f~6_>E61n_e0_V3@{U3^O;j{`^mNCJUj_>;7v zsMs6Hu3g7+@v+lSo;=yTYFqq}jZmQ-BK8K{C4kqi_i*jBaQE(Au0607V-zKeT;EPg zX(`vrn=L+e74+-Tqeok@_`tDa$G9I|$nTU5H*2V8@y()n*zqM?J1G!-1aX;CfDC9B zTnJ#j_%*n8Qb1)re*Bno7g0RG{Eb;IK14irJYJp$5Z6ac9~b_P?+5t~95~SRG$g?1 znFJ7p$xV&GZ18m~79TGRdfsc-BcX$9yXTR*n)mPD@1~O(_?cT$ZvFPucRmGlq&se0 zKrcUf^k}4hM*biEJOWKzz!qQe;CB_ZtSOO9Owg#lZAc=s65^rb{fZe(TYu_rk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> z - const bar = 'bar'; - - -
Foo bar={bar}
- - - diff --git a/packages/e2e-tests/vite-ssr/src/entry-client.mjs b/packages/e2e-tests/vite-ssr/src/entry-client.mjs deleted file mode 100644 index 6d665988d..000000000 --- a/packages/e2e-tests/vite-ssr/src/entry-client.mjs +++ /dev/null @@ -1,14 +0,0 @@ -import App from './App.svelte'; - -import { esm } from 'e2e-test-dep-esm-only'; -console.log(esm()); - -const app = new App({ - target: document.getElementById('svelte'), - hydrate: true, - props: { - world: 'svelte world' - } -}); - -export default app; diff --git a/packages/e2e-tests/vite-ssr/src/entry-server.mjs b/packages/e2e-tests/vite-ssr/src/entry-server.mjs deleted file mode 100644 index ff2ce25a3..000000000 --- a/packages/e2e-tests/vite-ssr/src/entry-server.mjs +++ /dev/null @@ -1,10 +0,0 @@ -import App from './App.svelte'; - -import { esm } from 'e2e-test-dep-esm-only'; -console.log(esm()); - -export async function render(url, manifest) { - return App.render({ - name: 'world' - }); -} diff --git a/packages/e2e-tests/vite-ssr/vite.config.js b/packages/e2e-tests/vite-ssr/vite.config.js deleted file mode 100644 index b0696aac2..000000000 --- a/packages/e2e-tests/vite-ssr/vite.config.js +++ /dev/null @@ -1,30 +0,0 @@ -const { defineConfig } = require('vite'); - -module.exports = defineConfig(async ({ command, mode }) => { - const { svelte } = await import('@sveltejs/vite-plugin-svelte'); - return { - plugins: [ - svelte({ - compilerOptions: { - hydratable: true /* required for clientside hydration */ - } - }) - ], - ssr: { - format: 'cjs' - }, - build: { - target: 'esnext', - minify: false, - assetsInlineLimit: 0 - }, - server: { - watch: { - // During tests we edit the files too fast and sometimes chokidar - // misses change events, so enforce polling for consistency - usePolling: true, - interval: 100 - } - } - }; -});