@sprucelabs/spruce-cli 24.0.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 (105) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/__tests__/behavioral/conversations/CreatingAConversationTopic.test.js +2 -2
  3. package/build/__tests__/behavioral/conversations/CreatingAConversationTopic.test.js.map +1 -1
  4. package/build/__tests__/behavioral/conversations/RegisteringConversationsOnBoot.test.js +1 -1
  5. package/build/__tests__/behavioral/conversations/RegisteringConversationsOnBoot.test.js.map +1 -1
  6. package/build/__tests__/behavioral/conversations/TestingAConversation.test.js +5 -5
  7. package/build/__tests__/behavioral/conversations/TestingAConversation.test.js.map +1 -1
  8. package/build/__tests__/behavioral/organization/CreatingAnOrg.test.js.map +1 -1
  9. package/build/__tests__/behavioral/tests/migrationToInstance/AbstractInstanceTest.d.ts +11 -0
  10. package/build/__tests__/behavioral/tests/migrationToInstance/AbstractInstanceTest.js +49 -0
  11. package/build/__tests__/behavioral/tests/migrationToInstance/AbstractInstanceTest.js.map +1 -0
  12. package/build/__tests__/behavioral/tests/migrationToInstance/InstanceBasedTesting.test.d.ts +5 -0
  13. package/build/__tests__/behavioral/tests/migrationToInstance/InstanceBasedTesting.test.js +34 -0
  14. package/build/__tests__/behavioral/tests/migrationToInstance/InstanceBasedTesting.test.js.map +1 -0
  15. package/build/__tests__/behavioral/tests/migrationToInstance/MigratingTests.test.d.ts +12 -0
  16. package/build/__tests__/behavioral/tests/migrationToInstance/MigratingTests.test.js +88 -0
  17. package/build/__tests__/behavioral/tests/migrationToInstance/MigratingTests.test.js.map +1 -0
  18. package/build/__tests__/behavioral/tests/migrationToInstance/StaticTestFinder.test.d.ts +13 -0
  19. package/build/__tests__/behavioral/tests/migrationToInstance/StaticTestFinder.test.js +109 -0
  20. package/build/__tests__/behavioral/tests/migrationToInstance/StaticTestFinder.test.js.map +1 -0
  21. package/build/__tests__/behavioral/tests/migrationToInstance/StaticTestsWhenAlreadyExists.test.d.ts +4 -0
  22. package/build/__tests__/behavioral/tests/migrationToInstance/StaticTestsWhenAlreadyExists.test.js +29 -0
  23. package/build/__tests__/behavioral/tests/migrationToInstance/StaticTestsWhenAlreadyExists.test.js.map +1 -0
  24. package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceMigrator.test.d.ts +26 -0
  25. package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceMigrator.test.js +259 -0
  26. package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceMigrator.test.js.map +1 -0
  27. package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceTestFileMigrator.test.d.ts +26 -0
  28. package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceTestFileMigrator.test.js +202 -0
  29. package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceTestFileMigrator.test.js.map +1 -0
  30. package/build/__tests__/behavioral/tests/migrationToInstance/support/AbstractInstanceTest.txt +24 -0
  31. package/build/__tests__/behavioral/tests/migrationToInstance/support/AbstractStaticTest.txt +24 -0
  32. package/build/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest.txt +36 -0
  33. package/build/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest2.txt +63 -0
  34. package/build/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest3.txt +222 -0
  35. package/build/__tests__/behavioral/tests/migrationToInstance/support/StaticTest.txt +34 -0
  36. package/build/__tests__/behavioral/tests/migrationToInstance/support/StaticTest2.txt +62 -0
  37. package/build/__tests__/behavioral/tests/migrationToInstance/support/StaticTest3.txt +221 -0
  38. package/build/__tests__/behavioral/tests/migrationToInstance/testFileContentsGenerators.d.ts +2 -0
  39. package/build/__tests__/behavioral/tests/migrationToInstance/testFileContentsGenerators.js +51 -0
  40. package/build/__tests__/behavioral/tests/migrationToInstance/testFileContentsGenerators.js.map +1 -0
  41. package/build/__tests__/behavioral/versions/ResolvingVersions.test.js +0 -3
  42. package/build/__tests__/behavioral/versions/ResolvingVersions.test.js.map +1 -1
  43. package/build/__tests__/implementation/OrganizationStore.test.js +2 -2
  44. package/build/__tests__/implementation/OrganizationStore.test.js.map +1 -1
  45. package/build/__tests__/testDirsAndFiles/static_test_migration_1/src/__tests__/AnotherStaticTest.test.ts +33 -0
  46. package/build/__tests__/testDirsAndFiles/static_test_migration_1/src/__tests__/ShouldBeIgnored.ts +0 -0
  47. package/build/__tests__/testDirsAndFiles/static_test_migration_1/src/__tests__/StaticTest1.test.ts +33 -0
  48. package/build/__tests__/testDirsAndFiles/static_test_migration_2/src/DoNotInclude.ts +0 -0
  49. package/build/__tests__/testDirsAndFiles/static_test_migration_2/src/__tests__/AStaticTest.test.ts +33 -0
  50. package/build/__tests__/testDirsAndFiles/static_test_migration_2/src/__tests__/AnotherStaticTest1.test.ts +33 -0
  51. package/build/__tests__/testDirsAndFiles/static_test_migration_3/NotAFileThatShouldBeMigrated.ts +0 -0
  52. package/build/__tests__/testDirsAndFiles/static_test_migration_3/src/__tests__/AStaticTest2.test.ts +17 -0
  53. package/build/__tests__/testDirsAndFiles/static_test_migration_3/src/__tests__/AbstractWhateverTest.ts +3 -0
  54. package/build/features/test/actions/CreateAction.d.ts +1 -0
  55. package/build/features/test/actions/CreateAction.js +13 -0
  56. package/build/features/test/actions/CreateAction.js.map +1 -1
  57. package/build/features/test/actions/MigrateAction.d.ts +17 -0
  58. package/build/features/test/actions/MigrateAction.js +39 -0
  59. package/build/features/test/actions/MigrateAction.js.map +1 -0
  60. package/build/tests/staticToInstanceMigration/StaticTestFinder.d.ts +8 -0
  61. package/build/tests/staticToInstanceMigration/StaticTestFinder.js +23 -0
  62. package/build/tests/staticToInstanceMigration/StaticTestFinder.js.map +1 -0
  63. package/build/tests/staticToInstanceMigration/StaticToInstanceMigrator.d.ts +58 -0
  64. package/build/tests/staticToInstanceMigration/StaticToInstanceMigrator.js +48 -0
  65. package/build/tests/staticToInstanceMigration/StaticToInstanceMigrator.js.map +1 -0
  66. package/build/tests/staticToInstanceMigration/StaticToInstanceTestFileMigrator.d.ts +12 -0
  67. package/build/tests/staticToInstanceMigration/StaticToInstanceTestFileMigrator.js +138 -0
  68. package/build/tests/staticToInstanceMigration/StaticToInstanceTestFileMigrator.js.map +1 -0
  69. package/package.json +27 -27
  70. package/src/__tests__/behavioral/conversations/CreatingAConversationTopic.test.ts +2 -2
  71. package/src/__tests__/behavioral/conversations/RegisteringConversationsOnBoot.test.ts +1 -1
  72. package/src/__tests__/behavioral/conversations/TestingAConversation.test.ts +5 -5
  73. package/src/__tests__/behavioral/organization/CreatingAnOrg.test.ts +0 -1
  74. package/src/__tests__/behavioral/tests/migrationToInstance/AbstractInstanceTest.ts +77 -0
  75. package/src/__tests__/behavioral/tests/migrationToInstance/InstanceBasedTesting.test.ts +19 -0
  76. package/src/__tests__/behavioral/tests/migrationToInstance/MigratingTests.test.ts +99 -0
  77. package/src/__tests__/behavioral/tests/migrationToInstance/StaticTestFinder.test.ts +72 -0
  78. package/src/__tests__/behavioral/tests/migrationToInstance/StaticTestsWhenAlreadyExists.test.ts +31 -0
  79. package/src/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceMigrator.test.ts +252 -0
  80. package/src/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceTestFileMigrator.test.ts +193 -0
  81. package/src/__tests__/behavioral/tests/migrationToInstance/support/AbstractInstanceTest.txt +24 -0
  82. package/src/__tests__/behavioral/tests/migrationToInstance/support/AbstractStaticTest.txt +24 -0
  83. package/src/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest.txt +36 -0
  84. package/src/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest2.txt +63 -0
  85. package/src/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest3.txt +222 -0
  86. package/src/__tests__/behavioral/tests/migrationToInstance/support/StaticTest.txt +34 -0
  87. package/src/__tests__/behavioral/tests/migrationToInstance/support/StaticTest2.txt +62 -0
  88. package/src/__tests__/behavioral/tests/migrationToInstance/support/StaticTest3.txt +221 -0
  89. package/src/__tests__/behavioral/tests/migrationToInstance/testFileContentsGenerators.ts +50 -0
  90. package/src/__tests__/behavioral/versions/ResolvingVersions.test.ts +1 -3
  91. package/src/__tests__/implementation/OrganizationStore.test.ts +6 -2
  92. package/src/__tests__/testDirsAndFiles/static_test_migration_1/src/__tests__/AnotherStaticTest.test.ts +33 -0
  93. package/src/__tests__/testDirsAndFiles/static_test_migration_1/src/__tests__/ShouldBeIgnored.ts +0 -0
  94. package/src/__tests__/testDirsAndFiles/static_test_migration_1/src/__tests__/StaticTest1.test.ts +33 -0
  95. package/src/__tests__/testDirsAndFiles/static_test_migration_2/src/DoNotInclude.ts +0 -0
  96. package/src/__tests__/testDirsAndFiles/static_test_migration_2/src/__tests__/AStaticTest.test.ts +33 -0
  97. package/src/__tests__/testDirsAndFiles/static_test_migration_2/src/__tests__/AnotherStaticTest1.test.ts +33 -0
  98. package/src/__tests__/testDirsAndFiles/static_test_migration_3/NotAFileThatShouldBeMigrated.ts +0 -0
  99. package/src/__tests__/testDirsAndFiles/static_test_migration_3/src/__tests__/AStaticTest2.test.ts +17 -0
  100. package/src/__tests__/testDirsAndFiles/static_test_migration_3/src/__tests__/AbstractWhateverTest.ts +3 -0
  101. package/src/features/test/actions/CreateAction.ts +17 -0
  102. package/src/features/test/actions/MigrateAction.ts +41 -0
  103. package/src/tests/staticToInstanceMigration/StaticTestFinder.ts +25 -0
  104. package/src/tests/staticToInstanceMigration/StaticToInstanceMigrator.ts +73 -0
  105. package/src/tests/staticToInstanceMigration/StaticToInstanceTestFileMigrator.ts +197 -0
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "24.0.0",
7
+ "version": "24.1.0",
8
8
  "skill": {
9
9
  "namespace": "spruce-cli",
10
10
  "upgradeIgnoreList": [
@@ -73,18 +73,18 @@
73
73
  },
74
74
  "dependencies": {
75
75
  "@jest/reporters": "^29.7.0",
76
- "@sprucelabs/error": "^6.0.566",
76
+ "@sprucelabs/error": "^6.0.577",
77
77
  "@sprucelabs/globby": "^2.0.501",
78
- "@sprucelabs/heartwood-view-controllers": "^116.0.15",
79
- "@sprucelabs/jest-json-reporter": "^8.0.567",
80
- "@sprucelabs/mercury-client": "^42.0.689",
81
- "@sprucelabs/mercury-event-emitter": "^42.0.689",
82
- "@sprucelabs/mercury-types": "^47.2.0",
83
- "@sprucelabs/schema": "^31.0.19",
84
- "@sprucelabs/spruce-core-schemas": "^40.1.605",
85
- "@sprucelabs/spruce-event-utils": "^40.1.394",
86
- "@sprucelabs/spruce-skill-utils": "^31.2.16",
87
- "@sprucelabs/spruce-templates": "^24.0.0",
78
+ "@sprucelabs/heartwood-view-controllers": "^117.2.5",
79
+ "@sprucelabs/jest-json-reporter": "^8.0.578",
80
+ "@sprucelabs/mercury-client": "^42.0.733",
81
+ "@sprucelabs/mercury-event-emitter": "^42.0.733",
82
+ "@sprucelabs/mercury-types": "^47.2.28",
83
+ "@sprucelabs/schema": "^31.0.44",
84
+ "@sprucelabs/spruce-core-schemas": "^40.1.634",
85
+ "@sprucelabs/spruce-event-utils": "^40.2.32",
86
+ "@sprucelabs/spruce-skill-utils": "^31.2.47",
87
+ "@sprucelabs/spruce-templates": "^24.1.0",
88
88
  "@typescript-eslint/eslint-plugin": "^7.7.1",
89
89
  "@typescript-eslint/parser": "^7.7.1",
90
90
  "cfonts": "^3.3.0",
@@ -101,31 +101,31 @@
101
101
  "md5": "^2.3.0",
102
102
  "open": "^8.4.2",
103
103
  "ora": "5.4.1",
104
- "semver": "^7.6.3",
104
+ "semver": "^7.7.1",
105
105
  "string-argv": "^0.3.2",
106
106
  "terminal-kit": "sprucelabsai/terminal-kit",
107
107
  "tree-kill": "^1.2.2",
108
108
  "tsutils": "^3.21.0",
109
109
  "typescript": "^5.7.3",
110
- "uuid": "^11.0.5"
110
+ "uuid": "^11.1.0"
111
111
  },
112
112
  "devDependencies": {
113
- "@sprucelabs/data-stores": "^28.5.24",
114
- "@sprucelabs/mercury-core-events": "^25.1.0",
115
- "@sprucelabs/resolve-path-aliases": "^2.0.527",
116
- "@sprucelabs/spruce-conversation-plugin": "^65.0.9",
117
- "@sprucelabs/spruce-deploy-plugin": "^65.0.9",
118
- "@sprucelabs/spruce-store-plugin": "^65.0.9",
119
- "@sprucelabs/spruce-test-fixtures": "^65.0.9",
120
- "@sprucelabs/test": "^9.0.67",
121
- "@sprucelabs/test-utils": "^5.1.546",
113
+ "@sprucelabs/data-stores": "^28.5.57",
114
+ "@sprucelabs/mercury-core-events": "^26.0.9",
115
+ "@sprucelabs/resolve-path-aliases": "^2.0.531",
116
+ "@sprucelabs/spruce-conversation-plugin": "^66.0.20",
117
+ "@sprucelabs/spruce-deploy-plugin": "^66.0.20",
118
+ "@sprucelabs/spruce-store-plugin": "^66.0.20",
119
+ "@sprucelabs/spruce-test-fixtures": "^66.0.20",
120
+ "@sprucelabs/test": "^9.0.71",
121
+ "@sprucelabs/test-utils": "^5.3.4",
122
122
  "@types/blessed": "^0.1.25",
123
123
  "@types/eslint": "^9.6.1",
124
124
  "@types/fs-extra": "^11.0.4",
125
125
  "@types/inquirer": "^9.0.7",
126
- "@types/lodash": "^4.17.14",
126
+ "@types/lodash": "^4.17.15",
127
127
  "@types/md5": "^2.3.5",
128
- "@types/node": "^22.10.7",
128
+ "@types/node": "^22.13.4",
129
129
  "@types/promise.allsettled": "^1.0.6",
130
130
  "@types/ps-node": "^0.1.3",
131
131
  "@types/semver": "^7.5.8",
@@ -138,7 +138,7 @@
138
138
  "concurrently": "^9.1.2",
139
139
  "conventional-changelog-sprucelabs": "2.0.1",
140
140
  "dotenv": "^16.4.7",
141
- "eslint": "^9.18.0",
141
+ "eslint": "^9.20.1",
142
142
  "eslint-config-spruce": "^11.2.26",
143
143
  "find-process": "^1.4.10",
144
144
  "jest": "^29.7.0",
@@ -571,5 +571,5 @@
571
571
  "open"
572
572
  ]
573
573
  },
574
- "gitHead": "4ae8247c0a6aeb36bc8d249c50303e01decb96c2"
574
+ "gitHead": "1dba2146c4738dbd9c94b2937b3553addee5a1a4"
575
575
  }
@@ -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({
@@ -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
+ }