-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathaddon.test.js
More file actions
52 lines (45 loc) · 1.64 KB
/
Copy pathaddon.test.js
File metadata and controls
52 lines (45 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { expect } from '@playwright/test';
import fs from 'node:fs';
import path from 'node:path';
import addon from '../src/index.js';
import { setupTest } from './setup/suite.js';
// set to true to enable browser testing
const browser = false;
const { test, prepareServer, testCases } = setupTest(
{ addon },
{
kinds: [
{
type: 'default',
options: { '@layerchart/sv': { demo: 'components/ArcChart/gradient-with-text' } }
}
],
filter: (testCase) => testCase.variant.includes('kit'),
browser
}
);
test.concurrent.for(testCases)(
'@layerchart/sv $kind.type $variant',
async (testCase, { page, ...ctx }) => {
const cwd = ctx.cwd(testCase);
// Check demo component was created
const demoPath = path.resolve(cwd, 'src/lib/layerchart/demos/ArcChart/gradient-with-text.svelte');
const demoContent = fs.readFileSync(demoPath, 'utf8');
expect(demoContent).toContain('layerchart');
expect(demoContent).toContain('ArcChart');
// Check route was updated to import the demo
const routePath = path.resolve(cwd, 'src/routes/+page.svelte');
const routeContent = fs.readFileSync(routePath, 'utf8');
expect(routeContent).toContain('Demo');
expect(routeContent).toContain('$lib/layerchart/demos/ArcChart/gradient-with-text.svelte');
// Check package.json has layerchart dependency
const pkgPath = path.resolve(cwd, 'package.json');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
expect(pkg.dependencies?.layerchart || pkg.devDependencies?.layerchart).toBeTruthy();
// For browser testing
if (browser) {
const { close } = await prepareServer({ cwd, page });
ctx.onTestFinished(async () => await close());
}
}
);