Skip to content

Commit ea217b5

Browse files
committed
switch things around!
1 parent 4d02345 commit ea217b5

File tree

14 files changed

+165
-114
lines changed

14 files changed

+165
-114
lines changed

packages/addons/_tests/_setup/suite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export function setupTest<Addons extends AddonMap>(
124124
};
125125
});
126126

127-
return { test, variants, prepareServer, flavors };
127+
return { test, flavors, prepareServer };
128128
}
129129

130130
type PrepareServerOptions = {

packages/addons/_tests/all-addons/test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ const defaultOptions = officialAddons.reduce<OptionMap<typeof addons>>((options,
1616
return options;
1717
}, {});
1818

19-
const { test, variants, prepareServer } = setupTest(addons);
19+
const { test, flavors, prepareServer } = setupTest(addons, {
20+
kinds: [{ type: 'default', options: defaultOptions }]
21+
});
2022

21-
const kitOnly = variants.filter((v) => v.startsWith('kit'));
22-
test.concurrent.for(kitOnly)('run all addons - %s', async (variant, { page, ...ctx }) => {
23-
const cwd = await ctx.run(variant, defaultOptions);
23+
test.concurrent.for(flavors)('run all addons - $variant', async (flavor, { page, ...ctx }) => {
24+
const cwd = ctx.run(flavor);
2425

2526
const { close } = await prepareServer({ cwd, page });
2627
// kill server process when we're done

packages/addons/_tests/devtools-json/test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import devtoolsJson from '../../devtools-json/index.ts';
44
import fs from 'node:fs';
55
import path from 'node:path';
66

7-
const { test, variants } = setupTest({ devtoolsJson }, { browser: false });
7+
const { test, flavors } = setupTest(
8+
{ devtoolsJson },
9+
{ kinds: [{ type: 'default', options: { devtoolsJson: {} } }], browser: false }
10+
);
811

9-
test.concurrent.for(variants)('default - %s', async (variant, ctx) => {
10-
const cwd = await ctx.run(variant, { devtoolsJson: {} });
12+
test.concurrent.for(flavors)('devtools-json $variant', (flavor, ctx) => {
13+
const cwd = ctx.run(flavor);
1114

12-
const ext = variant.includes('ts') ? 'ts' : 'js';
15+
const ext = flavor.variant.includes('ts') ? 'ts' : 'js';
1316
const viteFile = path.resolve(cwd, `vite.config.${ext}`);
1417
const viteContent = fs.readFileSync(viteFile, 'utf8');
1518

packages/addons/_tests/drizzle/test.ts

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,34 @@ import { setupTest } from '../_setup/suite.ts';
99
import drizzle from '../../drizzle/index.ts';
1010
import { pageServer, pageComp } from './fixtures.ts';
1111

12-
const { test, variants, prepareServer } = setupTest({ drizzle });
13-
1412
// only linux is supported for running docker containers in github runners
1513
const noDocker = process.env.CI && process.platform !== 'linux';
1614

15+
const { test, flavors, prepareServer } = setupTest(
16+
{ drizzle },
17+
{
18+
kinds: [
19+
{
20+
type: 'better-sqlite3',
21+
options: { drizzle: { database: 'sqlite', sqlite: 'better-sqlite3' } }
22+
},
23+
{
24+
type: 'libsql',
25+
options: { drizzle: { database: 'sqlite', sqlite: 'libsql' } }
26+
},
27+
{
28+
type: 'mysql2',
29+
options: { drizzle: { database: 'mysql', mysql: 'mysql2', docker: true } }
30+
},
31+
{
32+
type: 'postgres.js',
33+
options: { drizzle: { database: 'postgresql', postgresql: 'postgres.js', docker: true } }
34+
}
35+
],
36+
filter: (flavor) => flavor.variant.includes('kit')
37+
}
38+
);
39+
1740
beforeAll(() => {
1841
if (noDocker) return;
1942
const cwd = path.dirname(fileURLToPath(import.meta.url));
@@ -29,41 +52,27 @@ beforeAll(() => {
2952
};
3053
});
3154

32-
const kitOnly = variants.filter((v) => v.includes('kit'));
33-
const testCases = [
34-
{ name: 'better-sqlite3', options: { database: 'sqlite', sqlite: 'better-sqlite3' } },
35-
{ name: 'libsql', options: { database: 'sqlite', sqlite: 'libsql' } },
36-
{ name: 'mysql2', options: { database: 'mysql', mysql: 'mysql2', docker: true } },
37-
{
38-
name: 'postgres.js',
39-
options: { database: 'postgresql', postgresql: 'postgres.js', docker: true }
40-
}
41-
].flatMap((opts) => kitOnly.map((variant) => ({ ...opts, variant })));
42-
43-
test.concurrent.for(testCases)(
44-
'queries database - $name - $variant',
45-
async ({ options, variant }, { page, ...ctx }) => {
46-
if (options.docker && noDocker) ctx.skip();
47-
const cwd = await ctx.run(variant, { drizzle: options as any });
55+
test.concurrent.for(flavors)('drizzle $kind.type $variant', async (flavor, { page, ...ctx }) => {
56+
if (flavor.kind.options.drizzle.docker && noDocker) ctx.skip();
57+
const cwd = ctx.run(flavor);
4858

49-
const ts = variant === 'kit-ts';
50-
const drizzleConfig = path.resolve(cwd, `drizzle.config.${ts ? 'ts' : 'js'}`);
51-
const content = fs.readFileSync(drizzleConfig, 'utf8').replace(/strict: true[,\s]/, '');
52-
fs.writeFileSync(drizzleConfig, content, 'utf8');
59+
const ts = flavor.variant === 'kit-ts';
60+
const drizzleConfig = path.resolve(cwd, `drizzle.config.${ts ? 'ts' : 'js'}`);
61+
const content = fs.readFileSync(drizzleConfig, 'utf8').replace(/strict: true[,\s]/, '');
62+
fs.writeFileSync(drizzleConfig, content, 'utf8');
5363

54-
const routes = path.resolve(cwd, 'src', 'routes');
55-
const pagePath = path.resolve(routes, '+page.svelte');
56-
fs.writeFileSync(pagePath, pageComp, 'utf8');
64+
const routes = path.resolve(cwd, 'src', 'routes');
65+
const pagePath = path.resolve(routes, '+page.svelte');
66+
fs.writeFileSync(pagePath, pageComp, 'utf8');
5767

58-
const pageServerPath = path.resolve(routes, `+page.server.${ts ? 'ts' : 'js'}`);
59-
fs.writeFileSync(pageServerPath, pageServer, 'utf8');
68+
const pageServerPath = path.resolve(routes, `+page.server.${ts ? 'ts' : 'js'}`);
69+
fs.writeFileSync(pageServerPath, pageServer, 'utf8');
6070

61-
const { close } = await prepareServer({ cwd, page }, () => {
62-
execSync('npm run db:push', { cwd, stdio: 'pipe' });
63-
});
64-
// kill server process when we're done
65-
ctx.onTestFinished(async () => await close());
71+
const { close } = await prepareServer({ cwd, page }, () => {
72+
execSync('npm run db:push', { cwd, stdio: 'pipe' });
73+
});
74+
// kill server process when we're done
75+
ctx.onTestFinished(async () => await close());
6676

67-
expect(page.locator('[data-testid]')).toBeTruthy();
68-
}
69-
);
77+
expect(page.locator('[data-testid]')).toBeTruthy();
78+
});

packages/addons/_tests/eslint/test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ import { execSync } from 'node:child_process';
44
import { setupTest } from '../_setup/suite.ts';
55
import eslint from '../../eslint/index.ts';
66

7-
const { test, variants } = setupTest({ eslint }, { browser: false });
7+
const { test, flavors } = setupTest(
8+
{ eslint },
9+
{ kinds: [{ type: 'default', options: { eslint: {} } }], browser: false }
10+
);
811

9-
test.concurrent.for(variants)('core - %s', async (variant, { expect, ...ctx }) => {
10-
const cwd = await ctx.run(variant, { eslint: {} });
12+
test.concurrent.for(flavors)('eslint $variant', (flavor, { expect, ...ctx }) => {
13+
const cwd = ctx.run(flavor);
1114

1215
const unlintedFile = 'let foo = "";\nif (Boolean(foo)) {\n//\n}';
1316
fs.writeFileSync(path.resolve(cwd, 'src/lib/foo.js'), unlintedFile, 'utf8');
1417

15-
expect(() => execSync('pnpm install', { cwd, stdio: 'pipe' })).not.toThrow();
16-
1718
expect(() => execSync('pnpm lint', { cwd, stdio: 'pipe' })).toThrow();
1819

1920
expect(() => execSync('pnpm eslint --fix .', { cwd, stdio: 'pipe' })).not.toThrow();

packages/addons/_tests/lucia/test.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,31 @@ import { expect } from '@playwright/test';
22
import { setupTest } from '../_setup/suite.ts';
33
import lucia from '../../lucia/index.ts';
44
import drizzle from '../../drizzle/index.ts';
5+
import path from 'node:path';
6+
import fs from 'node:fs';
57

6-
const { test, variants, prepareServer } = setupTest({ drizzle, lucia });
8+
const { test, flavors, prepareServer } = setupTest(
9+
{ drizzle, lucia },
10+
{
11+
kinds: [
12+
{
13+
type: 'default',
14+
options: { drizzle: { database: 'sqlite', sqlite: 'libsql' }, lucia: { demo: true } }
15+
}
16+
],
17+
filter: (flavor) => flavor.variant.includes('kit')
18+
}
19+
);
720

8-
const kitOnly = variants.filter((v) => v.includes('kit'));
9-
test.concurrent.for(kitOnly)('core - %s', async (variant, { page, ...ctx }) => {
10-
const cwd = await ctx.run(variant, {
11-
drizzle: { database: 'sqlite', sqlite: 'libsql' },
12-
lucia: { demo: true }
13-
});
21+
test.concurrent.for(flavors)('lucia $variant', async (flavor, { page, ...ctx }) => {
22+
const cwd = ctx.run(flavor);
1423

1524
const { close } = await prepareServer({ cwd, page });
1625
// kill server process when we're done
1726
ctx.onTestFinished(async () => await close());
1827

19-
expect(true).toBe(true);
28+
const ext = flavor.variant.includes('ts') ? 'ts' : 'js';
29+
const filePath = path.resolve(cwd, `src/routes/demo/lucia/+page.server.${ext}`);
30+
const fileContent = fs.readFileSync(filePath, 'utf8');
31+
expect(fileContent).toContain(`export const actions`);
2032
});

packages/addons/_tests/mdsvex/test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ import { setupTest } from '../_setup/suite.ts';
88
import { svxFile } from './fixtures.ts';
99
import mdsvex from '../../mdsvex/index.ts';
1010

11-
const { test, variants, prepareServer } = setupTest({ mdsvex });
11+
const { test, flavors, prepareServer } = setupTest(
12+
{ mdsvex },
13+
{ kinds: [{ type: 'default', options: { mdsvex: {} } }] }
14+
);
1215

13-
test.concurrent.for(variants)('core - %s', async (variant, { page, ...ctx }) => {
14-
const cwd = await ctx.run(variant, { mdsvex: {} });
16+
test.concurrent.for(flavors)('mdsvex $variant', async (flavor, { page, ...ctx }) => {
17+
const cwd = ctx.run(flavor);
1518

1619
// ...add test files
17-
addFixture(cwd, variant);
20+
addFixture(cwd, flavor.variant);
1821

1922
const { close } = await prepareServer({ cwd, page });
2023
// kill server process when we're done
Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
import { expect } from '@playwright/test';
22
import { setupTest } from '../_setup/suite.ts';
33
import paraglide from '../../paraglide/index.ts';
4+
import fs from 'node:fs';
5+
import path from 'node:path';
46

5-
const { test, variants, prepareServer } = setupTest({ paraglide });
7+
const langs = ['en', 'fr', 'hu'];
68

7-
const kitOnly = variants.filter((v) => v.includes('kit'));
8-
test.concurrent.for(kitOnly)('core - %s', async (variant, { page, ...ctx }) => {
9-
const cwd = await ctx.run(variant, { paraglide: { demo: true, languageTags: 'en' } });
9+
const { test, flavors, prepareServer } = setupTest(
10+
{ paraglide },
11+
{
12+
kinds: [
13+
{ type: 'default', options: { paraglide: { demo: true, languageTags: langs.join(',') } } }
14+
],
15+
filter: (flavor) => flavor.variant.includes('kit')
16+
}
17+
);
18+
19+
test.concurrent.for(flavors)('paraglide $variant', async (flavor, { page, ...ctx }) => {
20+
const cwd = ctx.run(flavor);
1021

1122
const { close } = await prepareServer({ cwd, page });
1223
// kill server process when we're done
1324
ctx.onTestFinished(async () => await close());
1425

15-
expect(true).toBe(true);
26+
for (const lang of langs) {
27+
const filePath = path.resolve(cwd, `src/lib/paraglide/messages/${lang}.js`);
28+
const fileContent = fs.readFileSync(filePath, 'utf8');
29+
expect(fileContent).toContain(`hello_world`);
30+
}
1631
});

packages/addons/_tests/playwright/test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import path from 'node:path';
33
import { setupTest } from '../_setup/suite.ts';
44
import playwright from '../../playwright/index.ts';
55

6-
const { test, variants } = setupTest({ playwright }, { browser: false });
6+
const { test, flavors } = setupTest(
7+
{ playwright },
8+
{ kinds: [{ type: 'default', options: { playwright: {} } }], browser: false }
9+
);
710

8-
test.concurrent.for(variants)('core - %s', async (variant, { expect, ...ctx }) => {
9-
const cwd = await ctx.run(variant, { playwright: {} });
11+
test.concurrent.for(flavors)('playwright $variant', (flavor, { expect, ...ctx }) => {
12+
const cwd = ctx.run(flavor);
1013

11-
const ext = variant.includes('ts') ? 'ts' : 'js';
14+
const ext = flavor.variant.includes('ts') ? 'ts' : 'js';
1215
const playwrightConfig = path.resolve(cwd, `playwright.config.${ext}`);
1316
const configContent = fs.readFileSync(playwrightConfig, 'utf8');
1417

packages/addons/_tests/prettier/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { test, flavors } = setupTest(
99
{ kinds: [{ type: 'default', options: { prettier: {} } }], browser: false }
1010
);
1111

12-
test.concurrent.for(flavors)('core - %variant', (flavor, { expect, ...ctx }) => {
12+
test.concurrent.for(flavors)('prettier $variant', (flavor, { expect, ...ctx }) => {
1313
const cwd = ctx.run(flavor);
1414

1515
const unformattedFile = 'const foo = "bar"';

0 commit comments

Comments
 (0)