@neurodevs/ndx-cli 0.1.55 → 0.1.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/__tests__/AbstractCommandRunnerTest.d.ts +66 -0
- package/build/__tests__/AbstractCommandRunnerTest.js +264 -0
- package/build/__tests__/AbstractCommandRunnerTest.js.map +1 -0
- package/build/__tests__/modules/CliCommandRunner.test.d.ts +2 -94
- package/build/__tests__/modules/CliCommandRunner.test.js +2 -675
- package/build/__tests__/modules/CliCommandRunner.test.js.map +1 -1
- package/build/__tests__/modules/commands/BindSnippetCommand.test.d.ts +20 -0
- package/build/__tests__/modules/commands/BindSnippetCommand.test.js +111 -0
- package/build/__tests__/modules/commands/BindSnippetCommand.test.js.map +1 -0
- package/build/__tests__/modules/commands/CreateImplCommand.test.d.ts +13 -0
- package/build/__tests__/modules/commands/CreateImplCommand.test.js +112 -0
- package/build/__tests__/modules/commands/CreateImplCommand.test.js.map +1 -0
- package/build/__tests__/modules/commands/CreatePackageCommand.test.d.ts +10 -0
- package/build/__tests__/modules/commands/CreatePackageCommand.test.js +98 -0
- package/build/__tests__/modules/commands/CreatePackageCommand.test.js.map +1 -0
- package/build/__tests__/modules/commands/CreateUiCommand.test.d.ts +22 -0
- package/build/__tests__/modules/commands/CreateUiCommand.test.js +220 -0
- package/build/__tests__/modules/commands/CreateUiCommand.test.js.map +1 -0
- package/build/__tests__/modules/commands/UpgradePackageCommand.test.d.ts +11 -0
- package/build/__tests__/modules/commands/UpgradePackageCommand.test.js +90 -0
- package/build/__tests__/modules/commands/UpgradePackageCommand.test.js.map +1 -0
- package/build/modules/CliCommandRunner.d.ts +4 -2
- package/build/modules/CliCommandRunner.js +18 -7
- package/build/modules/CliCommandRunner.js.map +1 -1
- package/build/modules/commands/BindSnippetCommand.d.ts +16 -0
- package/build/modules/commands/BindSnippetCommand.js +67 -0
- package/build/modules/commands/BindSnippetCommand.js.map +1 -0
- package/package.json +2 -2
- package/src/__tests__/AbstractCommandRunnerTest.ts +321 -0
- package/src/__tests__/modules/CliCommandRunner.test.ts +3 -910
- package/src/__tests__/modules/commands/BindSnippetCommand.test.ts +129 -0
- package/src/__tests__/modules/commands/CreateImplCommand.test.ts +137 -0
- package/src/__tests__/modules/commands/CreatePackageCommand.test.ts +113 -0
- package/src/__tests__/modules/commands/CreateUiCommand.test.ts +297 -0
- package/src/__tests__/modules/commands/UpgradePackageCommand.test.ts +105 -0
- package/src/modules/CliCommandRunner.ts +19 -7
- package/src/modules/commands/BindSnippetCommand.ts +75 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { assert, generateId, test } from '@sprucelabs/test-utils'
|
|
2
|
+
import {
|
|
3
|
+
FakeSnippetKeybinder,
|
|
4
|
+
SnippetKeybinderOptions,
|
|
5
|
+
} from '@neurodevs/meta-node'
|
|
6
|
+
import {
|
|
7
|
+
callsToFakePrompts,
|
|
8
|
+
setFakeResponses,
|
|
9
|
+
} from '../../../testDoubles/prompts/fakePrompts'
|
|
10
|
+
import AbstractCommandRunnerTest from '../../AbstractCommandRunnerTest'
|
|
11
|
+
|
|
12
|
+
export default class BindSnippetCommandTest extends AbstractCommandRunnerTest {
|
|
13
|
+
protected static async beforeEach() {
|
|
14
|
+
await super.beforeEach()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@test()
|
|
18
|
+
protected static async createsInstance() {
|
|
19
|
+
const instance = await this.run()
|
|
20
|
+
|
|
21
|
+
assert.isTruthy(
|
|
22
|
+
instance,
|
|
23
|
+
`Failed to create instance for ${this.bindSnippetCommand}!`
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@test()
|
|
28
|
+
protected static async promptsUserForInput() {
|
|
29
|
+
await this.run()
|
|
30
|
+
|
|
31
|
+
assert.isEqualDeep(
|
|
32
|
+
callsToFakePrompts[0],
|
|
33
|
+
[
|
|
34
|
+
{
|
|
35
|
+
type: 'text',
|
|
36
|
+
name: 'name',
|
|
37
|
+
message: this.nameMessage,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: 'text',
|
|
41
|
+
name: 'description',
|
|
42
|
+
message: this.descriptionMessage,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: 'text',
|
|
46
|
+
name: 'lines',
|
|
47
|
+
message: this.linesMessage,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: 'text',
|
|
51
|
+
name: 'keybinding',
|
|
52
|
+
message: this.keybindingMessage,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
'Did not prompt user for expected input!'
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@test()
|
|
60
|
+
protected static async createsVscodeSnippetKeybinder() {
|
|
61
|
+
await this.run(this.promptResponses as any)
|
|
62
|
+
|
|
63
|
+
assert.isEqualDeep(
|
|
64
|
+
FakeSnippetKeybinder.callsToConstructor[0],
|
|
65
|
+
this.keybinderOptions,
|
|
66
|
+
'Did not create VscodeSnippetKeybinder with expected options!'
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@test()
|
|
71
|
+
protected static async runsVscodeSnippetKeybinder() {
|
|
72
|
+
await this.run()
|
|
73
|
+
|
|
74
|
+
assert.isEqual(
|
|
75
|
+
FakeSnippetKeybinder.numCallsToRun,
|
|
76
|
+
1,
|
|
77
|
+
'Did not call run on VscodeSnippetKeybinder!'
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@test()
|
|
82
|
+
protected static async doesNotContinueIfPromptsIsInterrupted() {
|
|
83
|
+
await this.run({
|
|
84
|
+
name: '',
|
|
85
|
+
description: '',
|
|
86
|
+
lines: '',
|
|
87
|
+
keybinding: '',
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
assert.isEqual(
|
|
91
|
+
FakeSnippetKeybinder.numCallsToRun,
|
|
92
|
+
0,
|
|
93
|
+
'Should not have called run on VscodeSnippetKeybinder!'
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private static readonly snippetName = generateId()
|
|
98
|
+
private static readonly snippetDescription = generateId()
|
|
99
|
+
private static readonly lines = `${generateId()}\n${generateId()}`
|
|
100
|
+
private static readonly keybinding = generateId()
|
|
101
|
+
|
|
102
|
+
private static readonly promptResponses: Record<string, unknown> = {
|
|
103
|
+
name: this.snippetName,
|
|
104
|
+
description: this.snippetDescription,
|
|
105
|
+
lines: this.lines,
|
|
106
|
+
keybinding: this.keybinding,
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private static readonly keybinderOptions: SnippetKeybinderOptions = {
|
|
110
|
+
name: this.snippetName,
|
|
111
|
+
description: this.snippetDescription,
|
|
112
|
+
lines: this.lines.split('\n'),
|
|
113
|
+
keybinding: this.keybinding,
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private static readonly nameMessage = `Snippet name? Example: Singleton class template`
|
|
117
|
+
private static readonly descriptionMessage = `Snippet description? Example: A class template based on the singleton pattern`
|
|
118
|
+
private static readonly linesMessage = `Snippet text content? Newlines allowed. Press Enter twice to finish`
|
|
119
|
+
private static readonly keybindingMessage = `Snippet keybinding? Examples: ctrl+alt+c, f4`
|
|
120
|
+
|
|
121
|
+
private static async run(responses?: Record<string, unknown>) {
|
|
122
|
+
setFakeResponses(responses ?? this.promptResponses)
|
|
123
|
+
|
|
124
|
+
const instance = this.CliCommandRunner([this.bindSnippetCommand])
|
|
125
|
+
await instance.run()
|
|
126
|
+
|
|
127
|
+
return instance
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { assert, test } from '@sprucelabs/test-utils'
|
|
2
|
+
import { callsToMkdir } from '@neurodevs/fake-node-core'
|
|
3
|
+
import { FakeAutomodule } from '@neurodevs/meta-node'
|
|
4
|
+
import {
|
|
5
|
+
callsToFakePrompts,
|
|
6
|
+
setFakeResponses,
|
|
7
|
+
} from '../../../testDoubles/prompts/fakePrompts'
|
|
8
|
+
import AbstractCommandRunnerTest from '../../AbstractCommandRunnerTest'
|
|
9
|
+
|
|
10
|
+
export default class CreateImplCommandTest extends AbstractCommandRunnerTest {
|
|
11
|
+
protected static async beforeEach() {
|
|
12
|
+
await super.beforeEach()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@test()
|
|
16
|
+
protected static async createsInstance() {
|
|
17
|
+
const instance = await this.run()
|
|
18
|
+
|
|
19
|
+
assert.isTruthy(
|
|
20
|
+
instance,
|
|
21
|
+
`Failed to create instance for ${this.createImplCommand}!`
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@test()
|
|
26
|
+
protected static async promptsUserForInput() {
|
|
27
|
+
await this.run()
|
|
28
|
+
|
|
29
|
+
assert.isEqualDeep(
|
|
30
|
+
callsToFakePrompts[0],
|
|
31
|
+
[
|
|
32
|
+
{
|
|
33
|
+
type: 'text',
|
|
34
|
+
name: 'interfaceName',
|
|
35
|
+
message: this.interfaceNameMessage,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
type: 'text',
|
|
39
|
+
name: 'implName',
|
|
40
|
+
message: this.implNameMessage,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
'Did not prompt user for expected input!'
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@test()
|
|
48
|
+
protected static async doesNotContinueIfPromptsIsInterrupted() {
|
|
49
|
+
await this.run({
|
|
50
|
+
interfaceName: '',
|
|
51
|
+
implName: '',
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
assert.isEqual(
|
|
55
|
+
FakeAutomodule.numCallsToRun,
|
|
56
|
+
0,
|
|
57
|
+
'Should not have called run on ImplAutomodule!'
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@test()
|
|
62
|
+
protected static async createsTestSaveDirIfNotExists() {
|
|
63
|
+
await this.run()
|
|
64
|
+
|
|
65
|
+
assert.isEqualDeep(
|
|
66
|
+
callsToMkdir[0],
|
|
67
|
+
{ path: this.implTestSaveDir, options: { recursive: true } },
|
|
68
|
+
'Did not create test save dir!'
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@test()
|
|
73
|
+
protected static async createsModuleSaveDirIfNotExists() {
|
|
74
|
+
await this.run()
|
|
75
|
+
|
|
76
|
+
assert.isEqualDeep(
|
|
77
|
+
callsToMkdir[1],
|
|
78
|
+
{ path: this.implModuleSaveDir, options: { recursive: true } },
|
|
79
|
+
'Did not create module save dir!'
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@test()
|
|
84
|
+
protected static async createsFakeSaveDirIfNotExists() {
|
|
85
|
+
await this.run()
|
|
86
|
+
|
|
87
|
+
assert.isEqualDeep(
|
|
88
|
+
callsToMkdir[2],
|
|
89
|
+
{
|
|
90
|
+
path: `src/testDoubles/${this.interfaceName}`,
|
|
91
|
+
options: { recursive: true },
|
|
92
|
+
},
|
|
93
|
+
'Did not create fake save dir!'
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@test()
|
|
98
|
+
protected static async createsImplAutomodule() {
|
|
99
|
+
await this.run()
|
|
100
|
+
|
|
101
|
+
assert.isEqualDeep(
|
|
102
|
+
FakeAutomodule.callsToConstructor[0],
|
|
103
|
+
{
|
|
104
|
+
testSaveDir: this.implTestSaveDir,
|
|
105
|
+
moduleSaveDir: this.implModuleSaveDir,
|
|
106
|
+
fakeSaveDir: this.implFakeSaveDir,
|
|
107
|
+
interfaceName: this.interfaceName,
|
|
108
|
+
implName: this.implName,
|
|
109
|
+
},
|
|
110
|
+
'Did not create ImplAutomodule with expected options!'
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@test()
|
|
115
|
+
protected static async runsImplAutomodule() {
|
|
116
|
+
await this.run()
|
|
117
|
+
|
|
118
|
+
assert.isEqual(
|
|
119
|
+
FakeAutomodule.numCallsToRun,
|
|
120
|
+
1,
|
|
121
|
+
'Did not call run on ImplAutomodule!'
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private static async run(responses?: Record<string, string>) {
|
|
126
|
+
setFakeResponses({
|
|
127
|
+
interfaceName: this.interfaceName,
|
|
128
|
+
implName: this.implName,
|
|
129
|
+
...responses,
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
const instance = this.CliCommandRunner([this.createImplCommand])
|
|
133
|
+
await instance.run()
|
|
134
|
+
|
|
135
|
+
return instance
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { assert, test } from '@sprucelabs/test-utils'
|
|
2
|
+
import { FakeAutopackage } from '@neurodevs/meta-node'
|
|
3
|
+
import {
|
|
4
|
+
callsToFakePrompts,
|
|
5
|
+
setFakeResponses,
|
|
6
|
+
} from '../../../testDoubles/prompts/fakePrompts'
|
|
7
|
+
import AbstractCommandRunnerTest from '../../AbstractCommandRunnerTest'
|
|
8
|
+
|
|
9
|
+
export default class CreatePackageCommandTest extends AbstractCommandRunnerTest {
|
|
10
|
+
protected static async beforeEach() {
|
|
11
|
+
await super.beforeEach()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@test()
|
|
15
|
+
protected static async createsInstance() {
|
|
16
|
+
const instance = await this.run()
|
|
17
|
+
|
|
18
|
+
assert.isTruthy(
|
|
19
|
+
instance,
|
|
20
|
+
`Failed to create instance for ${this.createPackageCommand}!`
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@test()
|
|
25
|
+
protected static async promptsUserForInput() {
|
|
26
|
+
await this.run()
|
|
27
|
+
|
|
28
|
+
assert.isEqualDeep(
|
|
29
|
+
JSON.stringify(callsToFakePrompts[0]),
|
|
30
|
+
JSON.stringify([
|
|
31
|
+
{
|
|
32
|
+
type: 'text',
|
|
33
|
+
name: 'packageName',
|
|
34
|
+
message: this.packageNameMessage,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: 'text',
|
|
38
|
+
name: 'description',
|
|
39
|
+
message: this.packageDescriptionMessage,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
type: 'text',
|
|
43
|
+
name: 'keywords',
|
|
44
|
+
message:
|
|
45
|
+
'Enter keywords (comma or space separated, lowercase, optional):',
|
|
46
|
+
initial: '',
|
|
47
|
+
format: (value: string) =>
|
|
48
|
+
value ? this.splitOnCommaOrWhitespace(value) : [],
|
|
49
|
+
},
|
|
50
|
+
]),
|
|
51
|
+
'Did not prompt user for expected input!'
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@test()
|
|
56
|
+
protected static async doesNotContinueIfPromptsIsInterrupted() {
|
|
57
|
+
await this.run({
|
|
58
|
+
packageName: '',
|
|
59
|
+
description: '',
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
assert.isEqual(
|
|
63
|
+
FakeAutopackage.numCallsToRun,
|
|
64
|
+
0,
|
|
65
|
+
'Should not have called run on Autopackage!'
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@test()
|
|
70
|
+
protected static async createsNpmAutopackage() {
|
|
71
|
+
await this.run()
|
|
72
|
+
|
|
73
|
+
assert.isEqualDeep(
|
|
74
|
+
FakeAutopackage.callsToConstructor[0],
|
|
75
|
+
{
|
|
76
|
+
name: this.packageName,
|
|
77
|
+
description: this.description,
|
|
78
|
+
keywords: this.keywordsWithDefaults,
|
|
79
|
+
gitNamespace: 'neurodevs',
|
|
80
|
+
npmNamespace: 'neurodevs',
|
|
81
|
+
installDir: this.expandHomeDir('~/dev'),
|
|
82
|
+
license: 'MIT',
|
|
83
|
+
author: 'Eric Yates <hello@ericthecurious.com>',
|
|
84
|
+
},
|
|
85
|
+
'Did not create NpmAutopackage with expected options!'
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@test()
|
|
90
|
+
protected static async runsNpmAutopackage() {
|
|
91
|
+
await this.run()
|
|
92
|
+
|
|
93
|
+
assert.isEqual(
|
|
94
|
+
FakeAutopackage.numCallsToRun,
|
|
95
|
+
1,
|
|
96
|
+
'Did not call run on NpmAutopackage!'
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private static async run(responses?: Record<string, string>) {
|
|
101
|
+
setFakeResponses({
|
|
102
|
+
packageName: this.packageName,
|
|
103
|
+
description: this.description,
|
|
104
|
+
keywords: this.keywords,
|
|
105
|
+
...responses,
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
const instance = this.CliCommandRunner([this.createPackageCommand])
|
|
109
|
+
await instance.run()
|
|
110
|
+
|
|
111
|
+
return instance
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { assert, test } from '@sprucelabs/test-utils'
|
|
2
|
+
import {
|
|
3
|
+
callsToExec,
|
|
4
|
+
resetCallsToExec,
|
|
5
|
+
callsToWriteFile,
|
|
6
|
+
callsToMkdir,
|
|
7
|
+
} from '@neurodevs/fake-node-core'
|
|
8
|
+
import { FakeAutomodule } from '@neurodevs/meta-node'
|
|
9
|
+
import {
|
|
10
|
+
callsToFakePrompts,
|
|
11
|
+
setFakeResponses,
|
|
12
|
+
} from '../../../testDoubles/prompts/fakePrompts'
|
|
13
|
+
import AbstractCommandRunnerTest from '../../AbstractCommandRunnerTest'
|
|
14
|
+
|
|
15
|
+
export default class CreateUiCommandTest extends AbstractCommandRunnerTest {
|
|
16
|
+
protected static async beforeEach() {
|
|
17
|
+
await super.beforeEach()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@test()
|
|
21
|
+
protected static async createsInstance() {
|
|
22
|
+
const instance = await this.run()
|
|
23
|
+
|
|
24
|
+
assert.isTruthy(
|
|
25
|
+
instance,
|
|
26
|
+
`Failed to create instance for ${this.createUiCommand}!`
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@test()
|
|
31
|
+
protected static async promptsInstallDependenciesIfMissing() {
|
|
32
|
+
this.setFakeReadToEmptyPackageJson()
|
|
33
|
+
|
|
34
|
+
await this.run()
|
|
35
|
+
|
|
36
|
+
assert.isEqualDeep(
|
|
37
|
+
callsToFakePrompts[0],
|
|
38
|
+
[
|
|
39
|
+
{
|
|
40
|
+
type: 'confirm',
|
|
41
|
+
name: 'shouldInstall',
|
|
42
|
+
message:
|
|
43
|
+
'Some required dependencies are missing! Press Enter to install, or any other key to abort.',
|
|
44
|
+
initial: true,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
'Did not prompt user for expected input!'
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@test()
|
|
52
|
+
protected static async installsDependenciesIfMissing() {
|
|
53
|
+
this.setFakeReadToEmptyPackageJson()
|
|
54
|
+
|
|
55
|
+
await this.run({
|
|
56
|
+
shouldInstall: true,
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
assert.isEqualDeep(
|
|
60
|
+
callsToExec[0],
|
|
61
|
+
this.installDependenciesCommand,
|
|
62
|
+
'Did not install dependencies!'
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@test()
|
|
67
|
+
protected static async installsDevDependenciesIfMissing() {
|
|
68
|
+
this.setFakeReadToEmptyPackageJson()
|
|
69
|
+
|
|
70
|
+
await this.run({
|
|
71
|
+
shouldInstall: true,
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
assert.isEqualDeep(
|
|
75
|
+
callsToExec[1],
|
|
76
|
+
this.installDevDependenciesCommand,
|
|
77
|
+
'Did not install dependencies!'
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@test()
|
|
82
|
+
protected static async installsIfAnyDepIsMissing() {
|
|
83
|
+
for (const dep of this.allRequiredDependencies) {
|
|
84
|
+
this.setFakeReadToAllInstalledExcept(dep)
|
|
85
|
+
resetCallsToExec()
|
|
86
|
+
|
|
87
|
+
await this.run({
|
|
88
|
+
shouldInstall: true,
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
assert.isEqual(
|
|
92
|
+
callsToExec[1],
|
|
93
|
+
this.installDevDependenciesCommand,
|
|
94
|
+
'Should not have installed devDependencies!'
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@test()
|
|
100
|
+
protected static async updatesTsconfigIfDepsWereMissing() {
|
|
101
|
+
this.setFakeReadToEmptyPackageJson()
|
|
102
|
+
this.setFakeReadFileResultToTsconfig()
|
|
103
|
+
|
|
104
|
+
await this.run({
|
|
105
|
+
shouldInstall: true,
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
assert.isEqualDeep(
|
|
109
|
+
callsToWriteFile[0],
|
|
110
|
+
{
|
|
111
|
+
file: this.tsconfigPath,
|
|
112
|
+
data: this.updatedTsconfigFile,
|
|
113
|
+
options: undefined,
|
|
114
|
+
},
|
|
115
|
+
'Did not update tsconfig!'
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@test()
|
|
120
|
+
protected static async createsSetupTestsIfDepsWereMissing() {
|
|
121
|
+
this.setFakeReadToEmptyPackageJson()
|
|
122
|
+
|
|
123
|
+
await this.run({
|
|
124
|
+
shouldInstall: true,
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
assert.isEqualDeep(
|
|
128
|
+
callsToWriteFile[1],
|
|
129
|
+
{
|
|
130
|
+
file: 'src/__tests__/setupTests.ts',
|
|
131
|
+
data: this.setupTestsFile,
|
|
132
|
+
options: undefined,
|
|
133
|
+
},
|
|
134
|
+
'Did not create setupTests script!'
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@test()
|
|
139
|
+
protected static async addsSetupTestsToPackageJsonIfDepsWereMissing() {
|
|
140
|
+
this.setFakeReadToEmptyPackageJson()
|
|
141
|
+
|
|
142
|
+
await this.run({
|
|
143
|
+
shouldInstall: true,
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
assert.isEqualDeep(
|
|
147
|
+
callsToWriteFile[2],
|
|
148
|
+
{
|
|
149
|
+
file: 'package.json',
|
|
150
|
+
data: JSON.stringify(
|
|
151
|
+
{
|
|
152
|
+
jest: {
|
|
153
|
+
setupFiles: [
|
|
154
|
+
'<rootDir>/build/__tests__/setupTests.js',
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
null,
|
|
159
|
+
4
|
|
160
|
+
),
|
|
161
|
+
options: undefined,
|
|
162
|
+
},
|
|
163
|
+
'Did not update package.json!'
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
@test()
|
|
168
|
+
protected static async recompilesTypescriptIfDepsWereMissing() {
|
|
169
|
+
this.setFakeReadToEmptyPackageJson()
|
|
170
|
+
|
|
171
|
+
await this.run({
|
|
172
|
+
shouldInstall: true,
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
assert.isEqualDeep(
|
|
176
|
+
callsToExec[2],
|
|
177
|
+
'npx tsc',
|
|
178
|
+
'Did not recompile typescript!'
|
|
179
|
+
)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
@test()
|
|
183
|
+
protected static async doesNotPromptIfDependenciesAreInstalled() {
|
|
184
|
+
this.setFakeReadToAllInstalled()
|
|
185
|
+
|
|
186
|
+
await this.run()
|
|
187
|
+
|
|
188
|
+
assert.isEqual(callsToFakePrompts.length, 1, 'Prompted too many times!')
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
@test()
|
|
192
|
+
protected static async promptsUserForInput() {
|
|
193
|
+
this.setFakeReadToAllInstalled()
|
|
194
|
+
|
|
195
|
+
await this.run()
|
|
196
|
+
|
|
197
|
+
assert.isEqualDeep(
|
|
198
|
+
callsToFakePrompts[0],
|
|
199
|
+
[
|
|
200
|
+
{
|
|
201
|
+
type: 'text',
|
|
202
|
+
name: 'componentName',
|
|
203
|
+
message: this.componentNameMessage,
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
'Did not prompt user for expected input!'
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
@test()
|
|
211
|
+
protected static async doesNotContinueIfPromptsIsInterrupted() {
|
|
212
|
+
await this.run({
|
|
213
|
+
componentName: '',
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
assert.isEqual(
|
|
217
|
+
FakeAutomodule.numCallsToRun,
|
|
218
|
+
0,
|
|
219
|
+
'Should not have called run on UiAutomodule!'
|
|
220
|
+
)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
@test()
|
|
224
|
+
protected static async createsTestSaveDirIfNotExists() {
|
|
225
|
+
await this.run()
|
|
226
|
+
|
|
227
|
+
assert.isEqualDeep(
|
|
228
|
+
callsToMkdir[0],
|
|
229
|
+
{ path: this.uiTestSaveDir, options: { recursive: true } },
|
|
230
|
+
'Did not create test save dir!'
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
@test()
|
|
235
|
+
protected static async createsModuleSaveDirIfNotExists() {
|
|
236
|
+
await this.run()
|
|
237
|
+
|
|
238
|
+
assert.isEqualDeep(
|
|
239
|
+
callsToMkdir[1],
|
|
240
|
+
{ path: this.uiModuleSaveDir, options: { recursive: true } },
|
|
241
|
+
'Did not create module save dir!'
|
|
242
|
+
)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
@test()
|
|
246
|
+
protected static async createsFakeSaveDirIfNotExists() {
|
|
247
|
+
await this.run()
|
|
248
|
+
|
|
249
|
+
assert.isEqualDeep(
|
|
250
|
+
callsToMkdir[2],
|
|
251
|
+
{
|
|
252
|
+
path: this.uiFakeSaveDir,
|
|
253
|
+
options: { recursive: true },
|
|
254
|
+
},
|
|
255
|
+
'Did not create fake save dir!'
|
|
256
|
+
)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
@test()
|
|
260
|
+
protected static async createsUiAutomodule() {
|
|
261
|
+
await this.run()
|
|
262
|
+
|
|
263
|
+
assert.isEqualDeep(
|
|
264
|
+
FakeAutomodule.callsToConstructor[0],
|
|
265
|
+
{
|
|
266
|
+
testSaveDir: this.uiTestSaveDir,
|
|
267
|
+
moduleSaveDir: this.uiModuleSaveDir,
|
|
268
|
+
fakeSaveDir: this.uiFakeSaveDir,
|
|
269
|
+
componentName: this.componentName,
|
|
270
|
+
},
|
|
271
|
+
'Did not create UiAutomodule with expected options!'
|
|
272
|
+
)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
@test()
|
|
276
|
+
protected static async runsUiAutomodule() {
|
|
277
|
+
await this.run()
|
|
278
|
+
|
|
279
|
+
assert.isEqual(
|
|
280
|
+
FakeAutomodule.numCallsToRun,
|
|
281
|
+
1,
|
|
282
|
+
'Did not call run on UiAutomodule!'
|
|
283
|
+
)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
private static async run(responses?: Record<string, string | boolean>) {
|
|
287
|
+
setFakeResponses({
|
|
288
|
+
componentName: this.componentName,
|
|
289
|
+
...responses,
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
const instance = this.CliCommandRunner([this.createUiCommand])
|
|
293
|
+
await instance.run()
|
|
294
|
+
|
|
295
|
+
return instance
|
|
296
|
+
}
|
|
297
|
+
}
|