Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(nx-prisma): migrate tests from jest to vitest #1175

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/nx-prisma/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
],
Expand Down
48 changes: 24 additions & 24 deletions plugins/nx-prisma/executors.json
Original file line number Diff line number Diff line change
@@ -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."
}
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/nx-prisma/generators.json
Original file line number Diff line number Diff line change
@@ -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."
}
}
Expand Down
9 changes: 0 additions & 9 deletions plugins/nx-prisma/jest.config.ts

This file was deleted.

4 changes: 3 additions & 1 deletion plugins/nx-prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
},
"files": [
"dist",
"!**/*.tsbuildinfo"
"!**/*.tsbuildinfo",
"generators.json",
"executors.json"
]
}
17 changes: 7 additions & 10 deletions plugins/nx-prisma/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
8 changes: 3 additions & 5 deletions plugins/nx-prisma/src/executors/deploy/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof import('@nx-tools/core')>()),
getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })),
};
});

Expand Down
8 changes: 3 additions & 5 deletions plugins/nx-prisma/src/executors/format/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof import('@nx-tools/core')>()),
getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })),
};
});

Expand Down
10 changes: 4 additions & 6 deletions plugins/nx-prisma/src/executors/generate/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof import('@nx-tools/core')>()),
getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })),
};
});

Expand All @@ -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 () => {
Expand Down
15 changes: 6 additions & 9 deletions plugins/nx-prisma/src/executors/migrate/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExecutorContext, 'nxJsonConfiguration' | 'projectGraph'> = {
root: 'workspace-root',
Expand All @@ -22,7 +15,11 @@ const context: Omit<ExecutorContext, 'nxJsonConfiguration' | 'projectGraph'> = {

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 () => {
Expand Down
8 changes: 3 additions & 5 deletions plugins/nx-prisma/src/executors/pull/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof import('@nx-tools/core')>()),
getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })),
};
});

Expand Down
8 changes: 3 additions & 5 deletions plugins/nx-prisma/src/executors/push/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof import('@nx-tools/core')>()),
getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })),
};
});

Expand Down
15 changes: 6 additions & 9 deletions plugins/nx-prisma/src/executors/reset/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExecutorContext, 'nxJsonConfiguration' | 'projectGraph'> = {
root: 'workspace-root',
Expand All @@ -22,7 +15,11 @@ const context: Omit<ExecutorContext, 'nxJsonConfiguration' | 'projectGraph'> = {

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 () => {
Expand Down
9 changes: 3 additions & 6 deletions plugins/nx-prisma/src/executors/resolve/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof import('@nx-tools/core')>()),
getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })),
};
});

const context: Omit<ExecutorContext, 'nxJsonConfiguration' | 'projectGraph'> = {
root: 'workspace-root',
projectsConfigurations: { version: 2, projects: { foo: { root: 'apps/foo' } } },
Expand Down
8 changes: 3 additions & 5 deletions plugins/nx-prisma/src/executors/seed/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof import('@nx-tools/core')>()),
getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })),
};
});

Expand Down
8 changes: 3 additions & 5 deletions plugins/nx-prisma/src/executors/status/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof import('@nx-tools/core')>()),
getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })),
};
});

Expand Down
8 changes: 3 additions & 5 deletions plugins/nx-prisma/src/executors/studio/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof import('@nx-tools/core')>()),
getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })),
};
});

Expand Down
8 changes: 3 additions & 5 deletions plugins/nx-prisma/src/executors/validate/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof import('@nx-tools/core')>()),
getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })),
};
});

Expand Down
Loading
Loading