diff --git a/libs/test-helpers/.eslintrc.json b/libs/test-helpers/.eslintrc.json new file mode 100644 index 0000000..9d9c0db --- /dev/null +++ b/libs/test-helpers/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/libs/test-helpers/README.md b/libs/test-helpers/README.md new file mode 100644 index 0000000..2cd48c4 --- /dev/null +++ b/libs/test-helpers/README.md @@ -0,0 +1,11 @@ +# test-helpers + +This library was generated with [Nx](https://nx.dev). + +## Building + +Run `nx build test-helpers` to build the library. + +## Running unit tests + +Run `nx test test-helpers` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/test-helpers/package.json b/libs/test-helpers/package.json new file mode 100644 index 0000000..57297bb --- /dev/null +++ b/libs/test-helpers/package.json @@ -0,0 +1,5 @@ +{ + "name": "@rovacc/test-helpers", + "version": "0.0.1", + "type": "commonjs" +} diff --git a/libs/test-helpers/project.json b/libs/test-helpers/project.json new file mode 100644 index 0000000..3b92b2e --- /dev/null +++ b/libs/test-helpers/project.json @@ -0,0 +1,31 @@ +{ + "name": "test-helpers", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/test-helpers/src", + "projectType": "library", + "targets": { + "build": { + "executor": "@nx/vite:build", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "dist/libs/test-helpers" + } + }, + "test": { + "executor": "@nx/vite:test", + "outputs": ["coverage/libs/test-helpers"], + "options": { + "passWithNoTests": true, + "reportsDirectory": "../../coverage/libs/test-helpers" + } + }, + "lint": { + "executor": "@nx/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": ["libs/test-helpers/**/*.ts"] + } + } + }, + "tags": [] +} diff --git a/libs/test-helpers/src/firestore/delete-collection.ts b/libs/test-helpers/src/firestore/delete-collection.ts new file mode 100644 index 0000000..f51aa7e --- /dev/null +++ b/libs/test-helpers/src/firestore/delete-collection.ts @@ -0,0 +1,15 @@ +export async function deleteCollection(collectionPath: string) { + const endpoint = process.env['FIRESTORE_EMULATOR_HOST'] as string + const project = process.env['GCLOUD_PROJECT'] as string + + const response = await fetch( + `http://${endpoint}/emulator/v1/projects/${project}/databases/(default)/documents/${collectionPath}`, + { + method: 'DELETE', + } + ); + if (response.status !== 200) { + throw new Error('Trouble clearing Emulator: ' + (await response.text())); + } +} + diff --git a/libs/test-helpers/src/firestore/index.ts b/libs/test-helpers/src/firestore/index.ts new file mode 100644 index 0000000..33ce528 --- /dev/null +++ b/libs/test-helpers/src/firestore/index.ts @@ -0,0 +1 @@ +export { deleteCollection } from './delete-collection' diff --git a/libs/test-helpers/src/index.ts b/libs/test-helpers/src/index.ts new file mode 100644 index 0000000..aeda3d0 --- /dev/null +++ b/libs/test-helpers/src/index.ts @@ -0,0 +1,2 @@ +export * from './firestore' +export * from './training/events' diff --git a/libs/test-helpers/src/training/events/build-training-completed-event.ts b/libs/test-helpers/src/training/events/build-training-completed-event.ts new file mode 100644 index 0000000..db2c7da --- /dev/null +++ b/libs/test-helpers/src/training/events/build-training-completed-event.ts @@ -0,0 +1,22 @@ +import { TrainingCompletedEvent, TrainingCompletedEventData } from '@rovacc/training-events-types' + +type Args = { + trainingId: string, + eventId?: string, + emittedAt?: Date, + override?: Partial +} + +export const buildTrainingCompletedEvent = (args: Args): TrainingCompletedEvent => ({ + trainingId: args.trainingId, + name: 'training-completed', + eventId: args.eventId ?? 'event-id', + emittedAt: args.emittedAt ?? new Date(), + system: 'rovacc-system-id', + correlationId: 'correlationId', + payload: { + reason: 'completed', + reasonDetailed: 'rating_upgraded', + ...args.override + } +}) diff --git a/libs/test-helpers/src/training/events/build-training-cpt-performed-event.ts b/libs/test-helpers/src/training/events/build-training-cpt-performed-event.ts new file mode 100644 index 0000000..668c0a4 --- /dev/null +++ b/libs/test-helpers/src/training/events/build-training-cpt-performed-event.ts @@ -0,0 +1,32 @@ +import { TrainingCptPerformedEvent, TrainingCptPerformedEventData } from '@rovacc/training-events-types' + +type Args = { + trainingId: string, + eventId?: string, + emittedAt?: Date, + override?: Partial +} + +export const buildTrainingCptPerformedEvent = (args: Args): TrainingCptPerformedEvent => ({ + trainingId: args.trainingId, + name: 'training-cpt-performed', + eventId: args.eventId ?? 'event-id', + emittedAt: args.emittedAt ?? new Date(), + system: 'rovacc-system-id', + correlationId: 'correlationId', + payload: { + assessedBy: { + id: 200200, + name: 'member-name' + }, + report: { + purpose: "cpt_ots", + workload: "light", + complexity: "routine", + traffic: "light", + comments: 'Session went well' + }, + passed: true, + ...args.override + } +}) diff --git a/libs/test-helpers/src/training/events/build-training-cpt-requested-event.ts b/libs/test-helpers/src/training/events/build-training-cpt-requested-event.ts new file mode 100644 index 0000000..aa15829 --- /dev/null +++ b/libs/test-helpers/src/training/events/build-training-cpt-requested-event.ts @@ -0,0 +1,21 @@ +import { TrainingCptRequestedEvent } from '@rovacc/training-events-types' + +type Args = { + trainingId: string, + eventId?: string, + emittedAt?: Date, + override?: Partial +} + +export const buildTrainingCptRequestedEvent = (args: Args): TrainingCptRequestedEvent => ({ + trainingId: args.trainingId, + name: 'training-cpt-requested', + eventId: args.eventId ?? 'event-id', + emittedAt: args.emittedAt ?? new Date(), + system: 'rovacc-system-id', + correlationId: 'correlationId', + payload: { + requestedBy: { id: 123123, name: 'Requested By Name' }, + ...args.override + } +}) diff --git a/libs/test-helpers/src/training/events/build-training-cpt-scheduled-event.ts b/libs/test-helpers/src/training/events/build-training-cpt-scheduled-event.ts new file mode 100644 index 0000000..d5ecdd7 --- /dev/null +++ b/libs/test-helpers/src/training/events/build-training-cpt-scheduled-event.ts @@ -0,0 +1,21 @@ +import { TrainingCptScheduledEvent } from '@rovacc/training-events-types' + +type Args = { + trainingId: string, + eventId?: string, + emittedAt?: Date, + override?: Partial +} + +export const buildTrainingCptScheduledEvent = (args: Args): TrainingCptScheduledEvent => ({ + trainingId: args.trainingId, + name: 'training-cpt-scheduled', + eventId: args.eventId ?? 'event-id', + emittedAt: args.emittedAt ?? new Date(), + system: 'rovacc-system-id', + correlationId: 'correlationId', + payload: { + scheduledAt: new Date(), + ...args.override + } +}) diff --git a/libs/test-helpers/src/training/events/build-training-intent-confirmation-expired-event.ts b/libs/test-helpers/src/training/events/build-training-intent-confirmation-expired-event.ts new file mode 100644 index 0000000..cc3f841 --- /dev/null +++ b/libs/test-helpers/src/training/events/build-training-intent-confirmation-expired-event.ts @@ -0,0 +1,19 @@ +import { TrainingIntentConfirmationExpiredEvent, TrainingIntentConfirmationExpiredEventData } from '@rovacc/training-events-types' + +type Args = { + trainingId: string, + eventId?: string, + emittedAt?: Date, + override?: Partial +} + +export const buildTrainingIntentConfirmationExpiredEvent = + (args: Args): TrainingIntentConfirmationExpiredEvent => ({ + name: 'training-intent-confirmation-expired', + trainingId: args.trainingId, + eventId: args.eventId ?? 'event-id', + emittedAt: args.emittedAt ?? new Date(), + system: 'rovacc-system-id', + correlationId: 'correlationId', + payload: {}, + }) diff --git a/libs/test-helpers/src/training/events/build-training-intent-confirmation-rejected-event.ts b/libs/test-helpers/src/training/events/build-training-intent-confirmation-rejected-event.ts new file mode 100644 index 0000000..252506d --- /dev/null +++ b/libs/test-helpers/src/training/events/build-training-intent-confirmation-rejected-event.ts @@ -0,0 +1,19 @@ +import { TrainingIntentConfirmationRejectedEvent, TrainingIntentConfirmationRejectedEventData } from '@rovacc/training-events-types' + +type Args = { + trainingId: string, + eventId?: string, + emittedAt?: Date, + override?: Partial +} + +export const buildTrainingIntentConfirmationRejectedEvent = + (args: Args): TrainingIntentConfirmationRejectedEvent => ({ + name: 'training-intent-confirmation-rejected', + trainingId: args.trainingId, + eventId: args.eventId ?? 'event-id', + emittedAt: args.emittedAt ?? new Date(), + system: 'rovacc-system-id', + correlationId: 'correlationId', + payload: {}, + }) diff --git a/libs/test-helpers/src/training/events/build-training-intent-confirmation-requested-event.ts b/libs/test-helpers/src/training/events/build-training-intent-confirmation-requested-event.ts new file mode 100644 index 0000000..1290a6c --- /dev/null +++ b/libs/test-helpers/src/training/events/build-training-intent-confirmation-requested-event.ts @@ -0,0 +1,18 @@ +import { TrainingIntentConfirmationRequestedEvent, TrainingIntentConfirmationRequestedEventData } from '@rovacc/training-events-types' + +type Args = { + trainingId: string, + eventId?: string, + emittedAt?: Date, + override?: Partial +} + +export const buildTrainingIntentConfirmationRequestedEvent = (args: Args): TrainingIntentConfirmationRequestedEvent => ({ + trainingId: args.trainingId, + name: 'training-intent-confirmation-requested', + eventId: args.eventId ?? 'event-id', + emittedAt: args.emittedAt ?? new Date(), + system: 'rovacc-system-id', + correlationId: 'correlationId', + payload: {} +}) diff --git a/libs/test-helpers/src/training/events/build-training-intent-confirmation-responded-event.ts b/libs/test-helpers/src/training/events/build-training-intent-confirmation-responded-event.ts new file mode 100644 index 0000000..5a6c496 --- /dev/null +++ b/libs/test-helpers/src/training/events/build-training-intent-confirmation-responded-event.ts @@ -0,0 +1,18 @@ +import { TrainingIntentConfirmationRespondedEvent, TrainingIntentConfirmationRespondedEventData } from '@rovacc/training-events-types' + +type Args = { + trainingId: string, + eventId?: string, + emittedAt?: Date, + override?: Partial +} + +export const buildTrainingIntentConfirmationRespondedEvent = (args: Args): TrainingIntentConfirmationRespondedEvent => ({ + trainingId: args.trainingId, + name: 'training-intent-confirmation-responded', + eventId: args.eventId ?? 'event-id', + emittedAt: args.emittedAt ?? new Date(), + system: 'rovacc-system-id', + correlationId: 'correlationId', + payload: {} +}) diff --git a/libs/test-helpers/src/training/events/build-training-intent-event.ts b/libs/test-helpers/src/training/events/build-training-intent-event.ts new file mode 100644 index 0000000..356e5bc --- /dev/null +++ b/libs/test-helpers/src/training/events/build-training-intent-event.ts @@ -0,0 +1,23 @@ +import { TrainingIntentEvent } from '@rovacc/training-events-types' + +type Args = { + trainingId: string, + eventId?: string, + emittedAt?: Date, + override?: Partial +} + +export const buildTrainingIntentEvent = (args: Args): TrainingIntentEvent => ({ + trainingId: args.trainingId, + name: 'training-intent', + eventId: args.eventId ?? 'event-id', + emittedAt: args.emittedAt ?? new Date(), + system: 'rovacc-system-id', + correlationId: 'correlationId', + payload: { + student: 123123123, + rating: 2, + purpose: 'acquire_rating', + ...args.override + } +}) diff --git a/libs/test-helpers/src/training/events/build-training-mentor-assigned-event.ts b/libs/test-helpers/src/training/events/build-training-mentor-assigned-event.ts new file mode 100644 index 0000000..e2936b5 --- /dev/null +++ b/libs/test-helpers/src/training/events/build-training-mentor-assigned-event.ts @@ -0,0 +1,22 @@ +import { TrainingMentorAssignedEvent, TrainingMentorAssignedEventData } from '@rovacc/training-events-types' + +type Args = { + trainingId: string, + eventId?: string, + emittedAt?: Date, + override?: Partial +} + +export const buildTrainingMentorAssignedEvent = (args: Args): TrainingMentorAssignedEvent => ({ + trainingId: args.trainingId, + name: 'training-mentor-assigned', + eventId: args.eventId ?? 'event-id', + emittedAt: args.emittedAt ?? new Date(), + system: 'rovacc-system-id', + correlationId: 'correlationId', + payload: { + mentor: { id: 200000, name: 'Mentor Name' }, + assignedBy: { id: 200200, name: 'Assigned By Name' }, + ...args.override + } +}) diff --git a/libs/test-helpers/src/training/events/build-training-mentor-reassigned-event.ts b/libs/test-helpers/src/training/events/build-training-mentor-reassigned-event.ts new file mode 100644 index 0000000..99c9353 --- /dev/null +++ b/libs/test-helpers/src/training/events/build-training-mentor-reassigned-event.ts @@ -0,0 +1,22 @@ +import { TrainingMentorReassignedEvent, TrainingMentorReassignedEventData } from '@rovacc/training-events-types' + +type Args = { + trainingId: string, + eventId?: string, + emittedAt?: Date, + override?: Partial +} + +export const buildTrainingMentorReassignedEvent = (args: Args): TrainingMentorReassignedEvent => ({ + trainingId: args.trainingId, + name: 'training-mentor-reassigned', + eventId: args.eventId ?? 'event-id', + emittedAt: args.emittedAt ?? new Date(), + system: 'rovacc-system-id', + correlationId: 'correlationId', + payload: { + mentor: { id: 200000, name: 'Mentor Name' }, + assignedBy: { id: 200200, name: 'Assigned By Name' }, + ...args.override + } +}) diff --git a/libs/test-helpers/src/training/events/build-training-session-performed-event.ts b/libs/test-helpers/src/training/events/build-training-session-performed-event.ts new file mode 100644 index 0000000..5992867 --- /dev/null +++ b/libs/test-helpers/src/training/events/build-training-session-performed-event.ts @@ -0,0 +1,29 @@ +import { TrainingSessionPerformedEvent, TrainingSessionPerformedEventData } from '@rovacc/training-events-types' + +type Args = { + trainingId: string, + eventId?: string, + emittedAt?: Date, + override?: Partial +} + +export const buildTrainingSessionPerformedEvent = (args: Args): TrainingSessionPerformedEvent => ({ + trainingId: args.trainingId, + name: 'training-session-performed', + eventId: args.eventId ?? 'event-id', + emittedAt: args.emittedAt ?? new Date(), + system: 'rovacc-system-id', + correlationId: 'correlationId', + payload: { + sessionId: 'session-id', + mentor: { id: 200000, name: 'Mentor Name' }, + report: { + purpose: "cpt_ots", + workload: "light", + complexity: "routine", + traffic: "light", + comments: 'Session went well' + }, + ...args.override + } +}) diff --git a/libs/test-helpers/src/training/events/build-training-session-scheduled-event.ts b/libs/test-helpers/src/training/events/build-training-session-scheduled-event.ts new file mode 100644 index 0000000..d7920a2 --- /dev/null +++ b/libs/test-helpers/src/training/events/build-training-session-scheduled-event.ts @@ -0,0 +1,22 @@ +import { TrainingSessionScheduledEvent, TrainingSessionScheduledEventData } from '@rovacc/training-events-types' + +type Args = { + trainingId: string, + eventId?: string, + emittedAt?: Date, + override?: Partial +} + +export const buildTrainingSessionScheduledEvent = (args: Args): TrainingSessionScheduledEvent => ({ + trainingId: args.trainingId, + name: 'training-session-scheduled', + eventId: args.eventId ?? 'event-id', + emittedAt: args.emittedAt ?? new Date(), + system: 'rovacc-system-id', + correlationId: 'correlationId', + payload: { + sessionId: 'session-id', + scheduledAt: new Date(), + ...args.override + } +}) diff --git a/libs/test-helpers/src/training/events/build-training-solo-performed-event.ts b/libs/test-helpers/src/training/events/build-training-solo-performed-event.ts new file mode 100644 index 0000000..8855829 --- /dev/null +++ b/libs/test-helpers/src/training/events/build-training-solo-performed-event.ts @@ -0,0 +1,29 @@ +import { TrainingSoloPerformedEvent, TrainingSoloPerformedEventData } from '@rovacc/training-events-types' + +type Args = { + trainingId: string, + eventId?: string, + emittedAt?: Date, + override?: Partial +} + +export const buildTrainingSoloPerformedEvent = (args: Args): TrainingSoloPerformedEvent => ({ + trainingId: args.trainingId, + name: 'training-solo-performed', + eventId: args.eventId ?? 'event-id', + emittedAt: args.emittedAt ?? new Date(), + system: 'rovacc-system-id', + correlationId: 'correlationId', + payload: { + requestedBy: { id: 200000, name: 'Requested By Name' }, + passed: true, + report: { + purpose: "cpt_ots", + workload: "light", + complexity: "routine", + traffic: "light", + comments: 'Session went well' + }, + ...args.override + } +}) diff --git a/libs/test-helpers/src/training/events/build-training-solo-requested-event.ts b/libs/test-helpers/src/training/events/build-training-solo-requested-event.ts new file mode 100644 index 0000000..b6ee520 --- /dev/null +++ b/libs/test-helpers/src/training/events/build-training-solo-requested-event.ts @@ -0,0 +1,21 @@ +import { TrainingSoloRequestedEvent, TrainingSoloRequestedEventData } from '@rovacc/training-events-types' + +type Args = { + trainingId: string, + eventId?: string, + emittedAt?: Date, + override?: Partial +} + +export const buildTrainingSoloRequestedEvent = (args: Args): TrainingSoloRequestedEvent => ({ + trainingId: args.trainingId, + name: 'training-solo-requested', + eventId: args.eventId ?? 'event-id', + emittedAt: args.emittedAt ?? new Date(), + system: 'rovacc-system-id', + correlationId: 'correlationId', + payload: { + requestedBy: { id: 200000, name: 'Requested By Name' }, + ...args.override + } +}) diff --git a/libs/test-helpers/src/training/events/build-training-solo-scheduled-event.ts b/libs/test-helpers/src/training/events/build-training-solo-scheduled-event.ts new file mode 100644 index 0000000..957090e --- /dev/null +++ b/libs/test-helpers/src/training/events/build-training-solo-scheduled-event.ts @@ -0,0 +1,21 @@ +import { TrainingSoloScheduledEvent, TrainingSoloScheduledEventData } from '@rovacc/training-events-types' + +type Args = { + trainingId: string, + eventId?: string, + emittedAt?: Date, + override?: Partial +} + +export const buildTrainingSoloScheduledEvent = (args: Args): TrainingSoloScheduledEvent => ({ + trainingId: args.trainingId, + name: 'training-solo-scheduled', + eventId: args.eventId ?? 'event-id', + emittedAt: args.emittedAt ?? new Date(), + system: 'rovacc-system-id', + correlationId: 'correlationId', + payload: { + scheduledAt: new Date(), + ...args.override + } +}) diff --git a/libs/test-helpers/src/training/events/build-training-test-assigned-event.ts b/libs/test-helpers/src/training/events/build-training-test-assigned-event.ts new file mode 100644 index 0000000..4016bbb --- /dev/null +++ b/libs/test-helpers/src/training/events/build-training-test-assigned-event.ts @@ -0,0 +1,21 @@ +import { TrainingTestAssignedEvent, TrainingTestAssignedEventData } from '@rovacc/training-events-types' + +type Args = { + trainingId: string, + eventId?: string, + emittedAt?: Date, + override?: Partial +} + +export const buildTrainingTestAssignedEvent = (args: Args): TrainingTestAssignedEvent => ({ + trainingId: args.trainingId, + name: 'training-test-assigned', + eventId: args.eventId ?? 'event-id', + emittedAt: args.emittedAt ?? new Date(), + system: 'rovacc-system-id', + correlationId: 'correlationId', + payload: { + assignedBy: { id: 200200, name: 'Assigned By Name' }, + ...args.override + } +}) diff --git a/libs/test-helpers/src/training/events/build-training-test-completed-event.ts b/libs/test-helpers/src/training/events/build-training-test-completed-event.ts new file mode 100644 index 0000000..0fcbfe3 --- /dev/null +++ b/libs/test-helpers/src/training/events/build-training-test-completed-event.ts @@ -0,0 +1,26 @@ +import { TrainingTestCompletedEvent, TrainingTestCompletedEventData } from '@rovacc/training-events-types' + +type Args = { + trainingId: string, + eventId?: string, + emittedAt?: Date, + override?: Partial +} + +export const buildTrainingTestCompletedEvent = (args: Args): TrainingTestCompletedEvent => ({ + trainingId: args.trainingId, + name: 'training-test-completed', + eventId: args.eventId ?? 'event-id', + emittedAt: args.emittedAt ?? new Date(), + system: 'rovacc-system-id', + correlationId: 'correlationId', + payload: { + passed: true, + report: { + passed: true, + result: 'passed', + willExpireAt: new Date() + }, + ...args.override + } +}) diff --git a/libs/test-helpers/src/training/events/index.ts b/libs/test-helpers/src/training/events/index.ts new file mode 100644 index 0000000..044fb64 --- /dev/null +++ b/libs/test-helpers/src/training/events/index.ts @@ -0,0 +1,18 @@ +export { buildTrainingCompletedEvent } from './build-training-completed-event' +export { buildTrainingCptPerformedEvent } from './build-training-cpt-performed-event' +export { buildTrainingCptRequestedEvent } from './build-training-cpt-requested-event' +export { buildTrainingCptScheduledEvent } from './build-training-cpt-scheduled-event' +export { buildTrainingIntentEvent } from './build-training-intent-event' +export { buildTrainingIntentConfirmationExpiredEvent } from './build-training-intent-confirmation-expired-event' +export { buildTrainingIntentConfirmationRejectedEvent } from './build-training-intent-confirmation-rejected-event' +export { buildTrainingIntentConfirmationRequestedEvent } from './build-training-intent-confirmation-requested-event' +export { buildTrainingIntentConfirmationRespondedEvent } from './build-training-intent-confirmation-responded-event' +export { buildTrainingMentorAssignedEvent } from './build-training-mentor-assigned-event' +export { buildTrainingMentorReassignedEvent } from './build-training-mentor-reassigned-event' +export { buildTrainingSessionPerformedEvent } from './build-training-session-performed-event' +export { buildTrainingSessionScheduledEvent } from './build-training-session-scheduled-event' +export { buildTrainingSoloPerformedEvent } from './build-training-solo-performed-event' +export { buildTrainingSoloScheduledEvent } from './build-training-solo-scheduled-event' +export { buildTrainingTestAssignedEvent } from './build-training-test-assigned-event' +export { buildTrainingTestCompletedEvent } from './build-training-test-completed-event' + diff --git a/libs/test-helpers/tsconfig.json b/libs/test-helpers/tsconfig.json new file mode 100644 index 0000000..bdf594c --- /dev/null +++ b/libs/test-helpers/tsconfig.json @@ -0,0 +1,23 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "module": "commonjs", + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "types": ["vitest"] + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/libs/test-helpers/tsconfig.lib.json b/libs/test-helpers/tsconfig.lib.json new file mode 100644 index 0000000..33eca2c --- /dev/null +++ b/libs/test-helpers/tsconfig.lib.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "declaration": true, + "types": ["node"] + }, + "include": ["src/**/*.ts"], + "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"] +} diff --git a/libs/test-helpers/tsconfig.spec.json b/libs/test-helpers/tsconfig.spec.json new file mode 100644 index 0000000..6d3be74 --- /dev/null +++ b/libs/test-helpers/tsconfig.spec.json @@ -0,0 +1,19 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"] + }, + "include": [ + "vite.config.ts", + "src/**/*.test.ts", + "src/**/*.spec.ts", + "src/**/*.test.tsx", + "src/**/*.spec.tsx", + "src/**/*.test.js", + "src/**/*.spec.js", + "src/**/*.test.jsx", + "src/**/*.spec.jsx", + "src/**/*.d.ts" + ] +} diff --git a/libs/test-helpers/vite.config.ts b/libs/test-helpers/vite.config.ts new file mode 100644 index 0000000..14af5f4 --- /dev/null +++ b/libs/test-helpers/vite.config.ts @@ -0,0 +1,58 @@ +/// +import { defineConfig } from 'vite'; + +import viteTsConfigPaths from 'vite-tsconfig-paths'; +import dts from 'vite-plugin-dts'; +import { joinPathFragments } from '@nx/devkit'; + +export default defineConfig({ + cacheDir: '../../node_modules/.vite/test-helpers', + + plugins: [ + dts({ + entryRoot: 'src', + tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'), + skipDiagnostics: true, + }), + + viteTsConfigPaths({ + root: '../../', + }), + ], + + // Uncomment this if you are using workers. + // worker: { + // plugins: [ + // viteTsConfigPaths({ + // root: '../../', + // }), + // ], + // }, + + // Configuration for building your library. + // See: https://vitejs.dev/guide/build.html#library-mode + build: { + lib: { + // Could also be a dictionary or array of multiple entry points. + entry: 'src/index.ts', + name: 'test-helpers', + fileName: 'index', + // Change this to the formats you want to support. + // Don't forgot to update your package.json as well. + formats: ['es', 'cjs'], + }, + rollupOptions: { + // External packages that should not be bundled into your library. + external: [], + }, + }, + + test: { + globals: true, + cache: { + dir: '../../node_modules/.vitest', + }, + environment: 'jsdom', + include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], + }, +});