Skip to content

Commit af78f22

Browse files
authored
Reintroduce cypress tests (#1130)
1 parent 533b7c6 commit af78f22

26 files changed

+304
-191
lines changed

bindings/wasm/build/replace_paths.js

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,54 @@
1-
const fs = require("fs/promises");
1+
const fs = require("fs");
22
const path = require("path");
33

44
/**
5-
* Replaces aliases defined in `tsconfig.json` files with their corresponding paths.
5+
* Replaces aliases defined in the `tsconfig.json` `paths` configuration in `js` and `ts` files.
66
* If more than one path is defined. The second path is used. Otherwise the first path.
7+
* @param {string} tsconfig - Path to tsconfig that should be processed
8+
* @param {string} dist - Folder of files that should be processed
9+
* @param {'resolve'=} mode - In "resolve" mode relative paths will be replaced paths relative to the processed file. Note: `basePath` in the tsconfig will not be considered.
710
*/
8-
async function main() {
9-
if (process.argv[2] === "node") await replace("tsconfig.json", "node");
10-
if (process.argv[2] === "web") await replace("tsconfig.web.json", "web");
11-
}
1211

13-
async function replace(tsconfig, dist) {
12+
function replace(tsconfig, dist, mode) {
1413
// Read tsconfig file.
15-
let data = JSON.parse(await fs.readFile(path.join(__dirname, `../lib/${tsconfig}`), "utf8"));
14+
const tsconfigPath = path.join(__dirname, '..', tsconfig);
15+
console.log(`\n using ${tsconfigPath}`);
16+
let data = JSON.parse(fs.readFileSync(path.join(__dirname, '..', tsconfig), "utf8"));
1617
let a = data.compilerOptions.paths;
1718
let keys = Object.keys(a);
1819

1920
// Get `.js` and `.ts` file names from directory.
20-
let files = await fs.readdir(path.join(__dirname, `../${dist}`), { withFileTypes: true });
21-
files = files.filter((directoryItem) => directoryItem.isFile()).map((file) => file.name);
21+
const distPath = path.join(__dirname, `../${dist}`);
22+
console.log(`\n working in ${distPath}`);
23+
let files = readdirSync(distPath);
2224
files = files.filter((fileName) => fileName.endsWith(".ts") || fileName.endsWith(".js"));
2325

2426
// Replace the Alias with the second path if present, otherwise use first path.
2527
for (let file of files) {
26-
let fileData = await fs.readFile(path.join(__dirname, `../${dist}/${file}`), "utf8");
28+
console.log(`\n processing ${file}`);
29+
let fileData = fs.readFileSync(file, "utf8");
2730
for (let key of keys) {
2831
let value = a[key][1] ?? a[key][0];
32+
33+
const absoluteIncludePath = path.resolve(path.dirname(tsconfigPath), value);
34+
if (mode == "resolve" && fs.existsSync(absoluteIncludePath)) {
35+
const absoluteFilePath = path.resolve(path.dirname(file));
36+
console.log(`\t calculating path from ${absoluteFilePath} to ${absoluteIncludePath}`);
37+
// replace `\` with `/` to convert windows paths to node compatible imports
38+
value = path.relative(absoluteFilePath, absoluteIncludePath).replace(/\\/g, '/');
39+
}
40+
41+
console.log(`\t replace ${key} with ${value}`);
2942
fileData = fileData.replaceAll(key, value);
3043
}
31-
await fs.writeFile(path.join(__dirname, `../${dist}/${file}`), fileData, "utf8");
44+
fs.writeFileSync(file, fileData, "utf8");
3245
}
3346
}
3447

35-
try {
36-
main().then(() => {});
37-
} catch (e) {
38-
console.log(e);
39-
return e;
48+
const readdirSync = (p, a = []) => {
49+
if (fs.statSync(p).isDirectory())
50+
fs.readdirSync(p).map(f => readdirSync(a[a.push(path.join(p, f)) - 1], a))
51+
return a
4052
}
53+
54+
replace(process.argv[2], process.argv[3], process.argv[4]);

bindings/wasm/cypress.config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import { defineConfig } from "cypress";
33
export default defineConfig({
44
screenshotOnRunFailure: false,
55
video: false,
6+
requestTimeout: 10000,
7+
defaultCommandTimeout: 60000,
68
retries: {
7-
runMode: 3,
9+
runMode: 3
810
},
911
e2e: {
10-
setupNodeEvents(on, config) {},
1112
supportFile: false,
12-
},
13+
}
1314
});

bindings/wasm/cypress/e2e/.gitkeep

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { setup } from '../../support/setup';
2+
import { createIdentity } from "../../../examples/dist/web/0_basic/0_create_did";
3+
4+
describe(
5+
"createIdentity",
6+
() => {
7+
it("Create Identity", async () => {
8+
await setup(createIdentity);
9+
});
10+
}
11+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { setup } from '../../support/setup';
2+
import { updateIdentity } from "../../../examples/dist/web/0_basic/1_update_did";
3+
4+
describe(
5+
"updateIdentity",
6+
() => {
7+
it("Update Identity", async () => {
8+
await setup(updateIdentity)
9+
});
10+
}
11+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { setup } from '../../support/setup';
2+
import { resolveIdentity } from "../../../examples/dist/web/0_basic/2_resolve_did";
3+
4+
describe(
5+
"resolveIdentity",
6+
() => {
7+
it("Resolve Identity", async () => {
8+
await setup(resolveIdentity)
9+
});
10+
}
11+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { setup } from '../../support/setup';
2+
import { deactivateIdentity } from "../../../examples/dist/web/0_basic/3_deactivate_did";
3+
4+
describe(
5+
"deactivateIdentity",
6+
() => {
7+
it("Deactivate Identity", async () => {
8+
await setup(deactivateIdentity)
9+
});
10+
}
11+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { setup } from '../../support/setup';
2+
import { deleteIdentity } from "../../../examples/dist/web/0_basic/4_delete_did";
3+
4+
describe(
5+
"deleteIdentity",
6+
() => {
7+
it("Delete Identity", async () => {
8+
await setup(deleteIdentity)
9+
});
10+
}
11+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { setup } from '../../support/setup';
2+
import { createVC } from "../../../examples/dist/web/0_basic/5_create_vc";
3+
4+
describe(
5+
"createVC",
6+
() => {
7+
it("Create Credential", async () => {
8+
await setup(createVC)
9+
});
10+
}
11+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { setup } from '../../support/setup';
2+
import { createVP } from "../../../examples/dist/web/0_basic/6_create_vp";
3+
4+
describe(
5+
"createVP",
6+
() => {
7+
it("Create Presentation", async () => {
8+
await setup(createVP)
9+
});
10+
}
11+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { setup } from '../../support/setup';
2+
import { revokeVC } from "../../../examples/dist/web/0_basic/7_revoke_vc";
3+
4+
describe(
5+
"revokeVC",
6+
() => {
7+
it("Revoke Credential", async () => {
8+
await setup(revokeVC)
9+
});
10+
}
11+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { setup } from '../../support/setup';
2+
import { didControlsDid } from "../../../examples/dist/web/1_advanced/0_did_controls_did";
3+
4+
describe(
5+
"didControlsDid",
6+
() => {
7+
it("DID Controls DID", async () => {
8+
await setup(didControlsDid)
9+
});
10+
}
11+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { setup } from '../../support/setup';
2+
import { didIssuesNft } from "../../../examples/dist/web/1_advanced/1_did_issues_nft";
3+
4+
describe(
5+
"didIssuesNft",
6+
() => {
7+
it("DID Issues NFT", async () => {
8+
await setup(didIssuesNft)
9+
});
10+
}
11+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { setup } from '../../support/setup';
2+
import { nftOwnsDid } from "../../../examples/dist/web/1_advanced/2_nft_owns_did";
3+
4+
describe(
5+
"nftOwnsDid",
6+
() => {
7+
it("NFT owns DID", async () => {
8+
await setup(nftOwnsDid)
9+
});
10+
}
11+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { setup } from '../../support/setup';
2+
import { didIssuesTokens } from "../../../examples/dist/web/1_advanced/3_did_issues_tokens";
3+
4+
describe(
5+
"didIssuesTokens",
6+
() => {
7+
it("DID Issues Tokens", async () => {
8+
await setup(didIssuesTokens)
9+
});
10+
}
11+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { setup } from '../../support/setup';
2+
import { keyExchange } from "../../../examples/dist/web/1_advanced/4_key_exchange";
3+
4+
describe(
5+
"keyExchange",
6+
() => {
7+
it("Key Exchange", async () => {
8+
await setup(keyExchange)
9+
});
10+
}
11+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { setup } from '../../support/setup';
2+
import { customResolution } from "../../../examples/dist/web/1_advanced/5_custom_resolution";
3+
4+
describe(
5+
"customResolution",
6+
() => {
7+
it("Custom Resolution", async () => {
8+
await setup(customResolution)
9+
});
10+
}
11+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { setup } from '../../support/setup';
2+
import { domainLinkage } from "../../../examples/dist/web/1_advanced/6_domain_linkage";
3+
4+
describe(
5+
"domainLinkage",
6+
() => {
7+
it("Domain Linkage", async () => {
8+
await setup(domainLinkage)
9+
});
10+
}
11+
);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as client from "@iota/client-wasm/web";
2+
import * as identity from "../../web";
3+
4+
export const setup = async (func) => {
5+
await client
6+
.init('../../../node_modules/@iota/client-wasm/web/wasm/client_wasm_bg.wasm')
7+
.then(async () => await identity.init('../../../web/identity_wasm_bg.wasm'))
8+
.then(func)
9+
}

bindings/wasm/examples/src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
KeyType,
99
MethodScope,
1010
VerificationMethod,
11-
} from "../../node";
11+
} from "@iota/identity-wasm/node";
1212

1313
export const API_ENDPOINT = "http://localhost:14265";
1414
export const FAUCET_ENDPOINT = "http://localhost:8091/api/enqueue";
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES6",
4+
"outDir": "./dist/web",
5+
"baseUrl": "./",
6+
"lib": ["ES6", "dom"],
7+
"esModuleInterop": true,
8+
"moduleResolution": "node",
9+
"paths": {
10+
"@iota/identity-wasm/node": ["../web"],
11+
"@iota/client-wasm/node": ["@iota/client-wasm/web"]
12+
}
13+
},
14+
"exclude": ["tests"]
15+
}

bindings/wasm/lib/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright 2021-2022 IOTA Stiftung
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import "./append_functions";
5-
export * from "./iota_identity_client";
6-
export * from "./jose/index";
4+
import "./append_functions.js";
5+
export * from "./iota_identity_client.js";
6+
export * from "./jose";
77

88
export * from "~identity_wasm";

bindings/wasm/lib/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"compilerOptions": {
44
"baseUrl": "./",
55
"paths": {
6-
"~identity_wasm": ["../node/identity_wasm"],
6+
"~identity_wasm": ["../node/identity_wasm", "./identity_wasm.js"],
77
"~client-wasm": ["../node_modules/@iota/client-wasm/node", "@iota/client-wasm/node"],
88
"../lib": ["."]
99
},

bindings/wasm/lib/tsconfig.web.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"compilerOptions": {
44
"baseUrl": "./",
55
"paths": {
6-
"~identity_wasm": ["../web/identity_wasm"],
6+
"~identity_wasm": ["../web/identity_wasm", "./identity_wasm.js"],
77
"~client-wasm": ["../node_modules/@iota/client-wasm/web", "@iota/client-wasm/web"],
88
"../lib": ["."]
99
},

0 commit comments

Comments
 (0)