Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2a35dd1
add vitest option to svelte-create
Jul 25, 2022
09d4ef3
added changeset
Jul 25, 2022
5fa5ec0
add c8 package for coverage
Jul 25, 2022
e4e9ccf
ran format
Jul 25, 2022
1bf7c59
add vitest option to fix typescript error
Jul 25, 2022
fdd3fcd
Remove svelte-testing-library
Jul 25, 2022
e75378f
update to just modify the vite.config.js
Jul 25, 2022
a168514
readd default vite-config for non vitest projects
Jul 25, 2022
e9e38a6
remove coverage testing
Jul 26, 2022
2f97dee
Merge branch 'master' into add-vitest-to-create
Rich-Harris Aug 17, 2022
8c451fe
create typescript/checkjs/no-typechecking variants of .ts files in sh…
Rich-Harris Aug 17, 2022
e48c02f
simplify include
Rich-Harris Aug 17, 2022
f59f9c0
add testMatch to base playwright configs, remove vitest+playwright co…
Rich-Harris Aug 17, 2022
0a8fc37
Update packages/create-svelte/scripts/build-templates.js
benmccann Sep 30, 2022
b512b49
Merge branch 'master' into add-vitest-to-create
benmccann Sep 30, 2022
691e874
Update packages/create-svelte/shared/+playwright+typescript/playwrigh…
benmccann Sep 30, 2022
78149b5
cleanup test patterns
benmccann Sep 30, 2022
c06a74f
newer version of vitest
benmccann Sep 30, 2022
db95545
sverdle test
benmccann Sep 30, 2022
e670e29
format
benmccann Sep 30, 2022
e71e21a
removed vitest globals
Sep 30, 2022
658dd56
Rename vite.config.ts to vite.config.js
Oct 3, 2022
8d3d11d
Fixed types on default vite config
Oct 3, 2022
01ab4ba
Merge remote-tracking branch 'upstream/HEAD' into add-vitest-to-create
Nov 10, 2022
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
5 changes: 5 additions & 0 deletions .changeset/dirty-teachers-hug.md
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
13 changes: 13 additions & 0 deletions packages/create-svelte/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ async function main() {
initial: false,
active: 'Yes',
inactive: 'No'
},
{
type: 'toggle',
name: 'vitest',
message: 'Add Vitest for unit testing?',
initial: false,
active: 'Yes',
inactive: 'No'
}
],
{
Expand Down Expand Up @@ -150,6 +158,11 @@ async function main() {
console.log(cyan(' https://playwright.dev'));
}

if (options.vitest) {
console.log(bold('✔ Vitest'));
console.log(cyan(' https://vitest.dev'));
}

console.log('\nInstall community-maintained integrations:');
console.log(cyan(' https://github.com/svelte-add/svelte-adders'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ await create(repo, {
eslint: false,
types: 'checkjs',
prettier: true,
playwright: false
playwright: false,
vitest: false
});
14 changes: 14 additions & 0 deletions packages/create-svelte/shared/+vitest+checkjs/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"types": ["vitest/globals"],
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
webServer: {
command: 'npm run build && npm run preview',
port: 4173
},
testMatch: 'tests/**/*.{js,ts}'
Comment thread
Rich-Harris marked this conversation as resolved.
Outdated
};

export default config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('@playwright/test').PlaywrightTestConfig} */
const config = {
webServer: {
command: 'npm run build && npm run preview',
port: 4173
},
testMatch: 'tests/**/*.js'
Comment thread
Rich-Harris marked this conversation as resolved.
Outdated
};

export default config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { sum } from './sum';

describe('sum test', () => {
it('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function sum(a: number, b: number): number {
return a + b;
}
14 changes: 14 additions & 0 deletions packages/create-svelte/shared/+vitest+typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"types": ["vitest/globals"],
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true
}
}
11 changes: 11 additions & 0 deletions packages/create-svelte/shared/+vitest+typescript/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'vite';
import viteConfig from './vite.config';

export default defineConfig({
...viteConfig,
plugins: viteConfig?.plugins ?? [],
test: {
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
globals: true
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function sum(a, b) {
return a + b;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { sum } from './sum';

describe('sum test', () => {
it('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
});
11 changes: 11 additions & 0 deletions packages/create-svelte/shared/+vitest-typescript/vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'vite';
import viteConfig from './vite.config';

export default defineConfig({
Comment thread
Rich-Harris marked this conversation as resolved.
Outdated
...viteConfig,
plugins: viteConfig?.plugins ?? [],
test: {
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
globals: true
}
});
10 changes: 10 additions & 0 deletions packages/create-svelte/shared/+vitest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"devDependencies": {
"vitest": "^0.19.1",
"c8": "^7.12.0"
},
"scripts": {
"test:unit": "vitest",
"coverage": "vitest run --coverage"
}
}
2 changes: 2 additions & 0 deletions packages/create-svelte/types/internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type Options = {
prettier: boolean;
eslint: boolean;
playwright: boolean;
vitest: boolean;
};

export type File = {
Expand All @@ -18,6 +19,7 @@ export type Condition =
| 'typescript'
| 'checkjs'
| 'playwright'
| 'vitest'
| 'skeleton'
| 'default';

Expand Down