Skip to content

Commit c8f20ca

Browse files
committed
fix: ensure pure module is exported
1 parent 5464ac2 commit c8f20ca

File tree

7 files changed

+47
-49
lines changed

7 files changed

+47
-49
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
"types": "./types/index.d.ts",
99
"default": "./src/index.js"
1010
},
11+
"./pure": {
12+
"types": "./types/index.d.ts",
13+
"default": "./src/pure.js"
14+
},
1115
"./svelte5": {
1216
"types": "./types/index.d.ts",
1317
"default": "./src/svelte5-index.js"
@@ -65,7 +69,6 @@
6569
"setup": "npm install && npm run validate",
6670
"test": "vitest run --coverage",
6771
"test:watch": "vitest",
68-
"test:update": "vitest run --update",
6972
"test:vitest:jsdom": "vitest run --coverage --environment jsdom",
7073
"test:vitest:happy-dom": "vitest run --coverage --environment happy-dom",
7174
"types": "svelte-check",

src/__tests__/__snapshots__/auto-cleanup-skip.test.js.snap

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/__tests__/auto-cleanup-skip.test.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/__tests__/auto-cleanup.test.js

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,52 @@
1-
import { render } from '@testing-library/svelte'
2-
import { describe, expect, test } from 'vitest'
1+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
32

43
import Comp from './fixtures/Comp.svelte'
4+
import { IS_SVELTE_5 } from './utils.js'
5+
6+
const importSvelteTestingLibrary = async () =>
7+
IS_SVELTE_5 ? import('../svelte5-index.js') : import('../index.js')
8+
9+
const importSvelteTestingLibraryPure = async () =>
10+
IS_SVELTE_5 ? import('../svelte5.js') : import('../pure.js')
11+
12+
const globalAfterEach = vi.fn()
513

614
describe('auto-cleanup', () => {
7-
// This just verifies that by importing STL in an
8-
// environment which supports afterEach (like jest)
9-
// we'll get automatic cleanup between tests.
10-
test('first', () => {
11-
render(Comp, { props: { name: 'world' } })
15+
beforeEach(() => {
16+
vi.resetModules()
17+
globalThis.afterEach = globalAfterEach
1218
})
1319

14-
test('second', () => {
15-
expect(document.body.innerHTML).toEqual('')
20+
afterEach(() => {
21+
delete process.env.STL_SKIP_AUTO_CLEANUP
22+
delete globalThis.afterEach
1623
})
17-
})
1824

19-
describe('cleanup of two components', () => {
20-
// This just verifies that by importing STL in an
21-
// environment which supports afterEach (like jest)
22-
// we'll get automatic cleanup between tests.
23-
test('first', () => {
25+
test('calls afterEach with cleanup if globally defined', async () => {
26+
const { render } = await importSvelteTestingLibrary()
2427
render(Comp, { props: { name: 'world' } })
25-
render(Comp, { props: { name: 'universe' } })
28+
29+
expect(globalAfterEach).toHaveBeenCalledTimes(1)
30+
expect(globalAfterEach).toHaveBeenLastCalledWith(expect.any(Function))
31+
32+
await afterEach.mock.lastCall[0]()
33+
34+
expect(document.body).toBeEmptyDOMElement()
2635
})
2736

28-
test('second', () => {
29-
expect(document.body.innerHTML).toEqual('')
37+
test('does not call afterEach if process STL_SKIP_AUTO_CLEANUP is set', async () => {
38+
process.env.STL_SKIP_AUTO_CLEANUP = 'true'
39+
40+
const { render } = await importSvelteTestingLibrary()
41+
render(Comp, { props: { name: 'world' } })
42+
43+
expect(globalAfterEach).toHaveBeenCalledTimes(0)
44+
})
45+
46+
test('does not call afterEach if you import from `pure`', async () => {
47+
const { render } = await importSvelteTestingLibraryPure()
48+
render(Comp, { props: { name: 'world' } })
49+
50+
expect(globalAfterEach).toHaveBeenCalledTimes(0)
3051
})
3152
})

src/__tests__/cleanup.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('cleanup', () => {
1919
renderSubject()
2020
cleanup()
2121

22-
expect(onDestroyed).toHaveBeenCalledOnce()
22+
expect(onDestroyed).toHaveBeenCalledTimes(1)
2323
})
2424

2525
test('cleanup handles unexpected errors during mount', () => {

src/__tests__/mount.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('mount and destroy', () => {
1515

1616
expect(content).toBeInTheDocument()
1717
await act()
18-
expect(onMounted).toHaveBeenCalledOnce()
18+
expect(onMounted).toHaveBeenCalledTimes(1)
1919
})
2020

2121
test('component is destroyed', async () => {
@@ -28,6 +28,6 @@ describe('mount and destroy', () => {
2828

2929
expect(content).not.toBeInTheDocument()
3030
await act()
31-
expect(onDestroyed).toHaveBeenCalledOnce()
31+
expect(onDestroyed).toHaveBeenCalledTimes(1)
3232
})
3333
})

src/__tests__/rerender.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('rerender', () => {
2323
await rerender({ props: { name: 'Dolly' } })
2424

2525
expect(element).toHaveTextContent('Hello Dolly!')
26-
expect(console.warn).toHaveBeenCalledOnce()
26+
expect(console.warn).toHaveBeenCalledTimes(1)
2727
expect(console.warn).toHaveBeenCalledWith(
2828
expect.stringMatching(/deprecated/iu)
2929
)

0 commit comments

Comments
 (0)