@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
@@ -0,0 +1,33 @@
1
+ import { fake } from '@sprucelabs/spruce-test-fixtures'
2
+ import AbstractSpruceTest, {
3
+ test,
4
+ assert,
5
+ errorAssert,
6
+ } from '@sprucelabs/test-utils'
7
+
8
+ @fake.login()
9
+ export default class StaticTestFinderTest extends AbstractSpruceTest {
10
+ @test()
11
+ protected static async throwsWithMissing() {
12
+ const finder = StaticTestFinder.Finder()
13
+ const err = await assert.doesThrowAsync(() => finder.find())
14
+ errorAssert.assertError(err, 'MISSING_PARAMETERS', {
15
+ parameters: ['lookupDir'],
16
+ })
17
+ }
18
+
19
+ @test()
20
+ protected static async yourNextTest() {
21
+ assert.isTrue(false)
22
+ }
23
+ }
24
+
25
+ class StaticTestFinder {
26
+ public static Finder() {
27
+ return new this()
28
+ }
29
+
30
+ public async find() {
31
+ // assertOptions({}, ['lookupDir'])
32
+ }
33
+ }
@@ -0,0 +1,33 @@
1
+ import { fake } from '@sprucelabs/spruce-test-fixtures'
2
+ import AbstractSpruceTest, {
3
+ test,
4
+ assert,
5
+ errorAssert,
6
+ } from '@sprucelabs/test-utils'
7
+
8
+ @fake.login()
9
+ export default class StaticTestFinderTest extends AbstractSpruceTest {
10
+ @test()
11
+ protected static async throwsWithMissing() {
12
+ const finder = StaticTestFinder.Finder()
13
+ const err = await assert.doesThrowAsync(() => finder.find())
14
+ errorAssert.assertError(err, 'MISSING_PARAMETERS', {
15
+ parameters: ['lookupDir'],
16
+ })
17
+ }
18
+
19
+ @test()
20
+ protected static async yourNextTest() {
21
+ assert.isTrue(false)
22
+ }
23
+ }
24
+
25
+ class StaticTestFinder {
26
+ public static Finder() {
27
+ return new this()
28
+ }
29
+
30
+ public async find() {
31
+ // assertOptions({}, ['lookupDir'])
32
+ }
33
+ }
@@ -0,0 +1,33 @@
1
+ import { fake } from '@sprucelabs/spruce-test-fixtures'
2
+ import AbstractSpruceTest, {
3
+ test,
4
+ assert,
5
+ errorAssert,
6
+ } from '@sprucelabs/test-utils'
7
+
8
+ @fake.login()
9
+ export default class StaticTestFinderTest extends AbstractSpruceTest {
10
+ @test()
11
+ protected static async throwsWithMissing() {
12
+ const finder = StaticTestFinder.Finder()
13
+ const err = await assert.doesThrowAsync(() => finder.find())
14
+ errorAssert.assertError(err, 'MISSING_PARAMETERS', {
15
+ parameters: ['lookupDir'],
16
+ })
17
+ }
18
+
19
+ @test()
20
+ protected static async yourNextTest() {
21
+ assert.isTrue(false)
22
+ }
23
+ }
24
+
25
+ class StaticTestFinder {
26
+ public static Finder() {
27
+ return new this()
28
+ }
29
+
30
+ public async find() {
31
+ // assertOptions({}, ['lookupDir'])
32
+ }
33
+ }
@@ -0,0 +1,33 @@
1
+ import { fake } from '@sprucelabs/spruce-test-fixtures'
2
+ import AbstractSpruceTest, {
3
+ test,
4
+ assert,
5
+ errorAssert,
6
+ } from '@sprucelabs/test-utils'
7
+
8
+ @fake.login()
9
+ export default class StaticTestFinderTest extends AbstractSpruceTest {
10
+ @test()
11
+ protected static async throwsWithMissing() {
12
+ const finder = StaticTestFinder.Finder()
13
+ const err = await assert.doesThrowAsync(() => finder.find())
14
+ errorAssert.assertError(err, 'MISSING_PARAMETERS', {
15
+ parameters: ['lookupDir'],
16
+ })
17
+ }
18
+
19
+ @test()
20
+ protected static async yourNextTest() {
21
+ assert.isTrue(false)
22
+ }
23
+ }
24
+
25
+ class StaticTestFinder {
26
+ public static Finder() {
27
+ return new this()
28
+ }
29
+
30
+ public async find() {
31
+ // assertOptions({}, ['lookupDir'])
32
+ }
33
+ }
@@ -0,0 +1,17 @@
1
+ import { fake } from "@sprucelabs/spruce-test-fixtures";
2
+ import {
3
+ test,
4
+ assert,
5
+ } from "@sprucelabs/test-utils";
6
+ import AbstractWhateverTest from "./AbstractWhateverTest";
7
+
8
+ @fake.login()
9
+ export default class StaticTestFinderTest extends AbstractWhateverTest {
10
+ @test()
11
+ protected static async throwsWithMissing() {}
12
+
13
+ @test()
14
+ protected static async yourNextTest() {
15
+ assert.isTrue(false);
16
+ }
17
+ }
@@ -0,0 +1,3 @@
1
+ import AbstractSpruceTest from "@sprucelabs/test-utils";
2
+
3
+ export default abstract class AbstractWhateverTest extends AbstractSpruceTest {}
@@ -5,6 +5,7 @@ export default class CreateAction extends AbstractAction<OptionsSchema> {
5
5
  optionsSchema: SpruceSchemas.SpruceCli.v2020_07_22.CreateTestOptionsSchema;
6
6
  invocationMessage: string;
7
7
  execute(options: Options): Promise<FeatureActionResponse>;
8
+ private doesStaticTestAlreadyExist;
8
9
  private promptForSubDir;
9
10
  private promptForParentTestClassAndOptionallyInstallDependencies;
10
11
  private optionallyInstallFeatureBasedOnSelection;
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const path_1 = __importDefault(require("path"));
7
+ const globby_1 = __importDefault(require("@sprucelabs/globby"));
7
8
  const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
8
9
  const spruce_skill_utils_2 = require("@sprucelabs/spruce-skill-utils");
9
10
  const createTestOptions_schema_1 = __importDefault(require("./../../../.spruce/schemas/spruceCli/v2020_07_22/createTestOptions.schema"));
@@ -29,6 +30,7 @@ class CreateAction extends AbstractAction_1.default {
29
30
  this.ui.startLoading('Generating test file...');
30
31
  const writer = this.Writer('test');
31
32
  const isTestFixturesInstalled = !!this.Service('pkg').get('devDependencies.@sprucelabs/spruce-test-fixtures');
33
+ let doesStaticTestExist = await this.doesStaticTestAlreadyExist(resolvedDestination);
32
34
  const results = await writer.writeTest(resolvedDestination, {
33
35
  ...normalizedOptions,
34
36
  type,
@@ -36,12 +38,23 @@ class CreateAction extends AbstractAction_1.default {
36
38
  parentTestClass,
37
39
  isTestFixturesInstalled,
38
40
  namePascal: namePascal ?? spruce_skill_utils_1.namesUtil.toPascal(nameCamel),
41
+ testType: doesStaticTestExist ? 'static' : 'instance',
39
42
  });
40
43
  return {
41
44
  files: results,
42
45
  hints: ["run `spruce test` in your skill when you're ready!"],
43
46
  };
44
47
  }
48
+ async doesStaticTestAlreadyExist(resolvedDestination) {
49
+ const matches = await (0, globby_1.default)(resolvedDestination + `/**/*.test.ts`);
50
+ let doesStaticTestExist = false;
51
+ const match = matches[0];
52
+ if (match) {
53
+ const contents = spruce_skill_utils_2.diskUtil.readFile(matches[0]);
54
+ doesStaticTestExist = contents.includes('static');
55
+ }
56
+ return doesStaticTestExist;
57
+ }
45
58
  async promptForSubDir(resolvedDestination) {
46
59
  const match = await this.ui.prompt({
47
60
  type: 'directory',
@@ -1 +1 @@
1
- {"version":3,"file":"CreateAction.js","sourceRoot":"","sources":["../../../../src/features/test/actions/CreateAction.ts"],"names":[],"mappings":";;;;;AAAA,gDAA2B;AAC3B,uEAA0D;AAC1D,uEAAyD;AAEzD,8HAAmG;AACnG,0EAAiD;AAIjD,MAAqB,YAAa,SAAQ,wBAA6B;IAC5D,aAAa,GAAG,kCAAsB,CAAA;IACtC,iBAAiB,GAAG,uBAAuB,CAAA;IAE3C,KAAK,CAAC,OAAO,CAAC,OAAgB;QACjC,MAAM,iBAAiB,GAAG,IAAI,CAAC,2BAA2B,CAAC,OAAO,CAAC,CAAA;QACnE,MAAM,EAAE,kBAAkB,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,GACrD,iBAAiB,CAAA;QAErB,IAAI,mBAAmB,GAAG,6BAAQ,CAAC,WAAW,CAC1C,IAAI,CAAC,GAAG,EACR,kBAAkB,EAClB,IAAI,CACP,CAAA;QAED,IAAI,eAEgE,CAAA;QAEpE,MAAM,WAAW,GAAG,IAAI,CAAC,MAAqB,CAAA;QAC9C,MAAM,UAAU,GAAG,MAAM,WAAW,CAAC,0BAA0B,EAAE,CAAA;QAEjE,IAAI,6BAAQ,CAAC,YAAY,CAAC,mBAAmB,CAAC,EAAE,CAAC;YAC7C,mBAAmB;gBACf,MAAM,IAAI,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAA;QACvD,CAAC;QAED,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,eAAe;gBACX,MAAM,IAAI,CAAC,wDAAwD,CAC/D,UAAU,EACV,eAAe,EACf,mBAAmB,CACtB,CAAA;QACT,CAAC;QAED,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,yBAAyB,CAAC,CAAA;QAE/C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAEl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,KAAK,CAAC,wCAAwC,CAClD,KAA2B;QAE3B,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;YACpB,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAC/C,KAAK,CAAC,WAAW,CACpB,CAAA;YAED,IAAI,CAAC,WAAW,EAAE,CAAC;gBACf,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,cAAc,KAAK,CAAC,IAAI,KAAK,CAAC,CAAA;gBACnD,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;oBACxB,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,WAAkB,EAAE,CAAC;iBACjD,CAAC,CAAA;gBACF,IAAI,CAAC,EAAE,CAAC,WAAW,EAAE,CAAA;YACzB,CAAC;QACL,CAAC;IACL,CAAC;IAEO,6BAA6B,CACjC,KAA2B,EAC3B,mBAA2B;QAO3B,OAAO;YACH,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,eAAe,EAAE,KAAK,CAAC,eAAe;YACtC,UAAU,EACN,KAAK,CAAC,MAAM;gBACZ,6BAAQ,CAAC,mBAAmB,CACxB,mBAAmB;gBACnB,YAAY;gBACZ,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,cAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CACvD;SACR,CAAA;IACL,CAAC;CACJ;AA1KD,+BA0KC"}
@@ -0,0 +1,17 @@
1
+ import AbstractAction from '../../AbstractAction';
2
+ import { FeatureActionResponse } from '../../features.types';
3
+ export default class MigrationAction extends AbstractAction<OptionsSchema> {
4
+ optionsSchema: {
5
+ id: string;
6
+ fields: {};
7
+ };
8
+ commandAliases: string[];
9
+ invocationMessage: string;
10
+ execute(): Promise<FeatureActionResponse>;
11
+ }
12
+ declare const optionsSchema: {
13
+ id: string;
14
+ fields: {};
15
+ };
16
+ type OptionsSchema = typeof optionsSchema;
17
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const schema_1 = require("@sprucelabs/schema");
7
+ const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
8
+ const StaticTestFinder_1 = __importDefault(require("../../../tests/staticToInstanceMigration/StaticTestFinder"));
9
+ const StaticToInstanceMigrator_1 = __importDefault(require("../../../tests/staticToInstanceMigration/StaticToInstanceMigrator"));
10
+ const StaticToInstanceTestFileMigrator_1 = __importDefault(require("../../../tests/staticToInstanceMigration/StaticToInstanceTestFileMigrator"));
11
+ const AbstractAction_1 = __importDefault(require("../../AbstractAction"));
12
+ class MigrationAction extends AbstractAction_1.default {
13
+ optionsSchema = optionsSchema;
14
+ commandAliases = ['migrate.tests'];
15
+ invocationMessage = 'Migrating tests from static to instance... 🌲';
16
+ async execute() {
17
+ const testFinder = StaticTestFinder_1.default.Finder();
18
+ const testFileMigrator = StaticToInstanceTestFileMigrator_1.default.Migrator();
19
+ const migrator = StaticToInstanceMigrator_1.default.Migrator({
20
+ testFinder,
21
+ testFileMigrator,
22
+ });
23
+ const path = spruce_skill_utils_1.diskUtil.resolvePath(this.cwd, 'src', '__tests__');
24
+ const { totalTestsSkipped, totalTestsUpdated } = await migrator.run(path);
25
+ return {
26
+ headline: 'Migrated tests from static to instance based.',
27
+ summaryLines: [
28
+ `${totalTestsUpdated} test${totalTestsUpdated === 1 ? '' : 's'} updated`,
29
+ `${totalTestsSkipped} test${totalTestsSkipped === 1 ? '' : 's'} skipped`,
30
+ ],
31
+ };
32
+ }
33
+ }
34
+ exports.default = MigrationAction;
35
+ const optionsSchema = (0, schema_1.buildSchema)({
36
+ id: 'migrateTests',
37
+ fields: {},
38
+ });
39
+ //# sourceMappingURL=MigrateAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MigrateAction.js","sourceRoot":"","sources":["../../../../src/features/test/actions/MigrateAction.ts"],"names":[],"mappings":";;;;;AAAA,+CAAgD;AAChD,uEAAyD;AACzD,iHAA4F;AAC5F,iIAA4G;AAC5G,iJAA4H;AAC5H,0EAAiD;AAGjD,MAAqB,eAAgB,SAAQ,wBAA6B;IAC/D,aAAa,GAAG,aAAa,CAAA;IAC7B,cAAc,GAAG,CAAC,eAAe,CAAC,CAAA;IAClC,iBAAiB,GAAG,+CAA+C,CAAA;IAEnE,KAAK,CAAC,OAAO;QAChB,MAAM,UAAU,GAAG,0BAAoB,CAAC,MAAM,EAAE,CAAA;QAChD,MAAM,gBAAgB,GAAG,0CAAoC,CAAC,QAAQ,EAAE,CAAA;QACxE,MAAM,QAAQ,GAAG,kCAA4B,CAAC,QAAQ,CAAC;YACnD,UAAU;YACV,gBAAgB;SACnB,CAAC,CAAA;QAEF,MAAM,IAAI,GAAG,6BAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,WAAW,CAAC,CAAA;QAC/D,MAAM,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,GAC1C,MAAM,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAE5B,OAAO;YACH,QAAQ,EAAE,+CAA+C;YACzD,YAAY,EAAE;gBACV,GAAG,iBAAiB,QAAQ,iBAAiB,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,UAAU;gBACxE,GAAG,iBAAiB,QAAQ,iBAAiB,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,UAAU;aAC3E;SACJ,CAAA;IACL,CAAC;CACJ;AAzBD,kCAyBC;AAED,MAAM,aAAa,GAAG,IAAA,oBAAW,EAAC;IAC9B,EAAE,EAAE,cAAc;IAClB,MAAM,EAAE,EAAE;CACb,CAAC,CAAA"}
@@ -0,0 +1,8 @@
1
+ export default class StaticTestFinderImpl implements StaticTestFinder {
2
+ static Class?: new () => StaticTestFinder;
3
+ static Finder(): StaticTestFinder;
4
+ find(lookupDir: string): Promise<string[]>;
5
+ }
6
+ export interface StaticTestFinder {
7
+ find(lookupDir: string): Promise<string[]>;
8
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const globby_1 = __importDefault(require("@sprucelabs/globby"));
7
+ const schema_1 = require("@sprucelabs/schema");
8
+ class StaticTestFinderImpl {
9
+ static Class;
10
+ static Finder() {
11
+ return new (this.Class ?? this)();
12
+ }
13
+ async find(lookupDir) {
14
+ (0, schema_1.assertOptions)({ lookupDir }, ['lookupDir']);
15
+ const matches = await (0, globby_1.default)([
16
+ `${lookupDir}/**/Abstract*Test.ts`,
17
+ `${lookupDir}/**/*.test.ts`,
18
+ ]);
19
+ return matches;
20
+ }
21
+ }
22
+ exports.default = StaticTestFinderImpl;
23
+ //# sourceMappingURL=StaticTestFinder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StaticTestFinder.js","sourceRoot":"","sources":["../../../src/tests/staticToInstanceMigration/StaticTestFinder.ts"],"names":[],"mappings":";;;;;AAAA,gEAAuC;AACvC,+CAAkD;AAElD,MAAqB,oBAAoB;IAC9B,MAAM,CAAC,KAAK,CAA6B;IAEzC,MAAM,CAAC,MAAM;QAChB,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,EAAE,CAAA;IACrC,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,SAAiB;QAC/B,IAAA,sBAAa,EAAC,EAAE,SAAS,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAA;QAE3C,MAAM,OAAO,GAAG,MAAM,IAAA,gBAAM,EAAC;YACzB,GAAG,SAAS,sBAAsB;YAClC,GAAG,SAAS,eAAe;SAC9B,CAAC,CAAA;QAEF,OAAO,OAAO,CAAA;IAClB,CAAC;CACJ;AAjBD,uCAiBC"}
@@ -0,0 +1,58 @@
1
+ import StaticTestFinder from './StaticTestFinder';
2
+ import { StaticToInstanceTestFileMigrator } from './StaticToInstanceTestFileMigrator';
3
+ export default class StaticToInstanceMigratorImpl implements StaticToInstanceMigrator {
4
+ static diskUtil: {
5
+ writeFile(destination: string, contents: string): void;
6
+ readDir(destination: string): string[];
7
+ readFile(source: string): string;
8
+ deleteFile(destination: string): void;
9
+ createDir(destination: string): void;
10
+ moveDir(source: string, destination: string): void;
11
+ moveFile(source: string, destination: string): void;
12
+ copyDir(source: string, destination: string): Promise<unknown>;
13
+ deleteDir(target: string): void;
14
+ doesFileExist(target: string): boolean;
15
+ isDir(target: string): boolean;
16
+ isDirPath(path: string): boolean;
17
+ isFile(target: string): boolean;
18
+ doesDirExist(target: string): boolean;
19
+ resolveHashSprucePath(cwd: string, ...filePath: string[]): string;
20
+ doesHashSprucePathExist(cwd: string, ...filePath: string[]): boolean;
21
+ resolveBuiltHashSprucePath(cwd: string, ...filePath: string[]): string;
22
+ doesBuiltHashSprucePathExist(cwd: string, ...filePath: string[]): boolean;
23
+ isFileDifferent(destination: string, contents: string): boolean;
24
+ deleteEmptyDirs(dir: string): void;
25
+ resolvePath(cwd: string, ...filePath: string[]): string;
26
+ resolveRelativePath(path1: string, path2: string): string;
27
+ resolveFile(...pathItems: string[]): string | false;
28
+ createTempDir(...files: string[]): string;
29
+ createRandomTempDir(): string;
30
+ hasFileChanged(...filePath: string[]): boolean;
31
+ markFileAsUnchanged(...filePath: string[]): void;
32
+ resolveCacheDirForDir(dir: string): string;
33
+ resolveFileInHashSpruceDir(cwd: string, ...filePath: string[]): string;
34
+ getFileChangedCacheFile(file: string): string;
35
+ };
36
+ static Class?: new (options: StaticToInstanceMigratorOptions) => StaticToInstanceMigrator;
37
+ private testFinder;
38
+ private testFileMigrator;
39
+ protected constructor(options: StaticToInstanceMigratorOptions);
40
+ static Migrator(options: StaticToInstanceMigratorOptions): StaticToInstanceMigrator;
41
+ run(lookupDir: string): Promise<{
42
+ totalTestsUpdated: number;
43
+ totalTestsSkipped: number;
44
+ }>;
45
+ private readFile;
46
+ private writeFile;
47
+ }
48
+ export interface StaticToInstanceMigratorOptions {
49
+ testFinder: StaticTestFinder;
50
+ testFileMigrator: StaticToInstanceTestFileMigrator;
51
+ }
52
+ export interface StaticToInstanceMigratorResults {
53
+ totalTestsUpdated: number;
54
+ totalTestsSkipped: number;
55
+ }
56
+ export interface StaticToInstanceMigrator {
57
+ run(lookupDir: string): Promise<StaticToInstanceMigratorResults>;
58
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const schema_1 = require("@sprucelabs/schema");
4
+ const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
5
+ class StaticToInstanceMigratorImpl {
6
+ static diskUtil = spruce_skill_utils_1.diskUtil;
7
+ static Class;
8
+ testFinder;
9
+ testFileMigrator;
10
+ constructor(options) {
11
+ const { testFinder, testFileMigrator } = options;
12
+ this.testFinder = testFinder;
13
+ this.testFileMigrator = testFileMigrator;
14
+ }
15
+ static Migrator(options) {
16
+ (0, schema_1.assertOptions)(options, ['testFinder', 'testFileMigrator']);
17
+ return new (this.Class ?? this)(options);
18
+ }
19
+ async run(lookupDir) {
20
+ (0, schema_1.assertOptions)({ lookupDir }, ['lookupDir']);
21
+ const matches = await this.testFinder.find(lookupDir);
22
+ let totalTestsUpdated = 0;
23
+ let totalTestsSkipped = 0;
24
+ for (const match of matches) {
25
+ const contents = this.readFile(match);
26
+ const updated = this.testFileMigrator.migrate(contents);
27
+ if (contents === updated) {
28
+ totalTestsSkipped++;
29
+ }
30
+ else {
31
+ totalTestsUpdated++;
32
+ this.writeFile(match, updated);
33
+ }
34
+ }
35
+ return {
36
+ totalTestsUpdated,
37
+ totalTestsSkipped,
38
+ };
39
+ }
40
+ readFile(match) {
41
+ return StaticToInstanceMigratorImpl.diskUtil.readFile(match);
42
+ }
43
+ writeFile(match, updated) {
44
+ StaticToInstanceMigratorImpl.diskUtil.writeFile(match, updated);
45
+ }
46
+ }
47
+ exports.default = StaticToInstanceMigratorImpl;
48
+ //# sourceMappingURL=StaticToInstanceMigrator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StaticToInstanceMigrator.js","sourceRoot":"","sources":["../../../src/tests/staticToInstanceMigration/StaticToInstanceMigrator.ts"],"names":[],"mappings":";;AAAA,+CAAkD;AAClD,uEAAyD;AAIzD,MAAqB,4BAA4B;IAGtC,MAAM,CAAC,QAAQ,GAAG,6BAAQ,CAAA;IAC1B,MAAM,CAAC,KAAK,CAEU;IAErB,UAAU,CAAkB;IAC5B,gBAAgB,CAAkC;IAE1D,YAAsB,OAAwC;QAC1D,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAA;QAChD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;IAC5C,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,OAAwC;QAC3D,IAAA,sBAAa,EAAC,OAAO,EAAE,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC,CAAA;QAC1D,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,CAAA;IAC5C,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,SAAiB;QAC9B,IAAA,sBAAa,EAAC,EAAE,SAAS,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAA;QAC3C,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAErD,IAAI,iBAAiB,GAAG,CAAC,CAAA;QACzB,IAAI,iBAAiB,GAAG,CAAC,CAAA;QAEzB,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC1B,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;YACrC,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;YACvD,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;gBACvB,iBAAiB,EAAE,CAAA;YACvB,CAAC;iBAAM,CAAC;gBACJ,iBAAiB,EAAE,CAAA;gBACnB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;YAClC,CAAC;QACL,CAAC;QAED,OAAO;YACH,iBAAiB;YACjB,iBAAiB;SACpB,CAAA;IACL,CAAC;IAEO,QAAQ,CAAC,KAAa;QAC1B,OAAO,4BAA4B,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IAChE,CAAC;IAEO,SAAS,CAAC,KAAa,EAAE,OAAe;QAC5C,4BAA4B,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IACnE,CAAC;;AApDL,+CAqDC"}
@@ -0,0 +1,12 @@
1
+ export default class StaticToInstanceTestFileMigratorImpl implements StaticToInstanceTestFileMigrator {
2
+ static Class?: new () => StaticToInstanceTestFileMigrator;
3
+ static Migrator(): StaticToInstanceTestFileMigrator;
4
+ migrate(contents: string): string;
5
+ private hasSuiteImport;
6
+ private findThisCalls;
7
+ private removeStaticFromDeclaration;
8
+ private fixNonNullAssertions;
9
+ }
10
+ export interface StaticToInstanceTestFileMigrator {
11
+ migrate(contents: string): string;
12
+ }
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const schema_1 = require("@sprucelabs/schema");
4
+ class StaticToInstanceTestFileMigratorImpl {
5
+ static Class;
6
+ static Migrator() {
7
+ return new (this.Class ?? this)();
8
+ }
9
+ migrate(contents) {
10
+ (0, schema_1.assertOptions)({ contents }, ['contents']);
11
+ // 1a. Remove `static ` only when it appears immediately before a method
12
+ // that has the `@test()` decorator
13
+ // 1b. If the contents include `export default abstract class`,
14
+ // remove `static` from all methods
15
+ const includesAbstractExport = contents.includes('export default abstract class');
16
+ let cleanedUp = includesAbstractExport
17
+ ? contents.replaceAll(' static ', ' ')
18
+ : contents.replace(
19
+ // Matches @test() or @seed(...) followed (on next line) by optional visibility and `static`.
20
+ /(@(?:test\(\)|seed\([^)]*\))\s*\n\s*(?:public|protected)\s+)static\s+/g, '$1');
21
+ // 2. Add `@suite()` above `export default class` if it's not already present
22
+ if (!cleanedUp.includes('@suite')) {
23
+ cleanedUp = cleanedUp.replace(/export default class/, '@suite()\nexport default class');
24
+ }
25
+ // 3. Ensure `suite` is imported from `@sprucelabs/test-utils`
26
+ if (!this.hasSuiteImport(cleanedUp)) {
27
+ if (cleanedUp.includes('{ test')) {
28
+ cleanedUp = cleanedUp.replace('{ test', '{ test, suite');
29
+ }
30
+ else if (cleanedUp.includes('test }')) {
31
+ cleanedUp = cleanedUp.replace('test }', 'test, suite }');
32
+ }
33
+ else {
34
+ cleanedUp = cleanedUp.replace('test,', 'test,\n suite,');
35
+ }
36
+ }
37
+ const thisCallNames = this.findThisCalls(cleanedUp);
38
+ for (const name of thisCallNames) {
39
+ cleanedUp = this.removeStaticFromDeclaration(cleanedUp, name);
40
+ }
41
+ // 4. lifecicle methods
42
+ const methods = ['beforeEach', 'afterEach'];
43
+ for (const method of methods) {
44
+ cleanedUp = cleanedUp.replace(`protected static async ${method}()`, `protected async ${method}()`);
45
+ }
46
+ cleanedUp = this.fixNonNullAssertions(cleanedUp);
47
+ return cleanedUp;
48
+ }
49
+ hasSuiteImport(text) {
50
+ const pattern = new RegExp(`import\\s+(?:[\\s\\S]*?\\bsuite\\b[\\s\\S]*?)\\s+from\\s+['"]@sprucelabs/test-utils['"]`);
51
+ return pattern.test(text);
52
+ }
53
+ findThisCalls(contents) {
54
+ // Matches `this.myProp` if followed by space, punctuation, parentheses, or end of string
55
+ const thisPropertyRegex = /this\.(\w+)(?=[\s.(),;]|$)/g;
56
+ const names = [];
57
+ let match;
58
+ while ((match = thisPropertyRegex.exec(contents)) !== null) {
59
+ const propName = match[1];
60
+ if (!names.includes(propName)) {
61
+ names.push(propName);
62
+ }
63
+ }
64
+ return names;
65
+ }
66
+ removeStaticFromDeclaration(contents, name) {
67
+ /**
68
+ * 1) Remove `static` for methods/getters/setters, e.g.:
69
+ * private static async doSomething() => private async doSomething()
70
+ * private static get value() => private get value()
71
+ * private static set value(v) => private set value(v)
72
+ */
73
+ const methodPattern = new RegExp(`((?:public|protected|private)?\\s+)?` + // group 1
74
+ `static\\s+` + // literal "static "
75
+ `(?:(async)\\s+)?` + // group 2: "async"?
76
+ `(?:(get|set)\\s+)?` + // group 3: "get" or "set"?
77
+ `(${name})\\s*\\(`, // group 4: the identifier + '('
78
+ 'g');
79
+ let updated = contents.replace(methodPattern, (match, g1, g2, g3, g4) => {
80
+ const asyncPart = g2 ? g2 + ' ' : '';
81
+ const accessorPart = g3 ? g3 + ' ' : '';
82
+ // Rebuild the declaration without "static"
83
+ return `${g1 ?? ''}${asyncPart}${accessorPart}${g4}(`;
84
+ });
85
+ /**
86
+ * 2) Remove `static` from property declarations and add a non-null assertion.
87
+ * e.g.
88
+ * private static myProp: Type => private myProp!: Type
89
+ */
90
+ const propertyPattern = new RegExp(`((?:public|protected|private)?\\s+)?` + // group 1: optional visibility
91
+ `static\\s+` + // literal "static "
92
+ `(${name})` + // group 2: the property name
93
+ `(?=[\\s=:\\[;]|$)`, // lookahead: space, '=', ':', '[', ';', or end-of-string
94
+ 'g');
95
+ updated = updated.replace(propertyPattern, (match, g1, g2) => {
96
+ // g1 = "private " / "public " / "protected " or empty
97
+ // g2 = property name
98
+ return `${g1 ?? ''}${g2}!`;
99
+ });
100
+ return updated;
101
+ }
102
+ fixNonNullAssertions(contents) {
103
+ const lines = contents.split('\n');
104
+ const propertyRegex = /^(\s*)(public|protected|private)(\s+readonly)?\s+(\w+)\s*(!)?\s*:\s*([^=;]+)(=.*)?;?$/;
105
+ const updatedLines = lines.map((originalLine) => {
106
+ // Skip lines containing "static"
107
+ if (originalLine.includes('static')) {
108
+ return originalLine;
109
+ }
110
+ const match = originalLine.match(propertyRegex);
111
+ if (!match) {
112
+ return originalLine;
113
+ }
114
+ let [, leadingWhitespace, visibility, readonlyPart = '', propName, exclamation, typeDecl, assignment,] = match;
115
+ // Trim trailing whitespace from the type
116
+ typeDecl = typeDecl.trim();
117
+ if (assignment) {
118
+ // Remove the bang if there's an assignment
119
+ exclamation = '';
120
+ // Remove trailing semicolon
121
+ assignment = assignment.replace(/;$/, '');
122
+ // Ensure we always have " = " at the start
123
+ // E.g. "=something" => " = something"
124
+ assignment = assignment.replace(/^=\s*/, ' = ');
125
+ }
126
+ else {
127
+ // No assignment? Add bang
128
+ exclamation = '!';
129
+ }
130
+ // Rebuild line, preserving leading indentation
131
+ const rebuilt = `${leadingWhitespace}${visibility}${readonlyPart} ${propName}${exclamation}: ${typeDecl}${assignment ?? ''}`;
132
+ return rebuilt;
133
+ });
134
+ return updatedLines.join('\n');
135
+ }
136
+ }
137
+ exports.default = StaticToInstanceTestFileMigratorImpl;
138
+ //# sourceMappingURL=StaticToInstanceTestFileMigrator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StaticToInstanceTestFileMigrator.js","sourceRoot":"","sources":["../../../src/tests/staticToInstanceMigration/StaticToInstanceTestFileMigrator.ts"],"names":[],"mappings":";;AAAA,+CAAkD;AAElD,MAAqB,oCAAoC;IAG9C,MAAM,CAAC,KAAK,CAA6C;IAEzD,MAAM,CAAC,QAAQ;QAClB,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,EAAE,CAAA;IACrC,CAAC;IAEM,OAAO,CAAC,QAAgB;QAC3B,IAAA,sBAAa,EAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAA;QAEzC,wEAAwE;QACxE,sCAAsC;QACtC,+DAA+D;QAC/D,uC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