@sprucelabs/spruce-cli 23.1.0 → 24.1.0

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 (135) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/LICENSE +21 -0
  3. package/build/__tests__/behavioral/DeployingToSandbox.test.d.ts +6 -1
  4. package/build/__tests__/behavioral/DeployingToSandbox.test.js +54 -35
  5. package/build/__tests__/behavioral/DeployingToSandbox.test.js.map +1 -1
  6. package/build/__tests__/behavioral/conversations/CreatingAConversationTopic.test.js +2 -2
  7. package/build/__tests__/behavioral/conversations/CreatingAConversationTopic.test.js.map +1 -1
  8. package/build/__tests__/behavioral/conversations/RegisteringConversationsOnBoot.test.js +1 -1
  9. package/build/__tests__/behavioral/conversations/RegisteringConversationsOnBoot.test.js.map +1 -1
  10. package/build/__tests__/behavioral/conversations/TestingAConversation.test.js +5 -5
  11. package/build/__tests__/behavioral/conversations/TestingAConversation.test.js.map +1 -1
  12. package/build/__tests__/behavioral/organization/CreatingAnOrg.test.js.map +1 -1
  13. package/build/__tests__/behavioral/schemas/CreatingSchemasWithGenerics.test.js +1 -1
  14. package/build/__tests__/behavioral/schemas/CreatingSchemasWithGenerics.test.js.map +1 -1
  15. package/build/__tests__/behavioral/tests/migrationToInstance/AbstractInstanceTest.d.ts +11 -0
  16. package/build/__tests__/behavioral/tests/migrationToInstance/AbstractInstanceTest.js +49 -0
  17. package/build/__tests__/behavioral/tests/migrationToInstance/AbstractInstanceTest.js.map +1 -0
  18. package/build/__tests__/behavioral/tests/migrationToInstance/InstanceBasedTesting.test.d.ts +5 -0
  19. package/build/__tests__/behavioral/tests/migrationToInstance/InstanceBasedTesting.test.js +34 -0
  20. package/build/__tests__/behavioral/tests/migrationToInstance/InstanceBasedTesting.test.js.map +1 -0
  21. package/build/__tests__/behavioral/tests/migrationToInstance/MigratingTests.test.d.ts +12 -0
  22. package/build/__tests__/behavioral/tests/migrationToInstance/MigratingTests.test.js +88 -0
  23. package/build/__tests__/behavioral/tests/migrationToInstance/MigratingTests.test.js.map +1 -0
  24. package/build/__tests__/behavioral/tests/migrationToInstance/StaticTestFinder.test.d.ts +13 -0
  25. package/build/__tests__/behavioral/tests/migrationToInstance/StaticTestFinder.test.js +109 -0
  26. package/build/__tests__/behavioral/tests/migrationToInstance/StaticTestFinder.test.js.map +1 -0
  27. package/build/__tests__/behavioral/tests/migrationToInstance/StaticTestsWhenAlreadyExists.test.d.ts +4 -0
  28. package/build/__tests__/behavioral/tests/migrationToInstance/StaticTestsWhenAlreadyExists.test.js +29 -0
  29. package/build/__tests__/behavioral/tests/migrationToInstance/StaticTestsWhenAlreadyExists.test.js.map +1 -0
  30. package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceMigrator.test.d.ts +26 -0
  31. package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceMigrator.test.js +259 -0
  32. package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceMigrator.test.js.map +1 -0
  33. package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceTestFileMigrator.test.d.ts +26 -0
  34. package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceTestFileMigrator.test.js +202 -0
  35. package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceTestFileMigrator.test.js.map +1 -0
  36. package/build/__tests__/behavioral/tests/migrationToInstance/support/AbstractInstanceTest.txt +24 -0
  37. package/build/__tests__/behavioral/tests/migrationToInstance/support/AbstractStaticTest.txt +24 -0
  38. package/build/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest.txt +36 -0
  39. package/build/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest2.txt +63 -0
  40. package/build/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest3.txt +222 -0
  41. package/build/__tests__/behavioral/tests/migrationToInstance/support/StaticTest.txt +34 -0
  42. package/build/__tests__/behavioral/tests/migrationToInstance/support/StaticTest2.txt +62 -0
  43. package/build/__tests__/behavioral/tests/migrationToInstance/support/StaticTest3.txt +221 -0
  44. package/build/__tests__/behavioral/tests/migrationToInstance/testFileContentsGenerators.d.ts +2 -0
  45. package/build/__tests__/behavioral/tests/migrationToInstance/testFileContentsGenerators.js +51 -0
  46. package/build/__tests__/behavioral/tests/migrationToInstance/testFileContentsGenerators.js.map +1 -0
  47. package/build/__tests__/behavioral/versions/ResolvingVersions.test.js +0 -3
  48. package/build/__tests__/behavioral/versions/ResolvingVersions.test.js.map +1 -1
  49. package/build/__tests__/implementation/OrganizationStore.test.js +2 -2
  50. package/build/__tests__/implementation/OrganizationStore.test.js.map +1 -1
  51. package/build/__tests__/implementation/TerminalInterface.test.d.ts +1 -0
  52. package/build/__tests__/implementation/TerminalInterface.test.js +6 -0
  53. package/build/__tests__/implementation/TerminalInterface.test.js.map +1 -1
  54. package/build/__tests__/testDirsAndFiles/static_test_migration_1/src/__tests__/AnotherStaticTest.test.ts +33 -0
  55. package/build/__tests__/testDirsAndFiles/static_test_migration_1/src/__tests__/ShouldBeIgnored.ts +0 -0
  56. package/build/__tests__/testDirsAndFiles/static_test_migration_1/src/__tests__/StaticTest1.test.ts +33 -0
  57. package/build/__tests__/testDirsAndFiles/static_test_migration_2/src/DoNotInclude.ts +0 -0
  58. package/build/__tests__/testDirsAndFiles/static_test_migration_2/src/__tests__/AStaticTest.test.ts +33 -0
  59. package/build/__tests__/testDirsAndFiles/static_test_migration_2/src/__tests__/AnotherStaticTest1.test.ts +33 -0
  60. package/build/__tests__/testDirsAndFiles/static_test_migration_3/NotAFileThatShouldBeMigrated.ts +0 -0
  61. package/build/__tests__/testDirsAndFiles/static_test_migration_3/src/__tests__/AStaticTest2.test.ts +17 -0
  62. package/build/__tests__/testDirsAndFiles/static_test_migration_3/src/__tests__/AbstractWhateverTest.ts +3 -0
  63. package/build/errors/SpruceError.js +1 -1
  64. package/build/errors/SpruceError.js.map +1 -1
  65. package/build/features/skill/actions/LoginAction.js +1 -2
  66. package/build/features/skill/actions/LoginAction.js.map +1 -1
  67. package/build/features/test/actions/CreateAction.d.ts +1 -0
  68. package/build/features/test/actions/CreateAction.js +13 -0
  69. package/build/features/test/actions/CreateAction.js.map +1 -1
  70. package/build/features/test/actions/MigrateAction.d.ts +17 -0
  71. package/build/features/test/actions/MigrateAction.js +39 -0
  72. package/build/features/test/actions/MigrateAction.js.map +1 -0
  73. package/build/index.js +0 -0
  74. package/build/tests/staticToInstanceMigration/StaticTestFinder.d.ts +8 -0
  75. package/build/tests/staticToInstanceMigration/StaticTestFinder.js +23 -0
  76. package/build/tests/staticToInstanceMigration/StaticTestFinder.js.map +1 -0
  77. package/build/tests/staticToInstanceMigration/StaticToInstanceMigrator.d.ts +58 -0
  78. package/build/tests/staticToInstanceMigration/StaticToInstanceMigrator.js +48 -0
  79. package/build/tests/staticToInstanceMigration/StaticToInstanceMigrator.js.map +1 -0
  80. package/build/tests/staticToInstanceMigration/StaticToInstanceTestFileMigrator.d.ts +12 -0
  81. package/build/tests/staticToInstanceMigration/StaticToInstanceTestFileMigrator.js +138 -0
  82. package/build/tests/staticToInstanceMigration/StaticToInstanceTestFileMigrator.js.map +1 -0
  83. package/build/utilities/isCi.js +1 -1
  84. package/build/utilities/isCi.js.map +1 -1
  85. package/package.json +28 -45
  86. package/src/__tests__/behavioral/DeployingToSandbox.test.ts +77 -44
  87. package/src/__tests__/behavioral/conversations/CreatingAConversationTopic.test.ts +2 -2
  88. package/src/__tests__/behavioral/conversations/RegisteringConversationsOnBoot.test.ts +1 -1
  89. package/src/__tests__/behavioral/conversations/TestingAConversation.test.ts +5 -5
  90. package/src/__tests__/behavioral/organization/CreatingAnOrg.test.ts +0 -1
  91. package/src/__tests__/behavioral/schemas/CreatingSchemasWithGenerics.test.ts +2 -1
  92. package/src/__tests__/behavioral/tests/migrationToInstance/AbstractInstanceTest.ts +77 -0
  93. package/src/__tests__/behavioral/tests/migrationToInstance/InstanceBasedTesting.test.ts +19 -0
  94. package/src/__tests__/behavioral/tests/migrationToInstance/MigratingTests.test.ts +99 -0
  95. package/src/__tests__/behavioral/tests/migrationToInstance/StaticTestFinder.test.ts +72 -0
  96. package/src/__tests__/behavioral/tests/migrationToInstance/StaticTestsWhenAlreadyExists.test.ts +31 -0
  97. package/src/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceMigrator.test.ts +252 -0
  98. package/src/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceTestFileMigrator.test.ts +193 -0
  99. package/src/__tests__/behavioral/tests/migrationToInstance/support/AbstractInstanceTest.txt +24 -0
  100. package/src/__tests__/behavioral/tests/migrationToInstance/support/AbstractStaticTest.txt +24 -0
  101. package/src/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest.txt +36 -0
  102. package/src/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest2.txt +63 -0
  103. package/src/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest3.txt +222 -0
  104. package/src/__tests__/behavioral/tests/migrationToInstance/support/StaticTest.txt +34 -0
  105. package/src/__tests__/behavioral/tests/migrationToInstance/support/StaticTest2.txt +62 -0
  106. package/src/__tests__/behavioral/tests/migrationToInstance/support/StaticTest3.txt +221 -0
  107. package/src/__tests__/behavioral/tests/migrationToInstance/testFileContentsGenerators.ts +50 -0
  108. package/src/__tests__/behavioral/versions/ResolvingVersions.test.ts +1 -3
  109. package/src/__tests__/implementation/OrganizationStore.test.ts +6 -2
  110. package/src/__tests__/implementation/TerminalInterface.test.ts +9 -0
  111. package/src/__tests__/testDirsAndFiles/static_test_migration_1/src/__tests__/AnotherStaticTest.test.ts +33 -0
  112. package/src/__tests__/testDirsAndFiles/static_test_migration_1/src/__tests__/ShouldBeIgnored.ts +0 -0
  113. package/src/__tests__/testDirsAndFiles/static_test_migration_1/src/__tests__/StaticTest1.test.ts +33 -0
  114. package/src/__tests__/testDirsAndFiles/static_test_migration_2/src/DoNotInclude.ts +0 -0
  115. package/src/__tests__/testDirsAndFiles/static_test_migration_2/src/__tests__/AStaticTest.test.ts +33 -0
  116. package/src/__tests__/testDirsAndFiles/static_test_migration_2/src/__tests__/AnotherStaticTest1.test.ts +33 -0
  117. package/src/__tests__/testDirsAndFiles/static_test_migration_3/NotAFileThatShouldBeMigrated.ts +0 -0
  118. package/src/__tests__/testDirsAndFiles/static_test_migration_3/src/__tests__/AStaticTest2.test.ts +17 -0
  119. package/src/__tests__/testDirsAndFiles/static_test_migration_3/src/__tests__/AbstractWhateverTest.ts +3 -0
  120. package/src/errors/SpruceError.ts +1 -1
  121. package/src/features/skill/actions/LoginAction.ts +8 -7
  122. package/src/features/test/actions/CreateAction.ts +17 -0
  123. package/src/features/test/actions/MigrateAction.ts +41 -0
  124. package/src/tests/staticToInstanceMigration/StaticTestFinder.ts +25 -0
  125. package/src/tests/staticToInstanceMigration/StaticToInstanceMigrator.ts +73 -0
  126. package/src/tests/staticToInstanceMigration/StaticToInstanceTestFileMigrator.ts +197 -0
  127. package/src/utilities/isCi.ts +1 -1
  128. package/.DS_Store +0 -0
  129. package/.env +0 -25
  130. package/.env-dev +0 -24
  131. package/.eslintcache +0 -1
  132. package/dist/spruce-darwin-arm64 +0 -0
  133. package/dist/spruce-linux-arm64 +0 -0
  134. package/junit.xml +0 -42
  135. package/yarn-error.log +0 -597
