@sprucelabs/spruce-cli 15.2.16 → 15.2.19

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/build/.spruce/events/events.contract.d.ts +102 -4
  3. package/build/.spruce/events/events.contract.js +3 -1
  4. package/build/.spruce/events/events.contract.js.map +1 -1
  5. package/build/.spruce/events/heartwood/didRegisterSkillViews.v2021_02_11.contract.d.ts +15 -0
  6. package/build/.spruce/events/heartwood/didRegisterSkillViews.v2021_02_11.contract.js +18 -3
  7. package/build/.spruce/events/heartwood/didRegisterSkillViews.v2021_02_11.contract.js.map +1 -1
  8. package/build/.spruce/events/heartwood/generateUrl.v2021_02_11.contract.d.ts +21 -4
  9. package/build/.spruce/events/heartwood/generateUrl.v2021_02_11.contract.js +24 -7
  10. package/build/.spruce/events/heartwood/generateUrl.v2021_02_11.contract.js.map +1 -1
  11. package/build/.spruce/events/heartwood/getSkillViews.v2021_02_11.contract.d.ts +18 -1
  12. package/build/.spruce/events/heartwood/getSkillViews.v2021_02_11.contract.js +21 -4
  13. package/build/.spruce/events/heartwood/getSkillViews.v2021_02_11.contract.js.map +1 -1
  14. package/build/.spruce/events/heartwood/listViews.v2021_02_11.contract.d.ts +39 -0
  15. package/build/.spruce/events/heartwood/listViews.v2021_02_11.contract.js +53 -0
  16. package/build/.spruce/events/heartwood/listViews.v2021_02_11.contract.js.map +1 -0
  17. package/build/.spruce/events/heartwood/registerSkillViews.v2021_02_11.contract.d.ts +11 -0
  18. package/build/.spruce/events/heartwood/registerSkillViews.v2021_02_11.contract.js +13 -2
  19. package/build/.spruce/events/heartwood/registerSkillViews.v2021_02_11.contract.js.map +1 -1
  20. package/build/__tests__/behavioral/skill/UpgradingASkill.test.d.ts +0 -7
  21. package/build/__tests__/behavioral/skill/UpgradingASkill.test.js +38 -403
  22. package/build/__tests__/behavioral/skill/UpgradingASkill.test.js.map +1 -1
  23. package/build/__tests__/behavioral/skill/UpgradingASkill2.test.d.ts +7 -15
  24. package/build/__tests__/behavioral/skill/UpgradingASkill2.test.js +218 -341
  25. package/build/__tests__/behavioral/skill/UpgradingASkill2.test.js.map +1 -1
  26. package/build/__tests__/behavioral/skill/UpgradingASkill3.test.d.ts +16 -5
  27. package/build/__tests__/behavioral/skill/UpgradingASkill3.test.js +416 -141
  28. package/build/__tests__/behavioral/skill/UpgradingASkill3.test.js.map +1 -1
  29. package/build/__tests__/behavioral/skill/UpgradingASkill4.test.d.ts +5 -8
  30. package/build/__tests__/behavioral/skill/UpgradingASkill4.test.js +147 -205
  31. package/build/__tests__/behavioral/skill/UpgradingASkill4.test.js.map +1 -1
  32. package/build/__tests__/behavioral/skill/UpgradingASkill5.test.d.ts +11 -0
  33. package/build/__tests__/behavioral/skill/UpgradingASkill5.test.js +357 -0
  34. package/build/__tests__/behavioral/skill/UpgradingASkill5.test.js.map +1 -0
  35. package/build/__tests__/behavioral/tests/CreatingATest.test.d.ts +3 -0
  36. package/build/__tests__/behavioral/tests/CreatingATest.test.js +142 -45
  37. package/build/__tests__/behavioral/tests/CreatingATest.test.js.map +1 -1
  38. package/package.json +74 -36
  39. package/src/.spruce/events/events.contract.ts +6 -0
  40. package/src/.spruce/events/heartwood/didRegisterSkillViews.v2021_02_11.contract.ts +15 -0
  41. package/src/.spruce/events/heartwood/generateUrl.v2021_02_11.contract.ts +21 -4
  42. package/src/.spruce/events/heartwood/getSkillViews.v2021_02_11.contract.ts +18 -1
  43. package/src/.spruce/events/heartwood/listViews.v2021_02_11.contract.ts +47 -0
  44. package/src/.spruce/events/heartwood/registerSkillViews.v2021_02_11.contract.ts +11 -0
  45. package/src/__tests__/behavioral/skill/UpgradingASkill.test.ts +0 -184
  46. package/src/__tests__/behavioral/skill/UpgradingASkill2.test.ts +120 -157
  47. package/src/__tests__/behavioral/skill/UpgradingASkill3.test.ts +184 -78
  48. package/src/__tests__/behavioral/skill/UpgradingASkill4.test.ts +90 -91
  49. package/src/__tests__/behavioral/skill/UpgradingASkill5.test.ts +128 -0
  50. package/src/__tests__/behavioral/tests/CreatingATest.test.ts +29 -12
