Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Jul 2, 2020
1 parent f8cf6af commit 6c7200f
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`blog example should succeed: blog example should succeed 1`] = `"success"`;
exports[`runtime blog: blog example should succeed 1`] = `"success"`;

exports[`blog-env example should not succeed: blog-env example should not succeed 1`] = `
exports[`runtime blog-env: blog-env example should not succeed 1`] = `
"error: Environment variable not found: SQLITE_URL.
--> schema.prisma:3
|
Expand All @@ -13,11 +13,11 @@ exports[`blog-env example should not succeed: blog-env example should not succee
Validation Error Count: 1"
`;

exports[`blog-env-postgresql example should succeed: blog-env-postgresql example should succeed 1`] = `"success"`;
exports[`runtime blog-env-postgresql: blog-env-postgresql example should succeed 1`] = `"success"`;

exports[`chmod example should succeed: chmod example should succeed 1`] = `"success"`;
exports[`runtime chmod: chmod example should succeed 1`] = `"success"`;

exports[`corruption example should not succeed: corruption example should not succeed 1`] = `
exports[`runtime corruption: corruption example should not succeed 1`] = `
"
Invalid \`prisma.user.findMany()\` invocation in
Expand All @@ -28,11 +28,11 @@ Make sure that the engine binary at is not corrupt.
"
`;

exports[`enums example should succeed: enums example should succeed 1`] = `"success"`;
exports[`runtime enums: enums example should succeed 1`] = `"success"`;

exports[`hooks example should succeed: hooks example should succeed 1`] = `"success"`;
exports[`runtime hooks: hooks example should succeed 1`] = `"success"`;

exports[`incorrect-column-type example should not succeed: incorrect-column-type example should not succeed 1`] = `
exports[`runtime incorrect-column-type: incorrect-column-type example should not succeed 1`] = `
"
Invalid \`prisma.user.findMany()\` invocation in
Expand All @@ -41,7 +41,7 @@ Invalid \`prisma.user.findMany()\` invocation in
Attempted to serialize scalar '123' with incompatible type 'String'"
`;

exports[`missing-binary example should not succeed: missing-binary example should not succeed 1`] = `
exports[`runtime missing-binary: missing-binary example should not succeed 1`] = `
"
Invalid \`prisma.user.findMany()\` invocation in
Expand Down Expand Up @@ -84,7 +84,7 @@ Then run \\"prisma generate\\" for your changes to take effect.
Read more about deploying Prisma Client: https:"
`;

exports[`missing-binary-native example should not succeed: missing-binary-native example should not succeed 1`] = `
exports[`runtime missing-binary-native: missing-binary-native example should not succeed 1`] = `
"
Invalid \`prisma.user.findMany()\` invocation in
Expand Down Expand Up @@ -123,7 +123,7 @@ but something went wrong. That's suboptimal.
Please create an issue at https:"
`;

exports[`missing-column example should not succeed: missing-column example should not succeed 1`] = `
exports[`runtime missing-column: missing-column example should not succeed 1`] = `
"
Invalid \`prisma.user.findMany()\` invocation in
Expand All @@ -133,7 +133,7 @@ Invalid \`prisma.user.findMany()\` invocation in
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(SqliteFailure(Error { code: Unknown, extended_code: 1 }, Some(\\"no such column: dev.User.name\\"))) })"
`;

exports[`missing-table example should not succeed: missing-table example should not succeed 1`] = `
exports[`runtime missing-table: missing-table example should not succeed 1`] = `
"
Invalid \`prisma.user.findMany()\` invocation in
Expand All @@ -143,8 +143,8 @@ Invalid \`prisma.user.findMany()\` invocation in
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(SqliteFailure(Error { code: Unknown, extended_code: 1 }, Some(\\"no such table: dev.User\\"))) })"
`;

exports[`new-line example should succeed: new-line example should succeed 1`] = `"success"`;
exports[`runtime new-line: new-line example should succeed 1`] = `"success"`;

exports[`restart example should succeed: restart example should succeed 1`] = `"success"`;
exports[`runtime restart: restart example should succeed 1`] = `"success"`;

exports[`transaction example should succeed: transaction example should succeed 1`] = `"success"`;
exports[`runtime transaction: transaction example should succeed 1`] = `"success"`;
61 changes: 42 additions & 19 deletions src/packages/client/src/__tests__/runtime-tests/runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { generateInFolder } from '../../utils/generateInFolder'
import { promisify } from 'util'
import rimraf from 'rimraf'
import stripAnsi from 'strip-ansi'
import { getPackedPackage } from '@prisma/sdk'
const del = promisify(rimraf)

jest.setTimeout(35000)
Expand All @@ -13,27 +14,42 @@ jest.setTimeout(35000)
process.setMaxListeners(100)

let subDirs = getSubDirs(__dirname)
const folderFilter = process.argv.length > 3 ? process.argv[3] : null
if (folderFilter) {
subDirs = subDirs.filter((dir) => dir.includes(folderFilter))
console.log(
`As ${folderFilter} is provided, only ${subDirs.join(
', ',
)} is being tested`,
)
const folderFilter = process.argv.length === 4 ? process.argv[3] : null

if (
folderFilter &&
!['--', '-u'].includes(folderFilter) &&
/[\w-]+/.test(folderFilter)
) {
const dirsLeft = subDirs.filter((dir) => dir.includes(folderFilter))
if (dirsLeft.length > 0) {
subDirs = dirsLeft
console.log(
`As ${folderFilter} is provided, only ${subDirs.join(
', ',
)} is being tested`,
)
}
}

console.log({ subDirs })
subDirs = subDirs.map((d) => path.relative(__dirname, d))

for (const dir of subDirs) {
const nodeModules = path.join(dir, 'node_modules')
const testName = path.basename(dir)
const shouldSucceed = shouldTestSucceed(dir)
let packageSource: string
beforeAll(async () => {
packageSource = (await getPackedPackage('@prisma/client')) as string
})

const testTitle = `${testName} example should${
shouldSucceed ? '' : ' not'
} succeed`
test.concurrent(testTitle, async () => {
describe('runtime', () => {
test.each(subDirs)('%s', async (dir) => {
dir = path.join(__dirname, dir)
const nodeModules = path.join(dir, 'node_modules')
const testName = path.basename(dir)
const shouldSucceed = shouldTestSucceed(dir)

const testTitle = `${testName} example should${
shouldSucceed ? '' : ' not'
} succeed`
// test.concurrent(testTitle, async (expect) => {
if (fs.existsSync(nodeModules)) {
await del(nodeModules)
}
Expand All @@ -44,6 +60,7 @@ for (const dir of subDirs) {
projectDir: dir,
useLocalRuntime: false,
transpile: true,
packageSource,
})

if (envVars) {
Expand All @@ -64,12 +81,18 @@ for (const dir of subDirs) {
// https://regex101.com/r/GPVRYg/1/
// remove the paths, so the tests can succeed on any machine
expect(
stripAnsi(e.message).replace(/(\/[\/\S+]+)/gm, ''),
stripAnsi(e.message)
.replace(/(\/[\/\S+]+)/gm, '')
.replace(/current\s+platform\s+\"\S\"/gim, 'current platform')
.replace(/the\s+platform\s+\"\S\"/gim, 'the platform X'),
).toMatchSnapshot(testTitle)
}
}
// })
})
}
})
// for (const dir of subDirs) {
// }

function getSubDirs(dir: string): string[] {
const files = fs.readdirSync(dir)
Expand Down
7 changes: 7 additions & 0 deletions src/packages/client/src/__tests__/types/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ import * as ts from 'typescript'
import { generateInFolder } from '../../utils/generateInFolder'
import rimraf from 'rimraf'
import { promisify } from 'util'
import { getPackedPackage } from '@prisma/sdk'
const del = promisify(rimraf)

jest.setTimeout(30000)

let packageSource: string
beforeAll(async () => {
packageSource = (await getPackedPackage('@prisma/client')) as string
})

describe('valid types', () => {
const subDirs = getSubDirs(__dirname)
for (const dir of subDirs) {
Expand All @@ -29,6 +35,7 @@ describe('valid types', () => {
projectDir: dir,
useLocalRuntime: false,
transpile: true,
packageSource,
})
const filePath = path.join(dir, 'index.ts')
expect(() => compileFile(filePath)).not.toThrow()
Expand Down
15 changes: 14 additions & 1 deletion src/packages/client/src/utils/generateInFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ import { generateClient } from '../generation/generateClient'
import { getPackedPackage } from '@prisma/sdk'
import Debug from '@prisma/debug'
const debug = Debug('generateInFolder')
import copy from '@apexearth/copy'

export interface GenerateInFolderOptions {
projectDir: string
useLocalRuntime?: boolean
transpile?: boolean
packageSource?: string
}

export async function generateInFolder({
projectDir,
useLocalRuntime = false,
transpile = true,
packageSource,
}: GenerateInFolderOptions): Promise<number> {
const before = performance.now()
if (!projectDir) {
Expand All @@ -49,7 +52,17 @@ export async function generateInFolder({
: path.join(projectDir, '@prisma/client')

if (transpile) {
await getPackedPackage('@prisma/client', outputDir)
if (packageSource) {
await copy({
from: packageSource, // when using yarn pack and extracting it, it includes a folder called "package"
to: outputDir,
recursive: true,
parallelJobs: 20,
overwrite: true,
})
} else {
await getPackedPackage('@prisma/client', outputDir)
}
}

const platform = await getPlatform()
Expand Down
38 changes: 21 additions & 17 deletions src/packages/sdk/src/getPackedPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ const del = promisify(rimraf)

export async function getPackedPackage(
name: string,
target: string,
target?: string,
packageDir?: string,
): Promise<void> {
if (!target) {
throw new Error(`Error in getPackage: Please provide a target`)
}
): Promise<string | void> {
packageDir =
packageDir ||
resolvePkg(name, { cwd: __dirname }) ||
Expand Down Expand Up @@ -61,18 +58,25 @@ export async function getPackedPackage(

await del(archivePath)

// make target dir
await makeDir(target)
/**
* Only if a target is provided, perform the copy
*/
if (target) {
// make target dir
await makeDir(target)

// copy stuff over
await copy({
from: path.join(tmpDir, 'package'), // when using yarn pack and extracting it, it includes a folder called "package"
to: target,
recursive: true,
parallelJobs: 20,
overwrite: true,
})
// copy stuff over
await copy({
from: path.join(tmpDir, 'package'), // when using yarn pack and extracting it, it includes a folder called "package"
to: target,
recursive: true,
parallelJobs: 20,
overwrite: true,
})

// delete tmp dir
await del(tmpDir)
}

// delete tmp dir
await del(tmpDir)
return path.join(tmpDir, 'package')
}
2 changes: 0 additions & 2 deletions src/scripts/ci/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,12 @@ async function getNewPatchDevVersion(
const newVersion = `2.${minor}.${newPatch}`
const versions = [...(await getAllVersions(packages, 'dev', newVersion))]
const maxIncrement = getMaxPatchVersionIncrement(versions)
console.log({ versions, maxIncrement, newVersion })

return `${newVersion}-dev.${maxIncrement + 1}`
}

function getDevVersionIncrements(versions: string[]): number[] {
const regex = /2\.\d+\.\d+-dev\.(\d+)/
console.log({ versionss: versions })
return versions
.filter((v) => v.trim().length > 0)
.map((v) => {
Expand Down

0 comments on commit 6c7200f

Please sign in to comment.