@@ -5,6 +5,7 @@ import { errorAssert } from '@sprucelabs/test-utils'
5
5
  import AbstractCliTest from '../../tests/AbstractCliTest'
6
6
  import testUtil from '../../tests/utilities/test.utility'
7
7
  import { ApiClient } from '../../types/apiClient.types'
8
+ import { RegisteredSkill } from '../../types/cli.types'
8
9
 
9
10
  export default class DeployingToSandboxTest extends AbstractCliTest {
10
11
  private static sandboxDemoNumber = process.env.SANDBOX_DEMO_NUMBER as string
@@ -56,7 +57,7 @@ export default class DeployingToSandboxTest extends AbstractCliTest {
56
57
  name: 'My new skill',
57
58
  })
58
59
 
59
- await this.resetCurrentSkill()
60
+ await this.unregisterCurrentSkill()
60
61
 
61
62
  const env = this.Service('env')
62
63
 
@@ -64,14 +65,12 @@ export default class DeployingToSandboxTest extends AbstractCliTest {
64
65
  env.unset('SKILL_NAME')
65
66
  env.unset('SKILL_SLUG')
66
67
 
67
- const results = await this.Action('skill', 'boot').execute({
68
- local: true,
69
- })
68
+ const results = await this.boot()
70
69
 
71
70
  assert.isTruthy(results.errors)
72
71
 
73
72
  errorAssert.assertError(results.errors[0], 'MISSING_PARAMETERS', {
74
- parameters: ['env.SKILL_NAME', 'env.SKILL_SLUG'],
73
+ parameters: ['env.SKILL_NAME'],
75
74
  })
76
75
  }
