diff --git a/plugins/nx-prisma/eslint.config.js b/plugins/nx-prisma/eslint.config.js index 6328eeb4..9586dfdf 100644 --- a/plugins/nx-prisma/eslint.config.js +++ b/plugins/nx-prisma/eslint.config.js @@ -8,7 +8,7 @@ module.exports = [ '@nx/dependency-checks': [ 'error', { - ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'], + ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}', '{projectRoot}/vite.config.{js,ts,mjs,mts}'], ignoredDependencies: ['prisma', 'ts-node', 'tsx'], }, ], diff --git a/plugins/nx-prisma/executors.json b/plugins/nx-prisma/executors.json index 4e0fb819..febb1fac 100644 --- a/plugins/nx-prisma/executors.json +++ b/plugins/nx-prisma/executors.json @@ -1,63 +1,63 @@ { "executors": { "deploy": { - "implementation": "./src/executors/deploy/executor", - "schema": "./src/executors/deploy/schema.json", + "implementation": "./dist/executors/deploy/executor", + "schema": "./dist/executors/deploy/schema.json", "description": "The migrate deploy command applies all pending migrations, and creates the database if it does not exist. Primarily used in non-development environments." }, "format": { - "implementation": "./src/executors/format/executor", - "schema": "./src/executors/format/schema.json", + "implementation": "./dist/executors/format/executor", + "schema": "./dist/executors/format/schema.json", "description": "Formats the Prisma Schema Language of the Prisma schema file." }, "generate": { - "implementation": "./src/executors/generate/executor", - "schema": "./src/executors/generate/schema.json", + "implementation": "./dist/executors/generate/executor", + "schema": "./dist/executors/generate/schema.json", "description": "The generate command generates assets like Prisma Client based on the generator and data model blocks defined in your schema.prisma file." }, "migrate": { - "implementation": "./src/executors/migrate/executor", - "schema": "./src/executors/migrate/schema.json", + "implementation": "./dist/executors/migrate/executor", + "schema": "./dist/executors/migrate/schema.json", "description": "The migrate dev command updates your database using migrations during development and creates the database if it does not exist." }, "pull": { - "implementation": "./src/executors/pull/executor", - "schema": "./src/executors/pull/schema.json", + "implementation": "./dist/executors/pull/executor", + "schema": "./dist/executors/pull/schema.json", "description": "The db pull command connects to your database and adds Prisma models to your Prisma schema that reflect the current database schema." }, "push": { - "implementation": "./src/executors/push/executor", - "schema": "./src/executors/push/schema.json", + "implementation": "./dist/executors/push/executor", + "schema": "./dist/executors/push/schema.json", "description": "The db push command pushes the state of your Prisma schema file to the database without using migrations. It creates the database if the database does not exist." }, "reset": { - "implementation": "./src/executors/reset/executor", - "schema": "./src/executors/reset/schema.json", + "implementation": "./dist/executors/reset/executor", + "schema": "./dist/executors/reset/schema.json", "description": "This command deletes and recreates the database, or performs a 'soft reset' by removing all data, tables, indexes, and other artifacts." }, "resolve": { - "implementation": "./src/executors/resolve/executor", - "schema": "./src/executors/resolve/schema.json", + "implementation": "./dist/executors/resolve/executor", + "schema": "./dist/executors/resolve/schema.json", "description": "The migrate resolve command allows you to solve migration history issues in production by marking a failed migration as already applied (supports baselining) or rolled back." }, "seed": { - "implementation": "./src/executors/seed/executor", - "schema": "./src/executors/seed/schema.json", + "implementation": "./dist/executors/seed/executor", + "schema": "./dist/executors/seed/schema.json", "description": "Seed your database." }, "status": { - "implementation": "./src/executors/status/executor", - "schema": "./src/executors/status/schema.json", + "implementation": "./dist/executors/status/executor", + "schema": "./dist/executors/status/schema.json", "description": "The prisma migrate status command looks up the migrations in migrations folder and the entries in the _prisma_migrations table and compiles information about the state of the migrations in your database." }, "studio": { - "implementation": "./src/executors/studio/executor", - "schema": "./src/executors/studio/schema.json", + "implementation": "./dist/executors/studio/executor", + "schema": "./dist/executors/studio/schema.json", "description": "The studio command allows you to interact with and manage your data interactively. It does this by starting a local web server with a web app configured with your project's data schema and records." }, "validate": { - "implementation": "./src/executors/validate/executor", - "schema": "./src/executors/validate/schema.json", + "implementation": "./dist/executors/validate/executor", + "schema": "./dist/executors/validate/schema.json", "description": "Validates the Prisma Schema Language of the Prisma schema file." } } diff --git a/plugins/nx-prisma/generators.json b/plugins/nx-prisma/generators.json index 1570ec7b..e2851a76 100644 --- a/plugins/nx-prisma/generators.json +++ b/plugins/nx-prisma/generators.json @@ -1,8 +1,8 @@ { "generators": { "configuration": { - "factory": "./src/generators/configuration/generator", - "schema": "./src/generators/configuration/schema.json", + "factory": "./dist/generators/configuration/generator", + "schema": "./dist/generators/configuration/schema.json", "description": "Add prisma configuration to a project." } } diff --git a/plugins/nx-prisma/jest.config.ts b/plugins/nx-prisma/jest.config.ts deleted file mode 100644 index e2fb8d6b..00000000 --- a/plugins/nx-prisma/jest.config.ts +++ /dev/null @@ -1,9 +0,0 @@ -export default { - displayName: 'nx-prisma', - preset: '../../jest.preset.js', - transform: { - '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }], - }, - moduleFileExtensions: ['ts', 'js', 'html'], - coverageDirectory: 'test-output/jest/coverage', -}; diff --git a/plugins/nx-prisma/package.json b/plugins/nx-prisma/package.json index 063b818d..afdb0c2d 100644 --- a/plugins/nx-prisma/package.json +++ b/plugins/nx-prisma/package.json @@ -30,6 +30,8 @@ }, "files": [ "dist", - "!**/*.tsbuildinfo" + "!**/*.tsbuildinfo", + "generators.json", + "executors.json" ] } diff --git a/plugins/nx-prisma/project.json b/plugins/nx-prisma/project.json index 65391448..7ab35a69 100644 --- a/plugins/nx-prisma/project.json +++ b/plugins/nx-prisma/project.json @@ -24,19 +24,16 @@ "input": "./plugins/nx-prisma/src", "glob": "**/*.d.ts", "output": "." - }, - { - "input": "./plugins/nx-prisma", - "glob": "generators.json", - "output": "." - }, - { - "input": "./plugins/nx-prisma", - "glob": "executors.json", - "output": "." } ] } + }, + "test": { + "executor": "@nx/vite:test", + "outputs": ["{options.reportsDirectory}"], + "options": { + "reportsDirectory": "../../coverage/plugins/nx-prisma" + } } } } diff --git a/plugins/nx-prisma/src/executors/deploy/executor.spec.ts b/plugins/nx-prisma/src/executors/deploy/executor.spec.ts index f0e97352..78c1e83a 100644 --- a/plugins/nx-prisma/src/executors/deploy/executor.spec.ts +++ b/plugins/nx-prisma/src/executors/deploy/executor.spec.ts @@ -3,12 +3,10 @@ import { expectCommandToHaveBeenCalled } from '../generate/executor.spec'; import executor from './executor'; import { DeployExecutorSchema } from './schema'; -jest.mock('@nx-tools/core', () => { - const originalModule = jest.requireActual('@nx-tools/core'); +vi.mock('@nx-tools/core', async (importOriginal) => { return { - __esModule: true, - ...originalModule, - getExecOutput: jest.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), + ...(await importOriginal()), + getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), }; }); diff --git a/plugins/nx-prisma/src/executors/format/executor.spec.ts b/plugins/nx-prisma/src/executors/format/executor.spec.ts index 471212ad..d9f2be55 100644 --- a/plugins/nx-prisma/src/executors/format/executor.spec.ts +++ b/plugins/nx-prisma/src/executors/format/executor.spec.ts @@ -3,12 +3,10 @@ import { expectCommandToHaveBeenCalled } from '../generate/executor.spec'; import executor from './executor'; import { FormatExecutorSchema } from './schema'; -jest.mock('@nx-tools/core', () => { - const originalModule = jest.requireActual('@nx-tools/core'); +vi.mock('@nx-tools/core', async (importOriginal) => { return { - __esModule: true, - ...originalModule, - getExecOutput: jest.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), + ...(await importOriginal()), + getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), }; }); diff --git a/plugins/nx-prisma/src/executors/generate/executor.spec.ts b/plugins/nx-prisma/src/executors/generate/executor.spec.ts index bc9311b1..36f3117d 100644 --- a/plugins/nx-prisma/src/executors/generate/executor.spec.ts +++ b/plugins/nx-prisma/src/executors/generate/executor.spec.ts @@ -3,12 +3,10 @@ import { ExecutorContext } from '@nx/devkit'; import executor from './executor'; import { GenerateExecutorSchema } from './schema'; -jest.mock('@nx-tools/core', () => { - const originalModule = jest.requireActual('@nx-tools/core'); +vi.mock('@nx-tools/core', async (importOriginal) => { return { - __esModule: true, - ...originalModule, - getExecOutput: jest.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), + ...(await importOriginal()), + getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), }; }); @@ -28,7 +26,7 @@ export const expectCommandToHaveBeenCalled = (cmd: string, args: string[]) => { describe('Generate Executor', () => { beforeEach(() => { - jest.spyOn(console, 'info').mockImplementation(() => true); + vi.spyOn(console, 'info').mockImplementation(() => true); }); it('can run with empty options', async () => { diff --git a/plugins/nx-prisma/src/executors/migrate/executor.spec.ts b/plugins/nx-prisma/src/executors/migrate/executor.spec.ts index 33bc6ad5..0fe0ca30 100644 --- a/plugins/nx-prisma/src/executors/migrate/executor.spec.ts +++ b/plugins/nx-prisma/src/executors/migrate/executor.spec.ts @@ -3,14 +3,7 @@ import { execSync } from 'node:child_process'; import executor from './executor'; import { MigrateExecutorSchema } from './schema'; -jest.mock('node:child_process', () => { - const originalModule = jest.requireActual('node:child_process'); - return { - __esModule: true, - ...originalModule, - execSync: jest.fn(), - }; -}); +vi.mock('node:child_process'); const context: Omit = { root: 'workspace-root', @@ -22,7 +15,11 @@ const context: Omit = { describe('Migrate Executor', () => { beforeEach(() => { - jest.spyOn(console, 'info').mockImplementation(() => true); + vi.spyOn(console, 'info').mockImplementation(() => true); + }); + + afterEach(() => { + vi.restoreAllMocks(); }); it('can run with empty options', async () => { diff --git a/plugins/nx-prisma/src/executors/pull/executor.spec.ts b/plugins/nx-prisma/src/executors/pull/executor.spec.ts index dfc44c6c..2b20e36c 100644 --- a/plugins/nx-prisma/src/executors/pull/executor.spec.ts +++ b/plugins/nx-prisma/src/executors/pull/executor.spec.ts @@ -3,12 +3,10 @@ import { expectCommandToHaveBeenCalled } from '../generate/executor.spec'; import executor from './executor'; import { PullExecutorSchema } from './schema'; -jest.mock('@nx-tools/core', () => { - const originalModule = jest.requireActual('@nx-tools/core'); +vi.mock('@nx-tools/core', async (importOriginal) => { return { - __esModule: true, - ...originalModule, - getExecOutput: jest.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), + ...(await importOriginal()), + getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), }; }); diff --git a/plugins/nx-prisma/src/executors/push/executor.spec.ts b/plugins/nx-prisma/src/executors/push/executor.spec.ts index 97f9e10e..057adc0a 100644 --- a/plugins/nx-prisma/src/executors/push/executor.spec.ts +++ b/plugins/nx-prisma/src/executors/push/executor.spec.ts @@ -3,12 +3,10 @@ import { expectCommandToHaveBeenCalled } from '../generate/executor.spec'; import executor from './executor'; import { PushExecutorSchema } from './schema'; -jest.mock('@nx-tools/core', () => { - const originalModule = jest.requireActual('@nx-tools/core'); +vi.mock('@nx-tools/core', async (importOriginal) => { return { - __esModule: true, - ...originalModule, - getExecOutput: jest.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), + ...(await importOriginal()), + getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), }; }); diff --git a/plugins/nx-prisma/src/executors/reset/executor.spec.ts b/plugins/nx-prisma/src/executors/reset/executor.spec.ts index 68def8b6..c8051fff 100644 --- a/plugins/nx-prisma/src/executors/reset/executor.spec.ts +++ b/plugins/nx-prisma/src/executors/reset/executor.spec.ts @@ -3,14 +3,7 @@ import { execSync } from 'node:child_process'; import executor from './executor'; import { ResetExecutorSchema } from './schema'; -jest.mock('node:child_process', () => { - const originalModule = jest.requireActual('node:child_process'); - return { - __esModule: true, - ...originalModule, - execSync: jest.fn(), - }; -}); +vi.mock('node:child_process'); const context: Omit = { root: 'workspace-root', @@ -22,7 +15,11 @@ const context: Omit = { describe('Reset Executor', () => { beforeEach(() => { - jest.spyOn(console, 'info').mockImplementation(() => true); + vi.spyOn(console, 'info').mockImplementation(() => true); + }); + + afterEach(() => { + vi.restoreAllMocks(); }); it('can run with empty options', async () => { diff --git a/plugins/nx-prisma/src/executors/resolve/executor.spec.ts b/plugins/nx-prisma/src/executors/resolve/executor.spec.ts index ecfc7ef4..240b88b1 100644 --- a/plugins/nx-prisma/src/executors/resolve/executor.spec.ts +++ b/plugins/nx-prisma/src/executors/resolve/executor.spec.ts @@ -3,15 +3,12 @@ import { expectCommandToHaveBeenCalled } from '../generate/executor.spec'; import executor from './executor'; import { ResolveExecutorSchema } from './schema'; -jest.mock('@nx-tools/core', () => { - const originalModule = jest.requireActual('@nx-tools/core'); +vi.mock('@nx-tools/core', async (importOriginal) => { return { - __esModule: true, - ...originalModule, - getExecOutput: jest.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), + ...(await importOriginal()), + getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), }; }); - const context: Omit = { root: 'workspace-root', projectsConfigurations: { version: 2, projects: { foo: { root: 'apps/foo' } } }, diff --git a/plugins/nx-prisma/src/executors/seed/executor.spec.ts b/plugins/nx-prisma/src/executors/seed/executor.spec.ts index 2b7e2dde..b3d33bc0 100644 --- a/plugins/nx-prisma/src/executors/seed/executor.spec.ts +++ b/plugins/nx-prisma/src/executors/seed/executor.spec.ts @@ -3,12 +3,10 @@ import { expectCommandToHaveBeenCalled } from '../generate/executor.spec'; import executor from './executor'; import { SeedExecutorSchema } from './schema'; -jest.mock('@nx-tools/core', () => { - const originalModule = jest.requireActual('@nx-tools/core'); +vi.mock('@nx-tools/core', async (importOriginal) => { return { - __esModule: true, - ...originalModule, - getExecOutput: jest.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), + ...(await importOriginal()), + getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), }; }); diff --git a/plugins/nx-prisma/src/executors/status/executor.spec.ts b/plugins/nx-prisma/src/executors/status/executor.spec.ts index abb1a3b1..d414a589 100644 --- a/plugins/nx-prisma/src/executors/status/executor.spec.ts +++ b/plugins/nx-prisma/src/executors/status/executor.spec.ts @@ -3,12 +3,10 @@ import { expectCommandToHaveBeenCalled } from '../generate/executor.spec'; import executor from './executor'; import { StatusExecutorSchema } from './schema'; -jest.mock('@nx-tools/core', () => { - const originalModule = jest.requireActual('@nx-tools/core'); +vi.mock('@nx-tools/core', async (importOriginal) => { return { - __esModule: true, - ...originalModule, - getExecOutput: jest.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), + ...(await importOriginal()), + getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), }; }); diff --git a/plugins/nx-prisma/src/executors/studio/executor.spec.ts b/plugins/nx-prisma/src/executors/studio/executor.spec.ts index 358769a5..16186678 100644 --- a/plugins/nx-prisma/src/executors/studio/executor.spec.ts +++ b/plugins/nx-prisma/src/executors/studio/executor.spec.ts @@ -3,12 +3,10 @@ import { expectCommandToHaveBeenCalled } from '../generate/executor.spec'; import executor from './executor'; import { StudioExecutorSchema } from './schema'; -jest.mock('@nx-tools/core', () => { - const originalModule = jest.requireActual('@nx-tools/core'); +vi.mock('@nx-tools/core', async (importOriginal) => { return { - __esModule: true, - ...originalModule, - getExecOutput: jest.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), + ...(await importOriginal()), + getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), }; }); diff --git a/plugins/nx-prisma/src/executors/validate/executor.spec.ts b/plugins/nx-prisma/src/executors/validate/executor.spec.ts index 0cbc0163..26e4f592 100644 --- a/plugins/nx-prisma/src/executors/validate/executor.spec.ts +++ b/plugins/nx-prisma/src/executors/validate/executor.spec.ts @@ -3,12 +3,10 @@ import { expectCommandToHaveBeenCalled } from '../generate/executor.spec'; import executor from './executor'; import { ValidateExecutorSchema } from './schema'; -jest.mock('@nx-tools/core', () => { - const originalModule = jest.requireActual('@nx-tools/core'); +vi.mock('@nx-tools/core', async (importOriginal) => { return { - __esModule: true, - ...originalModule, - getExecOutput: jest.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), + ...(await importOriginal()), + getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })), }; }); diff --git a/plugins/nx-prisma/tsconfig.lib.json b/plugins/nx-prisma/tsconfig.lib.json index d7a99538..693adfdc 100644 --- a/plugins/nx-prisma/tsconfig.lib.json +++ b/plugins/nx-prisma/tsconfig.lib.json @@ -14,5 +14,18 @@ "path": "../../packages/core/tsconfig.lib.json" } ], - "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"] + "exclude": [ + "vite.config.ts", + "vite.config.mts", + "vitest.config.ts", + "vitest.config.mts", + "src/**/*.test.ts", + "src/**/*.spec.ts", + "src/**/*.test.tsx", + "src/**/*.spec.tsx", + "src/**/*.test.js", + "src/**/*.spec.js", + "src/**/*.test.jsx", + "src/**/*.spec.jsx" + ] } diff --git a/plugins/nx-prisma/tsconfig.spec.json b/plugins/nx-prisma/tsconfig.spec.json index c67ac295..8c71d9e6 100644 --- a/plugins/nx-prisma/tsconfig.spec.json +++ b/plugins/nx-prisma/tsconfig.spec.json @@ -1,10 +1,24 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "outDir": "./out-tsc/jest", - "types": ["jest", "node"] + "outDir": "./out-tsc/vitest", + "types": ["vitest/globals", "vitest/importMeta", "vite/client", "node", "vitest"] }, - "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"], + "include": [ + "vite.config.ts", + "vite.config.mts", + "vitest.config.ts", + "vitest.config.mts", + "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" + ], "references": [ { "path": "./tsconfig.lib.json" diff --git a/plugins/nx-prisma/vite.config.ts b/plugins/nx-prisma/vite.config.ts new file mode 100644 index 00000000..64235406 --- /dev/null +++ b/plugins/nx-prisma/vite.config.ts @@ -0,0 +1,19 @@ +import { defineConfig } from 'vite'; + +export default defineConfig({ + root: __dirname, + cacheDir: '../../node_modules/.vite/plugins/nx-prisma', + plugins: [], + // Uncomment this if you are using workers. + // worker: { + // plugins: [ nxViteTsPaths() ], + // }, + test: { + watch: false, + globals: true, + environment: 'jsdom', + include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], + reporters: ['default'], + coverage: { reportsDirectory: '../../coverage/plugins/nx-prisma', provider: 'v8' }, + }, +});