Skip to content

test: extract tests directory out of src #433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
],
"files": [
"src",
"types",
"!__tests__"
"types"
],
"scripts": {
"all": "npm-run-all contributors:generate toc format types build test:vitest:* test:jest",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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))
Expand All @@ -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)
})
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/render.test-d.ts → tests/render.test-d.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/render.test.js → tests/render.test.js
Original file line number Diff line number Diff line change
@@ -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' }
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/rerender.test.js → tests/rerender.test.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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(() => {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"rootDir": "src",
"outDir": "types"
},
"exclude": ["src/**/__tests__/**"]
"include": ["src"]
}
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
6 changes: 3 additions & 3 deletions tsconfig.legacy.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
9 changes: 4 additions & 5 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
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/
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'),
},
},
})