diff --git a/packages/unplugin-analytics/test/build.test.ts b/packages/unplugin-analytics/test/build.test.ts new file mode 100644 index 0000000..b92fb2a --- /dev/null +++ b/packages/unplugin-analytics/test/build.test.ts @@ -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 = [ + ``, + ``, + ``, + `(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 = [ + ``, + ``, + ``, + `(window, document, "clarity", "script", "kwj19d7z4j")` + ]; + for (const text of expected) { + expect(indexHtml.indexOf(text) !== -1).toBeTruthy(); + } + }); + }, + 20 * 1000 +); diff --git a/packages/unplugin-analytics/test/index.test.ts b/packages/unplugin-analytics/test/index.test.ts deleted file mode 100644 index ebdfe9f..0000000 --- a/packages/unplugin-analytics/test/index.test.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { describe, it, expect } from 'vitest' - -describe('hello', () => { - it('should work', () => { - expect('Hello').toEqual('Hello'); - }); -}); diff --git a/packages/vite-plugin-analytics/test/build.test.ts b/packages/vite-plugin-analytics/test/build.test.ts index 384d64b..b5a5dcc 100644 --- a/packages/vite-plugin-analytics/test/build.test.ts +++ b/packages/vite-plugin-analytics/test/build.test.ts @@ -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', () => {