Repository: testing-library/svelte-testing-library
Pull request #433 (2025-05-07 14:25:49)

test: extract `tests` directory out of `src`
Test only change, good to merge if CI agrees


Patch:
diff --git a/jest.config.js b/jest.config.js
index 4857b64..ff518c4 100644
--- a/jest.config.js
+++ b/jest.config.js
@@ -4,23 +4,23 @@ const SVELTE_TRANSFORM_PATTERN =
   SVELTE_VERSION >= '5' ? '^.+\\.svelte(?:\\.js)?$' : '^.+\\.svelte$'
 
 export default {
-  testMatch: ['<rootDir>/src/__tests__/**/*.test.js'],
+  testMatch: ['<rootDir>/tests/**/*.test.js'],
   transform: {
     [SVELTE_TRANSFORM_PATTERN]: 'svelte-jester',
   },
   moduleFileExtensions: ['js', 'svelte'],
   extensionsToTreatAsEsm: ['.svelte'],
   testEnvironment: 'jsdom',
-  setupFilesAfterEnv: ['<rootDir>/src/__tests__/_jest-setup.js'],
+  setupFilesAfterEnv: ['<rootDir>/tests/_jest-setup.js'],
   injectGlobals: false,
   moduleNameMapper: {
-    '^vitest$': '<rootDir>/src/__tests__/_jest-vitest-alias.js',
+    '^vitest$': '<rootDir>/tests/_jest-vitest-alias.js',
+    '^@testing-library\\/svelte$': '<rootDir>/src/index.js',
   },
   resetMocks: true,
   restoreMocks: true,
   collectCoverageFrom: ['<rootDir>/src/**/*'],
   coveragePathIgnorePatterns: [
-    '/__tests__/',
     '<rootDir>/src/vite.js',
     '<rootDir>/src/vitest.js',
   ],
diff --git a/package.json b/package.json
index 8bab118..d686b2c 100644
--- a/package.json
+++ b/package.json
@@ -49,8 +49,7 @@
   ],
   "files": [
     "src",
-    "types",
-    "!__tests__"
+    "types"
   ],
   "scripts": {
     "all": "npm-run-all contributors:generate toc format types build test:vitest:* test:jest",
diff --git a/tsconfig.build.json b/tsconfig.build.json
index 0baa218..bfc566b 100644
--- a/tsconfig.build.json
+++ b/tsconfig.build.json
@@ -8,5 +8,5 @@
     "rootDir": "src",
     "outDir": "types"
   },
-  "exclude": ["src/**/__tests__/**"]
+  "include": ["src"]
 }
diff --git a/tsconfig.json b/tsconfig.json
index 0cc0fdf..fda8aba 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -6,7 +6,11 @@
     "skipLibCheck": true,
     "strict": true,
     "types": ["svelte", "vite/client", "vitest", "vitest/globals"],
+    "baseUrl": "./",
+    "paths": {
+      "@testing-library/svelte": ["./src"]
+    },
     "plugins": [{ "name": "typescript-svelte-plugin" }]
   },
-  "include": ["src"]
+  "include": ["src", "tests"]
 }
diff --git a/tsconfig.legacy.json b/tsconfig.legacy.json
index b5d9e57..304d872 100644
--- a/tsconfig.legacy.json
+++ b/tsconfig.legacy.json
@@ -1,8 +1,8 @@
 {
   "extends": ["./tsconfig.json"],
   "exclude": [
-    "src/__tests__/render-runes.test-d.ts",
-    "src/__tests__/fixtures/CompRunes.svelte",
-    "src/__tests__/fixtures/TypedRunes.svelte"
+    "tests/render-runes.test-d.ts",
+    "tests/fixtures/CompRunes.svelte",
+    "tests/fixtures/TypedRunes.svelte"
   ]
 }
diff --git a/vite.config.js b/vite.config.js
index 2db8a40..75bd66a 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -1,10 +1,9 @@
 import { createRequire } from 'node:module'
 
 import { svelte } from '@sveltejs/vite-plugin-svelte'
