@platforma-sdk/test 1.58.7 → 1.58.11

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,113 +1,101 @@
1
- import path from 'node:path';
2
- import * as fsp from 'node:fs/promises';
3
- import { MiddleLayer } from '@milaboratories/pl-middle-layer';
4
- import { plTest } from './test-pl.js';
5
- import { awaitStableState } from './util.js';
1
+ import { plTest } from "./test-pl.js";
2
+ import { awaitStableState } from "./util.js";
3
+ import { MiddleLayer } from "@milaboratories/pl-middle-layer";
4
+ import * as fsp from "node:fs/promises";
5
+ import path from "node:path";
6
6
 
7
+ //#region src/test-block.ts
7
8
  function normalizeABDOpts(timeoutOrOps) {
8
- let ops = {};
9
- if (timeoutOrOps !== undefined) {
10
- if (typeof timeoutOrOps === "object" && !(timeoutOrOps instanceof AbortSignal))
11
- ops = { ...ops, ...timeoutOrOps };
12
- else
13
- ops.timeout = timeoutOrOps;
14
- }
15
- const abortSignal = typeof ops.timeout === "undefined"
16
- ? AbortSignal.timeout(DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT)
17
- : typeof ops.timeout === "number"
18
- ? AbortSignal.timeout(ops.timeout)
19
- : ops.timeout;
20
- return {
21
- timeout: abortSignal,
22
- ignoreBlockError: Boolean(ops.ignoreBlockError),
23
- };
9
+ let ops = {};
10
+ if (timeoutOrOps !== void 0) if (typeof timeoutOrOps === "object" && !(timeoutOrOps instanceof AbortSignal)) ops = {
11
+ ...ops,
12
+ ...timeoutOrOps
13
+ };
14
+ else ops.timeout = timeoutOrOps;
15
+ return {
16
+ timeout: typeof ops.timeout === "undefined" ? AbortSignal.timeout(DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT) : typeof ops.timeout === "number" ? AbortSignal.timeout(ops.timeout) : ops.timeout,
17
+ ignoreBlockError: Boolean(ops.ignoreBlockError)
18
+ };
24
19
  }
25
- const DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT = 5000;
20
+ const DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT = 5e3;
26
21
  async function awaitBlockDone(prj, blockId, timeoutOrOps) {
27
- const ops = normalizeABDOpts(timeoutOrOps);
28
- const overview = prj.overview;
29
- const state = prj.getBlockState(blockId);
30
- while (true) {
31
- const overviewSnapshot = (await overview.getValue());
32
- const blockOverview = overviewSnapshot.blocks.find((b) => b.id == blockId);
33
- if (blockOverview === undefined)
34
- throw new Error(`Blocks not found: ${blockId}`);
35
- if (blockOverview.outputErrors) {
36
- if (ops.ignoreBlockError)
37
- return;
38
- else {
39
- let errorMessage = blockOverview.outputsError;
40
- if (errorMessage === undefined)
41
- errorMessage = blockOverview.exportsError;
42
- throw new Error("Block error: " + (errorMessage ?? "no message"));
43
- }
44
- }
45
- if (blockOverview.calculationStatus === "Done")
46
- return;
47
- if (blockOverview.calculationStatus !== "Running")
48
- throw new Error(`Unexpected block status, block not calculating anything at the moment: ${blockOverview.calculationStatus}`);
49
- try {
50
- await overview.awaitChange(ops.timeout);
51
- }
52
- catch (e) {
53
- console.dir(blockOverview, { depth: 5 });
54
- console.dir(await state.getValue(), { depth: 5 });
55
- throw new Error("Aborted while awaiting block done.", { cause: e });
56
- }
57
- }
22
+ const ops = normalizeABDOpts(timeoutOrOps);
23
+ const overview = prj.overview;
24
+ const state = prj.getBlockState(blockId);
25
+ while (true) {
26
+ const blockOverview = (await overview.getValue()).blocks.find((b) => b.id == blockId);
27
+ if (blockOverview === void 0) throw new Error(`Blocks not found: ${blockId}`);
28
+ if (blockOverview.outputErrors) if (ops.ignoreBlockError) return;
29
+ else {
30
+ let errorMessage = blockOverview.outputsError;
31
+ if (errorMessage === void 0) errorMessage = blockOverview.exportsError;
32
+ throw new Error("Block error: " + (errorMessage ?? "no message"));
33
+ }
34
+ if (blockOverview.calculationStatus === "Done") return;
35
+ if (blockOverview.calculationStatus !== "Running") throw new Error(`Unexpected block status, block not calculating anything at the moment: ${blockOverview.calculationStatus}`);
36
+ try {
37
+ await overview.awaitChange(ops.timeout);
38
+ } catch (e) {
39
+ console.dir(blockOverview, { depth: 5 });
40
+ console.dir(await state.getValue(), { depth: 5 });
41
+ throw new Error("Aborted while awaiting block done.", { cause: e });
42
+ }
43
+ }
58
44
  }
