forked from prisma/prisma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getConfig.test.ts
108 lines (93 loc) · 2.58 KB
/
getConfig.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import stripAnsi from 'strip-ansi'
import { getConfig } from '../..'
describe('getConfig', () => {
test('empty config', async () => {
const config = await getConfig({
datamodel: `
datasource db {
provider = "sqlite"
url = "file:../hello.db"
}
model A {
id Int @id
name String
}`,
})
expect(config.datasources).toHaveLength(1)
expect(config.datasources[0].provider).toEqual('sqlite')
expect(config.generators).toHaveLength(0)
expect(config.warnings).toHaveLength(0)
expect(config).toMatchSnapshot()
})
test('sqlite and createMany', async () => {
expect.assertions(1)
try {
await getConfig({
datamodel: `
datasource db {
provider = "sqlite"
url = "file:../hello.db"
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["createMany"]
}
model A {
id Int @id
name String
}`,
})
} catch (e) {
expect(stripAnsi(e.message)).toMatchInlineSnapshot(`
"Get config: Database provider \\"sqlite\\" and the preview feature \\"createMany\\" can't be used at the same time.
Please either remove the \\"createMany\\" feature flag or use any other database type that Prisma supports: postgres, mysql or sqlserver."
`)
}
})
test('with generator and datasource', async () => {
const config = await getConfig({
datamodel: `
datasource db {
url = "file:dev.db"
provider = "sqlite"
}
generator gen {
provider = "fancy-provider"
binaryTargets = ["native"]
}
model A {
id Int @id
name String
}`,
})
expect(config.datasources).toHaveLength(1)
expect(config.generators).toHaveLength(1)
expect(config.warnings).toHaveLength(0)
expect(config).toMatchSnapshot()
})
test('datasource with env var', async () => {
process.env.TEST_POSTGRES_URI_FOR_DATASOURCE =
'postgres://user:password@something:5432/db'
const config = await getConfig({
datamodel: `
datasource db {
provider = "postgresql"
url = env("TEST_POSTGRES_URI_FOR_DATASOURCE")
}
`,
})
expect(config).toMatchSnapshot()
})
test('datasource with env var - ignoreEnvVarErrors', async () => {
const config = await getConfig({
ignoreEnvVarErrors: true,
datamodel: `
datasource db {
provider = "postgresql"
url = env("SOMETHING-SOMETHING-1234")
}
`,
})
expect(config).toMatchSnapshot()
})
})