Skip to content

Commit

Permalink
feat(unplugin): test output
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Feb 27, 2024
1 parent acbb75d commit bcd3544
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
44 changes: 44 additions & 0 deletions packages/unplugin-analytics/test/build.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import fs from 'node:fs';
import path from 'node:path';
import { execSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';

import { describe, it, expect } from 'vitest';

describe(
'Examples',
() => {
it('should build nuxt', async () => {
const root = path.join(fileURLToPath(import.meta.url), '../../../../examples/nuxt/');
execSync(`pnpm run generate`, { cwd: root });
const indexHtml = await fs.promises.readFile(path.join(root, 'dist', 'index.html'), 'utf-8');

const expected = [
`<script defer data-website-id="a8602a4a-8d41-4df7-9797-5bd074785f2c" src="https://umami.onekuma.cn/script.js"></script>`,
`<script defer data-domain="garden.onekuma.cn" src="https://plausible.io/js/script.js"></script>`,
`<script defer data-cf-beacon="{&quot;token&quot;: &quot;aa68fa3bf166467082bc79ba029b057f&quot;}" src="https://static.cloudflareinsights.com/beacon.min.js"></script>`,
`(window, document, "clarity", "script", "kwj19d7z4j")`
];
for (const text of expected) {
expect(indexHtml.indexOf(text) !== -1).toBeTruthy();
}
});

it('should build astro', async () => {
const root = path.join(fileURLToPath(import.meta.url), '../../../../examples/astro/');
execSync(`pnpm run build`, { cwd: root });
const indexHtml = await fs.promises.readFile(path.join(root, 'dist', 'index.html'), 'utf-8');

const expected = [
`<script src="https://umami.onekuma.cn/script.js" defer data-website-id="a8602a4a-8d41-4df7-9797-5bd074785f2c"></script>`,
`<script src="https://plausible.io/js/script.js" defer data-domain="garden.onekuma.cn"></script>`,
`<script src="https://static.cloudflareinsights.com/beacon.min.js" defer data-cf-beacon="{&quot;token&quot;: &quot;aa68fa3bf166467082bc79ba029b057f&quot;}"></script>`,
`(window, document, "clarity", "script", "kwj19d7z4j")`
];
for (const text of expected) {
expect(indexHtml.indexOf(text) !== -1).toBeTruthy();
}
});
},
20 * 1000
);
7 changes: 0 additions & 7 deletions packages/unplugin-analytics/test/index.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/vite-plugin-analytics/test/build.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { build } from 'vite';

import { build } from 'vite';
import { describe, it, expect } from 'vitest';

describe('vite', () => {
Expand Down

0 comments on commit bcd3544

Please sign in to comment.