59
45
  const blockTest = plTest.extend({
60
- ml: async ({ pl, tmpFolder }, use) => {
61
- const frontendFolder = path.join(tmpFolder, "frontend");
62
- const downloadFolder = path.join(tmpFolder, "download");
63
- await fsp.mkdir(frontendFolder, { recursive: true });
64
- await fsp.mkdir(downloadFolder, { recursive: true });
65
- const ml = await MiddleLayer.init(pl, tmpFolder, {
66
- defaultTreeOptions: { pollingInterval: 250, stopPollingDelay: 500 },
67
- devBlockUpdateRecheckInterval: 300,
68
- localSecret: MiddleLayer.generateLocalSecret(),
69
- localProjections: [], // TODO must be different with local pl
70
- openFileDialogCallback: () => {
71
- throw new Error("Not implemented.");
72
- },
73
- });
74
- ml.addRuntimeCapability("requiresUIAPIVersion", 1);
75
- ml.addRuntimeCapability("requiresUIAPIVersion", 2);
76
- ml.addRuntimeCapability("requiresUIAPIVersion", 3);
77
- try {
78
- await use(ml);
79
- }
80
- finally {
81
- await ml.close();
82
- }
83
- },
84
- rawPrj: async ({ ml }, use) => {
85
- const pRid1 = await ml.createProject({ label: "Test Project" }, "test_project");
86
- await ml.openProject(pRid1);
87
- const prj = ml.getOpenedProject(pRid1);
88
- try {
89
- await use(prj);
90
- }
91
- finally {
92
- ml.closeProject(pRid1);
93
- }
94
- },
95
- helpers: async ({ ml, rawPrj }, use) => {
96
- await use({
97
- async awaitBlockDone(blockId, timeout) {
98
- await awaitBlockDone(rawPrj, blockId, timeout);
99
- },
100
- awaitBlockDoneAndGetStableBlockState: async (blockId, timeoutOrOps) => {
101
- const ops = normalizeABDOpts(timeoutOrOps);
102
- await awaitBlockDone(rawPrj, blockId, ops);
103
- return (await awaitStableState(rawPrj.getBlockState(blockId), ops.timeout));
104
- },
105
- async getLocalFileHandle(localPath) {
106
- return await ml.internalDriverKit.lsDriver.getLocalFileHandle(path.resolve(localPath));
107
- },
108
- });
109
- },
46
+ ml: async ({ pl, tmpFolder }, use) => {
47
+ const frontendFolder = path.join(tmpFolder, "frontend");
48
+ const downloadFolder = path.join(tmpFolder, "download");
49
+ await fsp.mkdir(frontendFolder, { recursive: true });
50
+ await fsp.mkdir(downloadFolder, { recursive: true });
51
+ const ml = await MiddleLayer.init(pl, tmpFolder, {
52
+ defaultTreeOptions: {
53
+ pollingInterval: 250,
54
+ stopPollingDelay: 500
55
+ },
56
+ devBlockUpdateRecheckInterval: 300,
57
+ localSecret: MiddleLayer.generateLocalSecret(),
58
+ localProjections: [],
59
+ openFileDialogCallback: () => {
60
+ throw new Error("Not implemented.");
61
+ }
62
+ });
63
+ ml.addRuntimeCapability("requiresUIAPIVersion", 1);
64
+ ml.addRuntimeCapability("requiresUIAPIVersion", 2);
65
+ ml.addRuntimeCapability("requiresUIAPIVersion", 3);
66
+ try {
67
+ await use(ml);
68
+ } finally {
69
+ await ml.close();
70
+ }
71
+ },
72
+ rawPrj: async ({ ml }, use) => {
73
+ const pRid1 = await ml.createProject({ label: "Test Project" }, "test_project");
74
+ await ml.openProject(pRid1);
75
+ const prj = ml.getOpenedProject(pRid1);
76
+ try {
77
+ await use(prj);
78
+ } finally {
79
+ ml.closeProject(pRid1);
80
+ }
81
+ },
82
+ helpers: async ({ ml, rawPrj }, use) => {
83
+ await use({
84
+ async awaitBlockDone(blockId, timeout) {
85
+ await awaitBlockDone(rawPrj, blockId, timeout);
86
+ },
87
+ awaitBlockDoneAndGetStableBlockState: async (blockId, timeoutOrOps) => {
88
+ const ops = normalizeABDOpts(timeoutOrOps);
89
+ await awaitBlockDone(rawPrj, blockId, ops);
90
+ return await awaitStableState(rawPrj.getBlockState(blockId), ops.timeout);
91
+ },
92
+ async getLocalFileHandle(localPath) {
93
+ return await ml.internalDriverKit.lsDriver.getLocalFileHandle(path.resolve(localPath));
94
+ }
95
+ });
96
+ }
110
97
  });
111
98
 
99
+ //#endregion
112
100
  export { DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT, blockTest };