77
76
 
@@ -81,12 +80,12 @@ export default class DeployingToSandboxTest extends AbstractCliTest {
81
80
 
82
81
  const expected = await this.getTotalSkills(client)
83
82
 
84
- const boot = await this.Action('skill', 'boot').execute({ local: true })
85
-
86
- boot.meta?.kill()
83
+ await assert.doesThrowAsync(
84
+ () => this.bootAndKill(),
85
+ "don't have access"
86
+ )
87
87
 
88
88
  const actual = await this.getTotalSkills(client)
89
-
90
89
  assert.isEqual(expected, actual)
91
90
  }
92
91
 
@@ -98,9 +97,7 @@ export default class DeployingToSandboxTest extends AbstractCliTest {
98
97
  name: 'My new skill',
99
98
  })
100
99
 
101
- const boot = await this.Action('skill', 'boot').execute({ local: true })
102
-
103
- boot.meta?.kill()
100
+ await this.bootAndKill()
104
101
 
105
102
  const skills = await this.fetchSkills(client)
106
103
 
@@ -113,20 +110,13 @@ export default class DeployingToSandboxTest extends AbstractCliTest {
113
110
  protected static async registersSkillAgain() {
114
111
  const { client } = await this.installAndSetupForSandbox()
115
112
 
116
- const skill = await this.getSkillFixture().registerCurrentSkill({
117
- name: 'My new skill',
118
- })
113
+ const skill = await this.registerCurrentSkill('My new skill')
119
114
 
120
- await this.resetCurrentSkill()
121
-
122
- const env = this.Service('env')
123
- env.set('SKILL_ID', skill.id)
124
- env.set('SKILL_NAME', skill.name)
125
- env.set('SKILL_SLUG', skill.slug)
115
+ await this.unregisterCurrentSkill()
126
116
 
127
- const boot = await this.Action('skill', 'boot').execute({ local: true })
117
+ this.updateEnv(skill)
128
118
 
129
- boot.meta?.kill()
119
+ await this.bootAndKill()
130
120
 
131
121
  const skills = await this.fetchSkills(client)
132
122
 
@@ -139,44 +129,81 @@ export default class DeployingToSandboxTest extends AbstractCliTest {
139
129
  @test()
140
130
  protected static async registersSkillAndCanBootAgain() {
141
131
  await this.installAndSetupForSandbox()
132
+ const skill = await this.registerCurrentSkill('My new skill')
133
+ await this.unregisterCurrentSkill()
142
134
 
143
- await this.getSkillFixture().registerCurrentSkill({
144
- name: 'My new skill',
145
- })
135
+ this.updateEnv(skill)
146
136
 
147
- await this.resetCurrentSkill()
148
-
149
- const boot = await this.Action('skill', 'boot').execute({ local: true })
150
-
151
- boot.meta?.kill()
152
-
153
- const boot2 = await this.Action('skill', 'boot').execute({
154
- local: true,
155
- })
156
-
157
- boot2.meta?.kill()
137
+ await this.bootAndKill()
138
+ await this.bootAndKill()
158
139
  }
159
140
 
160
141
  @test()
161
142
  protected static async canReRegisterAndThenRegisterConversationsWithoutCrash() {
162
143
  await this.installAndSetupForSandbox('conversation-with-sandbox')
163
144
 
164
- await this.getSkillFixture().registerCurrentSkill({
165
- name: 'Conversation test',
166
- })
167
-
168
- await this.resetCurrentSkill()
145
+ const skill = await this.registerCurrentSkill('Conversation test')
146
+ await this.unregisterCurrentSkill()
147
+ this.updateEnv(skill)
169
148
 
170
149
  await this.Action('conversation', 'create').execute({
171
150
  nameReadable: 'book an appointment',
172
151
  nameCamel: 'bookAnAppointment',
173
152
  })
174
153
 
175
- const boot = await this.Action('skill', 'boot').execute({ local: true })
154
+ await this.bootAndKill()
155
+ }
156
+
157
+ @test()
158
+ protected static async logsInSkillIfAlreadyRegisteredButMissingEnv() {
159
+ await this.installAndSetupForSandbox()
160
+
161
+ await this.registerCurrentSkill('Login if already registered')
162
+
163
+ const env = this.Service('env')
164
+
165
+ const originalSkillId = env.get('SKILL_ID')
166
+ const orginalSkillApiKey = env.get('SKILL_API_KEY')
167
+
168
+ env.set('SKILL_ID', 'this is garbage')
169
+
170
+ await this.bootAndKill()
171
+
172
+ delete process.env.SKILL_ID
173
+ delete process.env.SKILL_API_KEY
174
+
175
+ const skillId = env.get('SKILL_ID')
176
+ const apiKey = env.get('SKILL_API_KEY')
177
+
178
+ assert.isEqual(
179
+ skillId,
180
+ originalSkillId,
181
+ 'It logged in as the wrong skill!'
182
+ )
183
+
184
+ assert.isEqual(
185
+ apiKey,
186
+ orginalSkillApiKey,
187
+ 'It logged in with the wrong api key!'
188
+ )
189
+ }
176
190
 
191
+ private static updateEnv(skill: RegisteredSkill) {
192
+ const env = this.Service('env')
193
+ env.set('SKILL_ID', skill.id)
194
+ env.set('SKILL_NAME', skill.name)
195
+ }
196
+
197
+ private static async bootAndKill() {
198
+ const boot = await this.boot()
199
+ assert.isFalsy(boot.errors)
177
200
  boot.meta?.kill()
178
201
  }
179
202
 
203
+ private static async boot() {
204
+ return await this.Action('skill', 'boot').execute({ local: true })
205
+ }
206
+
180
207
  private static async installAndSetupForSandbox(cacheKey = 'sandbox') {
181
208
  const client = await this.getMercuryFixture().connectToApi()
182
209
 
@@ -202,7 +229,13 @@ export default class DeployingToSandboxTest extends AbstractCliTest {
202
229
  return skills
203
230
  }
204
231
 
205
- private static async resetCurrentSkill() {
232
+ private static async registerCurrentSkill(name: string) {
233
+ return await this.getSkillFixture().registerCurrentSkill({
234
+ name,
235
+ })
236
+ }
237
+
238
+ private static async unregisterCurrentSkill() {
206
239
  const isInstalled =
207
240
  this.Service('settings').isMarkedAsInstalled('skill')
208
241
  if (!isInstalled) {
@@ -5,12 +5,12 @@ import testUtil from '../../../tests/utilities/test.utility'
5
5
  import { CliInterface } from '../../../types/cli.types'
6
6
 
7
7
  export default class CreatingAConversationTopicTest extends AbstractCliTest {
8
- @test()
8
+ @test.skip('bring back if re introducing conversation topics')
9
9
  protected static async hasCreateConversationAction() {
10
10
  assert.isFunction(this.Action('conversation', 'create').execute)
11
11
  }
12
12
 
13
- @test()
13
+ @test.skip('bring back if re introducing conversation topics')
14
14
  protected static async createsValidConversationTopicDefinition() {
15
15
  const cli =
16
16
  await this.FeatureFixture().installCachedFeatures('conversation')
@@ -2,7 +2,7 @@ import { test, assert } from '@sprucelabs/test-utils'
2
2
  import AbstractEventTest from '../../../tests/AbstractEventTest'
3
3
 
4
4
  export default class RegisteringConversationsOnBootTest extends AbstractEventTest {
5
- @test()
5
+ @test.skip('bring back if re introducing conversation topics')
6
6
  protected static async canRegisterConversationsOnBoot() {
7
7
  const { currentSkill } =
8
8
  await this.seedDummySkillRegisterCurrentSkillAndInstallToOrg(
@@ -5,12 +5,12 @@ import AbstractCliTest from '../../../tests/AbstractCliTest'
5
5
  import testUtil from '../../../tests/utilities/test.utility'
6
6
 
7
7
  export default class TestingAConversationTest extends AbstractCliTest {
8
- @test()
8
+ @test.skip('bring back if re introducing conversation topics')
9
9
  protected static async hasTestConvoFeature() {
10
10
  assert.isFunction(this.Action('conversation', 'test').execute)
11
11
  }
12
12
 
13
- @test()
13
+ @test.skip('bring back if re introducing conversation topics')
14
14
  protected static async shouldRunWithoutConversationShouldShutdownOnItsOwn() {
15
15
  await this.FeatureFixture().installCachedFeatures('conversation')
16
16
 
@@ -33,7 +33,7 @@ export default class TestingAConversationTest extends AbstractCliTest {
33
33
  } while (psResults.length > 0)
34
34
  }
35
35
 
36
- @test()
36
+ @test.skip('bring back if re introducing conversation topics')
37
37
  protected static async runsUntilKilled() {
38
38
  await this.installAndCreateConversation()
39
39
 
@@ -59,7 +59,7 @@ export default class TestingAConversationTest extends AbstractCliTest {
59
59
  } while (psResults.length > 0)
60
60
  }
61
61
 
62
- @test()
62
+ @test.skip('bring back if re introducing conversation topics')
63
63
  protected static async doesntReturnErrorWhenKilled() {
64
64
  await this.installAndCreateConversation()
65
65
  const test = this.Action(
@@ -79,7 +79,7 @@ export default class TestingAConversationTest extends AbstractCliTest {
79
79
  assert.isFalsy(results.errors)
80
80
  }
81
81
 
82
- @test()
82
+ @test.skip('bring back if re introducing conversation topics')
83
83
  protected static async returnsErrorWhenScriptErrors() {
84
84
  const { createResults } = await this.installAndCreateConversation()
85
85
 
@@ -14,7 +14,6 @@ export default class CreatingAnOrgTest extends AbstractCliTest {
14
14
  const slug = `my-org-${new Date().getTime()}`
15
15
 
16
16
  await this.FeatureFixture().installCachedFeatures('organizations')
17
-
18
17
  await this.people.loginAsDemoPerson()
19
18
 
20
19
  const results = await this.Action('organization', 'create').execute({
@@ -25,12 +25,13 @@ export default class CreatingSchemasWithGenericsTest extends AbstractSchemaTest
25
25
  )
26
26
 
27
27
  const contents = diskUtil.readFile(match)
28
+
28
29
  assert.doesInclude(contents, '<Type extends string = string>')
29
30
  assert.doesInclude(contents, '<Type2 extends string = string>')
30
31
  assert.doesInclude(contents, '<Type>')
31
32
  assert.doesInclude(
32
33
  contents,
33
- "typedByGeneric'?: (Type2)| undefined | null"
34
+ "'typedByGeneric'?: (Type2) | undefined | null"
34
35
  )
35
36
 
36
37
  await this.assertValidActionResponseFiles(results)
@@ -0,0 +1,77 @@
1
+ import { diskUtil, namesUtil } from '@sprucelabs/spruce-skill-utils'
2
+ import { assert } from '@sprucelabs/test-utils'
3
+ import CreateAction from '../../../../features/test/actions/CreateAction'
4
+ import AbstractSkillTest from '../../../../tests/AbstractSkillTest'
5
+ import testUtil from '../../../../tests/utilities/test.utility'
6
+
7
+ export default abstract class AbstractInstanceTest extends AbstractSkillTest {
8
+ protected static skillCacheKey = 'tests'
9
+ protected static action: CreateAction
10
+
11
+ protected static async beforeEach() {
12
+ await super.beforeEach()
13
+
14
+ this.action = this.Action('test', 'create')
15
+ }
16
+
17
+ protected static async createTest(
18
+ name: string,
19
+ willPromptForSubDir = false
20
+ ) {
21
+ const promise = this.action.execute({
22
+ type: 'behavioral',
23
+ nameReadable: name,
24
+ nameCamel: namesUtil.toCamel(name),
25
+ namePascal: namesUtil.toPascal(name),
26
+ })
27
+
28
+ await this.ui.waitForInput()
29
+ await this.ui.sendInput('')
30
+
31
+ if (willPromptForSubDir) {
32
+ await this.ui.waitForInput()
33
+ await this.ui.sendInput('')
34
+ }
35
+
36
+ const results = await promise
37
+
38
+ assert.isFalsy(results.errors, 'Error creating test')
39
+ return results
40
+ }
41
+
42
+ protected static async createTestAndAssertContentsEqual(
43
+ name: string,
44
+ expected: string,
45
+
46
+ willPromptForSubDir = false
47
+ ) {
48
+ const testFile = await this.createTestAndGetCreatedFilePath(
49
+ name,
50
+ willPromptForSubDir
51
+ )
52
+
53
+ const contents = diskUtil.readFile(testFile)
54
+ assert.isEqual(
55
+ this.normalizeWhitespace(contents),
56
+ this.normalizeWhitespace(expected),
57
+ 'Instance test does not match expected'
58
+ )
59
+ }
60
+
61
+ protected static async createTestAndGetCreatedFilePath(
62
+ name: string,
63
+ willPromptForSubDir = false
64
+ ) {
65
+ const results = await this.createTest(name, willPromptForSubDir)
66
+
67
+ const testFile = testUtil.assertFileByNameInGeneratedFiles(
68
+ `${namesUtil.toPascal(name)}.test.ts`,
69
+ results.files
70
+ )
71
+ return testFile
72
+ }
73
+
74
+ protected static normalizeWhitespace(contents: string) {
75
+ return contents.replace(/\s/g, '')
76
+ }
77
+ }
@@ -0,0 +1,19 @@
1
+ import { test } from '@sprucelabs/test-utils'
2
+ import AbstractInstanceTest from './AbstractInstanceTest'
3
+ import { generateExpectedInstanceTestContents } from './testFileContentsGenerators'
4
+
5
+ export default class InstanceBasedTestingTest extends AbstractInstanceTest {
6
+ @test()
7
+ protected static async ifNoTestsExistCreatesInstanceTest() {
8
+ const name = 'My First Test'
9
+ const expected = generateExpectedInstanceTestContents(name)
10
+ await this.createTestAndAssertContentsEqual(name, expected)
11
+ }
12
+
13
+ @test()
14
+ protected static async secondTestAlsoInstance() {
15
+ const name = 'My Second Test'
16
+ const expected = generateExpectedInstanceTestContents(name)
17
+ await this.createTestAndAssertContentsEqual(name, expected, true)
18
+ }
19
+ }
@@ -0,0 +1,99 @@
1
+ import { test, assert } from '@sprucelabs/test-utils'
2
+ import MigrationAction from '../../../../features/test/actions/MigrateAction'
3
+ import AbstractSkillTest from '../../../../tests/AbstractSkillTest'
4
+ import StaticToInstanceMigratorImpl, {
5
+ StaticToInstanceMigrator,
6
+ StaticToInstanceMigratorOptions,
7
+ StaticToInstanceMigratorResults,
8
+ } from '../../../../tests/staticToInstanceMigration/StaticToInstanceMigrator'
9
+
10
+ export default class MigratingTestsTest extends AbstractSkillTest {
11
+ private static action: MigrationAction
12
+ protected static skillCacheKey = 'tests'
13
+
14
+ protected static async beforeEach() {
15
+ await super.beforeEach()
16
+ StaticToInstanceMigratorImpl.Class = FakeStaticToInstanceMigrator
17
+ this.action = this.Action('test', 'migrate')
18
+ }
19
+
20
+ @test()
21
+ protected static async hasMigrateAction() {
22
+ assert.isFunction(this.Action('test', 'migrate').execute)
23
+ }
24
+
25
+ @test()
26
+ protected static async migrateCreatsMigrator() {
27
+ const results = await this.execute()
28
+ assert.isFalsy(results.errors)
29
+ assert.isTruthy(this.migrator, 'Migrator not created')
30
+ }
31
+
32
+ @test()
33
+ protected static async migratorRunsMigratePassingLookupDir() {
34
+ await this.execute()
35
+ this.migrator.assertLookupCalledWith(
36
+ this.resolvePath('src', '__tests__')
37
+ )
38
+ }
39
+
40
+ @test('returns results from migrator 1', 1, 1)
41
+ @test('returns results from migrator 2', 2, 3)
42
+ protected static async returnsResultsFromMigrator(
43
+ totalTestsSkipped: number,
44
+ totalTestsUpdated: number
45
+ ) {
46
+ FakeStaticToInstanceMigrator.runResults = {
47
+ totalTestsSkipped,
48
+ totalTestsUpdated,
49
+ }
50
+
51
+ const results = await this.execute()
52
+ assert.isEqualDeep(results, {
53
+ headline: 'Migrated tests from static to instance based.',
54
+ summaryLines: [
55
+ `${totalTestsUpdated} test${totalTestsUpdated === 1 ? '' : 's'} updated`,
56
+ `${totalTestsSkipped} test${totalTestsSkipped === 1 ? '' : 's'} skipped`,
57
+ ],
58
+ })
59
+ }
60
+
61
+ private static get migrator(): FakeStaticToInstanceMigrator {
62
+ return FakeStaticToInstanceMigrator.instance
63
+ }
64
+
65
+ private static async execute() {
66
+ return await this.action.execute()
67
+ }
68
+ }
69
+
70
+ class FakeStaticToInstanceMigrator implements StaticToInstanceMigrator {
71
+ public static instance: FakeStaticToInstanceMigrator
72
+ private passedLookupDir?: string
73
+ public static runResults?: StaticToInstanceMigratorResults
74
+
75
+ public constructor(_options: StaticToInstanceMigratorOptions) {
76
+ FakeStaticToInstanceMigrator.instance = this
77
+ }
78
+
79
+ public async run(
80
+ lookupDir: string
81
+ ): Promise<StaticToInstanceMigratorResults> {
82
+ this.passedLookupDir = lookupDir
83
+
84
+ return (
85
+ FakeStaticToInstanceMigrator.runResults ?? {
86
+ totalTestsUpdated: 0,
87
+ totalTestsSkipped: 0,
88
+ }
89
+ )
90
+ }
91
+
92
+ public assertLookupCalledWith(expected: string) {
93
+ assert.isEqual(
94
+ this.passedLookupDir,
95
+ expected,
96
+ `Migrator.run was not called with expected lookup dir.`
97
+ )
98
+ }
99
+ }
@@ -0,0 +1,72 @@
1
+ import AbstractSpruceTest, {
2
+ test,
3
+ assert,
4
+ errorAssert,
5
+ suite,
6
+ } from '@sprucelabs/test-utils'
7
+ import StaticTestFinderImpl from '../../../../tests/staticToInstanceMigration/StaticTestFinder'
8
+
9
+ @suite()
10
+ export default class StaticTestFinderTest extends AbstractSpruceTest {
11
+ private finder: StaticTestFinderImpl = StaticTestFinderImpl.Finder()
12
+ private testPath?: string
13
+
14
+ @test()
15
+ protected async throwsWithMissing() {
16
+ //@ts-ignore
17
+ const err = await assert.doesThrowAsync(() => this.finder.find())
18
+ errorAssert.assertError(err, 'MISSING_PARAMETERS', {
19
+ parameters: ['lookupDir'],
20
+ })
21
+ }
22
+
23
+ @test()
24
+ protected async matchesStaticTests1() {
25
+ this.setTestMigrationDir('static_test_migration_1')
26
+ await this.assertFindResultsEqual([
27
+ 'AnotherStaticTest.test.ts',
28
+ 'StaticTest1.test.ts',
29
+ ])
30
+ }
31
+
32
+ @test()
33
+ protected async matchesStaticTests2() {
34
+ this.setTestMigrationDir('static_test_migration_2')
35
+ await this.assertFindResultsEqual([
36
+ 'AStaticTest.test.ts',
37
+ 'AnotherStaticTest1.test.ts',
38
+ ])
39
+ }
40
+
41
+ @test()
42
+ protected async includesAbstractTestsInOtherDirectories() {
43
+ this.setTestMigrationDir('static_test_migration_3')
44
+ await this.assertFindResultsEqual([
45
+ 'AbstractWhateverTest.ts',
46
+ 'AStaticTest2.test.ts',
47
+ ])
48
+ }
49
+
50
+ private async assertFindResultsEqual(files: string[]) {
51
+ const results = await this.find()
52
+ const expected = files.map((file) => this.resolveStaticTestFile(file))
53
+ assert.isEqualDeep(results, expected)
54
+ }
55
+
56
+ private async find() {
57
+ return await this.finder.find(this.testPath!)
58
+ }
59
+
60
+ private resolveStaticTestFile(file: string) {
61
+ return this.resolvePath(this.testPath!, 'src', '__tests__', file)
62
+ }
63
+
64
+ private setTestMigrationDir(dirName: string) {
65
+ this.testPath = this.resolvePath(
66
+ 'build',
67
+ '__tests__',
68
+ 'testDirsAndFiles',
69
+ dirName
70
+ )
71
+ }
72
+ }
@@ -0,0 +1,31 @@
1
+ import { diskUtil } from '@sprucelabs/spruce-skill-utils'
2
+ import { test } from '@sprucelabs/test-utils'
3
+ import AbstractInstanceTest from './AbstractInstanceTest'
4
+ import { generateExpectedStaticTestContents } from './testFileContentsGenerators'
5
+
6
+ export default class StaticTestsWhenAlreadyExistsTest extends AbstractInstanceTest {
7
+ @test()
8
+ protected static async canCreateStaticTestsWhenAlreadyExists() {
9
+ const testFile =
10
+ await this.createTestAndGetCreatedFilePath('AFirstTest')
11
+
12
+ diskUtil.writeFile(
13
+ testFile,
14
+ generateExpectedStaticTestContents('AFirstTest')
15
+ )
16
+
17
+ await this.createTestAndAssertContentsEqual(
18
+ 'ASecondTest',
19
+ generateExpectedStaticTestContents('ASecondTest'),
20
+ true
21
+ )
22
+
23
+ diskUtil.deleteFile(testFile)
24
+
25
+ await this.createTestAndAssertContentsEqual(
26
+ 'AThirdTest',
27
+ generateExpectedStaticTestContents('AThirdTest'),
28
+ true
29
+ )
30
+ }
31
+ }