@@ -1,128 +1,127 @@
1
+ import fsUtil from 'fs'
2
+ import { diskUtil } from '@sprucelabs/spruce-skill-utils'
1
3
  import { test, assert } from '@sprucelabs/test'
2
4
  import CommandService from '../../../services/CommandService'
3
5
  import AbstractCliTest from '../../../tests/AbstractCliTest'
4
6
 
5
7
  export default class UpgradingASkill4Test extends AbstractCliTest {
6
- @test()
7
- protected static async upgradeResetsEventCache() {
8
- await this.installSetListenerCacheAndBlockExecute()
9
-
10
- await assert.doesThrowAsync(() =>
11
- this.Action('node', 'upgrade').execute({})
12
- )
13
-
14
- const value = this.Settings().getListenerCache()
15
- assert.isFalsy(value)
8
+ protected static async beforeEach() {
9
+ await super.beforeEach()
10
+ CommandService.setMockResponse(new RegExp(/yarn rebuild/gis), {
11
+ code: 0,
12
+ })
16
13
  }
17
14
 
18
15
  @test()
19
- protected static async doesNotResetEventCacheWithOtherAction() {
20
- await this.installSetListenerCacheAndBlockExecute()
21
-
22
- await assert.doesThrowAsync(() => this.Action('schema', 'sync').execute({}))
16
+ protected static async restoresMissingPackagesAndPlugins() {
17
+ await this.FeatureFixture().installCachedFeatures('views')
23
18
 
24
- const value = this.Settings().getListenerCache()
25
- assert.isEqualDeep(value, { shouldBeDeleted: true })
26
- }
27
-
28
- @test('syncs schemas when schemas installed and schemas folder exists', true)
29
- @test(
30
- 'does not syncs schemas when schemas installed but schemas folder does not exist',
31
- false
32
- )
33
- protected static async shouldSyncSchemasIfSchemasIsInstalledAndSchemaFolderExists(
34
- shouldCreateSchema: boolean
35
- ) {
36
- await this.FeatureFixture().installCachedFeatures('schemas')
37
-
38
- CommandService.setMockResponse(new RegExp(/yarn/gis), {
39
- code: 0,
40
- })
19
+ const features = this.Service('pkg', process.cwd()).get(
20
+ 'testSkillCache.everything'
21
+ )
41
22
 
42
- if (shouldCreateSchema) {
43
- await this.Action('schema', 'create').execute({
44
- nameReadable: 'Test schema!',
45
- namePascal: 'AnotherTest',
46
- nameCamel: 'anotherTest',
47
- description: 'this is so great!',
23
+ const pkg = this.Service('pkg')
24
+ const checks: { nodeModule?: string; plugin?: string }[] = []
25
+
26
+ for (const feat of features) {
27
+ const { code } = feat
28
+ const nodeModule = `@sprucelabs/spruce-${code}-plugin`
29
+ const path = this.resolveHashSprucePath('features', `${code}.plugin.ts`)
30
+ const plugin = diskUtil.doesFileExist(path) ? path : undefined
31
+
32
+ checks.push({
33
+ nodeModule: pkg.get(['dependencies', nodeModule])
34
+ ? nodeModule
35
+ : undefined,
36
+ plugin,
48
37
  })
49
38
  }
50
39
 
51
- const emitter = this.getEmitter()
52
-
53
- let wasHit = false
54
-
55
- await emitter.on('feature.will-execute', (payload) => {
56
- if (payload.featureCode === 'schema' && payload.actionCode === 'sync') {
57
- wasHit = true
40
+ for (const check of checks) {
41
+ if (check.nodeModule) {
42
+ pkg.unset(['dependencies', check.nodeModule])
58
43
  }
44
+ if (check.plugin) {
45
+ diskUtil.deleteFile(check.plugin)
46
+ }
47
+ }
59
48
 
60
- return {}
61
- })
49
+ CommandService.setMockResponse(/yarn clean/, { code: 0 })
50
+ CommandService.setMockResponse(/yarn build.dev/, { code: 0 })
62
51
 
63
52
  await this.Action('node', 'upgrade').execute({})
64
53
 
65
- assert.isTrue(wasHit === shouldCreateSchema)
54
+ for (const check of checks) {
55
+ if (check.nodeModule) {
56
+ assert.isTruthy(
57
+ pkg.get(['dependencies', check.nodeModule]),
58
+ `${check.nodeModule} was not added back as a dependencies.`
59
+ )
60
+ }
61
+ if (check.plugin) {
62
+ assert.isTrue(
63
+ diskUtil.doesFileExist(check.plugin),
64
+ `${check.plugin} was not rewritten.`
65
+ )
66
+ }
67
+ }
66
68
  }
67
69
 
68
70
  @test()
69
- protected static async modulesMovedFromDevToProdDependenciesStayThere() {
70
- await this.FeatureFixture().installCachedFeatures('skills')
71
-
72
- await this.moveDependencyToProd('@sprucelabs/resolve-path-aliases')
73
- await this.moveDependencyToDev('@sprucelabs/error')
71
+ protected static async doesNotAskIfNewScriptsAreAddedToSkillFeature() {
72
+ const cli = await this.FeatureFixture().installCachedFeatures('skills')
74
73
 
75
- let wasMovedBackToDev = false
76
- let wasMovedBackToProd = false
74
+ const pkg = this.Service('pkg')
77
75
 
78
- CommandService.setMockResponse(new RegExp(/yarn/gis), {
79
- code: 0,
80
- callback: (_, args) => {
81
- if (
82
- args.indexOf('-D') > -1 &&
83
- args.indexOf('@sprucelabs/resolve-path-aliases') > -1
84
- ) {
85
- wasMovedBackToDev = true
86
- } else if (
87
- args.indexOf('-D') === -1 &&
88
- args.indexOf('@sprucelabs/error') > -1
89
- ) {
90
- wasMovedBackToProd = true
91
- }
92
- },
93
- })
76
+ const skillFeature = cli.getFeature('skill')
77
+ //@ts-ignore
78
+ skillFeature.scripts['taco'] = 'bravo'
94
79
 
95
80
  await this.Action('node', 'upgrade').execute({})
96
81
 
97
- assert.isFalse(wasMovedBackToDev, 'dependency moved back to dev')
98
- assert.isFalse(wasMovedBackToProd, 'dependency moved back to prod')
99
- }
82
+ assert.isEqual(pkg.get(['scripts', 'taco']), 'bravo')
100
83
 
101
- private static async moveDependencyToDev(name: string) {
102
- const pkg = this.Service('pkg')
103
- await pkg.uninstall(name)
104
- await pkg.install(name, { isDev: true })
84
+ this.assertSandboxListenerNotWritten()
105
85
  }
106
- private static async moveDependencyToProd(name: string) {
86
+
87
+ @test()
88
+ protected static async canOverwriteMultipleChangedScript() {
89
+ await this.FeatureFixture().installCachedFeatures('skills')
90
+
107
91
  const pkg = this.Service('pkg')
92
+ pkg.set({ path: ['scripts', 'build.dev'], value: 'taco' })
93
+ pkg.set({ path: ['scripts', 'watch.build.dev'], value: 'taco' })
108
94
 
109
- await pkg.uninstall(name)
110
- await pkg.install(name)
111
- }
95
+ const promise = this.Action('node', 'upgrade').execute({})
112
96
 
113
- private static async installSetListenerCacheAndBlockExecute() {
114
- await this.FeatureFixture().installCachedFeatures('events')
97
+ await this.waitForInput()
115
98
 
116
- const settings = this.Settings()
117
- settings.setListenerCache({ shouldBeDeleted: true })
99
+ let last = this.ui.getLastInvocation()
118
100
 
119
- const emitter = this.getEmitter()
120
- void emitter.on('feature.will-execute', () => {
121
- throw new Error('Stop!')
122
- })
101
+ assert.isEqual(last.command, 'prompt')
102
+ await this.ui.sendInput('overwrite')
103
+
104
+ last = this.ui.getLastInvocation()
105
+
106
+ assert.isEqual(last.command, 'prompt')
107
+ await this.ui.sendInput('overwrite')
108
+
109
+ await promise
110
+
111
+ assert.isNotEqual(pkg.get(['scripts', 'build.dev']), 'taco')
112
+ assert.isNotEqual(pkg.get(['scripts', 'watch.build.dev']), 'taco')
123
113
  }
124
114
 
125
- private static Settings() {
126
- return this.Service('eventSettings')
115
+ protected static assertSandboxListenerNotWritten() {
116
+ const listeners = this.resolvePath('src', 'listeners')
117
+ if (!diskUtil.doesDirExist(listeners)) {
118
+ return
119
+ }
120
+ const matches = fsUtil.readdirSync(listeners)
121
+ assert.isLength(
122
+ matches,
123
+ 0,
124
+ 'A sandbox listeners was written and it should not have been.'
125
+ )
127
126
  }
128
127
  }
@@ -0,0 +1,128 @@
1
+ import { test, assert } from '@sprucelabs/test'
2
+ import CommandService from '../../../services/CommandService'
3
+ import AbstractCliTest from '../../../tests/AbstractCliTest'
4
+
5
+ export default class UpgradingASkill5Test extends AbstractCliTest {
6
+ @test()
7
+ protected static async upgradeResetsEventCache() {
8
+ await this.installSetListenerCacheAndBlockExecute()
9
+
10
+ await assert.doesThrowAsync(() =>
11
+ this.Action('node', 'upgrade').execute({})
12
+ )
13
+
14
+ const value = this.Settings().getListenerCache()
15
+ assert.isFalsy(value)
16
+ }
17
+
18
+ @test()
19
+ protected static async doesNotResetEventCacheWithOtherAction() {
20
+ await this.installSetListenerCacheAndBlockExecute()
21
+
22
+ await assert.doesThrowAsync(() => this.Action('schema', 'sync').execute({}))
23
+
24
+ const value = this.Settings().getListenerCache()
25
+ assert.isEqualDeep(value, { shouldBeDeleted: true })
26
+ }
27
+
28
+ @test('syncs schemas when schemas installed and schemas folder exists', true)
29
+ @test(
30
+ 'does not syncs schemas when schemas installed but schemas folder does not exist',
31
+ false
32
+ )
33
+ protected static async shouldSyncSchemasIfSchemasIsInstalledAndSchemaFolderExists(
34
+ shouldCreateSchema: boolean
35
+ ) {
36
+ await this.FeatureFixture().installCachedFeatures('schemas')
37
+
38
+ CommandService.setMockResponse(new RegExp(/yarn/gis), {
39
+ code: 0,
40
+ })
41
+
42
+ if (shouldCreateSchema) {
43
+ await this.Action('schema', 'create').execute({
44
+ nameReadable: 'Test schema!',
45
+ namePascal: 'AnotherTest',
46
+ nameCamel: 'anotherTest',
47
+ description: 'this is so great!',
48
+ })
49
+ }
50
+
51
+ const emitter = this.getEmitter()
52
+
53
+ let wasHit = false
54
+
55
+ await emitter.on('feature.will-execute', (payload) => {
56
+ if (payload.featureCode === 'schema' && payload.actionCode === 'sync') {
57
+ wasHit = true
58
+ }
59
+
60
+ return {}
61
+ })
62
+
63
+ await this.Action('node', 'upgrade').execute({})
64
+
65
+ assert.isTrue(wasHit === shouldCreateSchema)
66
+ }
67
+
68
+ @test()
69
+ protected static async modulesMovedFromDevToProdDependenciesStayThere() {
70
+ await this.FeatureFixture().installCachedFeatures('skills')
71
+
72
+ await this.moveDependencyToProd('@sprucelabs/resolve-path-aliases')
73
+ await this.moveDependencyToDev('@sprucelabs/error')
74
+
75
+ let wasMovedBackToDev = false
76
+ let wasMovedBackToProd = false
77
+
78
+ CommandService.setMockResponse(new RegExp(/yarn/gis), {
79
+ code: 0,
80
+ callback: (_, args) => {
81
+ if (
82
+ args.indexOf('-D') > -1 &&
83
+ args.indexOf('@sprucelabs/resolve-path-aliases') > -1
84
+ ) {
85
+ wasMovedBackToDev = true
86
+ } else if (
87
+ args.indexOf('-D') === -1 &&
88
+ args.indexOf('@sprucelabs/error') > -1
89
+ ) {
90
+ wasMovedBackToProd = true
91
+ }
92
+ },
93
+ })
94
+
95
+ await this.Action('node', 'upgrade').execute({})
96
+
97
+ assert.isFalse(wasMovedBackToDev, 'dependency moved back to dev')
98
+ assert.isFalse(wasMovedBackToProd, 'dependency moved back to prod')
99
+ }
100
+
101
+ private static async moveDependencyToDev(name: string) {
102
+ const pkg = this.Service('pkg')
103
+ await pkg.uninstall(name)
104
+ await pkg.install(name, { isDev: true })
105
+ }
106
+ private static async moveDependencyToProd(name: string) {
107
+ const pkg = this.Service('pkg')
108
+
109
+ await pkg.uninstall(name)
110
+ await pkg.install(name)
111
+ }
112
+
113
+ private static async installSetListenerCacheAndBlockExecute() {
114
+ await this.FeatureFixture().installCachedFeatures('events')
115
+
116
+ const settings = this.Settings()
117
+ settings.setListenerCache({ shouldBeDeleted: true })
118
+
119
+ const emitter = this.getEmitter()
120
+ void emitter.on('feature.will-execute', () => {
121
+ throw new Error('Stop!')
122
+ })
123
+ }
124
+
125
+ private static Settings() {
126
+ return this.Service('eventSettings')
127
+ }
128
+ }
@@ -34,16 +34,7 @@ export default class CreatingBehavioralTestsTest extends AbstractTestTest {
34
34
  )
35
35
  protected static async canCreateBehavioralTest(testName: string) {
36
36
  LintService.enableLinting()
37
- const { promise } = await this.installAndStartTestActionAndWaitForInput()
38
-
39
- this.selectOptionBasedOnLabel(testName)
40
-
41
- const response = await promise
42
-
43
- const match = testUtil.assertFileByNameInGeneratedFiles(
44
- 'CanBookAppointment.test.ts',
45
- response.files
46
- )
37
+ const match = await this.createTestAndGetFile(testName)
47
38
 
48
39
  assert.doesInclude(match, 'behavioral')
49
40
 
@@ -100,8 +91,8 @@ export default class CreatingBehavioralTestsTest extends AbstractTestTest {
100
91
  await promise
101
92
  }
102
93
 
103
- @test('can select subdir 1', 'test')
104
- @test('can select subdir 2', 'test-2')
94
+ @test('can select sub dir 1', 'test')
95
+ @test('can select sub dir 2', 'test-2')
105
96
  protected static async selectingAnOptionRendersToSubDir(dirName: string) {
106
97
  await this.installTests()
107
98
  this.createTestSubDir('behavioral', dirName)
@@ -146,6 +137,13 @@ export default class CreatingBehavioralTestsTest extends AbstractTestTest {
146
137
  this.ui.reset()
147
138
  }
148
139
 
140
+ @test()
141
+ protected static async allTestsComeFakedToStart() {
142
+ const testFile = await this.createTestAndGetFile()
143
+ const contents = diskUtil.readFile(testFile)
144
+ assert.doesInclude(contents, 'fake.login()')
145
+ }
146
+
149
147
  private static createTestSubDir(...testDirs: string[]) {
150
148
  const newDir = this.resolveTestDir(...testDirs)
151
149
  diskUtil.createDir(newDir)
@@ -155,6 +153,15 @@ export default class CreatingBehavioralTestsTest extends AbstractTestTest {
155
153
  return this.resolvePath('src', '__tests__', ...testDirs)
156
154
  }
157
155
 
156
+ private static async createTest(testName = 'AbstractSpruceFixtureTest') {
157
+ const { promise } = await this.installAndStartTestActionAndWaitForInput()
158
+
159
+ this.selectOptionBasedOnLabel(testName)
160
+
161
+ const response = await promise
162
+ return response
163
+ }
164
+
158
165
  private static async installAndStartTestActionAndWaitForInput(
159
166
  testType = 'behavioral'
160
167
  ) {
@@ -174,4 +181,14 @@ export default class CreatingBehavioralTestsTest extends AbstractTestTest {
174
181
  await this.waitForInput()
175
182
  await this.ui.sendInput(selectedSubClass ?? '')
176
183
  }
184
+
185
+ private static async createTestAndGetFile(testName?: string) {
186
+ const response = await this.createTest(testName)
187
+
188
+ const match = testUtil.assertFileByNameInGeneratedFiles(
189
+ 'CanBookAppointment.test.ts',
190
+ response.files
191
+ )
192
+ return match
193
+ }
177
194
  }