+import { svelteTesting } from '@testing-library/svelte/vite'
 import { defineConfig } from 'vite'
 
-import { svelteTesting } from './src/vite.js'
-
 const require = createRequire(import.meta.url)
 
 // https://vitejs.dev/config/
@@ -12,17 +11,17 @@ export default defineConfig({
   plugins: [svelte(), svelteTesting()],
   test: {
     environment: 'jsdom',
-    setupFiles: ['./src/__tests__/_vitest-setup.js'],
+    setupFiles: ['./tests/_vitest-setup.js'],
     mockReset: true,
     unstubGlobals: true,
     unstubEnvs: true,
     coverage: {
       provider: 'v8',
       include: ['src/**/*'],
-      exclude: ['**/__tests__/**', 'src/vite.js', 'src/vitest.js'],
     },
     alias: {
-      '@testing-library/svelte': require.resolve('.'),
+      '@testing-library/svelte/vite': require.resolve('./src/vite.js'),
+      '@testing-library/svelte': require.resolve('./src/index.js'),
     },
   },
 })


Test patch:
diff --git a/src/__tests__/utils.js b/tests/_env.js
similarity index 100%
rename from src/__tests__/utils.js
rename to tests/_env.js
diff --git a/src/__tests__/_jest-setup.js b/tests/_jest-setup.js
similarity index 100%
rename from src/__tests__/_jest-setup.js
rename to tests/_jest-setup.js
diff --git a/src/__tests__/_jest-vitest-alias.js b/tests/_jest-vitest-alias.js
similarity index 100%
rename from src/__tests__/_jest-vitest-alias.js
rename to tests/_jest-vitest-alias.js
diff --git a/src/__tests__/_vitest-setup.js b/tests/_vitest-setup.js
similarity index 100%
rename from src/__tests__/_vitest-setup.js
rename to tests/_vitest-setup.js
diff --git a/src/__tests__/act.test.js b/tests/act.test.js
similarity index 100%
rename from src/__tests__/act.test.js
rename to tests/act.test.js
diff --git a/src/__tests__/auto-cleanup.test.js b/tests/auto-cleanup.test.js
similarity index 89%
rename from src/__tests__/auto-cleanup.test.js
rename to tests/auto-cleanup.test.js
index 7962925..d6ba28b 100644
--- a/src/__tests__/auto-cleanup.test.js
+++ b/tests/auto-cleanup.test.js
@@ -1,6 +1,6 @@
 import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
 
-import { IS_JEST } from './utils.js'
+import { IS_JEST } from './_env.js'
 
 // TODO(mcous, 2024-12-08): clearing module cache and re-importing
 // in Jest breaks Svelte's environment checking heuristics.
