-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Added Option to Automatically Add Vitest to New Projects using svelte-create #5708
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
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2a35dd1
add vitest option to svelte-create
bertybot 09d4ef3
added changeset
bertybot 5fa5ec0
add c8 package for coverage
bertybot e4e9ccf
ran format
bertybot 1bf7c59
add vitest option to fix typescript error
bertybot fdd3fcd
Remove svelte-testing-library
bertybot e75378f
update to just modify the vite.config.js
bertybot a168514
readd default vite-config for non vitest projects
bertybot e9e38a6
remove coverage testing
bertybot 2f97dee
Merge branch 'master' into add-vitest-to-create
Rich-Harris 8c451fe
create typescript/checkjs/no-typechecking variants of .ts files in sh…
Rich-Harris e48c02f
simplify include
Rich-Harris f59f9c0
add testMatch to base playwright configs, remove vitest+playwright co…
Rich-Harris 0a8fc37
Update packages/create-svelte/scripts/build-templates.js
benmccann b512b49
Merge branch 'master' into add-vitest-to-create
benmccann 691e874
Update packages/create-svelte/shared/+playwright+typescript/playwrigh…
benmccann 78149b5
cleanup test patterns
benmccann c06a74f
newer version of vitest
benmccann db95545
sverdle test
benmccann e670e29
format
benmccann e71e21a
removed vitest globals
bertybot 658dd56
Rename vite.config.ts to vite.config.js
bertybot 8d3d11d
Fixed types on default vite config
bertybot 01ab4ba
Merge remote-tracking branch 'upstream/HEAD' into add-vitest-to-create
bertybot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
--- | ||
'create-svelte': patch | ||
--- | ||
|
||
Added the option to add Vitest to new projects |
This file contains hidden or 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 hidden or 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
9 changes: 9 additions & 0 deletions
9
packages/create-svelte/shared/+default+vitest/src/routes/sverdle/game.test.ts
This file contains hidden or 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,9 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { Game } from './game'; | ||
|
||
describe('game test', () => { | ||
it('returns true when a valid word is entered', () => { | ||
const game = new Game(); | ||
expect(game.enter('zorro'.split(''))).toBe(true); | ||
}); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/create-svelte/shared/+playwright+skeletonlib/tests/test.ts
This file contains hidden or 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,6 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test('index page has expected h1', async ({ page }) => { | ||
await page.goto('/'); | ||
expect(await page.textContent('h1')).toBe('Welcome to SvelteKit'); | ||
}); |
This file contains hidden or 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 hidden or 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
7 changes: 7 additions & 0 deletions
7
packages/create-svelte/shared/+vitest+skeleton/src/index.test.ts
This file contains hidden or 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,7 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
|
||
describe('sum test', () => { | ||
it('adds 1 + 2 to equal 3', () => { | ||
expect(1 + 2).toBe(3); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/create-svelte/shared/+vitest+skeletonlib/src/index.test.ts
This file contains hidden or 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,7 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
|
||
describe('sum test', () => { | ||
it('adds 1 + 2 to equal 3', () => { | ||
expect(1 + 2).toBe(3); | ||
}); | ||
}); |
This file contains hidden or 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,8 @@ | ||
{ | ||
"devDependencies": { | ||
"vitest": "^0.23.4" | ||
}, | ||
"scripts": { | ||
"test:unit": "vitest" | ||
} | ||
} |
This file contains hidden or 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,11 @@ | ||
import { sveltekit } from '@sveltejs/kit/vite'; | ||
|
||
/** @type {import('vite').UserConfig} */ | ||
const config = { | ||
plugins: [sveltekit()], | ||
test: { | ||
include: ['src/**/*.{test,spec}.{js,ts}'] | ||
} | ||
}; | ||
|
||
export default config; |
3 changes: 1 addition & 2 deletions
3
packages/create-svelte/shared/vite.config.ts → packages/create-svelte/shared/vite.config.js
This file contains hidden or 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 hidden or 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
77 changes: 77 additions & 0 deletions
77
packages/create-svelte/templates/default/src/routes/sverdle/game.ts
This file contains hidden or 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,77 @@ | ||
import { words, allowed } from './words.server'; | ||
|
||
export class Game { | ||
index: number; | ||
guesses: string[]; | ||
answers: string[]; | ||
answer: string; | ||
|
||
/** | ||
* Create a game object from the player's cookie, or initialise a new game | ||
* @param {string | undefined} serialized | ||
*/ | ||
constructor(serialized: string | undefined = undefined) { | ||
if (serialized) { | ||
const [index, guesses, answers] = serialized.split('-'); | ||
|
||
this.index = +index; | ||
this.guesses = guesses ? guesses.split(' ') : []; | ||
this.answers = answers ? answers.split(' ') : []; | ||
} else { | ||
this.index = Math.floor(Math.random() * words.length); | ||
this.guesses = ['', '', '', '', '', '']; | ||
this.answers = /** @type {string[]} */ [] /***/; | ||
} | ||
|
||
this.answer = words[this.index]; | ||
} | ||
|
||
/** | ||
* Update game state based on a guess of a five-letter word. Returns | ||
* true if the guess was valid, false otherwise | ||
* @param {string[]} letters | ||
*/ | ||
enter(letters: string[]) { | ||
const word = letters.join(''); | ||
const valid = allowed.has(word); | ||
|
||
if (!valid) return false; | ||
|
||
this.guesses[this.answers.length] = word; | ||
|
||
const available = Array.from(this.answer); | ||
const answer = Array(5).fill('_'); | ||
|
||
// first, find exact matches | ||
for (let i = 0; i < 5; i += 1) { | ||
if (letters[i] === available[i]) { | ||
answer[i] = 'x'; | ||
available[i] = ' '; | ||
} | ||
} | ||
|
||
// then find close matches (this has to happen | ||
// in a second step, otherwise an early close | ||
// match can prevent a later exact match) | ||
for (let i = 0; i < 5; i += 1) { | ||
if (answer[i] === '_') { | ||
const index = available.indexOf(letters[i]); | ||
if (index !== -1) { | ||
answer[i] = 'c'; | ||
available[index] = ' '; | ||
} | ||
} | ||
} | ||
|
||
this.answers.push(answer.join('')); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Serialize game state so it can be set as a cookie | ||
*/ | ||
toString() { | ||
return `${this.index}-${this.guesses.join(' ')}-${this.answers.join(' ')}`; | ||
} | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One late note since I saw the topic of globals was already discussed:
Some libraries enable features automatically based on these globals and users coming from jest may be confused as to why things aren’t working the same way out of the box. One that got me was Testing Library, which enables auto cleanup only if the global is present. https://testing-library.com/docs/react-testing-library/api#cleanup (this is a link to react docs but it applies equally to the svelte version of the library)
I personally have globals enabled but I have a second tsconfig to add the global types to my testing folder, which I saw you are trying to avoid. I don’t think there’s one true answer here but just wanted to leave this note in case it benefits anyone.