Skip to content

Commit af78f22

Browse files
authored
Reintroduce cypress tests (iotaledger#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+
);

0 commit comments

Comments
 (0)