@superblocksteam/sdk 2.0.76 → 2.0.77-next.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.
@@ -1,9 +1,8 @@
1
1
  import os from "node:os";
2
2
  import path from "node:path";
3
3
  import { readAppApiYamlFile, LoopType } from "@superblocksteam/util";
4
- import { expect } from "chai";
5
4
  import fs from "fs-extra";
6
- import { describe, it } from "mocha";
5
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
7
6
  import { stringify as ymlstringify } from "yaml";
8
7
  import { FeatureFlags } from "../src/flag.js";
9
8
  import {
@@ -43,26 +42,24 @@ const NO_EXTRACT_SOURCE_CODE: ApiRepresentation = {
43
42
  minLinesForExtraction: 0,
44
43
  };
45
44
 
46
- describe("version-control", function () {
45
+ describe("version-control", () => {
47
46
  const testDir = USE_TEMP_TEST_DIR
48
47
  ? fs.mkdtempSync(path.join(os.tmpdir(), "test-output"))
49
48
  : new URL("../../test-output", import.meta.url).pathname;
50
49
 
51
- // eslint-disable-next-line mocha/no-top-level-hooks
52
- beforeEach(async function () {
50
+ beforeEach(async () => {
53
51
  // Clean up the temporary directory before each test, then create it
54
52
  await fs.rm(testDir, { recursive: true, force: true });
55
53
  await fs.ensureDir(testDir);
56
54
  });
57
55
 
58
- // eslint-disable-next-line mocha/no-top-level-hooks
59
- afterEach(async function () {
56
+ afterEach(async () => {
60
57
  // Clean up the temporary directory after each test
61
58
  await fs.rm(testDir, { recursive: true, force: true });
62
59
  });
63
60
 
64
- describe("writeAppApi", function () {
65
- it("should write app api to separate directory with correct name", async function () {
61
+ describe("writeAppApi", () => {
62
+ it("should write app api to separate directory with correct name", async () => {
66
63
  // Setup
67
64
  const api: ApiWrapper = {
68
65
  apiPb: {
@@ -89,8 +86,8 @@ describe("version-control", function () {
89
86
  await Promise.all(apiPromises);
90
87
 
91
88
  // Verify the ApiInfo object is correct
92
- expect(apiInfo.name).to.equal("Test API");
93
- expect(apiInfo.sourceFiles).to.deep.equal([]);
89
+ expect(apiInfo.name).toBe("Test API");
90
+ expect(apiInfo.sourceFiles).toEqual([]);
94
91
 
95
92
  // Verify the files exist and match expectations: one YAML file in directory nested under `apis`
96
93
  const apiDir = path.join(testDir, "apis");
@@ -100,13 +97,14 @@ describe("version-control", function () {
100
97
  await expectNoFileExists(apiDir, "test_api.yaml");
101
98
 
102
99
  // and can be read back in
103
- (await readApiFile(apiDir, "Test API")).to.deep.equal({
100
+ const readApi = await readApiFile(apiDir, "Test API");
101
+ expect(readApi).toEqual({
104
102
  api: api.apiPb,
105
103
  stepPathMap: {},
106
104
  });
107
105
  });
108
106
 
109
- it("should write app api to separate directory and extract large code blocks to separate files", async function () {
107
+ it("should write app api to separate directory and extract large code blocks to separate files", async () => {
110
108
  // Setup
111
109
  const api: ApiWrapper = {
112
110
  apiPb: {
@@ -143,23 +141,25 @@ describe("version-control", function () {
143
141
  await Promise.all(apiPromises);
144
142
 
145
143
  // Verify the ApiInfo object is correct
146
- expect(apiInfo.name).to.equal("Test API");
147
- expect(apiInfo.sourceFiles).to.deep.equal(["large_block.js"]);
144
+ expect(apiInfo.name).toBe("Test API");
145
+ expect(apiInfo.sourceFiles).toEqual(["large_block.js"]);
148
146
 
149
147
  // Verify the files exist and match expectations
150
148
  const apiDir = path.join(testDir, "apis");
151
- (await expectFileExists(apiDir, "test_api/api.yaml")).and.contains(
152
- "path: ./large_block.js",
153
- );
154
- (await expectFileExists(apiDir, "test_api/large_block.js")).and.includes(
155
- LARGE_JS_CONTENT,
149
+ const apiYaml = await expectFileExists(apiDir, "test_api/api.yaml");
150
+ expect(apiYaml).toContain("path: ./large_block.js");
151
+ const jsContent = await expectFileExists(
152
+ apiDir,
153
+ "test_api/large_block.js",
156
154
  );
155
+ expect(jsContent).toContain(LARGE_JS_CONTENT);
157
156
 
158
157
  // And does not have a YAML file in the `apis` directory
159
158
  await expectNoFileExists(apiDir, "test_api.yaml");
160
159
 
161
160
  // and can be read back in
162
- (await readApiFile(apiDir, api.apiPb.metadata.name)).to.deep.equal({
161
+ const readApi = await readApiFile(apiDir, api.apiPb.metadata.name);
162
+ expect(readApi).toEqual({
163
163
  api: api.apiPb,
164
164
  stepPathMap: {
165
165
  "Large Block": "./large_block.js",
@@ -167,7 +167,7 @@ describe("version-control", function () {
167
167
  });
168
168
  });
169
169
 
170
- it("should write app api with similarly-named steps to separate directory and extract large code blocks to separate files", async function () {
170
+ it("should write app api with similarly-named steps to separate directory and extract large code blocks to separate files", async () => {
171
171
  const stepName1 = "Large Block";
172
172
  const stepName2 = stepName1.toLocaleLowerCase();
173
173
 
@@ -216,29 +216,27 @@ describe("version-control", function () {
216
216
  await Promise.all(apiPromises);
217
217
 
218
218
  // Verify the ApiInfo object is correct
219
- expect(apiInfo.name).to.equal("Test API");
220
- expect(apiInfo.sourceFiles).to.deep.equal([
219
+ expect(apiInfo.name).toBe("Test API");
220
+ expect(apiInfo.sourceFiles).toEqual([
221
221
  "large_block.js",
222
222
  "large_block_1.js",
223
223
  ]);
224
224
 
225
225
  // Verify the files exist and match expectations
226
226
  const apiDir = path.join(testDir, "apis");
227
- (await expectFileExists(apiDir, "test_api/api.yaml")).and.contains(
228
- "path: ./large_block.js",
229
- );
230
- (await expectFileExists(apiDir, "test_api/large_block.js")).and.includes(
231
- LARGE_JS_CONTENT,
232
- );
233
- (
234
- await expectFileExists(apiDir, "test_api/large_block_1.js")
235
- ).and.includes(LARGER_JS_CONTENT);
227
+ const apiYaml = await expectFileExists(apiDir, "test_api/api.yaml");
228
+ expect(apiYaml).toContain("path: ./large_block.js");
229
+ const js1 = await expectFileExists(apiDir, "test_api/large_block.js");
230
+ expect(js1).toContain(LARGE_JS_CONTENT);
231
+ const js2 = await expectFileExists(apiDir, "test_api/large_block_1.js");
232
+ expect(js2).toContain(LARGER_JS_CONTENT);
236
233
 
237
234
  // And does not have a YAML file in the `apis` directory
238
235
  await expectNoFileExists(apiDir, "test_api.yaml");
239
236
 
240
237
  // and can be read back in
241
- (await readApiFile(apiDir, api.apiPb.metadata.name)).to.deep.equal({
238
+ const readApi = await readApiFile(apiDir, api.apiPb.metadata.name);
239
+ expect(readApi).toEqual({
242
240
  api: api.apiPb,
243
241
  stepPathMap: {
244
242
  "Large Block": "./large_block.js",
@@ -247,7 +245,7 @@ describe("version-control", function () {
247
245
  });
248
246
  });
249
247
 
250
- it("should write app api to separate directory and extract small code blocks to separate files", async function () {
248
+ it("should write app api to separate directory and extract small code blocks to separate files", async () => {
251
249
  // Setup
252
250
  const api: ApiWrapper = {
253
251
  apiPb: {
@@ -284,24 +282,26 @@ describe("version-control", function () {
284
282
  await Promise.all(apiPromises);
285
283
 
286
284
  // Verify the ApiInfo object is correct
287
- expect(apiInfo.name).to.equal("Test API");
288
- expect(apiInfo.sourceFiles).to.deep.equal(["small_block.js"]);
285
+ expect(apiInfo.name).toBe("Test API");
286
+ expect(apiInfo.sourceFiles).toEqual(["small_block.js"]);
289
287
 
290
288
  // Verify the files exist and match expectations: one YAML file in directory nested under `apis`
291
289
  const apisDir = path.join(testDir, "apis");
292
- (await expectFileExists(apisDir, "test_api/api.yaml")).and.contains(
293
- "path: ./small_block.js",
294
- );
295
- (await expectFileExists(apisDir, "test_api/small_block.js")).and.contains(
296
- SMALL_JS_CONTENT,
290
+ const apiYaml = await expectFileExists(apisDir, "test_api/api.yaml");
291
+ expect(apiYaml).toContain("path: ./small_block.js");
292
+ const jsContent = await expectFileExists(
293
+ apisDir,
294
+ "test_api/small_block.js",
297
295
  );
296
+ expect(jsContent).toContain(SMALL_JS_CONTENT);
298
297
  // And no separate code file and no nested directory with the files
299
298
  await expectNoFileExists(apisDir, "small_block.js");
300
299
  await expectNoFileExists(apisDir, "test_api.yaml");
301
300
  await expectNoFileExists(apisDir, "test_api/test_api.yaml");
302
301
 
303
302
  // and can be read back in
304
- (await readApiFile(apisDir, api.apiPb.metadata.name)).to.deep.equal({
303
+ const readApi = await readApiFile(apisDir, api.apiPb.metadata.name);
304
+ expect(readApi).toEqual({
305
305
  api: api.apiPb,
306
306
  stepPathMap: {
307
307
  "Small Block": "./small_block.js",
@@ -309,7 +309,7 @@ describe("version-control", function () {
309
309
  });
310
310
  });
311
311
 
312
- it("should write app api to apis directory and not extract code blocks to separate files", async function () {
312
+ it("should write app api to apis directory and not extract code blocks to separate files", async () => {
313
313
  // Setup
314
314
  const api: ApiWrapper = {
315
315
  apiPb: {
@@ -346,8 +346,8 @@ describe("version-control", function () {
346
346
  await Promise.all(apiPromises);
347
347
 
348
348
  // Verify the ApiInfo object is correct
349
- expect(apiInfo.name).to.equal("Test API");
350
- expect(apiInfo.sourceFiles).to.deep.equal([]);
349
+ expect(apiInfo.name).toBe("Test API");
350
+ expect(apiInfo.sourceFiles).toEqual([]);
351
351
 
352
352
  // Compute the expected YAML file content
353
353
  const expectedYamlContent = ymlstringify(api.apiPb, {
@@ -357,21 +357,21 @@ describe("version-control", function () {
357
357
 
358
358
  // Verify the files exist and match expectations
359
359
  const apisDir = path.join(testDir, "apis");
360
- (await expectFileExists(apisDir, "test_api.yaml")).and.equals(
361
- expectedYamlContent,
362
- );
360
+ const yamlContent = await expectFileExists(apisDir, "test_api.yaml");
361
+ expect(yamlContent).toBe(expectedYamlContent);
363
362
  await expectNoFileExists(apisDir, "large_block.js");
364
363
  await expectNoFileExists(apisDir, "test_api/test_api.yaml");
365
364
  await expectNoFileExists(apisDir, "test_api/large_block.js");
366
365
 
367
366
  // and can be read back in
368
- (await readApiFile(apisDir, api.apiPb.metadata.name)).to.deep.equal({
367
+ const readApi = await readApiFile(apisDir, api.apiPb.metadata.name);
368
+ expect(readApi).toEqual({
369
369
  api: api.apiPb,
370
370
  stepPathMap: {},
371
371
  });
372
372
  });
373
373
 
374
- it("should write api with try-catch, conditional, loop, and parallel JavaScript steps", async function () {
374
+ it("should write api with try-catch, conditional, loop, and parallel JavaScript steps", async () => {
375
375
  const api: ApiWrapper = {
376
376
  apiPb: {
377
377
  metadata: {
@@ -537,8 +537,8 @@ describe("version-control", function () {
537
537
  await Promise.all(apiPromises);
538
538
 
539
539
  // Verify the ApiInfo object is correct
540
- expect(apiInfo.name).to.equal("Try Catch API");
541
- expect(apiInfo.sourceFiles).to.deep.equal([
540
+ expect(apiInfo.name).toBe("Try Catch API");
541
+ expect(apiInfo.sourceFiles).toEqual([
542
542
  "else_if_step.js",
543
543
  "else_step.js",
544
544
  "if_step.js",
@@ -550,33 +550,47 @@ describe("version-control", function () {
550
550
 
551
551
  // Verify the files exist and match expectations
552
552
  const apiDir = path.join(testDir, "apis");
553
- (await expectFileExists(apiDir, "try_catch_api/api.yaml")).and.contains(
554
- "path: ./loop_step.js",
553
+ const apiYaml = await expectFileExists(
554
+ apiDir,
555
+ "try_catch_api/api.yaml",
556
+ );
557
+ expect(apiYaml).toContain("path: ./loop_step.js");
558
+ const loopJs = await expectFileExists(
559
+ apiDir,
560
+ "try_catch_api/loop_step.js",
561
+ );
562
+ expect(loopJs).toContain(LARGER_JS_CONTENT);
563
+ const secondJs = await expectFileExists(
564
+ apiDir,
565
+ "try_catch_api/second_block.js",
566
+ );
567
+ expect(secondJs).toContain(LARGE_JS_CONTENT);
568
+ const ifJs = await expectFileExists(apiDir, "try_catch_api/if_step.js");
569
+ expect(ifJs).toContain(LARGER_JS_CONTENT);
570
+ const elseIfJs = await expectFileExists(
571
+ apiDir,
572
+ "try_catch_api/else_if_step.js",
573
+ );
574
+ expect(elseIfJs).toContain(LARGE_JS_CONTENT);
575
+ const elseJs = await expectFileExists(
576
+ apiDir,
577
+ "try_catch_api/else_step.js",
578
+ );
579
+ expect(elseJs).toContain(LARGE_JS_CONTENT);
580
+ const path1Js = await expectFileExists(
581
+ apiDir,
582
+ "try_catch_api/path1_step.js",
555
583
  );
556
- (
557
- await expectFileExists(apiDir, "try_catch_api/loop_step.js")
558
- ).and.includes(LARGER_JS_CONTENT);
559
- (
560
- await expectFileExists(apiDir, "try_catch_api/second_block.js")
561
- ).and.includes(LARGE_JS_CONTENT);
562
- (
563
- await expectFileExists(apiDir, "try_catch_api/if_step.js")
564
- ).and.includes(LARGER_JS_CONTENT);
565
- (
566
- await expectFileExists(apiDir, "try_catch_api/else_if_step.js")
567
- ).and.includes(LARGE_JS_CONTENT);
568
- (
569
- await expectFileExists(apiDir, "try_catch_api/else_step.js")
570
- ).and.includes(LARGE_JS_CONTENT);
571
- (
572
- await expectFileExists(apiDir, "try_catch_api/path1_step.js")
573
- ).and.includes(LARGE_JS_CONTENT);
574
- (
575
- await expectFileExists(apiDir, "try_catch_api/path2_step.js")
576
- ).and.includes(SMALL_JS_CONTENT);
584
+ expect(path1Js).toContain(LARGE_JS_CONTENT);
585
+ const path2Js = await expectFileExists(
586
+ apiDir,
587
+ "try_catch_api/path2_step.js",
588
+ );
589
+ expect(path2Js).toContain(SMALL_JS_CONTENT);
577
590
 
578
591
  // and can be read back in
579
- (await readApiFile(apiDir, "Try Catch API")).to.deep.equal({
592
+ const readApi = await readApiFile(apiDir, "Try Catch API");
593
+ expect(readApi).toEqual({
580
594
  api: api.apiPb,
581
595
  stepPathMap: {
582
596
  "Else If Step": "./else_if_step.js",
@@ -607,14 +621,16 @@ describe("version-control", function () {
607
621
  await removeExistingFiles(existingFilePaths);
608
622
 
609
623
  // Verify the ApiInfo object is correct
610
- expect(apiInfo.name).to.equal("Try Catch API");
611
- expect(apiInfo.sourceFiles).to.deep.equal([]);
624
+ expect(apiInfo.name).toBe("Try Catch API");
625
+ expect(apiInfo.sourceFiles).toEqual([]);
612
626
 
613
627
  // Verify the files exist and match expectations
614
628
  const apiDir = path.join(testDir, "apis");
615
- (await expectFileExists(apiDir, "try_catch_api.yaml")).and.equals(
616
- expectedYamlContent,
629
+ const yamlContent = await expectFileExists(
630
+ apiDir,
631
+ "try_catch_api.yaml",
617
632
  );
633
+ expect(yamlContent).toBe(expectedYamlContent);
618
634
 
619
635
  // And no code files are created in a nested directory
620
636
  await expectNoFileExists(apiDir, "try_catch_api/api.yaml");
@@ -629,7 +645,8 @@ describe("version-control", function () {
629
645
  await expectNoFileExists(apiDir, "try_catch_api");
630
646
 
631
647
  // and can be read back in
632
- (await readApiFile(apiDir, "Try Catch API")).to.deep.equal({
648
+ const readApi = await readApiFile(apiDir, "Try Catch API");
649
+ expect(readApi).toEqual({
633
650
  api: api.apiPb,
634
651
  stepPathMap: {},
635
652
  });
@@ -637,14 +654,14 @@ describe("version-control", function () {
637
654
  });
638
655
  });
639
656
 
640
- describe("writeResourcesToDisk", function () {
657
+ describe("writeResourcesToDisk", () => {
641
658
  const mockFeatureFlags = new FeatureFlags({
642
659
  "superblocks.git.split.large.steps.enabled": true,
643
660
  "superblocks.git.split.large.steps.new.enabled": true,
644
661
  "superblocks.git.split.large.step.lines": 10,
645
662
  });
646
663
 
647
- it("should write single page app to separate directory and extract code blocks to separate files", async function () {
664
+ it("should write single page app to separate directory and extract code blocks to separate files", async () => {
648
665
  // Setup
649
666
  const resourceId = "9736f700-88d6-49fc-a519-245a20af248b";
650
667
  const testApi: ApiWithPb = {
@@ -706,29 +723,32 @@ describe("version-control", function () {
706
723
  `${testDir}/apps/test_app`,
707
724
  )) as SuperblocksApplicationConfig;
708
725
  // Verify the apis is undefined for the new format
709
- expect(config.apis).to.be.undefined;
726
+ expect(config.apis).toBeUndefined();
710
727
  // and the appApis is defined
711
- expect(config.appApis?.[testApi.id].name).to.equal(
728
+ expect(config.appApis?.[testApi.id].name).toBe(
712
729
  testApi.apiPb.metadata.name,
713
730
  );
714
731
 
715
732
  // Verify the files exist and match expectations
716
- expect(resourceConfig.location).to.equal("apps/test_app");
733
+ expect(resourceConfig.location).toBe("apps/test_app");
717
734
  await expectFileExists(testDir, "apps/test_app/application.yaml");
718
735
  await expectFileExists(testDir, "apps/test_app/page.yaml");
719
- (
720
- await expectFileExists(testDir, "apps/test_app/apis/test_api/api.yaml")
721
- ).and.contains("path: ./large_block.js");
722
- (
723
- await expectFileExists(
724
- testDir,
725
- "apps/test_app/apis/test_api/large_block.js",
726
- )
727
- ).and.includes(LARGE_JS_CONTENT);
736
+ const apiYaml = await expectFileExists(
737
+ testDir,
738
+ "apps/test_app/apis/test_api/api.yaml",
739
+ );
740
+ expect(apiYaml).toContain("path: ./large_block.js");
741
+ const jsContent = await expectFileExists(
742
+ testDir,
743
+ "apps/test_app/apis/test_api/large_block.js",
744
+ );
745
+ expect(jsContent).toContain(LARGE_JS_CONTENT);
728
746
  // and can be read back in
729
- (
730
- await readApiFile(`${testDir}/apps/test_app/apis`, "Test API")
731
- ).to.deep.equal({
747
+ const readApi = await readApiFile(
748
+ `${testDir}/apps/test_app/apis`,
749
+ "Test API",
750
+ );
751
+ expect(readApi).toEqual({
732
752
  api: testApi.apiPb,
733
753
  stepPathMap: {
734
754
  "Large Block": "./large_block.js",
@@ -736,7 +756,7 @@ describe("version-control", function () {
736
756
  });
737
757
  });
738
758
 
739
- it("should write backend to separate directory and extract code blocks to separate files", async function () {
759
+ it("should write backend to separate directory and extract code blocks to separate files", async () => {
740
760
  // Setup
741
761
  const resourceId = "9736f700-88d6-49fc-a519-245a20af248b";
742
762
  const testApi: ApiWrapper = {
@@ -784,27 +804,31 @@ describe("version-control", function () {
784
804
  const config = (await expectSuperblocksJsonFileExists(
785
805
  `${testDir}/backends/test_backend`,
786
806
  )) as SuperblocksBackendConfig;
787
- expect(config.sourceFiles).to.be.undefined;
807
+ expect(config.sourceFiles).toBeUndefined();
788
808
 
789
809
  // Verify the files exist and match expectations
790
- expect(resourceConfig.location).to.equal("backends/test_backend");
810
+ expect(resourceConfig.location).toBe("backends/test_backend");
791
811
  await expectFileExists(testDir, "backends/test_backend/api.yaml");
792
- (
793
- await expectFileExists(testDir, "backends/test_backend/api.yaml")
794
- ).and.contains(expectedYamlContent);
812
+ const yamlContent = await expectFileExists(
813
+ testDir,
814
+ "backends/test_backend/api.yaml",
815
+ );
816
+ expect(yamlContent).toContain(expectedYamlContent);
795
817
  await expectNoFileExists(
796
818
  testDir,
797
819
  "backends/test_backend/large_block.js",
798
820
  );
799
821
 
800
822
  // and can be read back in
801
- (await readApiFile(`${testDir}/backends/test_backend`)).to.deep.equal({
823
+ const readApi = await readApiFile(`${testDir}/backends/test_backend`);
824
+ expect(readApi).toEqual({
802
825
  api: testApi.apiPb,
803
826
  stepPathMap: {},
804
827
  });
805
828
  // and a push operation would consider it valid
806
- expect(await validateLocalResource(testDir, resourceConfig)).to.be
807
- .undefined;
829
+ expect(
830
+ await validateLocalResource(testDir, resourceConfig),
831
+ ).toBeUndefined();
808
832
  }
809
833
  // Write out the backend AND extract any code blocks
810
834
  {
@@ -825,29 +849,32 @@ describe("version-control", function () {
825
849
  const config = (await expectSuperblocksJsonFileExists(
826
850
  `${testDir}/backends/test_backend`,
827
851
  )) as SuperblocksBackendConfig;
828
- expect(config.sourceFiles).to.deep.equal(["large_block.js"]);
852
+ expect(config.sourceFiles).toEqual(["large_block.js"]);
829
853
 
830
854
  // Verify the files exist and match expectations
831
- expect(resourceConfig.location).to.equal("backends/test_backend");
832
- (
833
- await expectFileExists(testDir, "backends/test_backend/api.yaml")
834
- ).and.contains("path: ./large_block.js");
835
- (
836
- await expectFileExists(
837
- testDir,
838
- "backends/test_backend/large_block.js",
839
- )
840
- ).and.contains(LARGE_JS_CONTENT);
855
+ expect(resourceConfig.location).toBe("backends/test_backend");
856
+ const apiYaml = await expectFileExists(
857
+ testDir,
858
+ "backends/test_backend/api.yaml",
859
+ );
860
+ expect(apiYaml).toContain("path: ./large_block.js");
861
+ const jsContent = await expectFileExists(
862
+ testDir,
863
+ "backends/test_backend/large_block.js",
864
+ );
865
+ expect(jsContent).toContain(LARGE_JS_CONTENT);
841
866
  // and can be read back in
842
- (await readApiFile(`${testDir}/backends/test_backend`)).to.deep.equal({
867
+ const readApi = await readApiFile(`${testDir}/backends/test_backend`);
868
+ expect(readApi).toEqual({
843
869
  api: testApi.apiPb,
844
870
  stepPathMap: {
845
871
  "Large Block": "./large_block.js",
846
872
  },
847
873
  });
848
874
  // and a push operation would consider it valid
849
- expect(await validateLocalResource(testDir, resourceConfig)).to.be
850
- .undefined;
875
+ expect(
876
+ await validateLocalResource(testDir, resourceConfig),
877
+ ).toBeUndefined();
851
878
  }
852
879
  // Write out the backend AGAIN without extracting any code blocks
853
880
  {
@@ -868,38 +895,42 @@ describe("version-control", function () {
868
895
  const config = (await expectSuperblocksJsonFileExists(
869
896
  `${testDir}/backends/test_backend`,
870
897
  )) as SuperblocksBackendConfig;
871
- expect(config.sourceFiles).to.be.undefined;
898
+ expect(config.sourceFiles).toBeUndefined();
872
899
 
873
900
  // Verify the files exist and match expectations
874
- expect(resourceConfig.location).to.equal("backends/test_backend");
901
+ expect(resourceConfig.location).toBe("backends/test_backend");
875
902
  await expectFileExists(testDir, "backends/test_backend/api.yaml");
876
- (
877
- await expectFileExists(testDir, "backends/test_backend/api.yaml")
878
- ).and.contains(expectedYamlContent);
903
+ const yamlContent = await expectFileExists(
904
+ testDir,
905
+ "backends/test_backend/api.yaml",
906
+ );
907
+ expect(yamlContent).toContain(expectedYamlContent);
879
908
  await expectNoFileExists(
880
909
  testDir,
881
910
  "backends/test_backend/large_block.js",
882
911
  );
883
912
  // and can be read back in
884
- (await readApiFile(`${testDir}/backends/test_backend`)).to.deep.equal({
913
+ const readApi = await readApiFile(`${testDir}/backends/test_backend`);
914
+ expect(readApi).toEqual({
885
915
  api: testApi.apiPb,
886
916
  stepPathMap: {},
887
917
  });
888
918
  // and a push operation would consider it valid
889
- expect(await validateLocalResource(testDir, resourceConfig)).to.be
890
- .undefined;
919
+ expect(
920
+ await validateLocalResource(testDir, resourceConfig),
921
+ ).toBeUndefined();
891
922
  }
892
923
  });
893
924
  });
894
925
 
895
- describe("writeApplicationToDIsk", function () {
926
+ describe("writeApplicationToDIsk", () => {
896
927
  const mockFeatureFlags = new FeatureFlags({
897
928
  "superblocks.git.split.large.steps.enabled": true,
898
929
  "superblocks.git.split.large.steps.new.enabled": false,
899
930
  "superblocks.git.split.large.step.lines": 10,
900
931
  });
901
932
 
902
- it("should write multi-pageapp to disk", async function () {
933
+ it("should write multi-pageapp to disk", async () => {
903
934
  // Setup
904
935
  const resourceId = "9736f700-88d6-49fc-a519-245a20af248b";
905
936
  const testApi: ApiWithPb = {
@@ -961,30 +992,28 @@ describe("version-control", function () {
961
992
  `${testDir}/apps/test_app/`,
962
993
  )) as SuperblocksApplicationConfig;
963
994
  const page = config.pages?.[multiPageApp.pages[0].id];
964
- expect(page?.apis).to.be.undefined;
965
- expect(page?.pageApis?.[testApi.id]?.sourceFiles).to.deep.equal([
995
+ expect(page?.apis).toBeUndefined();
996
+ expect(page?.pageApis?.[testApi.id]?.sourceFiles).toEqual([
966
997
  "large_block.js",
967
998
  ]);
968
999
 
969
1000
  // Verify the files exist and match expectations
970
- expect(resourceConfig.location).to.equal("apps/test_app");
1001
+ expect(resourceConfig.location).toBe("apps/test_app");
971
1002
  await expectFileExists(testDir, "apps/test_app/application.yaml");
972
1003
  await expectFileExists(
973
1004
  testDir,
974
1005
  "apps/test_app/pages/test_page/page.yaml",
975
1006
  );
976
- (
977
- await expectFileExists(
978
- testDir,
979
- "apps/test_app/pages/test_page/apis/test_api/api.yaml",
980
- )
981
- ).and.includes("path: ./large_block.js");
982
- (
983
- await expectFileExists(
984
- testDir,
985
- "apps/test_app/pages/test_page/apis/test_api/large_block.js",
986
- )
987
- ).and.includes(LARGE_JS_CONTENT);
1007
+ const apiYaml = await expectFileExists(
1008
+ testDir,
1009
+ "apps/test_app/pages/test_page/apis/test_api/api.yaml",
1010
+ );
1011
+ expect(apiYaml).toContain("path: ./large_block.js");
1012
+ const jsContent = await expectFileExists(
1013
+ testDir,
1014
+ "apps/test_app/pages/test_page/apis/test_api/large_block.js",
1015
+ );
1016
+ expect(jsContent).toContain(LARGE_JS_CONTENT);
988
1017
 
989
1018
  // and does not have the files in the old format
990
1019
  await expectNoFileExists(
@@ -997,23 +1026,23 @@ describe("version-control", function () {
997
1026
  );
998
1027
 
999
1028
  // and can be read back in
1000
- (
1001
- await readApiFile(
1002
- `${testDir}/apps/test_app/pages/test_page/apis`,
1003
- "Test API",
1004
- )
1005
- ).to.deep.equal({
1029
+ const readApi = await readApiFile(
1030
+ `${testDir}/apps/test_app/pages/test_page/apis`,
1031
+ "Test API",
1032
+ );
1033
+ expect(readApi).toEqual({
1006
1034
  api: testApi.apiPb,
1007
1035
  stepPathMap: {
1008
1036
  "Large Block": "./large_block.js",
1009
1037
  },
1010
1038
  });
1011
1039
  // and a push operation would consider it valid
1012
- expect(await validateLocalResource(testDir, resourceConfig)).to.be
1013
- .undefined;
1040
+ expect(
1041
+ await validateLocalResource(testDir, resourceConfig),
1042
+ ).toBeUndefined();
1014
1043
  });
1015
1044
 
1016
- it("should write multi-pageapp to disk and overwrite existing files", async function () {
1045
+ it("should write multi-pageapp to disk and overwrite existing files", async () => {
1017
1046
  // Setup
1018
1047
  const resourceId = "9736f700-88d6-49fc-a519-245a20af248b";
1019
1048
  const testApi: ApiWithPb = {
@@ -1082,37 +1111,36 @@ describe("version-control", function () {
1082
1111
  `${testDir}/apps/test_app/`,
1083
1112
  )) as SuperblocksApplicationConfig;
1084
1113
  const page = config.pages?.[multiPageApp.pages[0].id];
1085
- expect(page?.pageApis).to.be.undefined;
1086
- expect(page?.apis).to.be.deep.equal({ "test-id": "Test API" });
1114
+ expect(page?.pageApis).toBeUndefined();
1115
+ expect(page?.apis).toEqual({ "test-id": "Test API" });
1087
1116
 
1088
1117
  // Verify the files exist and match expectations
1089
- expect(resourceConfig.location).to.equal("apps/test_app");
1118
+ expect(resourceConfig.location).toBe("apps/test_app");
1090
1119
  await expectFileExists(testDir, "apps/test_app/application.yaml");
1091
1120
  await expectFileExists(
1092
1121
  testDir,
1093
1122
  "apps/test_app/pages/test_page/page.yaml",
1094
1123
  );
1095
- (
1096
- await expectFileExists(
1097
- testDir,
1098
- "apps/test_app/pages/test_page/apis/test_api.yaml",
1099
- )
1100
- ).and.contains(expectedYamlContent);
1124
+ const yamlContent = await expectFileExists(
1125
+ testDir,
1126
+ "apps/test_app/pages/test_page/apis/test_api.yaml",
1127
+ );
1128
+ expect(yamlContent).toContain(expectedYamlContent);
1101
1129
  // And does not have the source code extracted
1102
1130
  await expectNoFileExists(
1103
1131
  testDir,
1104
1132
  "apps/test_app/pages/test_page/apis/test_api/large_block.js",
1105
1133
  );
1106
1134
  // and can be read back in
1107
- (
1108
- await readApiFile(
1109
- `${testDir}/apps/test_app/pages/test_page/apis`,
1110
- "Test API",
1111
- )
1112
- ).to.deep.equal({ api: testApi.apiPb, stepPathMap: {} });
1135
+ const readApi = await readApiFile(
1136
+ `${testDir}/apps/test_app/pages/test_page/apis`,
1137
+ "Test API",
1138
+ );
1139
+ expect(readApi).toEqual({ api: testApi.apiPb, stepPathMap: {} });
1113
1140
  // and a push operation would consider it valid
1114
- expect(await validateLocalResource(testDir, resourceConfig)).to.be
1115
- .undefined;
1141
+ expect(
1142
+ await validateLocalResource(testDir, resourceConfig),
1143
+ ).toBeUndefined();
1116
1144
  }
1117
1145
 
1118
1146
  // Write out the same multi-page app again, but this time extract any code blocks
@@ -1132,30 +1160,28 @@ describe("version-control", function () {
1132
1160
  `${testDir}/apps/test_app/`,
1133
1161
  )) as SuperblocksApplicationConfig;
1134
1162
  const page = config.pages?.[multiPageApp.pages[0].id];
1135
- expect(page?.apis).to.be.undefined;
1136
- expect(page?.pageApis?.[testApi.id]?.sourceFiles).to.deep.equal([
1163
+ expect(page?.apis).toBeUndefined();
1164
+ expect(page?.pageApis?.[testApi.id]?.sourceFiles).toEqual([
1137
1165
  "large_block.js",
1138
1166
  ]);
1139
1167
 
1140
1168
  // Verify the files exist and match expectations
1141
- expect(resourceConfig.location).to.equal("apps/test_app");
1169
+ expect(resourceConfig.location).toBe("apps/test_app");
1142
1170
  await expectFileExists(testDir, "apps/test_app/application.yaml");
1143
1171
  await expectFileExists(
1144
1172
  testDir,
1145
1173
  "apps/test_app/pages/test_page/page.yaml",
1146
1174
  );
1147
- (
1148
- await expectFileExists(
1149
- testDir,
1150
- "apps/test_app/pages/test_page/apis/test_api/api.yaml",
1151
- )
1152
- ).and.contains("path: ./large_block.js");
1153
- (
1154
- await expectFileExists(
1155
- testDir,
1156
- "apps/test_app/pages/test_page/apis/test_api/large_block.js",
1157
- )
1158
- ).and.includes(LARGE_JS_CONTENT);
1175
+ const apiYaml = await expectFileExists(
1176
+ testDir,
1177
+ "apps/test_app/pages/test_page/apis/test_api/api.yaml",
1178
+ );
1179
+ expect(apiYaml).toContain("path: ./large_block.js");
1180
+ const jsContent = await expectFileExists(
1181
+ testDir,
1182
+ "apps/test_app/pages/test_page/apis/test_api/large_block.js",
1183
+ );
1184
+ expect(jsContent).toContain(LARGE_JS_CONTENT);
1159
1185
  // And the old file no longer exists
1160
1186
  await expectNoFileExists(
1161
1187
  testDir,
@@ -1166,20 +1192,20 @@ describe("version-control", function () {
1166
1192
  "apps/test_app/pages/test_page/apis/test_api/test_api.yaml",
1167
1193
  );
1168
1194
  // and can be read back in
1169
- (
1170
- await readApiFile(
1171
- `${testDir}/apps/test_app/pages/test_page/apis`,
1172
- "Test API",
1173
- )
1174
- ).to.deep.equal({
1195
+ const readApi = await readApiFile(
1196
+ `${testDir}/apps/test_app/pages/test_page/apis`,
1197
+ "Test API",
1198
+ );
1199
+ expect(readApi).toEqual({
1175
1200
  api: testApi.apiPb,
1176
1201
  stepPathMap: {
1177
1202
  "Large Block": "./large_block.js",
1178
1203
  },
1179
1204
  });
1180
1205
  // and a push operation would consider it valid
1181
- expect(await validateLocalResource(testDir, resourceConfig)).to.be
1182
- .undefined;
1206
+ expect(
1207
+ await validateLocalResource(testDir, resourceConfig),
1208
+ ).toBeUndefined();
1183
1209
  }
1184
1210
 
1185
1211
  // Write out the same multi-page app again, but this time with shorter code that should be extracted
@@ -1203,51 +1229,49 @@ describe("version-control", function () {
1203
1229
  `${testDir}/apps/test_app/`,
1204
1230
  )) as SuperblocksApplicationConfig;
1205
1231
  const page = config.pages?.[multiPageApp.pages[0].id];
1206
- expect(page?.apis).to.be.undefined;
1207
- expect(page?.pageApis?.[testApi.id]?.sourceFiles).to.deep.equal([
1232
+ expect(page?.apis).toBeUndefined();
1233
+ expect(page?.pageApis?.[testApi.id]?.sourceFiles).toEqual([
1208
1234
  "large_block.js",
1209
1235
  ]);
1210
1236
 
1211
1237
  // Verify the files exist and match expectations
1212
- expect(resourceConfig.location).to.equal("apps/test_app");
1238
+ expect(resourceConfig.location).toBe("apps/test_app");
1213
1239
  await expectFileExists(testDir, "apps/test_app/application.yaml");
1214
1240
  await expectFileExists(
1215
1241
  testDir,
1216
1242
  "apps/test_app/pages/test_page/page.yaml",
1217
1243
  );
1218
- (
1219
- await expectFileExists(
1220
- testDir,
1221
- "apps/test_app/pages/test_page/apis/test_api/api.yaml",
1222
- )
1223
- ).and.contains("path: ./large_block.js");
1244
+ const apiYaml = await expectFileExists(
1245
+ testDir,
1246
+ "apps/test_app/pages/test_page/apis/test_api/api.yaml",
1247
+ );
1248
+ expect(apiYaml).toContain("path: ./large_block.js");
1224
1249
  // And does have the source code extracted
1225
- (
1226
- await expectFileExists(
1227
- testDir,
1228
- "apps/test_app/pages/test_page/apis/test_api/large_block.js",
1229
- )
1230
- ).and.includes(SMALL_JS_CONTENT);
1250
+ const jsContent = await expectFileExists(
1251
+ testDir,
1252
+ "apps/test_app/pages/test_page/apis/test_api/large_block.js",
1253
+ );
1254
+ expect(jsContent).toContain(SMALL_JS_CONTENT);
1231
1255
  // And does not have the old file
1232
1256
  await expectNoFileExists(
1233
1257
  testDir,
1234
1258
  "apps/test_app/pages/test_page/apis/test_api.yaml",
1235
1259
  );
1236
1260
  // and can be read back in
1237
- (
1238
- await readApiFile(
1239
- `${testDir}/apps/test_app/pages/test_page/apis`,
1240
- "Test API",
1241
- )
1242
- ).to.deep.equal({
1261
+ const readApi = await readApiFile(
1262
+ `${testDir}/apps/test_app/pages/test_page/apis`,
1263
+ "Test API",
1264
+ );
1265
+ expect(readApi).toEqual({
1243
1266
  api: testApi.apiPb,
1244
1267
  stepPathMap: {
1245
1268
  "Large Block": "./large_block.js",
1246
1269
  },
1247
1270
  });
1248
1271
  // and a push operation would consider it valid
1249
- expect(await validateLocalResource(testDir, resourceConfig)).to.be
1250
- .undefined;
1272
+ expect(
1273
+ await validateLocalResource(testDir, resourceConfig),
1274
+ ).toBeUndefined();
1251
1275
  }
1252
1276
 
1253
1277
  // Write out the same multi-page app again, again with large code so files are extracted
@@ -1271,30 +1295,28 @@ describe("version-control", function () {
1271
1295
  `${testDir}/apps/test_app/`,
1272
1296
  )) as SuperblocksApplicationConfig;
1273
1297
  const page = config.pages?.[multiPageApp.pages[0].id];
1274
- expect(page?.apis).to.be.undefined;
1275
- expect(page?.pageApis?.[testApi.id]?.sourceFiles).to.deep.equal([
1298
+ expect(page?.apis).toBeUndefined();
1299
+ expect(page?.pageApis?.[testApi.id]?.sourceFiles).toEqual([
1276
1300
  "large_block.js",
1277
1301
  ]);
1278
1302
 
1279
1303
  // Verify the files exist and match expectations
1280
- expect(resourceConfig.location).to.equal("apps/test_app");
1304
+ expect(resourceConfig.location).toBe("apps/test_app");
1281
1305
  await expectFileExists(testDir, "apps/test_app/application.yaml");
1282
1306
  await expectFileExists(
1283
1307
  testDir,
1284
1308
  "apps/test_app/pages/test_page/page.yaml",
1285
1309
  );
1286
- (
1287
- await expectFileExists(
1288
- testDir,
1289
- "apps/test_app/pages/test_page/apis/test_api/api.yaml",
1290
- )
1291
- ).and.contains("path: ./large_block.js");
1292
- (
1293
- await expectFileExists(
1294
- testDir,
1295
- "apps/test_app/pages/test_page/apis/test_api/large_block.js",
1296
- )
1297
- ).and.includes(LARGE_JS_CONTENT);
1310
+ const apiYaml = await expectFileExists(
1311
+ testDir,
1312
+ "apps/test_app/pages/test_page/apis/test_api/api.yaml",
1313
+ );
1314
+ expect(apiYaml).toContain("path: ./large_block.js");
1315
+ const jsContent = await expectFileExists(
1316
+ testDir,
1317
+ "apps/test_app/pages/test_page/apis/test_api/large_block.js",
1318
+ );
1319
+ expect(jsContent).toContain(LARGE_JS_CONTENT);
1298
1320
  // And the old file no longer exists
1299
1321
  await expectNoFileExists(
1300
1322
  testDir,
@@ -1306,20 +1328,20 @@ describe("version-control", function () {
1306
1328
  "apps/test_app/pages/test_page/apis/test_api/test_api.yaml",
1307
1329
  );
1308
1330
  // and can be read back in
1309
- (
1310
- await readApiFile(
1311
- `${testDir}/apps/test_app/pages/test_page/apis`,
1312
- "Test API",
1313
- )
1314
- ).to.deep.equal({
1331
+ const readApi = await readApiFile(
1332
+ `${testDir}/apps/test_app/pages/test_page/apis`,
1333
+ "Test API",
1334
+ );
1335
+ expect(readApi).toEqual({
1315
1336
  api: testApi.apiPb,
1316
1337
  stepPathMap: {
1317
1338
  "Large Block": "./large_block.js",
1318
1339
  },
1319
1340
  });
1320
1341
  // and a push operation would consider it valid
1321
- expect(await validateLocalResource(testDir, resourceConfig)).to.be
1322
- .undefined;
1342
+ expect(
1343
+ await validateLocalResource(testDir, resourceConfig),
1344
+ ).toBeUndefined();
1323
1345
  }
1324
1346
 
1325
1347
  // Write out the multi-page app again without extracting any code blocks
@@ -1341,30 +1363,28 @@ describe("version-control", function () {
1341
1363
  });
1342
1364
 
1343
1365
  // Verify the files exist and match expectations
1344
- expect(resourceConfig.location).to.equal("apps/test_app");
1366
+ expect(resourceConfig.location).toBe("apps/test_app");
1345
1367
  await expectFileExists(testDir, "apps/test_app/application.yaml");
1346
1368
  await expectFileExists(
1347
1369
  testDir,
1348
1370
  "apps/test_app/pages/test_page/page.yaml",
1349
1371
  );
1350
- (
1351
- await expectFileExists(
1352
- testDir,
1353
- "apps/test_app/pages/test_page/apis/test_api.yaml",
1354
- )
1355
- ).and.contains(expectedYamlContent);
1372
+ const yamlContent = await expectFileExists(
1373
+ testDir,
1374
+ "apps/test_app/pages/test_page/apis/test_api.yaml",
1375
+ );
1376
+ expect(yamlContent).toContain(expectedYamlContent);
1356
1377
  // And does not have the source code extracted
1357
1378
  await expectNoFileExists(
1358
1379
  testDir,
1359
1380
  "apps/test_app/pages/test_page/apis/test_api/large_block.js",
1360
1381
  );
1361
1382
  // and can be read back in
1362
- (
1363
- await readApiFile(
1364
- `${testDir}/apps/test_app/pages/test_page/apis`,
1365
- "Test API",
1366
- )
1367
- ).to.deep.equal({
1383
+ const readApi = await readApiFile(
1384
+ `${testDir}/apps/test_app/pages/test_page/apis`,
1385
+ "Test API",
1386
+ );
1387
+ expect(readApi).toEqual({
1368
1388
  api: testApi.apiPb,
1369
1389
  stepPathMap: {},
1370
1390
  });
@@ -1376,31 +1396,28 @@ describe("version-control", function () {
1376
1396
  async function expectFileExists(
1377
1397
  testDir: string,
1378
1398
  relativePath: string,
1379
- ): Promise<Chai.Assertion> {
1399
+ ): Promise<string> {
1380
1400
  const filePath = path.join(testDir, relativePath);
1381
- await expect(await fs.pathExists(filePath)).to.be.true;
1401
+ expect(await fs.pathExists(filePath)).toBe(true);
1382
1402
  const content = await fs.readFile(filePath, "utf8");
1383
- return expect(content);
1403
+ return content;
1384
1404
  }
1385
1405
 
1386
1406
  async function expectNoFileExists(testDir: string, relativePath: string) {
1387
1407
  const filePath = path.join(testDir, relativePath);
1388
- expect(await fs.pathExists(filePath)).to.be.false;
1408
+ expect(await fs.pathExists(filePath)).toBe(false);
1389
1409
  }
1390
1410
 
1391
- async function readApiFile(
1392
- testDir: string,
1393
- apiName?: string,
1394
- ): Promise<Chai.Assertion> {
1411
+ async function readApiFile(testDir: string, apiName?: string) {
1395
1412
  const api = await readAppApiYamlFile(testDir, apiName);
1396
- return expect(api);
1413
+ return api;
1397
1414
  }
1398
1415
 
1399
1416
  async function expectSuperblocksJsonFileExists(
1400
1417
  testDir: string,
1401
1418
  ): Promise<SuperblocksConfig> {
1402
1419
  const filePath = path.join(testDir, ".superblocks/superblocks.json");
1403
- await expect(await fs.pathExists(filePath)).to.be.true;
1420
+ expect(await fs.pathExists(filePath)).toBe(true);
1404
1421
  const content = await fs.readFile(filePath, "utf8");
1405
1422
  return JSON.parse(content) as SuperblocksConfig;
1406
1423
  }