Skip to content

Commit

Permalink
chore: add test for scan dependencies (#980)
Browse files Browse the repository at this point in the history
* chore: add test for scan dependencies

* fix: actual test

* fix: use vite from pkg.pr.new as a dep for scan-deps

* fix: use pkg.pr.new as root vite dep

* chore: add usual vite config to scan deps

* fix: use patched vite version, bump deps for audit, dedupe

* chore(test): add svelte4 syntax checks

---------

Co-authored-by: dominikg <dominik.goepel@gmx.de>
  • Loading branch information
paoloricciuti and dominikg authored Sep 11, 2024
1 parent 9be5d4b commit 8cf6dd7
Show file tree
Hide file tree
Showing 19 changed files with 383 additions and 414 deletions.
3 changes: 2 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export default {
'.changeset/pre.json',
'**/vite.config.js.timestamp-*.mjs',
'packages/e2e-tests/dynamic-compile-options/src/components/A.svelte',
'packages/playground/big/src/pages/**' // lots of generated files
'packages/playground/big/src/pages/**', // lots of generated files
'packages/e2e-tests/scan-deps/src/Svelte*.svelte' // various syntax tests that require no format
],
options: {
rangeEnd: 0
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"svelte-eslint-parser": "^0.41.0",
"typescript": "^5.5.4",
"typescript-eslint": "^8.3.0",
"vite": "^5.4.2",
"vite": "^5.4.4",
"vitest": "^2.0.5"
},
"lint-staged": {
Expand All @@ -74,7 +74,8 @@
"@sveltejs/vite-plugin-svelte-inspector": "workspace:^",
"svelte": "$svelte",
"vite": "$vite",
"@types/node@<=20.12.0": "20.11.5"
"@types/node@<=20.12.0": "20.11.5",
"send@<0.19.0": "^0.19.0"
},
"onlyBuiltDependencies": [
"esbuild"
Expand Down
18 changes: 18 additions & 0 deletions packages/e2e-tests/scan-deps/__tests__/scan-deps.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { e2eServer, getText } from '~utils';
import { describe, expect, it } from 'vitest';
describe('vite import scan', () => {
it('should not fail to discover dependencies exported from script module', async () => {
// vite logs an error if scan fails but continues, so validate no errors logged
expect(
e2eServer.logs.server.err.length,
`unexpected errors:\n${e2eServer.logs.server.err.join('\n')}`
).toBe(0);
});
it('should work with exports from module context', async () => {
expect(await getText('#svelte5')).toBe('svelte5');
expect(await getText('#svelte4double')).toBe('svelte4double');
expect(await getText('#svelte4single')).toBe('svelte4single');
expect(await getText('#svelte4none')).toBe('svelte4none');
expect(await getText('#svelte4space')).toBe('svelte4space');
});
});
13 changes: 13 additions & 0 deletions packages/e2e-tests/scan-deps/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Svelte</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions packages/e2e-tests/scan-deps/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "e2e-tests-scan-deps",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite --force",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "workspace:^",
"svelte": "^5.0.0-next.242",
"vite": "^5.4.2"
}
}
Binary file added packages/e2e-tests/scan-deps/public/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions packages/e2e-tests/scan-deps/src/App.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script>
import { svelte5 } from './Svelte5.svelte';
import { svelte4double } from './Svelte4DoubleQuote.svelte';
import { svelte4single } from './Svelte4SingleQuote.svelte';
import { svelte4none } from './Svelte4NoQuote.svelte';
import { svelte4space } from './Svelte4WithSpace.svelte';
</script>

<div id="svelte5">{svelte5}</div>
<div id="svelte4double">{svelte4double}</div>
<div id="svelte4single">{svelte4single}</div>
<div id="svelte4none">{svelte4none}</div>
<div id="svelte4space">{svelte4space}</div>
4 changes: 4 additions & 0 deletions packages/e2e-tests/scan-deps/src/Svelte4DoubleQuote.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- eslint-disable-next-line svelte/valid-compile -->
<script context="module">
export const svelte4double = 'svelte4double';
</script>
4 changes: 4 additions & 0 deletions packages/e2e-tests/scan-deps/src/Svelte4NoQuote.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- eslint-disable-next-line svelte/valid-compile -->
<script context=module>
export const svelte4none = 'svelte4none';
</script>
4 changes: 4 additions & 0 deletions packages/e2e-tests/scan-deps/src/Svelte4SingleQuote.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- eslint-disable-next-line svelte/valid-compile -->
<script context='module'>
export const svelte4single = 'svelte4single';
</script>
5 changes: 5 additions & 0 deletions packages/e2e-tests/scan-deps/src/Svelte4WithSpace.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- prettier-ignore -->
<!-- eslint-disable-next-line svelte/valid-compile -->
<script context= "module">
export const svelte4space = 'svelte4space';
</script>
3 changes: 3 additions & 0 deletions packages/e2e-tests/scan-deps/src/Svelte5.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script module>
export const svelte5 = 'svelte5';
</script>
3 changes: 3 additions & 0 deletions packages/e2e-tests/scan-deps/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import App from './App.svelte';
import { mount } from 'svelte';
mount(App, { target: document.body });
2 changes: 2 additions & 0 deletions packages/e2e-tests/scan-deps/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference types="svelte" />
/// <reference types="vite/client" />
1 change: 1 addition & 0 deletions packages/e2e-tests/scan-deps/svelte.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
19 changes: 19 additions & 0 deletions packages/e2e-tests/scan-deps/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [svelte()],
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
}
},
build: {
minify: false,
sourcemap: true // must be true for hermetic build test!
}
});
4 changes: 2 additions & 2 deletions packages/e2e-tests/vite-ssr-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"cross-env": "^7.0.3",
"decamelize": "^6.0.0",
"e2e-test-dep-esm-only": "workspace:^",
"express": "^4.19.2",
"express": "^4.20.0",
"npm-run-all2": "^6.2.2",
"serve-static": "^1.15.0",
"serve-static": "^1.16.0",
"svelte": "^5.0.0-next.242",
"vite": "^5.4.2"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"compression": "^1.7.4",
"express": "^4.19.2",
"express": "^4.20.0",
"sirv": "^2.0.4"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 8cf6dd7

Please sign in to comment.