forked from prisma/prisma
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCLI.test.ts
More file actions
83 lines (71 loc) · 2.72 KB
/
Copy pathCLI.test.ts
File metadata and controls
83 lines (71 loc) · 2.72 KB
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
import { jestConsoleContext, jestContext } from '@prisma/get-platform'
import { DbPull } from '@prisma/migrate'
import { CLI } from '../../CLI'
const ctx = jestContext.new().add(jestConsoleContext()).assemble()
const cliInstance = CLI.new(
{
// init: Init.new(),
// migrate: MigrateCommand.new({
// diff: MigrateDiff.new(),
// dev: MigrateDev.new(),
// status: MigrateStatus.new(),
// resolve: MigrateResolve.new(),
// reset: MigrateReset.new(),
// deploy: MigrateDeploy.new(),
// }),
// db: DbCommand.new({
// pull: DbPull.new(),
// push: DbPush.new(),
// // drop: DbDrop.new(),
// seed: DbSeed.new(),
// }),
/**
* @deprecated since version 2.30.0, use `db pull` instead (renamed)
*/
introspect: DbPull.new(),
// dev: Dev.new(),
// studio: Studio.new(),
// generate: Generate.new(),
// version: Version.new(),
// validate: Validate.new(),
// format: Format.new(),
// telemetry: Telemetry.new(),
},
['version', 'init', 'migrate', 'db', 'introspect', 'dev', 'studio', 'generate', 'validate', 'format', 'telemetry'],
)
it('no params should return help', async () => {
const spy = jest.spyOn(cliInstance, 'help').mockImplementation(() => 'Help Me')
await cliInstance.parse([])
expect(spy).toHaveBeenCalledTimes(1)
spy.mockRestore()
})
it('wrong flag', async () => {
const spy = jest.spyOn(cliInstance, 'help').mockImplementation(() => 'Help Me')
await cliInstance.parse(['--something'])
expect(spy).toHaveBeenCalledTimes(1)
spy.mockRestore()
})
it('help flag', async () => {
const spy = jest.spyOn(cliInstance, 'help').mockImplementation(() => 'Help Me')
await cliInstance.parse(['--help'])
expect(spy).toHaveBeenCalledTimes(1)
spy.mockRestore()
})
it('unknown command', async () => {
await expect(cliInstance.parse(['doesnotexist'])).resolves.toThrow()
})
it('introspect should include deprecation warning', async () => {
const result = cliInstance.parse(['introspect'])
await expect(result).rejects.toMatchInlineSnapshot(`
"Could not find a schema.prisma file that is required for this command.
You can either provide it with --schema, set it as \`prisma.schema\` in your package.json or put it into the default location ./prisma/schema.prisma https://pris.ly/d/prisma-schema-location"
`)
expect(ctx.mocked['console.log'].mock.calls).toHaveLength(0)
expect(ctx.mocked['console.info'].mock.calls).toHaveLength(0)
expect(ctx.mocked['console.warn'].mock.calls.join('\n')).toMatchInlineSnapshot(`
"prisma:warn
prisma:warn The prisma introspect command is deprecated. Please use prisma db pull instead.
prisma:warn "
`)
expect(ctx.mocked['console.error'].mock.calls).toHaveLength(0)
})