From ed57c66bb5d7cdeff838ef08a91c730b528e7dfd Mon Sep 17 00:00:00 2001 From: Michael Cousins Date: Wed, 15 May 2024 17:32:17 -0400 Subject: [PATCH 01/19] feat(svelte5): add support for Svelte 5 modules --- src/transformer.js | 20 +++++++++++++++++--- src/utils.js | 13 +++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/transformer.js b/src/transformer.js index 0b97710..ce052e1 100644 --- a/src/transformer.js +++ b/src/transformer.js @@ -1,10 +1,10 @@ import { execSync } from 'child_process' import { basename, extname } from 'path' import { pathToFileURL } from 'url' -import { compile, preprocess as sveltePreprocess } from 'svelte/compiler' +import * as SvelteCompiler from 'svelte/compiler' import { getSvelteConfig } from './svelteconfig.js' -import { dynamicImport, IS_COMMON_JS, isSvelte3 } from './utils.js' +import { dynamicImport, IS_COMMON_JS, isSvelte3, isSvelteModule } from './utils.js' const currentFileExtension = (global.__dirname !== undefined ? extname(__filename) : extname(pathToFileURL(import.meta.url).toString())).replace('.', '') @@ -29,7 +29,7 @@ const processAsync = async (source, filename, jestOptions) => { const svelteConfigPath = getSvelteConfig(rootMode, filename, preprocess) const svelteConfig = await dynamicImport(svelteConfigPath) - const processed = await sveltePreprocess( + const processed = await SvelteCompiler.preprocess( source, svelteConfig.default.preprocess || {}, { filename } @@ -91,6 +91,8 @@ const compiler = (format, options = {}, filename, processedCode, processedMap) = opts.format = format } + const compile = isSvelteModule(filename) ? compileModule : compileComponent + let result try { result = compile(processedCode, opts) @@ -115,6 +117,18 @@ const compiler = (format, options = {}, filename, processedCode, processedMap) = } } +const compileComponent = (processedCode, opts) => { + return SvelteCompiler.compile(processedCode, opts) +} + +const compileModule = (processedCode, opts) => { + return SvelteCompiler.compileModule(processedCode, { + filename: opts.filename, + dev: opts.dev, + generate: opts.ssr ? 'server' : 'client', + }) +} + export default { process: processSync, processAsync diff --git a/src/utils.js b/src/utils.js index a3a21bd..81ad104 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,8 +1,17 @@ import { pathToFileURL } from 'url' -import { VERSION } from 'svelte/compiler' +import * as SvelteCompiler from 'svelte/compiler' export const dynamicImport = async (filename) => import(pathToFileURL(filename).toString()) export const IS_COMMON_JS = typeof module !== 'undefined' -export const isSvelte3 = (version = VERSION) => version.startsWith('3') +export const isSvelte3 = (version = SvelteCompiler.VERSION) => version.startsWith('3') + +export const DEFAULT_SVELTE_MODULE_INFIX = ['.svelte.'] + +export const DEFAULT_SVELTE_MODULE_EXT = ['.js', '.ts'] + +export const isSvelteModule = (filename) => + typeof SvelteCompiler.compileModule === 'function' && + DEFAULT_SVELTE_MODULE_INFIX.some((infix) => filename.includes(infix)) && + DEFAULT_SVELTE_MODULE_EXT.some((ext) => filename.endsWith(ext)); From 17917eec45c3158964c0a37e4a3f29961b1298ab Mon Sep 17 00:00:00 2001 From: Michael Cousins Date: Mon, 20 May 2024 12:55:43 -0500 Subject: [PATCH 02/19] test(e2e): add simple Svelte 5 suite --- e2e/README.md | 14 ++++ e2e/svelte-5/package.json | 36 ++++++++ e2e/svelte-5/src/legacy.svelte | 11 +++ e2e/svelte-5/src/legacy.test.js | 38 +++++++++ e2e/svelte-5/src/modern.svelte | 11 +++ e2e/svelte-5/src/modern.test.js | 38 +++++++++ e2e/svelte-5/src/module.svelte.js | 13 +++ e2e/svelte-5/src/module.test.js | 19 +++++ e2e/svelte-5/svelte.config.js | 1 + package.json | 3 +- pnpm-lock.yaml | 131 ++++++++++++++++++++++++++++++ 11 files changed, 314 insertions(+), 1 deletion(-) create mode 100644 e2e/svelte-5/package.json create mode 100644 e2e/svelte-5/src/legacy.svelte create mode 100644 e2e/svelte-5/src/legacy.test.js create mode 100644 e2e/svelte-5/src/modern.svelte create mode 100644 e2e/svelte-5/src/modern.test.js create mode 100644 e2e/svelte-5/src/module.svelte.js create mode 100644 e2e/svelte-5/src/module.test.js create mode 100644 e2e/svelte-5/svelte.config.js diff --git a/e2e/README.md b/e2e/README.md index fbce399..3af7200 100644 --- a/e2e/README.md +++ b/e2e/README.md @@ -81,3 +81,17 @@ test('should show the proper label', () => { npm run test ``` +## Svelte 5 (ESM) + +A minimal Svelte 5 test to ensure Svelte 5 components and `.svelte.js` modules work with Jest. + +### Bootstrapping the project + +No special steps were taken to create this suite. It only contains a few components and their associated tests. + +### Run the tests + +```shell +pnpm build +pnpm e2e:svelte-5 +``` diff --git a/e2e/svelte-5/package.json b/e2e/svelte-5/package.json new file mode 100644 index 0000000..b8e47df --- /dev/null +++ b/e2e/svelte-5/package.json @@ -0,0 +1,36 @@ +{ + "name": "@svelte-jester-e2e/svelte-5", + "version": "1.0.0", + "private": true, + "type": "module", + "scripts": { + "test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --no-warnings\" jest --coverage", + "test:watch": "pnpm run test --watch" + }, + "devDependencies": { + "jest": "^29.7.0", + "jest-environment-jsdom": "^29.7.0", + "svelte": "^5.0.0-next.136", + "svelte-jester": "workspace:*" + }, + "dependenciesMeta": { + "svelte-jester": { + "injected": true + } + }, + "jest": { + "transform": { + "^.+\\.svelte(?:\\.js)?$": [ + "svelte-jester" + ] + }, + "moduleFileExtensions": [ + "js", + "svelte" + ], + "extensionsToTreatAsEsm": [ + ".svelte" + ], + "testEnvironment": "jsdom" + } +} diff --git a/e2e/svelte-5/src/legacy.svelte b/e2e/svelte-5/src/legacy.svelte new file mode 100644 index 0000000..ffa3fac --- /dev/null +++ b/e2e/svelte-5/src/legacy.svelte @@ -0,0 +1,11 @@ + + + +{#if showGreeting} +

hello {name}

+{/if} diff --git a/e2e/svelte-5/src/legacy.test.js b/e2e/svelte-5/src/legacy.test.js new file mode 100644 index 0000000..b102f94 --- /dev/null +++ b/e2e/svelte-5/src/legacy.test.js @@ -0,0 +1,38 @@ +import { test, afterEach } from "@jest/globals"; +import { mount, unmount, tick } from "svelte"; + +import Subject from "./legacy.svelte"; + +let component; + +afterEach(() => { + unmount(component); + component = undefined; +}); + +test("render", () => { + component = mount(Subject, { + target: document.body, + props: { name: "alice" }, + }); + + const button = document.querySelector("button"); + + expect(button).toBeInstanceOf(HTMLButtonElement); +}); + +test("interaction", async () => { + component = mount(Subject, { + target: document.body, + props: { name: "alice" }, + }); + + const button = document.querySelector("button"); + + button.click(); + await tick(); + + const message = document.querySelector("p"); + + expect(message.textContent).toMatch(/hello alice/iu); +}); diff --git a/e2e/svelte-5/src/modern.svelte b/e2e/svelte-5/src/modern.svelte new file mode 100644 index 0000000..4062846 --- /dev/null +++ b/e2e/svelte-5/src/modern.svelte @@ -0,0 +1,11 @@ + + + +{#if showGreeting} +

hello {name}

+{/if} diff --git a/e2e/svelte-5/src/modern.test.js b/e2e/svelte-5/src/modern.test.js new file mode 100644 index 0000000..edb93ba --- /dev/null +++ b/e2e/svelte-5/src/modern.test.js @@ -0,0 +1,38 @@ +import { test, afterEach } from "@jest/globals"; +import { mount, unmount, tick } from "svelte"; + +import Subject from "./modern.svelte"; + +let component; + +afterEach(() => { + unmount(component); + component = undefined; +}); + +test("render", () => { + component = mount(Subject, { + target: document.body, + props: { name: "alice" }, + }); + + const button = document.querySelector("button"); + + expect(button).toBeInstanceOf(HTMLButtonElement); +}); + +test("interaction", async () => { + component = mount(Subject, { + target: document.body, + props: { name: "alice" }, + }); + + const button = document.querySelector("button"); + + button.click(); + await tick(); + + const message = document.querySelector("p"); + + expect(message.textContent).toMatch(/hello alice/iu); +}); diff --git a/e2e/svelte-5/src/module.svelte.js b/e2e/svelte-5/src/module.svelte.js new file mode 100644 index 0000000..4686755 --- /dev/null +++ b/e2e/svelte-5/src/module.svelte.js @@ -0,0 +1,13 @@ +export const createCounter = () => { + let count = $state(0); + + return { + get count() { + return count; + }, + + increment() { + count = count + 1; + }, + }; +}; diff --git a/e2e/svelte-5/src/module.test.js b/e2e/svelte-5/src/module.test.js new file mode 100644 index 0000000..544063b --- /dev/null +++ b/e2e/svelte-5/src/module.test.js @@ -0,0 +1,19 @@ +import { test } from "@jest/globals"; + +import * as Subject from "./module.svelte.js"; + +test("get current count", () => { + const subject = Subject.createCounter(); + const result = subject.count; + + expect(result).toBe(0); +}); + +test("increment", () => { + const subject = Subject.createCounter(); + + subject.increment(); + const result = subject.count; + + expect(result).toBe(1); +}); diff --git a/e2e/svelte-5/svelte.config.js b/e2e/svelte-5/svelte.config.js new file mode 100644 index 0000000..ff8b4c5 --- /dev/null +++ b/e2e/svelte-5/svelte.config.js @@ -0,0 +1 @@ +export default {}; diff --git a/package.json b/package.json index 190fea3..3b9d4cf 100644 --- a/package.json +++ b/package.json @@ -37,9 +37,10 @@ "test": "pnpm test:esm && pnpm test:cjs", "test:esm": "pnpm build && cross-env NODE_OPTIONS=--experimental-vm-modules jest src/__tests__/transformer.test.js", "test:cjs": "pnpm build && jest src/__tests__/transformer.test.cjs", - "e2e": "pnpm e2e:svelte && pnpm e2e:sveltekit", + "e2e": "pnpm e2e:svelte && pnpm e2e:sveltekit && pnpm e2e:svelte-5", "e2e:svelte": "cd e2e/svelte && pnpm test", "e2e:sveltekit": "cd e2e/sveltekit && pnpm test", + "e2e:svelte-5": "cd e2e/svelte-5 && pnpm test", "test:nocache": "pnpm install && jest --clearCache && pnpm test -- --no-cache", "test:watch": "pnpm test -- --watch", "test:update": "pnpm test -- --updateSnapshot --coverage", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5db456f..4518e67 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -110,6 +110,24 @@ importers: specifier: ^5.0.4 version: 5.0.4(@babel/core@7.24.5)(sass@1.75.0)(svelte@3.59.2)(typescript@5.1.6) + e2e/svelte-5: + devDependencies: + jest: + specifier: ^29.7.0 + version: 29.7.0 + jest-environment-jsdom: + specifier: ^29.7.0 + version: 29.7.0 + svelte: + specifier: ^5.0.0-next.136 + version: 5.0.0-next.136 + svelte-jester: + specifier: workspace:* + version: file:(jest@29.7.0)(svelte@5.0.0-next.136) + dependenciesMeta: + svelte-jester: + injected: true + e2e/sveltekit: devDependencies: '@babel/core': @@ -4101,6 +4119,14 @@ packages: acorn: 8.10.0 dev: true + /acorn-typescript@1.4.13(acorn@8.11.3): + resolution: {integrity: sha512-xsc9Xv0xlVfwp2o7sQ+GCQ1PgbkdcpWdTzrwXxO3xDMTAywVS3oXVOcOHuRjAPkS4P9b+yc/qNF15460v+jp4Q==} + peerDependencies: + acorn: '>=8.9.0' + dependencies: + acorn: 8.11.3 + dev: true + /acorn-walk@8.2.0: resolution: {integrity: sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==} engines: {node: '>=0.4.0'} @@ -4112,6 +4138,12 @@ packages: hasBin: true dev: true + /acorn@8.11.3: + resolution: {integrity: sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==} + engines: {node: '>=0.4.0'} + hasBin: true + dev: true + /add-stream@1.0.0: resolution: {integrity: sha512-qQLMr+8o0WC4FZGQTcJiKBVC59JylcPSrTtk6usvmIDFUOCKegapy1VHQwRbFMOFyb/inzUVqHs+eMYKDM1YeQ==} dev: true @@ -4285,6 +4317,12 @@ packages: dequal: 2.0.3 dev: true + /axobject-query@4.0.0: + resolution: {integrity: sha512-+60uv1hiVFhHZeO+Lz0RYzsVHy5Wr1ayX0mwda9KPDVLNJgZ1T9Ny7VmFbLDzxsH0D87I86vgj3gFrjTJUYznw==} + dependencies: + dequal: 2.0.3 + dev: true + /babel-jest@29.6.1(@babel/core@7.22.9): resolution: {integrity: sha512-qu+3bdPEQC6KZSPz+4Fyjbga5OODNcp49j6GKzG1EKbkfyJBxEYGVUmVGpwCSeGouG52R4EgYMLb6p9YeEEQ4A==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -5758,6 +5796,13 @@ packages: estraverse: 5.3.0 dev: true + /esrap@1.2.2: + resolution: {integrity: sha512-F2pSJklxx1BlQIQgooczXCPHmcWpn6EsP5oo73LQfonG9fIlIENQ8vMmfGXeojP9MrkzUNAfyU5vdFlR9shHAw==} + dependencies: + '@jridgewell/sourcemap-codec': 1.4.15 + '@types/estree': 1.0.5 + dev: true + /esrecurse@4.3.0: resolution: {integrity: sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==} engines: {node: '>=4.0'} @@ -6516,6 +6561,12 @@ packages: '@types/estree': 1.0.5 dev: true + /is-reference@3.0.2: + resolution: {integrity: sha512-v3rht/LgVcsdZa3O2Nqs+NMowLOxeOm7Ay9+/ARQ2F+qEoANRcqrjAZKGN0v8ymUetZGgkp26LTnGT7H0Qo9Pg==} + dependencies: + '@types/estree': 1.0.5 + dev: true + /is-regex@1.1.4: resolution: {integrity: sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==} engines: {node: '>= 0.4'} @@ -6812,6 +6863,29 @@ packages: - utf-8-validate dev: true + /jest-environment-jsdom@29.7.0: + resolution: {integrity: sha512-k9iQbsf9OyOfdzWH8HDmrRT0gSIcX+FLNW7IQq94tFX0gynPwqDTW0Ho6iMVNjGz/nb+l/vW3dWM2bbLLpkbXA==} + engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + peerDependencies: + canvas: ^2.5.0 + peerDependenciesMeta: + canvas: + optional: true + dependencies: + '@jest/environment': 29.7.0 + '@jest/fake-timers': 29.7.0 + '@jest/types': 29.6.3 + '@types/jsdom': 20.0.1 + '@types/node': 20.4.2 + jest-mock: 29.7.0 + jest-util: 29.7.0 + jsdom: 20.0.3 + transitivePeerDependencies: + - bufferutil + - supports-color + - utf-8-validate + dev: true + /jest-environment-node@29.7.0: resolution: {integrity: sha512-DOSwCRqXirTOyheM+4d5YZOrWcdu0LNZ87ewUoywbcb2XR4wKgqiG8vNeYwhjFMbEkfju7wx2GYH0P2gevGvFw==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -7109,6 +7183,27 @@ packages: - ts-node dev: true + /jest@29.7.0: + resolution: {integrity: sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==} + engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + hasBin: true + peerDependencies: + node-notifier: ^8.0.1 || ^9.0.0 || ^10.0.0 + peerDependenciesMeta: + node-notifier: + optional: true + dependencies: + '@jest/core': 29.7.0 + '@jest/types': 29.6.3 + import-local: 3.1.0 + jest-cli: 29.7.0 + transitivePeerDependencies: + - '@types/node' + - babel-plugin-macros + - supports-color + - ts-node + dev: true + /js-tokens@4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} dev: true @@ -9104,6 +9199,25 @@ packages: periscopic: 3.1.0 dev: true + /svelte@5.0.0-next.136: + resolution: {integrity: sha512-M3jHAIfWZ7K+hjZdvu2p53ZtWE843yubxJfjxeQw9XiwMYG5z6quCA5u8r23GrxAp20JBl36B6ucbZvLUf0Z/g==} + engines: {node: '>=18'} + dependencies: + '@ampproject/remapping': 2.2.1 + '@jridgewell/sourcemap-codec': 1.4.15 + '@types/estree': 1.0.5 + acorn: 8.11.3 + acorn-typescript: 1.4.13(acorn@8.11.3) + aria-query: 5.3.0 + axobject-query: 4.0.0 + esm-env: 1.0.0 + esrap: 1.2.2 + is-reference: 3.0.2 + locate-character: 3.0.0 + magic-string: 0.30.5 + zimmerframe: 1.1.2 + dev: true + /symbol-tree@3.2.4: resolution: {integrity: sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==} dev: true @@ -9813,6 +9927,23 @@ packages: engines: {node: '>=10'} dev: true + /zimmerframe@1.1.2: + resolution: {integrity: sha512-rAbqEGa8ovJy4pyBxZM70hg4pE6gDgaQ0Sl9M3enG3I0d6H4XSAM3GeNGLKnsBpuijUow064sf7ww1nutC5/3w==} + dev: true + /zwitch@1.0.5: resolution: {integrity: sha512-V50KMwwzqJV0NpZIZFwfOD5/lyny3WlSzRiXgA0G7VUnRlqttta1L6UQIHzd6EuBY/cHGfwTIck7w1yH6Q5zUw==} dev: true + + file:(jest@29.7.0)(svelte@5.0.0-next.136): + resolution: {directory: '', type: directory} + id: 'file:' + name: svelte-jester + engines: {node: '>=16', pnpm: ^8.0.0} + peerDependencies: + jest: '>= 27' + svelte: '>= 3' + dependencies: + jest: 29.7.0 + svelte: 5.0.0-next.136 + dev: true From 6a51913d9e28e326b0dfd744830237eeb3a6d9d6 Mon Sep 17 00:00:00 2001 From: Michael Cousins Date: Mon, 20 May 2024 14:05:17 -0500 Subject: [PATCH 03/19] fixup: run pnpm install to sync injected svelte-jester --- e2e/svelte-5/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/svelte-5/package.json b/e2e/svelte-5/package.json index b8e47df..0afe320 100644 --- a/e2e/svelte-5/package.json +++ b/e2e/svelte-5/package.json @@ -4,7 +4,7 @@ "private": true, "type": "module", "scripts": { - "test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --no-warnings\" jest --coverage", + "test": "pnpm install && NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --no-warnings\" jest --coverage", "test:watch": "pnpm run test --watch" }, "devDependencies": { From cbf67fbbc4b9ff0efe177c5f6cd5bca1c8f91c61 Mon Sep 17 00:00:00 2001 From: Michael Cousins Date: Thu, 23 May 2024 10:59:06 -0400 Subject: [PATCH 04/19] fixup: skip Svelte 5 module tests while failing --- e2e/README.md | 8 ++------ e2e/svelte-5/package.json | 2 +- e2e/svelte-5/src/module.test.js | 8 +++++--- pnpm-lock.yaml | 28 ++++++++++++++-------------- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/e2e/README.md b/e2e/README.md index 3af7200..9f70edd 100644 --- a/e2e/README.md +++ b/e2e/README.md @@ -83,13 +83,9 @@ npm run test ## Svelte 5 (ESM) -A minimal Svelte 5 test to ensure Svelte 5 components and `.svelte.js` modules work with Jest. +A minimal Svelte 5 test to ensure Svelte 5 components and `.svelte.js` modules work with Jest. No special steps were taken to create this suite. It only contains a few components and their associated tests. -### Bootstrapping the project - -No special steps were taken to create this suite. It only contains a few components and their associated tests. - -### Run the tests +### Run the Svelte 5 tests ```shell pnpm build diff --git a/e2e/svelte-5/package.json b/e2e/svelte-5/package.json index 0afe320..7930339 100644 --- a/e2e/svelte-5/package.json +++ b/e2e/svelte-5/package.json @@ -10,7 +10,7 @@ "devDependencies": { "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", - "svelte": "^5.0.0-next.136", + "svelte": "^5.0.0-next.139", "svelte-jester": "workspace:*" }, "dependenciesMeta": { diff --git a/e2e/svelte-5/src/module.test.js b/e2e/svelte-5/src/module.test.js index 544063b..3238d52 100644 --- a/e2e/svelte-5/src/module.test.js +++ b/e2e/svelte-5/src/module.test.js @@ -1,15 +1,17 @@ import { test } from "@jest/globals"; -import * as Subject from "./module.svelte.js"; +// TODO(mcous, 2024-05-23): this import fails +// See https://github.com/svelteness/svelte-jester/pull/283 +// import * as Subject from "./module.svelte.js"; -test("get current count", () => { +test.skip("get current count", () => { const subject = Subject.createCounter(); const result = subject.count; expect(result).toBe(0); }); -test("increment", () => { +test.skip("increment", () => { const subject = Subject.createCounter(); subject.increment(); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4518e67..12acdc8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -119,11 +119,11 @@ importers: specifier: ^29.7.0 version: 29.7.0 svelte: - specifier: ^5.0.0-next.136 - version: 5.0.0-next.136 + specifier: ^5.0.0-next.139 + version: 5.0.0-next.139 svelte-jester: specifier: workspace:* - version: file:(jest@29.7.0)(svelte@5.0.0-next.136) + version: file:(jest@29.7.0)(svelte@5.0.0-next.139) dependenciesMeta: svelte-jester: injected: true @@ -4107,16 +4107,16 @@ packages: /acorn-globals@7.0.1: resolution: {integrity: sha512-umOSDSDrfHbTNPuNpC2NSnnA3LUrqpevPb4T9jRx4MagXNS0rs+gwiTcAvqCRmsD6utzsrzNt+ebm00SNWiC3Q==} dependencies: - acorn: 8.10.0 + acorn: 8.11.3 acorn-walk: 8.2.0 dev: true - /acorn-jsx@5.3.2(acorn@8.10.0): + /acorn-jsx@5.3.2(acorn@8.11.3): resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==} peerDependencies: acorn: ^6.0.0 || ^7.0.0 || ^8.0.0 dependencies: - acorn: 8.10.0 + acorn: 8.11.3 dev: true /acorn-typescript@1.4.13(acorn@8.11.3): @@ -4760,7 +4760,7 @@ packages: dependencies: '@jridgewell/sourcemap-codec': 1.4.15 '@types/estree': 1.0.5 - acorn: 8.10.0 + acorn: 8.11.3 estree-walker: 3.0.3 periscopic: 3.1.0 dev: true @@ -5778,8 +5778,8 @@ packages: resolution: {integrity: sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: - acorn: 8.10.0 - acorn-jsx: 5.3.2(acorn@8.10.0) + acorn: 8.11.3 + acorn-jsx: 5.3.2(acorn@8.11.3) eslint-visitor-keys: 3.4.1 dev: true @@ -8113,7 +8113,7 @@ packages: dependencies: '@types/estree': 1.0.5 estree-walker: 3.0.3 - is-reference: 3.0.1 + is-reference: 3.0.2 dev: true /picocolors@1.0.0: @@ -9199,8 +9199,8 @@ packages: periscopic: 3.1.0 dev: true - /svelte@5.0.0-next.136: - resolution: {integrity: sha512-M3jHAIfWZ7K+hjZdvu2p53ZtWE843yubxJfjxeQw9XiwMYG5z6quCA5u8r23GrxAp20JBl36B6ucbZvLUf0Z/g==} + /svelte@5.0.0-next.139: + resolution: {integrity: sha512-g9u7sQjIFdmacxMstZyq1z8jh+CYJjqJzTJ111jFjW4znUKsKmv7Gd2Lwq5n+t6/VxF/HnZ3+/7i6yAEZ2Bg9g==} engines: {node: '>=18'} dependencies: '@ampproject/remapping': 2.2.1 @@ -9935,7 +9935,7 @@ packages: resolution: {integrity: sha512-V50KMwwzqJV0NpZIZFwfOD5/lyny3WlSzRiXgA0G7VUnRlqttta1L6UQIHzd6EuBY/cHGfwTIck7w1yH6Q5zUw==} dev: true - file:(jest@29.7.0)(svelte@5.0.0-next.136): + file:(jest@29.7.0)(svelte@5.0.0-next.139): resolution: {directory: '', type: directory} id: 'file:' name: svelte-jester @@ -9945,5 +9945,5 @@ packages: svelte: '>= 3' dependencies: jest: 29.7.0 - svelte: 5.0.0-next.136 + svelte: 5.0.0-next.139 dev: true From ecbdcf7da79e9946576394d385df10e37fb1522e Mon Sep 17 00:00:00 2001 From: Michael Cousins Date: Wed, 29 May 2024 11:09:01 -0400 Subject: [PATCH 05/19] fixup: cross-platform shell support --- e2e/svelte-5/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/svelte-5/package.json b/e2e/svelte-5/package.json index 7930339..dee9624 100644 --- a/e2e/svelte-5/package.json +++ b/e2e/svelte-5/package.json @@ -4,7 +4,7 @@ "private": true, "type": "module", "scripts": { - "test": "pnpm install && NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --no-warnings\" jest --coverage", + "test": "pnpm install && NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" jest --coverage", "test:watch": "pnpm run test --watch" }, "devDependencies": { From c0b6a8b9e09ab67b683bb90ed55b0d5fca5e0693 Mon Sep 17 00:00:00 2001 From: Michael Cousins Date: Wed, 29 May 2024 11:10:05 -0400 Subject: [PATCH 06/19] fixup: cross-platform shell support (remember to `git add` this time) --- e2e/svelte-5/.npmrc | 1 + 1 file changed, 1 insertion(+) create mode 100644 e2e/svelte-5/.npmrc diff --git a/e2e/svelte-5/.npmrc b/e2e/svelte-5/.npmrc new file mode 100644 index 0000000..3bd3b7d --- /dev/null +++ b/e2e/svelte-5/.npmrc @@ -0,0 +1 @@ +shell-emulator=true From a9b21e12d97e5a11d0c0085d82345a9cb8e7b6ef Mon Sep 17 00:00:00 2001 From: Sebastian Rothe Date: Mon, 10 Jun 2024 22:22:22 +0200 Subject: [PATCH 07/19] fix: let tests complete on node 16 - 22 --- src/__tests__/transformer.test.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__tests__/transformer.test.cjs b/src/__tests__/transformer.test.cjs index 6d76e8d..16e1b42 100644 --- a/src/__tests__/transformer.test.cjs +++ b/src/__tests__/transformer.test.cjs @@ -69,7 +69,7 @@ describe('CJS transformer', () => { it('should fail, if console.logs are enabled during preprocessing and there is a console.log statement in the svelte config', () => { expect( () => runTransformer('BasicComp', { preprocess: true, rootMode: 'upward', showConsoleLog: true }) - ).toThrow(/^Unexpected token T in JSON at position 0$/) + ).toThrow(/^Unexpected token .*T.*/) }) it('should pass, if console.logs are disabled (default) during preprocessing and there is a console.log statement in the svelte config', () => { From d3bd30556511336284120b01cb925ffbe45b5fe3 Mon Sep 17 00:00:00 2001 From: Sebastian Rothe Date: Mon, 10 Jun 2024 22:22:39 +0200 Subject: [PATCH 08/19] chore: formatting --- e2e/svelte-5/src/legacy.test.js | 44 +++++++++++++++---------------- e2e/svelte-5/src/modern.test.js | 44 +++++++++++++++---------------- e2e/svelte-5/src/module.svelte.js | 16 +++++------ e2e/svelte-5/src/module.test.js | 24 ++++++++--------- e2e/svelte-5/svelte.config.js | 2 +- 5 files changed, 65 insertions(+), 65 deletions(-) diff --git a/e2e/svelte-5/src/legacy.test.js b/e2e/svelte-5/src/legacy.test.js index b102f94..029f5dd 100644 --- a/e2e/svelte-5/src/legacy.test.js +++ b/e2e/svelte-5/src/legacy.test.js @@ -1,38 +1,38 @@ -import { test, afterEach } from "@jest/globals"; -import { mount, unmount, tick } from "svelte"; +import { test, afterEach } from '@jest/globals' +import { mount, unmount, tick } from 'svelte' -import Subject from "./legacy.svelte"; +import Subject from './legacy.svelte' -let component; +let component afterEach(() => { - unmount(component); - component = undefined; -}); + unmount(component) + component = undefined +}) -test("render", () => { +test('render', () => { component = mount(Subject, { target: document.body, - props: { name: "alice" }, - }); + props: { name: 'alice' } + }) - const button = document.querySelector("button"); + const button = document.querySelector('button') - expect(button).toBeInstanceOf(HTMLButtonElement); -}); + expect(button).toBeInstanceOf(HTMLButtonElement) +}) -test("interaction", async () => { +test('interaction', async () => { component = mount(Subject, { target: document.body, - props: { name: "alice" }, - }); + props: { name: 'alice' } + }) - const button = document.querySelector("button"); + const button = document.querySelector('button') - button.click(); - await tick(); + button.click() + await tick() - const message = document.querySelector("p"); + const message = document.querySelector('p') - expect(message.textContent).toMatch(/hello alice/iu); -}); + expect(message.textContent).toMatch(/hello alice/iu) +}) diff --git a/e2e/svelte-5/src/modern.test.js b/e2e/svelte-5/src/modern.test.js index edb93ba..947b951 100644 --- a/e2e/svelte-5/src/modern.test.js +++ b/e2e/svelte-5/src/modern.test.js @@ -1,38 +1,38 @@ -import { test, afterEach } from "@jest/globals"; -import { mount, unmount, tick } from "svelte"; +import { test, afterEach } from '@jest/globals' +import { mount, unmount, tick } from 'svelte' -import Subject from "./modern.svelte"; +import Subject from './modern.svelte' -let component; +let component afterEach(() => { - unmount(component); - component = undefined; -}); + unmount(component) + component = undefined +}) -test("render", () => { +test('render', () => { component = mount(Subject, { target: document.body, - props: { name: "alice" }, - }); + props: { name: 'alice' } + }) - const button = document.querySelector("button"); + const button = document.querySelector('button') - expect(button).toBeInstanceOf(HTMLButtonElement); -}); + expect(button).toBeInstanceOf(HTMLButtonElement) +}) -test("interaction", async () => { +test('interaction', async () => { component = mount(Subject, { target: document.body, - props: { name: "alice" }, - }); + props: { name: 'alice' } + }) - const button = document.querySelector("button"); + const button = document.querySelector('button') - button.click(); - await tick(); + button.click() + await tick() - const message = document.querySelector("p"); + const message = document.querySelector('p') - expect(message.textContent).toMatch(/hello alice/iu); -}); + expect(message.textContent).toMatch(/hello alice/iu) +}) diff --git a/e2e/svelte-5/src/module.svelte.js b/e2e/svelte-5/src/module.svelte.js index 4686755..3f6a15b 100644 --- a/e2e/svelte-5/src/module.svelte.js +++ b/e2e/svelte-5/src/module.svelte.js @@ -1,13 +1,13 @@ export const createCounter = () => { - let count = $state(0); + let count = $state(0) return { - get count() { - return count; + get count () { + return count }, - increment() { - count = count + 1; - }, - }; -}; + increment () { + count = count + 1 + } + } +} diff --git a/e2e/svelte-5/src/module.test.js b/e2e/svelte-5/src/module.test.js index 3238d52..a15ee81 100644 --- a/e2e/svelte-5/src/module.test.js +++ b/e2e/svelte-5/src/module.test.js @@ -1,21 +1,21 @@ -import { test } from "@jest/globals"; +import { test } from '@jest/globals' // TODO(mcous, 2024-05-23): this import fails // See https://github.com/svelteness/svelte-jester/pull/283 // import * as Subject from "./module.svelte.js"; -test.skip("get current count", () => { - const subject = Subject.createCounter(); - const result = subject.count; +test.skip('get current count', () => { + const subject = Subject.createCounter() + const result = subject.count - expect(result).toBe(0); -}); + expect(result).toBe(0) +}) -test.skip("increment", () => { - const subject = Subject.createCounter(); +test.skip('increment', () => { + const subject = Subject.createCounter() - subject.increment(); - const result = subject.count; + subject.increment() + const result = subject.count - expect(result).toBe(1); -}); + expect(result).toBe(1) +}) diff --git a/e2e/svelte-5/svelte.config.js b/e2e/svelte-5/svelte.config.js index ff8b4c5..b1c6ea4 100644 --- a/e2e/svelte-5/svelte.config.js +++ b/e2e/svelte-5/svelte.config.js @@ -1 +1 @@ -export default {}; +export default {} From df6d2a3515ef5d9595eeab04ffd6a49c42234f62 Mon Sep 17 00:00:00 2001 From: Sebastian Rothe Date: Mon, 10 Jun 2024 22:57:15 +0200 Subject: [PATCH 09/19] fix: use different matcher to pass linter --- e2e/svelte-5/package.json | 4 ++++ e2e/svelte-5/src/legacy.test.js | 3 +-- e2e/svelte-5/src/modern.test.js | 3 +-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/e2e/svelte-5/package.json b/e2e/svelte-5/package.json index dee9624..32d3aa5 100644 --- a/e2e/svelte-5/package.json +++ b/e2e/svelte-5/package.json @@ -8,6 +8,7 @@ "test:watch": "pnpm run test --watch" }, "devDependencies": { + "@testing-library/jest-dom": "^6.4.5", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", "svelte": "^5.0.0-next.139", @@ -31,6 +32,9 @@ "extensionsToTreatAsEsm": [ ".svelte" ], + "setupFilesAfterEnv": [ + "@testing-library/jest-dom" + ], "testEnvironment": "jsdom" } } diff --git a/e2e/svelte-5/src/legacy.test.js b/e2e/svelte-5/src/legacy.test.js index 029f5dd..46b0bc4 100644 --- a/e2e/svelte-5/src/legacy.test.js +++ b/e2e/svelte-5/src/legacy.test.js @@ -1,4 +1,3 @@ -import { test, afterEach } from '@jest/globals' import { mount, unmount, tick } from 'svelte' import Subject from './legacy.svelte' @@ -18,7 +17,7 @@ test('render', () => { const button = document.querySelector('button') - expect(button).toBeInstanceOf(HTMLButtonElement) + expect(button).toHaveRole('button') }) test('interaction', async () => { diff --git a/e2e/svelte-5/src/modern.test.js b/e2e/svelte-5/src/modern.test.js index 947b951..5d63937 100644 --- a/e2e/svelte-5/src/modern.test.js +++ b/e2e/svelte-5/src/modern.test.js @@ -1,4 +1,3 @@ -import { test, afterEach } from '@jest/globals' import { mount, unmount, tick } from 'svelte' import Subject from './modern.svelte' @@ -18,7 +17,7 @@ test('render', () => { const button = document.querySelector('button') - expect(button).toBeInstanceOf(HTMLButtonElement) + expect(button).toHaveRole('button') }) test('interaction', async () => { From 586a6d84948cfb43ffd76264bcb4310a580f7d6f Mon Sep 17 00:00:00 2001 From: Sebastian Rothe Date: Mon, 10 Jun 2024 22:58:08 +0200 Subject: [PATCH 10/19] feat: add $state rune to globals --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 3b9d4cf..700da5f 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,8 @@ "jest", "it", "expect", - "describe" + "describe", + "$state" ] } } From 9a1cb2366211e3f8a006029dcf1aa5cb95c133ca Mon Sep 17 00:00:00 2001 From: Sebastian Rothe Date: Mon, 10 Jun 2024 23:27:27 +0200 Subject: [PATCH 11/19] feat: run e2e tests during validation --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 700da5f..402b12c 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "test:watch": "pnpm test -- --watch", "test:update": "pnpm test -- --updateSnapshot --coverage", "setup": "pnpm install && pnpm validate", - "validate": "pnpm lint && pnpm test:nocache", + "validate": "pnpm lint && pnpm test:nocache && pnpm e2e", "release": "standard-version" }, "standard-version": { From 1248b3678118251ff03f46331bc994162d2e3966 Mon Sep 17 00:00:00 2001 From: Sebastian Rothe Date: Tue, 11 Jun 2024 00:22:28 +0200 Subject: [PATCH 12/19] fix: add option no-cache --- e2e/svelte-5/package.json | 2 +- e2e/svelte/package.json | 2 +- e2e/sveltekit/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/svelte-5/package.json b/e2e/svelte-5/package.json index 32d3aa5..303921a 100644 --- a/e2e/svelte-5/package.json +++ b/e2e/svelte-5/package.json @@ -4,7 +4,7 @@ "private": true, "type": "module", "scripts": { - "test": "pnpm install && NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" jest --coverage", + "test": "pnpm install && NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" jest --coverage --no-cache", "test:watch": "pnpm run test --watch" }, "devDependencies": { diff --git a/e2e/svelte/package.json b/e2e/svelte/package.json index ba608fd..552abc0 100644 --- a/e2e/svelte/package.json +++ b/e2e/svelte/package.json @@ -6,7 +6,7 @@ "build": "rollup -c", "dev": "rollup -c -w", "start": "sirv public --no-clear", - "test": "jest src", + "test": "jest src --no-cache", "test:watch": "pnpm run test -- --watch" }, "devDependencies": { diff --git a/e2e/sveltekit/package.json b/e2e/sveltekit/package.json index 00c2c01..7ac698d 100644 --- a/e2e/sveltekit/package.json +++ b/e2e/sveltekit/package.json @@ -8,7 +8,7 @@ "preview": "vite preview", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", - "test": "svelte-kit sync && cross-env NODE_OPTIONS=--experimental-vm-modules jest src --config jest.config.json", + "test": "svelte-kit sync && cross-env NODE_OPTIONS=--experimental-vm-modules jest src --config jest.config.json --no-cache", "test:watch": "pnpm run test -- --watch" }, "devDependencies": { From 2f89077f2748a499714f01e2d797df17b4f6419e Mon Sep 17 00:00:00 2001 From: Sebastian Rothe Date: Tue, 11 Jun 2024 00:27:44 +0200 Subject: [PATCH 13/19] fix: pass linter --- e2e/svelte-5/src/module.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/e2e/svelte-5/src/module.test.js b/e2e/svelte-5/src/module.test.js index a15ee81..d7cf1a6 100644 --- a/e2e/svelte-5/src/module.test.js +++ b/e2e/svelte-5/src/module.test.js @@ -3,6 +3,7 @@ import { test } from '@jest/globals' // TODO(mcous, 2024-05-23): this import fails // See https://github.com/svelteness/svelte-jester/pull/283 // import * as Subject from "./module.svelte.js"; +const Subject = {} test.skip('get current count', () => { const subject = Subject.createCounter() From 5f1d5f53eb2a34ae21d8f3a367ae0973568f9d48 Mon Sep 17 00:00:00 2001 From: Sebastian Rothe Date: Tue, 11 Jun 2024 00:28:10 +0200 Subject: [PATCH 14/19] feat: add jest-dom --- pnpm-lock.yaml | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 12acdc8..4355653 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -112,6 +112,9 @@ importers: e2e/svelte-5: devDependencies: + '@testing-library/jest-dom': + specifier: ^6.4.5 + version: 6.4.5(@types/jest@29.5.3)(jest@29.7.0) jest: specifier: ^29.7.0 version: 29.7.0 @@ -208,6 +211,10 @@ packages: resolution: {integrity: sha512-E09FiIft46CmH5Qnjb0wsW54/YQd69LsxeKUOWawmws1XWvyFGURnAChH0mlr7YPFR1ofwvUQfcL0J3lMxXqPA==} dev: true + /@adobe/css-tools@4.4.0: + resolution: {integrity: sha512-Ff9+ksdQQB3rMncgqDK78uLznstjyfIf2Arnh22pW8kBpLs6rpKDwgnZT46hin5Hl1WzazzK64DOrhSwYpS7bQ==} + dev: true + /@ampproject/remapping@2.2.1: resolution: {integrity: sha512-lFMjJTrFL3j7L9yBxwYfCq2k6qqwHyzuUl/XBnif78PWTJYyL/dfowQHWE3sp6U6ZzqWiiIZnpTMO96zhkjwtg==} engines: {node: '>=6.0.0'} @@ -3899,6 +3906,39 @@ packages: redent: 3.0.0 dev: true + /@testing-library/jest-dom@6.4.5(@types/jest@29.5.3)(jest@29.7.0): + resolution: {integrity: sha512-AguB9yvTXmCnySBP1lWjfNNUwpbElsaQ567lt2VdGqAdHtpieLgjmcVyv1q7PMIvLbgpDdkWV5Ydv3FEejyp2A==} + engines: {node: '>=14', npm: '>=6', yarn: '>=1'} + peerDependencies: + '@jest/globals': '>= 28' + '@types/bun': latest + '@types/jest': '>= 28' + jest: '>= 28' + vitest: '>= 0.32' + peerDependenciesMeta: + '@jest/globals': + optional: true + '@types/bun': + optional: true + '@types/jest': + optional: true + jest: + optional: true + vitest: + optional: true + dependencies: + '@adobe/css-tools': 4.4.0 + '@babel/runtime': 7.22.6 + '@types/jest': 29.5.3 + aria-query: 5.3.0 + chalk: 3.0.0 + css.escape: 1.5.1 + dom-accessibility-api: 0.6.3 + jest: 29.7.0 + lodash: 4.17.21 + redent: 3.0.0 + dev: true + /@testing-library/svelte@3.2.2(svelte@3.59.2): resolution: {integrity: sha512-IKwZgqbekC3LpoRhSwhd0JswRGxKdAGkf39UiDXTywK61YyLXbCYoR831e/UUC6EeNW4hiHPY+2WuovxOgI5sw==} engines: {node: '>= 10'} @@ -5261,6 +5301,10 @@ packages: resolution: {integrity: sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==} dev: true + /dom-accessibility-api@0.6.3: + resolution: {integrity: sha512-7ZgogeTnjuHbo+ct10G9Ffp0mif17idi0IyWNVA/wcwcm7NPOD/WEHVP3n7n3MhXqxoIYm8d6MuZohYWIZ4T3w==} + dev: true + /dom-serializer@1.4.1: resolution: {integrity: sha512-VHwB3KfrcOOkelEG2ZOfxqLZdfkil8PtJi4P8N2MMXucZq2yLp75ClViUlOVwyoHEDjYU433Aq+5zWP61+RGag==} dependencies: From 01c82c712ba44e9180a159d5b6a444a4bb248894 Mon Sep 17 00:00:00 2001 From: Sebastian Rothe Date: Tue, 11 Jun 2024 00:30:23 +0200 Subject: [PATCH 15/19] fix: remove obsolete step --- RELEASE.md | 1 - 1 file changed, 1 deletion(-) diff --git a/RELEASE.md b/RELEASE.md index 6d7f002..b7c9931 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -3,7 +3,6 @@ 1. `pnpm run lint` 1. `pnpm run toc` 1. `pnpm run setup` -1. `pnpm run validate` 1. Raise Version 1. `pnpm run build` 1. `pnpm run release` or with specific version `npx standard-version --release-as 3.0.0` From 3b76f7d56d7f78be8e6cbfff57a8f78dd89f2c6f Mon Sep 17 00:00:00 2001 From: Sebastian Rothe Date: Tue, 11 Jun 2024 00:38:50 +0200 Subject: [PATCH 16/19] chore: formatting --- src/transformer.js | 4 ++-- src/utils.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/transformer.js b/src/transformer.js index ce052e1..6da70fc 100644 --- a/src/transformer.js +++ b/src/transformer.js @@ -92,7 +92,7 @@ const compiler = (format, options = {}, filename, processedCode, processedMap) = } const compile = isSvelteModule(filename) ? compileModule : compileComponent - + let result try { result = compile(processedCode, opts) @@ -125,7 +125,7 @@ const compileModule = (processedCode, opts) => { return SvelteCompiler.compileModule(processedCode, { filename: opts.filename, dev: opts.dev, - generate: opts.ssr ? 'server' : 'client', + generate: opts.ssr ? 'server' : 'client' }) } diff --git a/src/utils.js b/src/utils.js index 81ad104..2a07a20 100644 --- a/src/utils.js +++ b/src/utils.js @@ -14,4 +14,4 @@ export const DEFAULT_SVELTE_MODULE_EXT = ['.js', '.ts'] export const isSvelteModule = (filename) => typeof SvelteCompiler.compileModule === 'function' && DEFAULT_SVELTE_MODULE_INFIX.some((infix) => filename.includes(infix)) && - DEFAULT_SVELTE_MODULE_EXT.some((ext) => filename.endsWith(ext)); + DEFAULT_SVELTE_MODULE_EXT.some((ext) => filename.endsWith(ext)) From f9a947d18255ef4cbe36239e936f705908d32cc2 Mon Sep 17 00:00:00 2001 From: Sebastian Rothe Date: Tue, 11 Jun 2024 00:39:08 +0200 Subject: [PATCH 17/19] feat: enable import --- e2e/svelte-5/src/module.test.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/e2e/svelte-5/src/module.test.js b/e2e/svelte-5/src/module.test.js index d7cf1a6..eb2e81e 100644 --- a/e2e/svelte-5/src/module.test.js +++ b/e2e/svelte-5/src/module.test.js @@ -1,9 +1,6 @@ import { test } from '@jest/globals' -// TODO(mcous, 2024-05-23): this import fails -// See https://github.com/svelteness/svelte-jester/pull/283 -// import * as Subject from "./module.svelte.js"; -const Subject = {} +import * as Subject from './module.svelte.js' test.skip('get current count', () => { const subject = Subject.createCounter() From 8356e0fe6b254919e52c287ecb7d8900f89d11fb Mon Sep 17 00:00:00 2001 From: Sebastian Rothe Date: Tue, 11 Jun 2024 00:39:17 +0200 Subject: [PATCH 18/19] fix: enable tests --- e2e/svelte-5/src/module.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/svelte-5/src/module.test.js b/e2e/svelte-5/src/module.test.js index eb2e81e..97a9465 100644 --- a/e2e/svelte-5/src/module.test.js +++ b/e2e/svelte-5/src/module.test.js @@ -2,14 +2,14 @@ import { test } from '@jest/globals' import * as Subject from './module.svelte.js' -test.skip('get current count', () => { +test('get current count', () => { const subject = Subject.createCounter() const result = subject.count expect(result).toBe(0) }) -test.skip('increment', () => { +test('increment', () => { const subject = Subject.createCounter() subject.increment() From 250441a429a2feb13f339a55394263e1542a889a Mon Sep 17 00:00:00 2001 From: Sebastian Rothe Date: Tue, 11 Jun 2024 00:42:38 +0200 Subject: [PATCH 19/19] fix: reduce visibility of const --- src/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils.js b/src/utils.js index 2a07a20..82539cf 100644 --- a/src/utils.js +++ b/src/utils.js @@ -7,9 +7,9 @@ export const IS_COMMON_JS = typeof module !== 'undefined' export const isSvelte3 = (version = SvelteCompiler.VERSION) => version.startsWith('3') -export const DEFAULT_SVELTE_MODULE_INFIX = ['.svelte.'] +const DEFAULT_SVELTE_MODULE_INFIX = ['.svelte.'] -export const DEFAULT_SVELTE_MODULE_EXT = ['.js', '.ts'] +const DEFAULT_SVELTE_MODULE_EXT = ['.js', '.ts'] export const isSvelteModule = (filename) => typeof SvelteCompiler.compileModule === 'function' &&