From e214af41e32288a5bc6aca15a827325ae5e22f1c Mon Sep 17 00:00:00 2001 From: DanSnow Date: Tue, 14 May 2024 13:59:35 +0800 Subject: [PATCH] test: add test to ensure all tracking event is used --- package.json | 1 + tests/tracking-event-used.spec.ts | 19 +++++++++++++++++++ yarn.lock | 11 +++++++++++ 3 files changed, 31 insertions(+) create mode 100644 tests/tracking-event-used.spec.ts diff --git a/package.json b/package.json index c801eb1d..644029b2 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "devDependencies": { "@0no-co/graphqlsp": "1.12.3", "@antfu/eslint-config": "2.18.0", + "@effect/vitest": "0.4.3", "@egoist/tailwindcss-icons": "1.8.0", "@iconify-json/lucide": "1.1.187", "@moonrepo/cli": "1.24.4", diff --git a/tests/tracking-event-used.spec.ts b/tests/tracking-event-used.spec.ts new file mode 100644 index 00000000..9259de49 --- /dev/null +++ b/tests/tracking-event-used.spec.ts @@ -0,0 +1,19 @@ +import { expect } from 'vitest' +import { Array, Effect } from 'effect' +import { fs, glob } from 'zx' +import { it } from '@effect/vitest' +import { trackEventSchema } from '../src/lib/tracking-schema' + +const eventNames = Array.fromIterable(trackEventSchema.optionsMap.keys()) as string[] + +it.effect('use all tracking event', () => { + return Effect.gen(function* () { + const files = yield* Effect.promise(() => glob(['src/**/*', '!**/__tests__/**/*', '!src/lib/tracking-schema/**/*'])) + const contents = yield* Effect.all( + files.map((file) => Effect.promise(() => fs.readFile(file, 'utf8'))), + { concurrency: 'unbounded' }, + ) + + expect(Array.every(eventNames, (name) => Array.some(contents, (content) => content.includes(name)))).toBe(true) + }) +}) diff --git a/yarn.lock b/yarn.lock index 449664e4..4badff1c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1078,6 +1078,16 @@ __metadata: languageName: node linkType: hard +"@effect/vitest@npm:0.4.3": + version: 0.4.3 + resolution: "@effect/vitest@npm:0.4.3" + peerDependencies: + effect: ^3.1.4 + vitest: ^1.4.0 + checksum: 10c0/a032147665be8b43ef9b37542b63a039446a8bf85bd6b4f325ff0cc1cc6830890e5e02db95ba808971b559267a4f7ad59ac9c4c02c4fbb431a614d99c6a87854 + languageName: node + linkType: hard + "@egoist/tailwindcss-icons@npm:1.8.0": version: 1.8.0 resolution: "@egoist/tailwindcss-icons@npm:1.8.0" @@ -3533,6 +3543,7 @@ __metadata: dependencies: "@0no-co/graphqlsp": "npm:1.12.3" "@antfu/eslint-config": "npm:2.18.0" + "@effect/vitest": "npm:0.4.3" "@egoist/tailwindcss-icons": "npm:1.8.0" "@formkit/auto-animate": "npm:^0.8.2" "@iconify-json/lucide": "npm:1.1.187"