113
- //# sourceMappingURL=test-block.js.map
101
+ //# sourceMappingURL=test-block.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"test-block.js","sources":["../src/test-block.ts"],"sourcesContent":["import path from \"node:path\";\nimport * as fsp from \"node:fs/promises\";\nimport type {\n InferBlockState,\n LocalImportFileHandle,\n Platforma,\n Project,\n} from \"@milaboratories/pl-middle-layer\";\nimport { MiddleLayer } from \"@milaboratories/pl-middle-layer\";\nimport { plTest } from \"./test-pl\";\nimport { awaitStableState } from \"./util\";\n\nexport type AwaitBlockDoneOps = {\n timeout?: number | AbortSignal;\n ignoreBlockError?: boolean;\n};\n\nexport type AwaitBlockDoneNormalized = {\n timeout: AbortSignal;\n ignoreBlockError: boolean;\n};\n\nfunction normalizeABDOpts(timeoutOrOps?: number | AwaitBlockDoneOps): AwaitBlockDoneNormalized {\n let ops: AwaitBlockDoneOps = {};\n if (timeoutOrOps !== undefined) {\n if (typeof timeoutOrOps === \"object\" && !(timeoutOrOps instanceof AbortSignal))\n ops = { ...ops, ...timeoutOrOps };\n else ops.timeout = timeoutOrOps;\n }\n const abortSignal =\n typeof ops.timeout === \"undefined\"\n ? AbortSignal.timeout(DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT)\n : typeof ops.timeout === \"number\"\n ? AbortSignal.timeout(ops.timeout)\n : ops.timeout;\n return {\n timeout: abortSignal,\n ignoreBlockError: Boolean(ops.ignoreBlockError),\n };\n}\n\nexport const DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT = 5000;\n\nasync function awaitBlockDone(\n prj: Project,\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps,\n) {\n const ops = normalizeABDOpts(timeoutOrOps);\n const overview = prj.overview;\n const state = prj.getBlockState(blockId);\n while (true) {\n const overviewSnapshot = (await overview.getValue())!;\n const blockOverview = overviewSnapshot.blocks.find((b) => b.id == blockId);\n if (blockOverview === undefined) throw new Error(`Blocks not found: ${blockId}`);\n if (blockOverview.outputErrors) {\n if (ops.ignoreBlockError) return;\n else {\n let errorMessage = blockOverview.outputsError;\n if (errorMessage === undefined) errorMessage = blockOverview.exportsError;\n throw new Error(\"Block error: \" + (errorMessage ?? \"no message\"));\n }\n }\n if (blockOverview.calculationStatus === \"Done\") return;\n if (blockOverview.calculationStatus !== \"Running\")\n throw new Error(\n `Unexpected block status, block not calculating anything at the moment: ${blockOverview.calculationStatus}`,\n );\n try {\n await overview.awaitChange(ops.timeout);\n } catch (e: any) {\n console.dir(blockOverview, { depth: 5 });\n console.dir(await state.getValue(), { depth: 5 });\n throw new Error(\"Aborted while awaiting block done.\", { cause: e });\n }\n }\n}\n\nexport interface RawHelpers {\n awaitBlockDone(blockId: string, timeoutOrOps?: number | AwaitBlockDoneOps): Promise<void>;\n awaitBlockDoneAndGetStableBlockState<Pl extends Platforma>(\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps,\n ): Promise<InferBlockState<Pl>>;\n getLocalFileHandle(localPath: string): Promise<LocalImportFileHandle>;\n}\n\nexport const blockTest = plTest.extend<{\n ml: MiddleLayer;\n rawPrj: Project;\n helpers: RawHelpers;\n}>({\n ml: async ({ pl, tmpFolder }, use) => {\n const frontendFolder = path.join(tmpFolder, \"frontend\");\n const downloadFolder = path.join(tmpFolder, \"download\");\n await fsp.mkdir(frontendFolder, { recursive: true });\n await fsp.mkdir(downloadFolder, { recursive: true });\n\n const ml = await MiddleLayer.init(pl, tmpFolder, {\n defaultTreeOptions: { pollingInterval: 250, stopPollingDelay: 500 },\n devBlockUpdateRecheckInterval: 300,\n localSecret: MiddleLayer.generateLocalSecret(),\n localProjections: [], // TODO must be different with local pl\n openFileDialogCallback: () => {\n throw new Error(\"Not implemented.\");\n },\n });\n ml.addRuntimeCapability(\"requiresUIAPIVersion\", 1);\n ml.addRuntimeCapability(\"requiresUIAPIVersion\", 2);\n ml.addRuntimeCapability(\"requiresUIAPIVersion\", 3);\n\n try {\n await use(ml);\n } finally {\n await ml.close();\n }\n },\n rawPrj: async ({ ml }, use) => {\n const pRid1 = await ml.createProject({ label: \"Test Project\" }, \"test_project\");\n await ml.openProject(pRid1);\n const prj = ml.getOpenedProject(pRid1);\n try {\n await use(prj);\n } finally {\n ml.closeProject(pRid1);\n }\n },\n helpers: async ({ ml, rawPrj }, use) => {\n await use({\n async awaitBlockDone(blockId, timeout) {\n await awaitBlockDone(rawPrj, blockId, timeout);\n },\n awaitBlockDoneAndGetStableBlockState: async <Pl extends Platforma>(\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps,\n ) => {\n const ops = normalizeABDOpts(timeoutOrOps);\n await awaitBlockDone(rawPrj, blockId, ops);\n return (await awaitStableState(\n rawPrj.getBlockState(blockId),\n ops.timeout,\n )) as InferBlockState<Pl>;\n },\n async getLocalFileHandle(localPath) {\n return await ml.internalDriverKit.lsDriver.getLocalFileHandle(path.resolve(localPath));\n },\n });\n },\n});\n"],"names":[],"mappings":";;;;;;AAsBA,SAAS,gBAAgB,CAAC,YAAyC,EAAA;IACjE,IAAI,GAAG,GAAsB,EAAE;AAC/B,IAAA,IAAI,YAAY,KAAK,SAAS,EAAE;QAC9B,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,EAAE,YAAY,YAAY,WAAW,CAAC;YAC5E,GAAG,GAAG,EAAE,GAAG,GAAG,EAAE,GAAG,YAAY,EAAE;;AAC9B,YAAA,GAAG,CAAC,OAAO,GAAG,YAAY;IACjC;AACA,IAAA,MAAM,WAAW,GACf,OAAO,GAAG,CAAC,OAAO,KAAK;AACrB,UAAE,WAAW,CAAC,OAAO,CAAC,gCAAgC;AACtD,UAAE,OAAO,GAAG,CAAC,OAAO,KAAK;cACrB,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO;AACjC,cAAE,GAAG,CAAC,OAAO;IACnB,OAAO;AACL,QAAA,OAAO,EAAE,WAAW;AACpB,QAAA,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAA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C,SAAS,CAAC,CAAC;YACxF,CAAC;AACF,SAAA,CAAC;IACJ,CAAC;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"test-block.js","names":[],"sources":["../src/test-block.ts"],"sourcesContent":["import path from \"node:path\";\nimport * as fsp from \"node:fs/promises\";\nimport type {\n InferBlockState,\n LocalImportFileHandle,\n Platforma,\n Project,\n} from \"@milaboratories/pl-middle-layer\";\nimport { MiddleLayer } from \"@milaboratories/pl-middle-layer\";\nimport { plTest } from \"./test-pl\";\nimport { awaitStableState } from \"./util\";\n\nexport type AwaitBlockDoneOps = {\n timeout?: number | AbortSignal;\n ignoreBlockError?: boolean;\n};\n\nexport type AwaitBlockDoneNormalized = {\n timeout: AbortSignal;\n ignoreBlockError: boolean;\n};\n\nfunction normalizeABDOpts(timeoutOrOps?: number | AwaitBlockDoneOps): AwaitBlockDoneNormalized {\n let ops: AwaitBlockDoneOps = {};\n if (timeoutOrOps !== undefined) {\n if (typeof timeoutOrOps === \"object\" && !(timeoutOrOps instanceof AbortSignal))\n ops = { ...ops, ...timeoutOrOps };\n else ops.timeout = timeoutOrOps;\n }\n const abortSignal =\n typeof ops.timeout === \"undefined\"\n ? AbortSignal.timeout(DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT)\n : typeof ops.timeout === \"number\"\n ? AbortSignal.timeout(ops.timeout)\n : ops.timeout;\n return {\n timeout: abortSignal,\n ignoreBlockError: Boolean(ops.ignoreBlockError),\n };\n}\n\nexport const DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT = 5000;\n\nasync function awaitBlockDone(\n prj: Project,\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps,\n) {\n const ops = normalizeABDOpts(timeoutOrOps);\n const overview = prj.overview;\n const state = prj.getBlockState(blockId);\n while (true) {\n const overviewSnapshot = (await overview.getValue())!;\n const blockOverview = overviewSnapshot.blocks.find((b) => b.id == blockId);\n if (blockOverview === undefined) throw new Error(`Blocks not found: ${blockId}`);\n if (blockOverview.outputErrors) {\n if (ops.ignoreBlockError) return;\n else {\n let errorMessage = blockOverview.outputsError;\n if (errorMessage === undefined) errorMessage = blockOverview.exportsError;\n throw new Error(\"Block error: \" + (errorMessage ?? \"no message\"));\n }\n }\n if (blockOverview.calculationStatus === \"Done\") return;\n if (blockOverview.calculationStatus !== \"Running\")\n throw new Error(\n `Unexpected block status, block not calculating anything at the moment: ${blockOverview.calculationStatus}`,\n );\n try {\n await overview.awaitChange(ops.timeout);\n } catch (e: any) {\n console.dir(blockOverview, { depth: 5 });\n console.dir(await state.getValue(), { depth: 5 });\n throw new Error(\"Aborted while awaiting block done.\", { cause: e });\n }\n }\n}\n\nexport interface RawHelpers {\n awaitBlockDone(blockId: string, timeoutOrOps?: number | AwaitBlockDoneOps): Promise<void>;\n awaitBlockDoneAndGetStableBlockState<Pl extends Platforma>(\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps,\n ): Promise<InferBlockState<Pl>>;\n getLocalFileHandle(localPath: string): Promise<LocalImportFileHandle>;\n}\n\nexport const blockTest = plTest.extend<{\n ml: MiddleLayer;\n rawPrj: Project;\n helpers: RawHelpers;\n}>({\n ml: async ({ pl, tmpFolder }, use) => {\n const frontendFolder = path.join(tmpFolder, \"frontend\");\n const downloadFolder = path.join(tmpFolder, \"download\");\n await fsp.mkdir(frontendFolder, { recursive: true });\n await fsp.mkdir(downloadFolder, { recursive: true });\n\n const ml = await MiddleLayer.init(pl, tmpFolder, {\n defaultTreeOptions: { pollingInterval: 250, stopPollingDelay: 500 },\n devBlockUpdateRecheckInterval: 300,\n localSecret: MiddleLayer.generateLocalSecret(),\n localProjections: [], // TODO must be different with local pl\n openFileDialogCallback: () => {\n throw new Error(\"Not implemented.\");\n },\n });\n ml.addRuntimeCapability(\"requiresUIAPIVersion\", 1);\n ml.addRuntimeCapability(\"requiresUIAPIVersion\", 2);\n ml.addRuntimeCapability(\"requiresUIAPIVersion\", 3);\n\n try {\n await use(ml);\n } finally {\n await ml.close();\n }\n },\n rawPrj: async ({ ml }, use) => {\n const pRid1 = await ml.createProject({ label: \"Test Project\" }, \"test_project\");\n await ml.openProject(pRid1);\n const prj = ml.getOpenedProject(pRid1);\n try {\n await use(prj);\n } finally {\n ml.closeProject(pRid1);\n }\n },\n helpers: async ({ ml, rawPrj }, use) => {\n await use({\n async awaitBlockDone(blockId, timeout) {\n await awaitBlockDone(rawPrj, blockId, timeout);\n },\n awaitBlockDoneAndGetStableBlockState: async <Pl extends Platforma>(\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps,\n ) => {\n const ops = normalizeABDOpts(timeoutOrOps);\n await awaitBlockDone(rawPrj, blockId, ops);\n return (await awaitStableState(\n rawPrj.getBlockState(blockId),\n ops.timeout,\n )) as InferBlockState<Pl>;\n },\n async getLocalFileHandle(localPath) {\n return await ml.internalDriverKit.lsDriver.getLocalFileHandle(path.resolve(localPath));\n },\n });\n },\n});\n"],"mappings":";;;;;;;AAsBA,SAAS,iBAAiB,cAAqE;CAC7F,IAAI,MAAyB,EAAE;AAC/B,KAAI,iBAAiB,OACnB,KAAI,OAAO,iBAAiB,YAAY,EAAE,wBAAwB,aAChE,OAAM;EAAE,GAAG;EAAK,GAAG;EAAc;KAC9B,KAAI,UAAU;AAQrB,QAAO;EACL,SANA,OAAO,IAAI,YAAY,cACnB,YAAY,QAAQ,iCAAiC,GACrD,OAAO,IAAI,YAAY,WACrB,YAAY,QAAQ,IAAI,QAAQ,GAChC,IAAI;EAGV,kBAAkB,QAAQ,IAAI,iBAAiB;EAChD;;AAGH,MAAa,mCAAmC;AAEhD,eAAe,eACb,KACA,SACA,cACA;CACA,MAAM,MAAM,iBAAiB,aAAa;CAC1C,MAAM,WAAW,IAAI;CACrB,MAAM,QAAQ,IAAI,cAAc,QAAQ;AACxC,QAAO,MAAM;EAEX,MAAM,iBADoB,MAAM,SAAS,UAAU,EACZ,OAAO,MAAM,MAAM,EAAE,MAAM,QAAQ;AAC1E,MAAI,kBAAkB,OAAW,OAAM,IAAI,MAAM,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7B,MAAM,QAAQ,MAAM,GAAG,cAAc,EAAE,OAAO,gBAAgB,EAAE,eAAe;AAC/E,QAAM,GAAG,YAAY,MAAM;EAC3B,MAAM,MAAM,GAAG,iBAAiB,MAAM;AACtC,MAAI;AACF,SAAM,IAAI,IAAI;YACN;AACR,MAAG,aAAa,MAAM;;;CAG1B,SAAS,OAAO,EAAE,IAAI,UAAU,QAAQ;AACtC,QAAM,IAAI;GACR,MAAM,eAAe,SAAS,SAAS;AACrC,UAAM,eAAe,QAAQ,SAAS,QAAQ;;GAEhD,sCAAsC,OACpC,SACA,iBACG;IACH,MAAM,MAAM,iBAAiB,aAAa;AAC1C,UAAM,eAAe,QAAQ,SAAS,IAAI;AAC1C,WAAQ,MAAM,iBACZ,OAAO,cAAc,QAAQ,EAC7B,IAAI,QACL;;GAEH,MAAM,mBAAmB,WAAW;AAClC,WAAO,MAAM,GAAG,kBAAkB,SAAS,mBAAmB,KAAK,QAAQ,UAAU,CAAC;;GAEzF,CAAC;;CAEL,CAAC"}
package/dist/test-pl.cjs CHANGED
@@ -1,101 +1,68 @@
1
- 'use strict';
1
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
+ let _milaboratories_pl_middle_layer = require("@milaboratories/pl-middle-layer");
3
+ let _milaboratories_pl_tree = require("@milaboratories/pl-tree");
4
+ let node_crypto = require("node:crypto");
5
+ let node_fs_promises = require("node:fs/promises");
6
+ node_fs_promises = require_runtime.__toESM(node_fs_promises);
7
+ let node_path = require("node:path");
8
+ node_path = require_runtime.__toESM(node_path);
9
+ let vitest = require("vitest");
2
10
 
