-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: jest 27 + svelte jester 2 and refactors to support that
* fix: svelte-jester@2 + jest@27 Signed-off-by: Patrick Lee Scott <pat@patscott.io> * fix: configure extensionsToTreatAsEsm, experimental-vm-modules, and rm esbuild-jest Signed-off-by: Patrick Lee Scott <pat@patscott.io> * fix: use babel for babel-plugin-transform-vite-meta-env Signed-off-by: Patrick Lee Scott <pat@patscott.io> * feat: TestHarness for sveltekit testing Signed-off-by: Patrick Lee Scott <pat@patscott.io> * fix: upgrade + cleanup deps Signed-off-by: Patrick Lee Scott <pat@patscott.io>
- Loading branch information
1 parent
715e4e3
commit 1b38af0
Showing
11 changed files
with
9,120 additions
and
8,196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,3 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"node": "current" | ||
} | ||
} | ||
] | ||
] | ||
"plugins": ["babel-plugin-transform-vite-meta-env"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<script> | ||
import {setContext} from 'svelte'; | ||
import {writable} from 'svelte/store'; | ||
export let Component; | ||
export let stores = { | ||
page: writable({ path: '/' }), | ||
navigating: writable(null), | ||
session: writable(null), | ||
}; | ||
setContext('__svelte__', stores); | ||
</script> | ||
|
||
<svelte:component this={Component} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,16 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import '@testing-library/jest-dom/extend-expect' | ||
import { render } from '@testing-library/svelte' | ||
import checkout from '$routes/checkout.svelte' | ||
|
||
jest.mock('$app/env.js', () => ({ | ||
amp: false, | ||
browser: true, | ||
dev: true, | ||
mode: 'test' | ||
})) | ||
|
||
jest.mock('$app/navigation.js', () => ({ | ||
goto: jest.fn() | ||
})) | ||
|
||
jest.mock('svelte', () => { | ||
const { writable } = require('svelte/store') | ||
const actualSvelte = jest.requireActual('svelte') | ||
const fakeGetContext = jest.fn((name) => { | ||
if (name === '__svelte__') { | ||
return fakeSvelteKitContext | ||
} | ||
}) | ||
const fakeSvelteKitContext = { | ||
page: writable({ | ||
path: '/checkout' | ||
}), | ||
navigating: writable(false) | ||
} | ||
|
||
const mockedSvelteKit = { | ||
...actualSvelte, | ||
getContext: fakeGetContext | ||
} | ||
return mockedSvelteKit | ||
}) | ||
|
||
describe('routes/checkout.svelte', () => { | ||
it('should compile', async () => { | ||
const { getByText } = render(checkout) | ||
expect(getByText('Checkout')).toBeInTheDocument() | ||
}) | ||
}) | ||
import '@testing-library/jest-dom/extend-expect' | ||
import { render } from '@testing-library/svelte' | ||
import TestHarness from '../helpers/TestHarness.svelte' | ||
import checkout from '$routes/checkout.svelte' | ||
|
||
describe('routes/checkout.svelte', () => { | ||
|
||
it.only('should render in test harness', async () => { | ||
const { getByText } = render(TestHarness, { Component: checkout }) | ||
expect(getByText('Checkout')).toBeInTheDocument() | ||
}) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,16 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import '@testing-library/jest-dom/extend-expect' | ||
import { render } from '@testing-library/svelte' | ||
import downsell from '$routes/downsell.svelte' | ||
|
||
jest.mock('$app/env.js', () => ({ | ||
amp: false, | ||
browser: true, | ||
dev: true, | ||
mode: 'test' | ||
})) | ||
|
||
jest.mock('$app/navigation.js', () => ({ | ||
goto: jest.fn() | ||
})) | ||
|
||
jest.mock('svelte', () => { | ||
const { writable } = require('svelte/store') | ||
const actualSvelte = jest.requireActual('svelte') | ||
const fakeGetContext = jest.fn((name) => { | ||
if (name === '__svelte__') { | ||
return fakeSvelteKitContext | ||
} | ||
}) | ||
const fakeSvelteKitContext = { | ||
page: writable({ | ||
path: '/downsell' | ||
}), | ||
navigating: writable(false) | ||
} | ||
|
||
const mockedSvelteKit = { | ||
...actualSvelte, | ||
getContext: fakeGetContext | ||
} | ||
return mockedSvelteKit | ||
}) | ||
|
||
describe('routes/downsell.svelte', () => { | ||
it('should compile', async () => { | ||
const { getByText } = render(downsell) | ||
expect(getByText('Downsell')).toBeInTheDocument() | ||
}) | ||
}) | ||
import '@testing-library/jest-dom/extend-expect' | ||
import { render } from '@testing-library/svelte' | ||
import TestHarness from '../helpers/TestHarness.svelte' | ||
import downsell from '$routes/downsell.svelte' | ||
|
||
describe('routes/downsell.svelte', () => { | ||
|
||
it.only('should render in test harness', async () => { | ||
const { getByText } = render(TestHarness, { Component: downsell }) | ||
expect(getByText('Downsell')).toBeInTheDocument() | ||
}) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,16 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import '@testing-library/jest-dom/extend-expect' | ||
import { render } from '@testing-library/svelte' | ||
import oto from '$routes/oto.svelte' | ||
|
||
jest.mock('$app/env.js', () => ({ | ||
amp: false, | ||
browser: true, | ||
dev: true, | ||
mode: 'test' | ||
})) | ||
|
||
jest.mock('$app/navigation.js', () => ({ | ||
goto: jest.fn() | ||
})) | ||
|
||
jest.mock('svelte', () => { | ||
const { writable } = require('svelte/store') | ||
const actualSvelte = jest.requireActual('svelte') | ||
const fakeGetContext = jest.fn((name) => { | ||
if (name === '__svelte__') { | ||
return fakeSvelteKitContext | ||
} | ||
}) | ||
const fakeSvelteKitContext = { | ||
page: writable({ | ||
path: '/oto' | ||
}), | ||
navigating: writable(false) | ||
} | ||
|
||
const mockedSvelteKit = { | ||
...actualSvelte, | ||
getContext: fakeGetContext | ||
} | ||
return mockedSvelteKit | ||
}) | ||
|
||
describe('routes/oto.svelte', () => { | ||
it('should compile', async () => { | ||
const { getByText } = render(oto) | ||
expect(getByText('One time offer!')).toBeInTheDocument() | ||
}) | ||
}) | ||
import '@testing-library/jest-dom/extend-expect' | ||
import { render } from '@testing-library/svelte' | ||
import TestHarness from '../helpers/TestHarness.svelte' | ||
import oto from '$routes/oto.svelte' | ||
|
||
describe('routes/oto.svelte', () => { | ||
|
||
it.only('should render in test harness', async () => { | ||
const { getByText } = render(TestHarness, { Component: oto }) | ||
expect(getByText('One time offer!')).toBeInTheDocument() | ||
}) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,16 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import '@testing-library/jest-dom/extend-expect' | ||
import { render } from '@testing-library/svelte' | ||
import thankyou from '$routes/thank-you.svelte' | ||
|
||
jest.mock('$app/env.js', () => ({ | ||
amp: false, | ||
browser: true, | ||
dev: true, | ||
mode: 'test' | ||
})) | ||
|
||
jest.mock('$app/navigation.js', () => ({ | ||
goto: jest.fn() | ||
})) | ||
|
||
jest.mock('svelte', () => { | ||
const { writable } = require('svelte/store') | ||
const actualSvelte = jest.requireActual('svelte') | ||
const fakeGetContext = jest.fn((name) => { | ||
if (name === '__svelte__') { | ||
return fakeSvelteKitContext | ||
} | ||
}) | ||
const fakeSvelteKitContext = { | ||
page: writable({ | ||
path: '/thank-you' | ||
}), | ||
navigating: writable(false) | ||
} | ||
|
||
const mockedSvelteKit = { | ||
...actualSvelte, | ||
getContext: fakeGetContext | ||
} | ||
return mockedSvelteKit | ||
}) | ||
|
||
describe('routes/thankyou.svelte', () => { | ||
it('should compile', async () => { | ||
const { getByText } = render(thankyou) | ||
expect(getByText('Thanks!')).toBeInTheDocument() | ||
}) | ||
}) | ||
import '@testing-library/jest-dom/extend-expect' | ||
import { render } from '@testing-library/svelte' | ||
import TestHarness from '../helpers/TestHarness.svelte' | ||
import thankyou from '$routes/thank-you.svelte' | ||
|
||
describe('routes/thankyou.svelte', () => { | ||
|
||
it.only('should render in test harness', async () => { | ||
const { getByText } = render(TestHarness, { Component: thankyou }) | ||
expect(getByText('Thanks!')).toBeInTheDocument() | ||
}) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,16 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import '@testing-library/jest-dom/extend-expect' | ||
import { render } from '@testing-library/svelte' | ||
import upsell from '$routes/upsell.svelte' | ||
|
||
jest.mock('$app/env.js', () => ({ | ||
amp: false, | ||
browser: true, | ||
dev: true, | ||
mode: 'test' | ||
})) | ||
|
||
jest.mock('$app/navigation.js', () => ({ | ||
goto: jest.fn() | ||
})) | ||
|
||
jest.mock('svelte', () => { | ||
const { writable } = require('svelte/store') | ||
const actualSvelte = jest.requireActual('svelte') | ||
const fakeGetContext = jest.fn((name) => { | ||
if (name === '__svelte__') { | ||
return fakeSvelteKitContext | ||
} | ||
}) | ||
const fakeSvelteKitContext = { | ||
page: writable({ | ||
path: '/upsell' | ||
}), | ||
navigating: writable(false) | ||
} | ||
|
||
const mockedSvelteKit = { | ||
...actualSvelte, | ||
getContext: fakeGetContext | ||
} | ||
return mockedSvelteKit | ||
}) | ||
|
||
describe('routes/upsell.svelte', () => { | ||
it('should compile', async () => { | ||
const { getByText } = render(upsell) | ||
expect(getByText('Upsell')).toBeInTheDocument() | ||
}) | ||
}) | ||
import '@testing-library/jest-dom/extend-expect' | ||
import { render } from '@testing-library/svelte' | ||
import TestHarness from '../helpers/TestHarness.svelte' | ||
import upsell from '$routes/upsell.svelte' | ||
|
||
describe('routes/upsell.svelte', () => { | ||
|
||
it.only('should render in test harness', async () => { | ||
const { getByText } = render(TestHarness, { Component: upsell }) | ||
expect(getByText('Upsell')).toBeInTheDocument() | ||
}) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.