-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (56 loc) · 1.75 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// @ts-check
import fs from "node:fs";
import { initSimnet } from "@hirosystems/clarinet-sdk";
/** @type import("vitest").Environment */
export default {
name: "clarinet",
transformMode: "web",
async setupVM() {
const nodeVM = await import("node:vm");
const context = nodeVM.createContext();
return {
getVmContext() {
return context;
},
teardown() {},
};
},
async setup(global, options) {
const covFilename = options.clarinet.coverageFilename || "lcov.info";
const costsFilename =
options.clarinet.costsFilename || "costs-reports.json";
const { coverage, costs } = options.clarinet;
if (coverage && fs.existsSync(covFilename)) fs.rmSync(covFilename);
if (costs && fs.existsSync(costsFilename)) fs.rmSync(costsFilename);
const { manifestPath } = options.clarinet;
const simnet = await initSimnet(manifestPath, false, {
trackCosts: costs,
trackCoverage: coverage,
});
global.testEnvironment = "clarinet";
global.simnet = simnet;
global.coverageReports = [];
global.costsReports = [];
global.options = options;
return {
async teardown() {
if (coverage) {
fs.writeFileSync(covFilename, global.coverageReports.join("\n"));
}
if (costs) {
try {
const costs = global.costsReports.map((r) => JSON.parse(r)).flat();
fs.writeFileSync(costsFilename, JSON.stringify(costs, null, 2));
} catch (e) {
console.warn(`Failed to write costs reports file.`);
}
}
delete global.testEnvironment;
delete global.simnet;
delete global.coverageReports;
delete global.costsReports;
delete global.options;
},
};
},
};