-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
make-command.spec.ts
106 lines (88 loc) · 2.97 KB
/
make-command.spec.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
/*
* @adonisjs/assembler
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import test from 'japa'
import { join } from 'path'
import { Ioc } from '@adonisjs/fold'
import { Kernel } from '@adonisjs/ace'
import { Filesystem } from '@poppinss/dev-utils'
import { Application } from '@adonisjs/application/build/standalone'
import { toNewlineArray } from '../test-helpers'
import MakeCommand from '../commands/Make/Command'
const fs = new Filesystem(join(__dirname, '__app'))
const templates = new Filesystem(join(__dirname, '..', 'templates'))
test.group('Make Command', (group) => {
group.before(() => {
process.env.ADONIS_ACE_CWD = fs.basePath
})
group.after(() => {
delete process.env.ADONIS_ACE_CWD
})
group.afterEach(async () => {
await fs.cleanup()
})
test('make a command inside the default directory', async (assert) => {
await fs.add('.adonisrc.json', JSON.stringify({}))
const app = new Application(fs.basePath, new Ioc(), {}, {})
const command = new MakeCommand(app, new Kernel(app))
command.name = 'greet'
await command.handle()
const GreetCommand = await fs.get('commands/Greet.ts')
const CommandTemplate = await templates.get('command.txt')
assert.deepEqual(
toNewlineArray(GreetCommand),
toNewlineArray(
CommandTemplate
.replace('${filename}', 'Greet')
.replace('${toCommandName(filename)}', 'greet'),
),
)
})
test('make a command inside a custom directory', async (assert) => {
await fs.add('.adonisrc.json', JSON.stringify({
directories: {
commands: './foo',
},
}))
const app = new Application(fs.basePath, new Ioc(), {}, {})
const command = new MakeCommand(app, new Kernel(app))
command.name = 'greet'
await command.handle()
const GreetCommand = await fs.get('foo/Greet.ts')
const CommandTemplate = await templates.get('command.txt')
assert.deepEqual(
toNewlineArray(GreetCommand),
toNewlineArray(
CommandTemplate
.replace('${filename}', 'Greet')
.replace('${toCommandName(filename)}', 'greet'),
),
)
})
test('convert camelcase command path to colon seperated name', async (assert) => {
await fs.add('.adonisrc.json', JSON.stringify({
directories: {
commands: './foo',
},
}))
const app = new Application(fs.basePath, new Ioc(), {}, {})
const command = new MakeCommand(app, new Kernel(app))
command.name = 'RunInstructions'
await command.handle()
const GreetCommand = await fs.get('foo/RunInstructions.ts')
const CommandTemplate = await templates.get('command.txt')
assert.deepEqual(
toNewlineArray(GreetCommand),
toNewlineArray(
CommandTemplate
.replace('${filename}', 'RunInstructions')
.replace('${toCommandName(filename)}', 'run:instructions'),
),
)
})
})