@superblocksteam/sdk 2.0.75-next.3 → 2.0.75

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