Skip to content

Commit

Permalink
chore: use swc instead of ts-jest for some packages (#11848)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolg42 committed Feb 25, 2022
1 parent fbc6142 commit db7d42f
Show file tree
Hide file tree
Showing 27 changed files with 314 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codesee-arch-diagram.yml
Expand Up @@ -47,7 +47,7 @@ jobs:
step: mapUpload
api_token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }}
github_ref: ${{ github.ref }}

- name: Insights
id: insights
uses: Codesee-io/codesee-map-action@latest
Expand Down
2 changes: 2 additions & 0 deletions helpers/compile/plugins/depCheckPlugin.ts
Expand Up @@ -17,6 +17,8 @@ const unusedIgnore = [
'typescript',
'ts-node',
'ts-jest',
'@swc/core',
'@swc/jest',
'jest',

// these are missing 3rd party deps
Expand Down
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -73,6 +73,7 @@
"prettier": "2.5.1",
"redis": "3.1.2",
"redis-lock": "0.1.4",
"regenerator-runtime": "^0.13.9",
"resolve": "1.21.0",
"safe-buffer": "5.2.1",
"semver": "7.3.5",
Expand All @@ -86,9 +87,9 @@
"util": "0.12.4"
},
"lint-staged": {
"*.{md,yml,yaml,json}": "prettier --write",
"*.{md,yml,json}": "prettier --write",
"*.{js,ts}": [
"eslint",
"eslint --fix",
"prettier --write"
]
}
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/jest.config.js
@@ -1,5 +1,7 @@
module.exports = {
preset: 'ts-jest',
transform: {
'^.+\\.ts$': '@swc/jest',
},
testEnvironment: 'node',
testMatch: ['**/src/__tests__/**/*.test.ts'],
collectCoverage: process.env.CI ? true : false,
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/package.json
Expand Up @@ -74,6 +74,8 @@
"@prisma/sdk": "workspace:*",
"@prisma/studio": "0.458.0",
"@prisma/studio-server": "0.458.0",
"@swc/core": "1.2.141",
"@swc/jest": "0.2.17",
"@types/debug": "4.1.7",
"@types/fs-extra": "9.0.13",
"@types/jest": "27.4.0",
Expand Down Expand Up @@ -104,7 +106,6 @@
"rimraf": "3.0.2",
"strip-ansi": "6.0.1",
"tempy": "1.0.1",
"ts-jest": "27.1.3",
"typescript": "4.5.4"
},
"scripts": {
Expand Down
12 changes: 10 additions & 2 deletions packages/cli/src/Init.ts
@@ -1,7 +1,15 @@
import type { ConnectorType } from '@prisma/generator-helper'
import type { Command } from '@prisma/sdk'
import { arg, canConnectToDatabase, format, getCommandWithExecutor, HelpError, link, logger } from '@prisma/sdk'
import { protocolToConnectorType } from '@prisma/sdk/dist/convertCredentials'
import {
arg,
canConnectToDatabase,
format,
getCommandWithExecutor,
HelpError,
link,
logger,
protocolToConnectorType,
} from '@prisma/sdk'
import chalk from 'chalk'
import dotenv from 'dotenv'
import fs from 'fs'
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/bin.ts
Expand Up @@ -43,7 +43,6 @@ import { Init } from './Init'
When running bin.ts with ts-node with DEBUG="*"
This error shows and blocks the execution
Quick hack is to comment the Studio import and usage to use the CLI without building it...
prisma:cli Error: Cannot find module '@prisma/sdk'
prisma:cli Require stack:
prisma:cli - /Users/j42/Dev/prisma-meow/node_modules/.pnpm/@prisma+studio-pcw@0.456.0/node_modules/@prisma/studio-pcw/dist/index.js
Expand Down
4 changes: 3 additions & 1 deletion packages/engine-core/jest.config.js
@@ -1,5 +1,7 @@
module.exports = {
preset: 'ts-jest',
transform: {
'^.+\\.ts$': '@swc/jest',
},
testEnvironment: 'node',
testMatch: ['**/src/__tests__/**/*.test.ts'],
collectCoverage: process.env.CI ? true : false,
Expand Down
3 changes: 2 additions & 1 deletion packages/engine-core/package.json
Expand Up @@ -19,12 +19,13 @@
],
"bugs": "https://github.com/prisma/prisma/issues",
"devDependencies": {
"@swc/core": "1.2.141",
"@swc/jest": "0.2.17",
"@types/jest": "27.4.0",
"@types/node": "12.20.46",
"esbuild": "0.13.14",
"jest": "27.5.1",
"jest-junit": "13.0.0",
"ts-jest": "27.1.3",
"typescript": "4.5.4"
},
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion packages/generator-helper/jest.config.js
@@ -1,5 +1,7 @@
module.exports = {
preset: 'ts-jest',
transform: {
'^.+\\.ts$': '@swc/jest',
},
testEnvironment: 'node',
testMatch: ['**/src/__tests__/**/*.test.ts'],
collectCoverage: process.env.CI ? true : false,
Expand Down
5 changes: 3 additions & 2 deletions packages/generator-helper/package.json
Expand Up @@ -28,16 +28,17 @@
"scripts": {
"dev": "DEV=true node -r esbuild-register helpers/build.ts",
"build": "node -r esbuild-register helpers/build.ts",
"prepublishOnly": "pnpm run build && pnpm run test",
"prepublishOnly": "pnpm run build",
"test": "jest"
},
"devDependencies": {
"@swc/core": "1.2.141",
"@swc/jest": "0.2.17",
"@types/jest": "27.4.0",
"@types/node": "12.20.46",
"esbuild": "0.13.14",
"jest": "27.5.1",
"jest-junit": "13.0.0",
"ts-jest": "27.1.3",
"ts-node": "10.4.0",
"typescript": "4.5.4"
},
Expand Down
4 changes: 3 additions & 1 deletion packages/integration-tests/jest.config.js
@@ -1,5 +1,7 @@
module.exports = {
preset: 'ts-jest',
transform: {
'^.+\\.ts$': '@swc/jest',
},
testEnvironment: 'node',
testMatch: ['**/src/__tests__/**/*.test.ts'],
collectCoverage: process.env.CI ? true : false,
Expand Down
3 changes: 2 additions & 1 deletion packages/integration-tests/package.json
Expand Up @@ -15,6 +15,8 @@
"devDependencies": {
"@prisma/sdk": "workspace:*",
"@sindresorhus/slugify": "1.1.2",
"@swc/core": "1.2.141",
"@swc/jest": "0.2.17",
"@types/jest": "27.4.0",
"@types/mssql": "7.1.5",
"@types/node": "12.20.46",
Expand All @@ -34,7 +36,6 @@
"string-hash": "1.1.3",
"strip-ansi": "6.0.1",
"tempy": "1.0.1",
"ts-jest": "27.1.3",
"ts-node": "10.4.0",
"typescript": "4.5.4",
"verror": "1.10.1"
Expand Down
4 changes: 3 additions & 1 deletion packages/migrate/jest.config.js
@@ -1,5 +1,7 @@
module.exports = {
preset: 'ts-jest',
transform: {
'^.+\\.ts$': '@swc/jest',
},
testEnvironment: 'node',
testMatch: ['**/src/__tests__/**/*.test.ts'],
collectCoverage: process.env.CI ? true : false,
Expand Down
3 changes: 2 additions & 1 deletion packages/migrate/package.json
Expand Up @@ -23,6 +23,8 @@
"@prisma/engines-version": "3.11.0-10.9560988356b774751f83944ede75acb2f45f8794",
"@prisma/generator-helper": "workspace:*",
"@prisma/sdk": "workspace:*",
"@swc/core": "1.2.141",
"@swc/jest": "0.2.17",
"@types/jest": "27.4.0",
"@types/node": "12.20.46",
"@types/pg": "8.6.4",
Expand All @@ -35,7 +37,6 @@
"make-dir": "3.1.0",
"mock-stdin": "1.0.0",
"tempy": "1.0.1",
"ts-jest": "27.1.3",
"typescript": "4.5.4"
},
"peerDependencies": {
Expand Down
34 changes: 17 additions & 17 deletions packages/migrate/src/__tests__/DbPull.test.ts
Expand Up @@ -57,7 +57,7 @@ describe('common/sqlite', () => {
ctx.fixture('introspection/sqlite')
const introspect = new DbPull()
const result = introspect.parse(['--print', '--url', 'invalidstring'])
await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`Unknown database type invalidstring:`)
await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`Unknown protocol invalidstring:`)
expect(ctx.mocked['console.log'].mock.calls.join('\n')).toMatchSnapshot()
expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``)
expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(``)
Expand Down Expand Up @@ -107,9 +107,9 @@ describe('common/sqlite', () => {
const introspect = new DbPull()
const result = introspect.parse(['--print', '--url', 'postgresql://root:prisma@/prisma'])
await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`
Error parsing connection string: empty host in database URL
Error parsing connection string: empty host in database URL
`)
`)
expect(ctx.mocked['console.log'].mock.calls.join('\n')).toMatchSnapshot()
expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``)
expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(``)
Expand Down Expand Up @@ -229,18 +229,18 @@ describe('common/sqlite', () => {
const result = DbPull.new().parse([])
await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`
P4001 The introspected database was empty:
P4001 The introspected database was empty:
prisma db pull could not create any models in your schema.prisma file and you will not be able to generate Prisma Client with the prisma generate command.
prisma db pull could not create any models in your schema.prisma file and you will not be able to generate Prisma Client with the prisma generate command.
To fix this, you have two options:
To fix this, you have two options:
- manually create a table in your database.
- make sure the database connection URL inside the datasource block in schema.prisma points to a database that is not empty (it must contain at least one table).
- manually create a table in your database.
- make sure the database connection URL inside the datasource block in schema.prisma points to a database that is not empty (it must contain at least one table).
Then you can run prisma db pull again.
Then you can run prisma db pull again.
`)
`)
expect(ctx.mocked['console.log'].mock.calls.join('\n')).toMatchInlineSnapshot(``)
expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(`
Prisma schema loaded from prisma/schema.prisma
Expand All @@ -257,18 +257,18 @@ describe('common/sqlite', () => {
const result = DbPull.new().parse([])
await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`
P4001 The introspected database was empty:
P4001 The introspected database was empty:
prisma db pull could not create any models in your schema.prisma file and you will not be able to generate Prisma Client with the prisma generate command.
prisma db pull could not create any models in your schema.prisma file and you will not be able to generate Prisma Client with the prisma generate command.
To fix this, you have two options:
To fix this, you have two options:
- manually create a table in your database.
- make sure the database connection URL inside the datasource block in schema.prisma points to a database that is not empty (it must contain at least one table).
- manually create a table in your database.
- make sure the database connection URL inside the datasource block in schema.prisma points to a database that is not empty (it must contain at least one table).
Then you can run prisma db pull again.
Then you can run prisma db pull again.
`)
`)
expect(ctx.mocked['console.log'].mock.calls.join('\n')).toMatchInlineSnapshot(``)
expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(`
Prisma schema loaded from prisma/schema.prisma
Expand Down
1 change: 0 additions & 1 deletion packages/migrate/src/__tests__/MigrateResolve.test.ts
@@ -1,7 +1,6 @@
import { jestConsoleContext, jestContext } from '@prisma/sdk'

import { MigrateResolve } from '../commands/MigrateResolve'
import { SetupParams, setupPostgres, tearDownPostgres } from '../utils/setupPostgres'

const ctx = jestContext.new().add(jestConsoleContext()).assemble()

Expand Down
2 changes: 1 addition & 1 deletion packages/migrate/src/commands/DbPull.ts
Expand Up @@ -12,8 +12,8 @@ import {
IntrospectionEngine,
link,
loadEnvFile,
protocolToConnectorType,
} from '@prisma/sdk'
import { protocolToConnectorType } from '@prisma/sdk/dist/convertCredentials'
import chalk from 'chalk'
import fs from 'fs'
import path from 'path'
Expand Down
37 changes: 19 additions & 18 deletions packages/migrate/src/commands/MigrateDiff.ts
Expand Up @@ -9,37 +9,38 @@ import type { EngineArgs, EngineResults } from '../types'
import { MigrateDiffNeedsPreviewFeatureFlagError } from '../utils/errors'

const debug = Debug('prisma:migrate:diff')
export class MigrateDiff implements Command {
public static new(): MigrateDiff {
return new MigrateDiff()
}

public static helpOptions = format(
`${chalk.bold('Usage')}
const helpOptions = format(
`${chalk.bold('Usage')}
${chalk.dim('$')} prisma migrate diff --preview-feature [options]
${chalk.dim('$')} prisma migrate diff --preview-feature [options]
${chalk.bold('Options')}
-h, --help Display this help message
-h, --help Display this help message
${chalk.italic('From and To inputs (1 `--from-...` and 1 `--to-...` must be provided):')}
--from-url / --to-url A datasource URL
--from-empty / --to-empty Flag to assume from or to is an empty datamodel
--from-schema-datamodel / --to-schema-datamodel Path to a Prisma schema file, uses the datamodel for the diff
--from-url / --to-url A datasource URL
--from-empty / --to-empty Flag to assume from or to is an empty datamodel
--from-schema-datamodel / --to-schema-datamodel Path to a Prisma schema file, uses the datamodel for the diff
--from-schema-datasource / --to-schema-datasource Path to a Prisma schema file, uses the datasource url for the diff
--from-migrations / --to-migrations Path to the Prisma Migrate migrations directory
--from-migrations / --to-migrations Path to the Prisma Migrate migrations directory
${chalk.italic('Shadow database (only required if using --from-migrations or --to-migrations):')}
--shadow-database-url URL for the shadow database
--shadow-database-url URL for the shadow database
${chalk.italic('Output format:')}
--script Render a SQL script to stdout instead of the default human readable summary (not supported on MongoDB)
--script Render a SQL script to stdout instead of the default human readable summary (not supported on MongoDB)
${chalk.bold('Flag')}
--preview-feature Run Preview Prisma commands`,
)
--preview-feature Run Preview Prisma commands`,
)

export class MigrateDiff implements Command {
public static new(): MigrateDiff {
return new MigrateDiff()
}

private static help = format(`
${
Expand All @@ -64,7 +65,7 @@ The default output is a human readable diff, it can be rendered as SQL using \`-
See the documentation for more information ${link('https://pris.ly/d/migrate-diff')}
${this.helpOptions}
${helpOptions}
${chalk.bold('Examples')}
From database to database as summary
Expand Down Expand Up @@ -257,7 +258,7 @@ ${chalk.bold('Examples')}

public help(error?: string): string | HelpError {
if (error) {
throw new HelpError(`\n${error}\n\n${MigrateDiff.helpOptions}`)
throw new HelpError(`\n${error}\n\n${helpOptions}`)
}
return MigrateDiff.help
}
Expand Down
4 changes: 3 additions & 1 deletion packages/sdk/jest.config.js
@@ -1,5 +1,7 @@
module.exports = {
preset: 'ts-jest',
transform: {
'^.+\\.ts$': '@swc/jest',
},
testEnvironment: 'node',
testMatch: ['**/src/__tests__/**/*.test.ts'],
collectCoverage: process.env.CI ? true : false,
Expand Down
5 changes: 3 additions & 2 deletions packages/sdk/package.json
Expand Up @@ -21,7 +21,7 @@
"scripts": {
"dev": "DEV=true node -r esbuild-register helpers/build.ts",
"build": "node -r esbuild-register helpers/build.ts",
"prepublishOnly": "pnpm run build && pnpm run test",
"prepublishOnly": "pnpm run build",
"test": "jest --verbose"
},
"files": [
Expand All @@ -30,6 +30,8 @@
"scripts"
],
"devDependencies": {
"@swc/core": "1.2.141",
"@swc/jest": "0.2.17",
"@types/jest": "27.4.0",
"@types/node": "12.20.46",
"@types/resolve": "1.20.1",
Expand All @@ -38,7 +40,6 @@
"esbuild": "0.13.14",
"jest": "27.5.1",
"jest-junit": "13.0.0",
"ts-jest": "27.1.3",
"ts-node": "10.4.0",
"typescript": "4.5.4"
},
Expand Down

0 comments on commit db7d42f

Please sign in to comment.