Skip to content

Commit 497d7ec

Browse files
committed
remove missing global fail() function from tests
1 parent 64c658e commit 497d7ec

23 files changed

Lines changed: 743 additions & 896 deletions

File tree

packages/client/src/__tests__/core/embedded-package.spec.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ describe("Embedded package", () => {
3535
},
3636
});
3737

38-
if (!result.ok) fail(result.error);
39-
expect(result.value).toBeTruthy();
40-
expect(typeof result.value).toBe("number");
41-
expect(result.value).toEqual(2);
38+
expect(result).toStrictEqual(ResultOk(2));
4239
});
4340

4441
it("can get a file from wrapper", async () => {
@@ -154,26 +151,20 @@ const testEmbeddedPackageWithFile = async (
154151
const receivedManifestResult = await client.getFile(wrapperUri, {
155152
path: "wrap.info",
156153
});
157-
if (!receivedManifestResult.ok) fail(receivedManifestResult.error);
158-
const receivedManifest = receivedManifestResult.value as Uint8Array;
159-
expect(receivedManifest).toEqual(expectedManifest);
154+
expect(receivedManifestResult).toEqual(ResultOk(expectedManifest))
160155

161156
const expectedWasmModule = await fs.promises.readFile(
162157
`${wrapperPath}/wrap.wasm`
163158
);
164159
const receivedWasmModuleResult = await client.getFile(wrapperUri, {
165160
path: "wrap.wasm",
166161
});
167-
if (!receivedWasmModuleResult.ok) fail(receivedWasmModuleResult.error);
168-
const receivedWasmModule = receivedWasmModuleResult.value as Uint8Array;
169-
expect(receivedWasmModule).toEqual(expectedWasmModule);
162+
expect(receivedWasmModuleResult).toEqual(ResultOk(expectedWasmModule))
163+
170164

171165
const receivedHelloFileResult = await client.getFile(wrapperUri, {
172166
path: filePath,
173167
encoding: "utf-8",
174168
});
175-
if (!receivedHelloFileResult.ok) fail(receivedHelloFileResult.error);
176-
const receivedHelloFile = receivedHelloFileResult.value as Uint8Array;
177-
178-
expect(receivedHelloFile).toEqual(fileText);
169+
expect(receivedHelloFileResult).toEqual(ResultOk(fileText))
179170
};

packages/client/src/__tests__/core/embedded-wrapper.spec.ts

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ const simpleWrapperUri = `fs/${wrapperPath}`;
1414

1515
describe("Embedded wrapper", () => {
1616
it("can invoke an embedded wrapper", async () => {
17-
const manifestBuffer = fs.readFileSync(path.join(wrapperPath, "wrap.info"))
18-
const wasmModuleBuffer = fs.readFileSync(path.join(wrapperPath, "wrap.wasm"))
17+
const manifestBuffer = fs.readFileSync(path.join(wrapperPath, "wrap.info"));
18+
const wasmModuleBuffer = fs.readFileSync(
19+
path.join(wrapperPath, "wrap.wasm")
20+
);
1921

2022
let wrapper: Wrapper = await WasmWrapper.from(
2123
manifestBuffer,
@@ -33,19 +35,18 @@ describe("Embedded wrapper", () => {
3335
method: "add",
3436
args: {
3537
a: 1,
36-
b: 1
38+
b: 1,
3739
},
3840
});
3941

40-
if (!result.ok) fail(result.error);
41-
expect(result.value).toBeTruthy();
42-
expect(typeof result.value).toBe("number");
43-
expect(result.value).toEqual(2);
42+
expect(result).toStrictEqual(ResultOk(2));
4443
});
4544

4645
it("can get a file from wrapper", async () => {
47-
const manifestBuffer = fs.readFileSync(path.join(wrapperPath, "wrap.info"))
48-
const wasmModuleBuffer = fs.readFileSync(path.join(wrapperPath, "wrap.wasm"))
46+
const manifestBuffer = fs.readFileSync(path.join(wrapperPath, "wrap.info"));
47+
const wasmModuleBuffer = fs.readFileSync(
48+
path.join(wrapperPath, "wrap.wasm")
49+
);
4950
const testFilePath = "hello.txt";
5051
const testFileText = "Hello Test!";
5152

@@ -63,8 +64,10 @@ describe("Embedded wrapper", () => {
6364
});
6465

6566
it("can add embedded wrapper through file reader", async () => {
66-
const manifestBuffer = fs.readFileSync(path.join(wrapperPath, "wrap.info"))
67-
const wasmModuleBuffer = fs.readFileSync(path.join(wrapperPath, "wrap.wasm"))
67+
const manifestBuffer = fs.readFileSync(path.join(wrapperPath, "wrap.info"));
68+
const wasmModuleBuffer = fs.readFileSync(
69+
path.join(wrapperPath, "wrap.wasm")
70+
);
6871
const testFilePath = "hello.txt";
6972
const testFileText = "Hello Test!";
7073

@@ -86,8 +89,10 @@ describe("Embedded wrapper", () => {
8689
});
8790

8891
it("can add embedded wrapper with async wrap manifest", async () => {
89-
const manifestBuffer = fs.readFileSync(path.join(wrapperPath, "wrap.info"))
90-
const wasmModuleBuffer = fs.readFileSync(path.join(wrapperPath, "wrap.wasm"))
92+
const manifestBuffer = fs.readFileSync(path.join(wrapperPath, "wrap.info"));
93+
const wasmModuleBuffer = fs.readFileSync(
94+
path.join(wrapperPath, "wrap.wasm")
95+
);
9196
const testFilePath = "hello.txt";
9297
const testFileText = "Hello Test!";
9398

@@ -109,8 +114,10 @@ describe("Embedded wrapper", () => {
109114
});
110115

111116
it("can add embedded wrapper with async wasm module", async () => {
112-
const manifestBuffer = fs.readFileSync(path.join(wrapperPath, "wrap.info"))
113-
const wasmModuleBuffer = fs.readFileSync(path.join(wrapperPath, "wrap.wasm"))
117+
const manifestBuffer = fs.readFileSync(path.join(wrapperPath, "wrap.info"));
118+
const wasmModuleBuffer = fs.readFileSync(
119+
path.join(wrapperPath, "wrap.wasm")
120+
);
114121
const testFilePath = "hello.txt";
115122
const testFileText = "Hello Test!";
116123

@@ -148,25 +155,19 @@ const testEmbeddedWrapperWithFile = async (
148155
const receivedManifestResult = await client.getFile(simpleWrapperUri, {
149156
path: "wrap.info",
150157
});
151-
if (!receivedManifestResult.ok) fail(receivedManifestResult.error);
152-
const receivedManifest = receivedManifestResult.value as Uint8Array;
153-
expect(receivedManifest).toEqual(expectedManifest);
158+
expect(receivedManifestResult).toEqual(ResultOk(expectedManifest));
154159

155-
const expectedWasmModule =
156-
await fs.promises.readFile(`${wrapperPath}/wrap.wasm`);
160+
const expectedWasmModule = await fs.promises.readFile(
161+
`${wrapperPath}/wrap.wasm`
162+
);
157163
const receivedWasmModuleResult = await client.getFile(simpleWrapperUri, {
158164
path: "wrap.wasm",
159165
});
160-
if (!receivedWasmModuleResult.ok) fail(receivedWasmModuleResult.error);
161-
const receivedWasmModule = receivedWasmModuleResult.value as Uint8Array;
162-
expect(receivedWasmModule).toEqual(expectedWasmModule);
166+
expect(receivedWasmModuleResult).toEqual(ResultOk(expectedWasmModule));
163167

164168
const receivedHelloFileResult = await client.getFile(simpleWrapperUri, {
165169
path: filePath,
166170
encoding: "utf-8",
167171
});
168-
if (!receivedHelloFileResult.ok) fail(receivedHelloFileResult.error);
169-
const receivedHelloFile = receivedHelloFileResult.value as Uint8Array;
170-
171-
expect(receivedHelloFile).toEqual(fileText);
172+
expect(receivedHelloFileResult).toEqual(ResultOk(fileText));
172173
};

packages/client/src/__tests__/core/plugin-wrapper.spec.ts

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { IWrapPackage, Uri } from "@polywrap/core-js";
33
import { WrapManifest } from "@polywrap/wrap-manifest-types-js";
44
import { PluginPackage, PluginModule } from "@polywrap/plugin-js";
55
import { UriResolver } from "@polywrap/uri-resolvers-js";
6-
import * as SysBundle from "@polywrap/sys-config-bundle-js"
6+
import * as SysBundle from "@polywrap/sys-config-bundle-js";
7+
import { ResultOk } from "@polywrap/result";
78

89
jest.setTimeout(200000);
910

@@ -40,26 +41,21 @@ describe("plugin-wrapper", () => {
4041
test("plugin map types", async () => {
4142
const implementationUri = Uri.from("wrap://ens/some-implementation.eth");
4243
const mockPlugin = mockMapPlugin();
43-
const client = new PolywrapClient(
44-
{
45-
resolver: UriResolver.from([
46-
{
47-
uri: implementationUri,
48-
package: mockPlugin,
49-
},
50-
]),
51-
}
52-
);
44+
const client = new PolywrapClient({
45+
resolver: UriResolver.from([
46+
{
47+
uri: implementationUri,
48+
package: mockPlugin,
49+
},
50+
]),
51+
});
5352

5453
const getResult = await client.invoke({
5554
uri: implementationUri,
5655
method: "getMap",
5756
});
58-
59-
if (!getResult.ok) fail(getResult.error);
60-
expect(getResult.value).toBeTruthy();
61-
expect(getResult.value).toMatchObject(
62-
new Map<string, number>().set("a", 1).set("b", 2)
57+
expect(getResult).toStrictEqual(
58+
ResultOk(new Map<string, number>().set("a", 1).set("b", 2))
6359
);
6460

6561
const updateResult = await client.invoke({
@@ -69,28 +65,23 @@ describe("plugin-wrapper", () => {
6965
map: new Map<string, number>().set("b", 1).set("c", 5),
7066
},
7167
});
72-
73-
if (!updateResult.ok) fail(updateResult.error);
74-
expect(updateResult.value).toBeTruthy();
75-
expect(updateResult.value).toMatchObject(
76-
new Map<string, number>().set("a", 1).set("b", 3).set("c", 5)
68+
expect(updateResult).toStrictEqual(
69+
ResultOk(new Map<string, number>().set("a", 1).set("b", 3).set("c", 5))
7770
);
7871
});
7972

8073
test("get manifest should fetch wrap manifest from plugin", async () => {
81-
const client = new PolywrapClient(
82-
{
83-
resolver: UriResolver.from([
84-
{
85-
uri: Uri.from(SysBundle.bundle.http.uri),
86-
package: SysBundle.bundle.http.package as IWrapPackage
87-
},
88-
]),
89-
}
74+
const client = new PolywrapClient({
75+
resolver: UriResolver.from([
76+
{
77+
uri: Uri.from(SysBundle.bundle.http.uri),
78+
package: SysBundle.bundle.http.package as IWrapPackage,
79+
},
80+
]),
81+
});
82+
const manifestResult = await client.getManifest(SysBundle.bundle.http.uri);
83+
expect(manifestResult).toMatchObject(
84+
ResultOk({ type: "plugin", name: "Http" })
9085
);
91-
const manifest = await client.getManifest(SysBundle.bundle.http.uri);
92-
if (!manifest.ok) fail(manifest.error);
93-
expect(manifest.value.type).toEqual("plugin");
94-
expect(manifest.value.name).toEqual("Http");
9586
});
9687
});

0 commit comments

Comments
 (0)