3
- var plMiddleLayer = require('@milaboratories/pl-middle-layer');
4
- var plTree = require('@milaboratories/pl-tree');
5
- var node_crypto = require('node:crypto');
6
- var fsp = require('node:fs/promises');
7
- var path = require('node:path');
8
- var vitest = require('vitest');
9
-
10
- function _interopNamespaceDefault(e) {
11
- var n = Object.create(null);
12
- if (e) {
13
- Object.keys(e).forEach(function (k) {
14
- if (k !== 'default') {
15
- var d = Object.getOwnPropertyDescriptor(e, k);
16
- Object.defineProperty(n, k, d.get ? d : {
17
- enumerable: true,
18
- get: function () { return e[k]; }
19
- });
20
- }
21
- });
22
- }
23
- n.default = e;
24
- return Object.freeze(n);
25
- }
26
-
27
- var fsp__namespace = /*#__PURE__*/_interopNamespaceDefault(fsp);
28
-
29
- // oxlint-disable-next-line jest/expect-expect jest/no-disabled-tests
11
+ //#region src/test-pl.ts
30
12
  const plTest = vitest.test.extend({
31
- tmpFolder: async ({ onTestFinished }, use) => {
32
- const workFolder = path.resolve(`work/${node_crypto.randomUUID()}`);
33
- await fsp__namespace.mkdir(workFolder, { recursive: true });
34
- await use(workFolder);
35
- onTestFinished(async (context) => {
36
- if (context.task.result?.state === "pass") {
37
- await fsp__namespace.rm(workFolder, { recursive: true });
38
- }
39
- else {
40
- console.log(`TEST FAILED TMP FOLDER IS PRESERVED: ${workFolder}`);
41
- }
42
- });
43
- },
44
- pl: async ({ onTestFinished }, use) => {
45
- const alternativeRoot = `test_${Date.now()}_${node_crypto.randomUUID()}`;
46
- let altRootId = plMiddleLayer.NullResourceId;
47
- const client = await plMiddleLayer.TestHelpers.getTestClient(alternativeRoot);
48
- altRootId = client.clientRoot;
49
- try {
50
- await use(client);
51
- }
52
- finally {
53
- // Close the test client to avoid dangling gRPC channels
54
- // that can cause segfaults during process exit
55
- await client.close();
56
- }
57
- onTestFinished(async (context) => {
58
- if (context.task.result?.state === "pass") {
59
- const rawClient = await plMiddleLayer.TestHelpers.getTestClient();
60
- try {
61
- await rawClient.deleteAlternativeRoot(alternativeRoot);
62
- }
63
- finally {
64
- // Close the cleanup client to avoid dangling gRPC channels
65
- // that can cause segfaults during process exit
66
- await rawClient.close();
67
- }
68
- }
69
- else {
70
- console.log(`TEST FAILED SO ALTERNATIVE ROOT IS PRESERVED IN PL: ${alternativeRoot} (${plMiddleLayer.resourceIdToString(altRootId)})`);
71
- }
72
- });
73
- },
74
- createTree: async ({ pl }, use) => {
75
- const trees = new Map();
76
- try {
77
- await use((res, ops) => {
78
- let treePromise = trees.get(res);
79
- if (treePromise === undefined) {
80
- treePromise = plTree.SynchronizedTreeState.init(pl, res, ops ?? {
81
- pollingInterval: 200,
82
- stopPollingDelay: 400,
83
- });
84
- trees.set(res, treePromise);
85
- }
86
- return treePromise;
87
- });
88
- }
89
- finally {
90
- for (const [, treePromise] of trees) {
91
- await (await treePromise).terminate();
92
- }
93
- }
94
- },
95
- rootTree: async ({ pl, createTree: tree }, use) => {
96
- await use(await tree(pl.clientRoot));
97
- },
13
+ tmpFolder: async ({ onTestFinished }, use) => {
14
+ const workFolder = node_path.default.resolve(`work/${(0, node_crypto.randomUUID)()}`);
15
+ await node_fs_promises.mkdir(workFolder, { recursive: true });
16
+ await use(workFolder);
17
+ onTestFinished(async (context) => {
18
+ if (context.task.result?.state === "pass") await node_fs_promises.rm(workFolder, { recursive: true });
19
+ else console.log(`TEST FAILED TMP FOLDER IS PRESERVED: ${workFolder}`);
20
+ });
21
+ },
22
+ pl: async ({ onTestFinished }, use) => {
23
+ const alternativeRoot = `test_${Date.now()}_${(0, node_crypto.randomUUID)()}`;
24
+ let altRootId = _milaboratories_pl_middle_layer.NullResourceId;
25
+ const client = await _milaboratories_pl_middle_layer.TestHelpers.getTestClient(alternativeRoot);
26
+ altRootId = client.clientRoot;
27
+ try {
28
+ await use(client);
29
+ } finally {
30
+ await client.close();
31
+ }
32
+ onTestFinished(async (context) => {
33
+ if (context.task.result?.state === "pass") {
34
+ const rawClient = await _milaboratories_pl_middle_layer.TestHelpers.getTestClient();
35
+ try {
36
+ await rawClient.deleteAlternativeRoot(alternativeRoot);
37
+ } finally {
38
+ await rawClient.close();
39
+ }
40
+ } else console.log(`TEST FAILED SO ALTERNATIVE ROOT IS PRESERVED IN PL: ${alternativeRoot} (${(0, _milaboratories_pl_middle_layer.resourceIdToString)(altRootId)})`);
41
+ });
42
+ },
43
+ createTree: async ({ pl }, use) => {
44
+ const trees = /* @__PURE__ */ new Map();
45
+ try {
46
+ await use((res, ops) => {
47
+ let treePromise = trees.get(res);
48
+ if (treePromise === void 0) {
49
+ treePromise = _milaboratories_pl_tree.SynchronizedTreeState.init(pl, res, ops ?? {
50
+ pollingInterval: 200,
51
+ stopPollingDelay: 400
52
+ });
53
+ trees.set(res, treePromise);
54
+ }
55
+ return treePromise;
56
+ });
57
+ } finally {
58
+ for (const [, treePromise] of trees) await (await treePromise).terminate();
59
+ }
60
+ },
61
+ rootTree: async ({ pl, createTree: tree }, use) => {
62
+ await use(await tree(pl.clientRoot));
63
+ }
98
64
  });