@@ -19,7 +19,7 @@ describe.skipIf(IS_JEST)('auto-cleanup', () => {
   })
 
   test('calls afterEach with cleanup if globally defined', async () => {
-    const { render } = await import('../index.js')
+    const { render } = await import('@testing-library/svelte')
 
     expect(globalAfterEach).toHaveBeenCalledTimes(1)
     expect(globalAfterEach).toHaveBeenLastCalledWith(expect.any(Function))
@@ -35,7 +35,7 @@ describe.skipIf(IS_JEST)('auto-cleanup', () => {
   test('does not call afterEach if process STL_SKIP_AUTO_CLEANUP is set', async () => {
     process.env.STL_SKIP_AUTO_CLEANUP = 'true'
 
-    await import('../index.js')
+    await import('@testing-library/svelte')
 
     expect(globalAfterEach).toHaveBeenCalledTimes(0)
   })
diff --git a/src/__tests__/cleanup.test.js b/tests/cleanup.test.js
similarity index 100%
rename from src/__tests__/cleanup.test.js
rename to tests/cleanup.test.js
diff --git a/src/__tests__/context.test.js b/tests/context.test.js
similarity index 100%
rename from src/__tests__/context.test.js
rename to tests/context.test.js
diff --git a/src/__tests__/debug.test.js b/tests/debug.test.js
similarity index 100%
rename from src/__tests__/debug.test.js
rename to tests/debug.test.js
diff --git a/src/__tests__/events.test.js b/tests/events.test.js
similarity index 100%
rename from src/__tests__/events.test.js
rename to tests/events.test.js
diff --git a/src/__tests__/fixtures/Comp.svelte b/tests/fixtures/Comp.svelte
similarity index 100%
rename from src/__tests__/fixtures/Comp.svelte
rename to tests/fixtures/Comp.svelte
diff --git a/src/__tests__/fixtures/CompRunes.svelte b/tests/fixtures/CompRunes.svelte
similarity index 100%
rename from src/__tests__/fixtures/CompRunes.svelte
rename to tests/fixtures/CompRunes.svelte
diff --git a/src/__tests__/fixtures/Context.svelte b/tests/fixtures/Context.svelte
similarity index 100%
rename from src/__tests__/fixtures/Context.svelte
rename to tests/fixtures/Context.svelte
diff --git a/src/__tests__/fixtures/Mounter.svelte b/tests/fixtures/Mounter.svelte
similarity index 100%
rename from src/__tests__/fixtures/Mounter.svelte
rename to tests/fixtures/Mounter.svelte
diff --git a/src/__tests__/fixtures/Transitioner.svelte b/tests/fixtures/Transitioner.svelte
similarity index 100%
rename from src/__tests__/fixtures/Transitioner.svelte
rename to tests/fixtures/Transitioner.svelte
diff --git a/src/__tests__/fixtures/Typed.svelte b/tests/fixtures/Typed.svelte
similarity index 100%
rename from src/__tests__/fixtures/Typed.svelte
rename to tests/fixtures/Typed.svelte
diff --git a/src/__tests__/fixtures/TypedRunes.svelte b/tests/fixtures/TypedRunes.svelte
similarity index 100%
rename from src/__tests__/fixtures/TypedRunes.svelte
rename to tests/fixtures/TypedRunes.svelte
diff --git a/src/__tests__/mount.test.js b/tests/mount.test.js
similarity index 100%
rename from src/__tests__/mount.test.js
rename to tests/mount.test.js
diff --git a/src/__tests__/multi-base.test.js b/tests/multi-base.test.js
similarity index 100%
rename from src/__tests__/multi-base.test.js
rename to tests/multi-base.test.js
diff --git a/src/__tests__/render-runes.test-d.ts b/tests/render-runes.test-d.ts
similarity index 97%
rename from src/__tests__/render-runes.test-d.ts
rename to tests/render-runes.test-d.ts
index 51b7cfa..1e42544 100644
--- a/src/__tests__/render-runes.test-d.ts
+++ b/tests/render-runes.test-d.ts
@@ -1,7 +1,7 @@
+import * as subject from '@testing-library/svelte'
 import { expectTypeOf } from 'expect-type'
 import { describe, test, vi } from 'vitest'
 
-import * as subject from '../index.js'
 import LegacyComponent from './fixtures/Typed.svelte'
 import Component from './fixtures/TypedRunes.svelte'
 
diff --git a/src/__tests__/render-utilities.test-d.ts b/tests/render-utilities.test-d.ts
similarity index 97%
rename from src/__tests__/render-utilities.test-d.ts
rename to tests/render-utilities.test-d.ts
index d1e3869..c72f761 100644
--- a/src/__tests__/render-utilities.test-d.ts
+++ b/tests/render-utilities.test-d.ts
@@ -1,7 +1,7 @@
+import * as subject from '@testing-library/svelte'
 import { expectTypeOf } from 'expect-type'
 import { describe, test } from 'vitest'
 
-import * as subject from '../index.js'
 import Component from './fixtures/Comp.svelte'
 
 describe('render query and utility types', () => {
diff --git a/src/__tests__/render.test-d.ts b/tests/render.test-d.ts
similarity index 97%
rename from src/__tests__/render.test-d.ts
rename to tests/render.test-d.ts
index bf0a611..eb1c639 100644
--- a/src/__tests__/render.test-d.ts
+++ b/tests/render.test-d.ts
@@ -1,8 +1,8 @@
+import * as subject from '@testing-library/svelte'
 import { expectTypeOf } from 'expect-type'
 import { ComponentProps } from 'svelte'
 import { describe, test } from 'vitest'
 
-import * as subject from '../index.js'
 import Component from './fixtures/Typed.svelte'
 
 describe('types', () => {
diff --git a/src/__tests__/render.test.js b/tests/render.test.js
similarity index 98%
rename from src/__tests__/render.test.js
rename to tests/render.test.js
index f396751..943c920 100644
--- a/src/__tests__/render.test.js
+++ b/tests/render.test.js
@@ -1,7 +1,7 @@
 import { render } from '@testing-library/svelte'
 import { beforeAll, describe, expect, test } from 'vitest'
 
-import { COMPONENT_FIXTURES } from './utils.js'
+import { COMPONENT_FIXTURES } from './_env.js'
 
 describe.each(COMPONENT_FIXTURES)('render ($mode)', ({ component }) => {
   const props = { name: 'World' }
diff --git a/src/__tests__/rerender.test.js b/tests/rerender.test.js
similarity index 95%
rename from src/__tests__/rerender.test.js
rename to tests/rerender.test.js
index 52acd0f..2a20143 100644
--- a/src/__tests__/rerender.test.js
+++ b/tests/rerender.test.js
@@ -1,7 +1,7 @@
 import { act, render, screen } from '@testing-library/svelte'
 import { beforeAll, describe, expect, test, vi } from 'vitest'
 
-import { COMPONENT_FIXTURES, IS_SVELTE_5, MODE_RUNES } from './utils.js'
+import { COMPONENT_FIXTURES, IS_SVELTE_5, MODE_RUNES } from './_env.js'
 
 describe.each(COMPONENT_FIXTURES)('rerender ($mode)', ({ mode, component }) => {
   let Comp
diff --git a/src/__tests__/transition.test.js b/tests/transition.test.js
similarity index 94%
rename from src/__tests__/transition.test.js
rename to tests/transition.test.js
index a9c8e02..3acf1d0 100644
--- a/src/__tests__/transition.test.js
+++ b/tests/transition.test.js
@@ -2,8 +2,8 @@ import { render, screen, waitFor } from '@testing-library/svelte'
 import { userEvent } from '@testing-library/user-event'
 import { beforeEach, describe, expect, test, vi } from 'vitest'
 
+import { IS_JSDOM, IS_SVELTE_5 } from './_env.js'
 import Transitioner from './fixtures/Transitioner.svelte'
-import { IS_JSDOM, IS_SVELTE_5 } from './utils.js'
 
 describe.skipIf(IS_SVELTE_5)('transitions', () => {
   beforeEach(() => {
diff --git a/src/__tests__/vite-plugin.test.js b/tests/vite-plugin.test.js
similarity index 98%
rename from src/__tests__/vite-plugin.test.js
rename to tests/vite-plugin.test.js
index 9232f65..92fc8f5 100644
--- a/src/__tests__/vite-plugin.test.js
+++ b/tests/vite-plugin.test.js
@@ -1,7 +1,7 @@
+import { svelteTesting } from '@testing-library/svelte/vite'
 import { beforeEach, describe, expect, test, vi } from 'vitest'
 
-import { svelteTesting } from '../vite.js'
-import { IS_JEST } from './utils.js'
+import { IS_JEST } from './_env.js'
 
 describe.skipIf(IS_JEST)('vite plugin', () => {
   beforeEach(() => {