99
65
 
66
+ //#endregion
100
67
  exports.plTest = plTest;
101
- //# sourceMappingURL=test-pl.cjs.map
68
+ //# sourceMappingURL=test-pl.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"test-pl.cjs","sources":["../src/test-pl.ts"],"sourcesContent":["import type { OptionalResourceId, PlClient, ResourceId } from \"@milaboratories/pl-middle-layer\";\nimport { NullResourceId, resourceIdToString, TestHelpers } from \"@milaboratories/pl-middle-layer\";\nimport type { SynchronizedTreeOps } from \"@milaboratories/pl-tree\";\nimport { SynchronizedTreeState } from \"@milaboratories/pl-tree\";\nimport { randomUUID } from \"node:crypto\";\nimport * as fsp from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { test } from \"vitest\";\n\n// oxlint-disable-next-line jest/expect-expect jest/no-disabled-tests\nexport const plTest = test.extend<{\n pl: PlClient;\n createTree: (res: ResourceId, ops?: SynchronizedTreeOps) => Promise<SynchronizedTreeState>;\n rootTree: SynchronizedTreeState;\n tmpFolder: string;\n}>({\n tmpFolder: async ({ onTestFinished }, use) => {\n const workFolder = path.resolve(`work/${randomUUID()}`);\n await fsp.mkdir(workFolder, { recursive: true });\n await use(workFolder);\n onTestFinished(async (context) => {\n if (context.task.result?.state === \"pass\") {\n await fsp.rm(workFolder, { recursive: true });\n } else {\n console.log(`TEST FAILED TMP FOLDER IS PRESERVED: ${workFolder}`);\n }\n });\n },\n\n pl: async ({ onTestFinished }, use) => {\n const alternativeRoot = `test_${Date.now()}_${randomUUID()}`;\n let altRootId: OptionalResourceId = NullResourceId;\n const client = await TestHelpers.getTestClient(alternativeRoot);\n altRootId = client.clientRoot;\n try {\n await use(client);\n } finally {\n // Close the test client to avoid dangling gRPC channels\n // that can cause segfaults during process exit\n await client.close();\n }\n onTestFinished(async (context) => {\n if (context.task.result?.state === \"pass\") {\n const rawClient = await TestHelpers.getTestClient();\n try {\n await rawClient.deleteAlternativeRoot(alternativeRoot);\n } finally {\n // Close the cleanup client to avoid dangling gRPC channels\n // that can cause segfaults during process exit\n await rawClient.close();\n }\n } else {\n console.log(\n `TEST FAILED SO ALTERNATIVE ROOT IS PRESERVED IN PL: ${alternativeRoot} (${resourceIdToString(\n altRootId,\n )})`,\n );\n }\n });\n },\n\n createTree: async ({ pl }, use) => {\n const trees = new Map<ResourceId, Promise<SynchronizedTreeState>>();\n try {\n await use((res, ops) => {\n let treePromise = trees.get(res);\n if (treePromise === undefined) {\n treePromise = SynchronizedTreeState.init(\n pl,\n res,\n ops ?? {\n pollingInterval: 200,\n stopPollingDelay: 400,\n },\n );\n trees.set(res, treePromise);\n }\n return treePromise;\n });\n } finally {\n for (const [, treePromise] of trees) {\n await (await treePromise).terminate();\n }\n }\n },\n\n rootTree: async ({ pl, createTree: tree }, use) => {\n await use(await tree(pl.clientRoot));\n },\n});\n"],"names":["test","randomUUID","fsp","NullResourceId","TestHelpers","resourceIdToString","SynchronizedTreeState"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA;AACO,MAAM,MAAM,GAAGA,WAAI,CAAC,MAAM,CAK9B;IACD,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,GAAG,KAAI;QAC3C,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,CAAA,KAAA,EAAQC,sBAAU,EAAE,CAAA,CAAE,CAAC;AACvD,QAAA,MAAMC,cAAG,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EA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AAKC,gCAAkB,CAC3F,SAAS,CACV,CAAA,CAAA,CAAG,CACL;YACH;AACF,QAAA,CAAC,CAAC;IACJ,CAAC;IAED,UAAU,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,GAAG,KAAI;AAChC,QAAA,MAAM,KAAK,GAAG,IAAI,GAAG,EAA8C;AACnE,QAAA,IAAI;AACF,YAAA,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAI;gBACrB,IAAI,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;AAChC,gBAAA,IAAI,WAAW,KAAK,SAAS,EAAE;oBAC7B,WAAW,GAAGC,4BAAqB,CAAC,IAAI,CACtC,EAAE,EACF,GAAG,EACH,GAAG,IAAI;AACL,wBAAA,eAAe,EAAE,GAAG;AACpB,wBAAA,gBAAgB,EAAE,GAAG;AACtB,qBAAA,CACF;AACD,oBAAA,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,WAAW,CAAC;gBAC7B;AACA,gBAAA,OAAO,WAAW;AACpB,YAAA,CAAC,CAAC;QACJ;gBAAU;YACR,KAAK,MAAM,GAAG,WAAW,CAAC,IAAI,KAAK,EAAE;AACnC,gBAAA,MAAM,CAAC,MAAM,WAAW,EAAE,SAAS,EAAE;YACvC;QACF;IACF,CAAC;AAED,IAAA,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,GAAG,KAAI;QAChD,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;IACtC,CAAC;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"test-pl.cjs","names":["test","path","fsp","NullResourceId","TestHelpers","SynchronizedTreeState"],"sources":["../src/test-pl.ts"],"sourcesContent":["import type { OptionalResourceId, PlClient, ResourceId } from \"@milaboratories/pl-middle-layer\";\nimport { NullResourceId, resourceIdToString, TestHelpers } from \"@milaboratories/pl-middle-layer\";\nimport type { SynchronizedTreeOps } from \"@milaboratories/pl-tree\";\nimport { SynchronizedTreeState } from \"@milaboratories/pl-tree\";\nimport { randomUUID } from \"node:crypto\";\nimport * as fsp from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { test } from \"vitest\";\n\n// oxlint-disable-next-line jest/expect-expect jest/no-disabled-tests\nexport const plTest = test.extend<{\n pl: PlClient;\n createTree: (res: ResourceId, ops?: SynchronizedTreeOps) => Promise<SynchronizedTreeState>;\n rootTree: SynchronizedTreeState;\n tmpFolder: string;\n}>({\n tmpFolder: async ({ onTestFinished }, use) => {\n const workFolder = path.resolve(`work/${randomUUID()}`);\n await fsp.mkdir(workFolder, { recursive: true });\n await use(workFolder);\n onTestFinished(async (context) => {\n if (context.task.result?.state === \"pass\") {\n await fsp.rm(workFolder, { recursive: true });\n } else {\n console.log(`TEST FAILED TMP FOLDER IS PRESERVED: ${workFolder}`);\n }\n });\n },\n\n pl: async ({ onTestFinished }, use) => {\n const alternativeRoot = `test_${Date.now()}_${randomUUID()}`;\n let altRootId: OptionalResourceId = NullResourceId;\n const client = await TestHelpers.getTestClient(alternativeRoot);\n altRootId = client.clientRoot;\n try {\n await use(client);\n } finally {\n // Close the test client to avoid dangling gRPC channels\n // that can cause segfaults during process exit\n await client.close();\n }\n onTestFinished(async (context) => {\n if (context.task.result?.state === \"pass\") {\n const rawClient = await TestHelpers.getTestClient();\n try {\n await rawClient.deleteAlternativeRoot(alternativeRoot);\n } finally {\n // Close the cleanup client to avoid dangling gRPC channels\n // that can cause segfaults during process exit\n await rawClient.close();\n }\n } else {\n console.log(\n `TEST FAILED SO ALTERNATIVE ROOT IS PRESERVED IN PL: ${alternativeRoot} (${resourceIdToString(\n altRootId,\n )})`,\n );\n }\n });\n },\n\n createTree: async ({ pl }, use) => {\n const trees = new Map<ResourceId, Promise<SynchronizedTreeState>>();\n try {\n await use((res, ops) => {\n let treePromise = trees.get(res);\n if (treePromise === undefined) {\n treePromise = SynchronizedTreeState.init(\n pl,\n res,\n ops ?? {\n pollingInterval: 200,\n stopPollingDelay: 400,\n },\n );\n trees.set(res, treePromise);\n }\n return treePromise;\n });\n } finally {\n for (const [, treePromise] of trees) {\n await (await treePromise).terminate();\n }\n }\n },\n\n rootTree: async ({ pl, createTree: tree }, use) => {\n await use(await tree(pl.clientRoot));\n },\n});\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,SAASA,YAAK,OAKxB;CACD,WAAW,OAAO,EAAE,kBAAkB,QAAQ;EAC5C,MAAM,aAAaC,kBAAK,QAAQ,qCAAoB,GAAG;AACvD,QAAMC,iBAAI,MAAM,YAAY,EAAE,WAAW,MAAM,CAAC;AAChD,QAAM,IAAI,WAAW;AACrB,iBAAe,OAAO,YAAY;AAChC,OAAI,QAAQ,KAAK,QAAQ,UAAU,OACjC,OAAMA,iBAAI,GAAG,YAAY,EAAE,WAAW,MAAM,CAAC;OAE7C,SAAQ,IAAI,wCAAwC,aAAa;IAEnE;;CAGJ,IAAI,OAAO,EAAE,kBAAkB,QAAQ;EACrC,MAAM,kBAAkB,QAAQ,KAAK,KAAK,CAAC,gCAAe;EAC1D,IAAI,YAAgCC;EACpC,MAAM,SAAS,MAAMC,4CAAY,cAAc,gBAAgB;AAC/D,cAAY,OAAO;AACnB,MAAI;AACF,SAAM,IAAI,OAAO;YACT;AAGR,SAAM,OAAO,OAAO;;AAEtB,iBAAe,OAAO,YAAY;AAChC,OAAI,QAAQ,KAAK,QAAQ,UAAU,QAAQ;IACzC,MAAM,YAAY,MAAMA,4CAAY,eAAe;AACnD,QAAI;AACF,WAAM,UAAU,sBAAsB,gBAAgB;cAC9C;AAGR,WAAM,UAAU,OAAO;;SAGzB,SAAQ,IACN,uDAAuD,gBAAgB,4DACrE,UACD,CAAC,GACH;IAEH;;CAGJ,YAAY,OAAO,EAAE,MAAM,QAAQ;EACjC,MAAM,wBAAQ,IAAI,KAAiD;AACnE,MAAI;AACF,SAAM,KAAK,KAAK,QAAQ;IACtB,IAAI,cAAc,MAAM,IAAI,IAAI;AAChC,QAAI,gBAAgB,QAAW;AAC7B,mBAAcC,8CAAsB,KAClC,IACA,KACA,OAAO;MACL,iBAAiB;MACjB,kBAAkB;MACnB,CACF;AACD,WAAM,IAAI,KAAK,YAAY;;AAE7B,WAAO;KACP;YACM;AACR,QAAK,MAAM,GAAG,gBAAgB,MAC5B,QAAO,MAAM,aAAa,WAAW;;;CAK3C,UAAU,OAAO,EAAE,IAAI,YAAY,QAAQ,QAAQ;AACjD,QAAM,IAAI,MAAM,KAAK,GAAG,WAAW,CAAC;;CAEvC,CAAC"}
package/dist/test-pl.d.ts CHANGED
@@ -1,10 +1,14 @@
1
- import type { PlClient, ResourceId } from "@milaboratories/pl-middle-layer";
2
- import type { SynchronizedTreeOps } from "@milaboratories/pl-tree";
3
- import { SynchronizedTreeState } from "@milaboratories/pl-tree";
4
- export declare const plTest: import("vitest").TestAPI<{
5
- pl: PlClient;
6
- createTree: (res: ResourceId, ops?: SynchronizedTreeOps) => Promise<SynchronizedTreeState>;
7
- rootTree: SynchronizedTreeState;
8
- tmpFolder: string;
1
+ import { PlClient, ResourceId } from "@milaboratories/pl-middle-layer";
2
+ import { SynchronizedTreeOps, SynchronizedTreeState } from "@milaboratories/pl-tree";
3
+ import * as vitest from "vitest";
4
+
5
+ //#region src/test-pl.d.ts
6
+ declare const plTest: vitest.TestAPI<{
7
+ pl: PlClient;
8
+ createTree: (res: ResourceId, ops?: SynchronizedTreeOps) => Promise<SynchronizedTreeState>;
9
+ rootTree: SynchronizedTreeState;
10
+ tmpFolder: string;
9
11
  }>;
12
+ //#endregion
13
+ export { plTest };
10
14
  //# sourceMappingURL=test-pl.d.ts.map
package/dist/test-pl.js CHANGED
@@ -1,80 +1,65 @@
1
- import { TestHelpers, resourceIdToString, NullResourceId } from '@milaboratories/pl-middle-layer';
2
- import { SynchronizedTreeState } from '@milaboratories/pl-tree';
3
- import { randomUUID } from 'node:crypto';
4
- import * as fsp from 'node:fs/promises';
5
- import path from 'node:path';
6
- import { test } from 'vitest';
1
+ import { NullResourceId, TestHelpers, resourceIdToString } from "@milaboratories/pl-middle-layer";
2
+ import { SynchronizedTreeState } from "@milaboratories/pl-tree";
3
+ import { randomUUID } from "node:crypto";
4
+ import * as fsp from "node:fs/promises";
5
+ import path from "node:path";
6
+ import { test } from "vitest";
7
7
 
8
- // oxlint-disable-next-line jest/expect-expect jest/no-disabled-tests
8
+ //#region src/test-pl.ts
9
9
  const plTest = test.extend({
10
- tmpFolder: async ({ onTestFinished }, use) => {
11
- const workFolder = path.resolve(`work/${randomUUID()}`);
12
- await fsp.mkdir(workFolder, { recursive: true });
13
- await use(workFolder);
14
- onTestFinished(async (context) => {
15
- if (context.task.result?.state === "pass") {
16
- await fsp.rm(workFolder, { recursive: true });
17
- }
18
- else {
19
- console.log(`TEST FAILED TMP FOLDER IS PRESERVED: ${workFolder}`);
20
- }
21
- });
22
- },
23
- pl: async ({ onTestFinished }, use) => {
24
- const alternativeRoot = `test_${Date.now()}_${randomUUID()}`;
25
- let altRootId = NullResourceId;
26
- const client = await TestHelpers.getTestClient(alternativeRoot);
27
- altRootId = client.clientRoot;
28
- try {
29
- await use(client);
30
- }
31
- finally {
32
- // Close the test client to avoid dangling gRPC channels
33
- // that can cause segfaults during process exit
34
- await client.close();
35
- }
36
- onTestFinished(async (context) => {
37
- if (context.task.result?.state === "pass") {
38
- const rawClient = await TestHelpers.getTestClient();
39
- try {
40
- await rawClient.deleteAlternativeRoot(alternativeRoot);
41
- }
42
- finally {
43
- // Close the cleanup client to avoid dangling gRPC channels
44
- // that can cause segfaults during process exit
45
- await rawClient.close();
46
- }
47
- }
48
- else {
49
- console.log(`TEST FAILED SO ALTERNATIVE ROOT IS PRESERVED IN PL: ${alternativeRoot} (${resourceIdToString(altRootId)})`);
50
- }
51
- });
52
- },
53
- createTree: async ({ pl }, use) => {
54
- const trees = new Map();
55
- try {
56
- await use((res, ops) => {
57
- let treePromise = trees.get(res);
58
- if (treePromise === undefined) {
59
- treePromise = SynchronizedTreeState.init(pl, res, ops ?? {
60
- pollingInterval: 200,
61
- stopPollingDelay: 400,
62
- });
63
- trees.set(res, treePromise);
64
- }
65
- return treePromise;
66
- });
67
- }
68
- finally {
69
- for (const [, treePromise] of trees) {
70
- await (await treePromise).terminate();
71
- }
72
- }
73
- },
74
- rootTree: async ({ pl, createTree: tree }, use) => {
75
- await use(await tree(pl.clientRoot));
76
- },
10
+ tmpFolder: async ({ onTestFinished }, use) => {
11
+ const workFolder = path.resolve(`work/${randomUUID()}`);
12
+ await fsp.mkdir(workFolder, { recursive: true });
13
+ await use(workFolder);
14
+ onTestFinished(async (context) => {
15
+ if (context.task.result?.state === "pass") await fsp.rm(workFolder, { recursive: true });
16
+ else console.log(`TEST FAILED TMP FOLDER IS PRESERVED: ${workFolder}`);
17
+ });
18
+ },
19
+ pl: async ({ onTestFinished }, use) => {
20
+ const alternativeRoot = `test_${Date.now()}_${randomUUID()}`;
21
+ let altRootId = NullResourceId;
22
+ const client = await TestHelpers.getTestClient(alternativeRoot);
23
+ altRootId = client.clientRoot;
24
+ try {
25
+ await use(client);
26
+ } finally {
27
+ await client.close();
28
+ }
29
+ onTestFinished(async (context) => {
30
+ if (context.task.result?.state === "pass") {
31
+ const rawClient = await TestHelpers.getTestClient();
32
+ try {
33
+ await rawClient.deleteAlternativeRoot(alternativeRoot);
34
+ } finally {
35
+ await rawClient.close();
36
+ }
37
+ } else console.log(`TEST FAILED SO ALTERNATIVE ROOT IS PRESERVED IN PL: ${alternativeRoot} (${resourceIdToString(altRootId)})`);
38
+ });
39
+ },
40
+ createTree: async ({ pl }, use) => {
41
+ const trees = /* @__PURE__ */ new Map();
42
+ try {
43
+ await use((res, ops) => {
44
+ let treePromise = trees.get(res);
45
+ if (treePromise === void 0) {
46
+ treePromise = SynchronizedTreeState.init(pl, res, ops ?? {
47
+ pollingInterval: 200,
48
+ stopPollingDelay: 400
49
+ });
50
+ trees.set(res, treePromise);
51
+ }
52
+ return treePromise;
53
+ });
54
+ } finally {
55
+ for (const [, treePromise] of trees) await (await treePromise).terminate();
56
+ }
57
+ },
58
+ rootTree: async ({ pl, createTree: tree }, use) => {
59
+ await use(await tree(pl.clientRoot));
60
+ }
77
61
  });
78
62
 
63
+ //#endregion
79
64
  export { plTest };
80
- //# sourceMappingURL=test-pl.js.map
65
+ //# sourceMappingURL=test-pl.js.map