-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathbuild.test.ts
More file actions
163 lines (130 loc) · 4.68 KB
/
build.test.ts
File metadata and controls
163 lines (130 loc) · 4.68 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import fs from "fs";
import path from "path";
import { expect } from "chai";
import { cleanTestDir, testDir } from "../testUtils.js";
import { initHandler } from "../../src/commands/init/handler.js";
import { buildHandler } from "../../src/commands/build/handler.js";
import {
defaultVariantsDirName,
defaultVariantsEnvValues
} from "../../src/params.js";
import { normalizeIpfsProvider } from "../../src/releaseUploader/ipfsNode/ipfsProvider.js";
const contentProvider = await normalizeIpfsProvider("remote");
// This test will create the following fake files
// ./dappnode_package.json => fake manifest
// ./dnp_0.0.0/ => build directory
//
// Then it will expect the function to generate transaction data
// and output it to the console and to ./dnp_0.0.0/deploy.txt
describe("Init and build simple package", function () {
this.timeout(120 * 1000);
before("Clean testDir", () => cleanTestDir());
after("Clean testDir", () => cleanTestDir());
before("Init repo", async () => {
await initHandler({
dir: testDir,
force: true,
yes: true
});
});
it("Should build and upload the current version", async () => {
const buildResults = await buildHandler({
dir: testDir,
provider: contentProvider,
upload_to: "ipfs",
timeout: "5min",
verbose: true
});
const releaseHashes = Object.entries(buildResults).flatMap(
([, { releaseMultiHash }]) => releaseMultiHash
);
expect(releaseHashes).to.have.lengthOf(1);
// Check returned hash is correct
expect(releaseHashes[0]).to.include("/ipfs/Qm");
});
});
describe("Init and build package variants", function () {
this.timeout(120 * 1000);
beforeEach("Clean testDir", () => cleanTestDir());
afterEach("Clean testDir", () => cleanTestDir());
beforeEach("Init multi-variant repo", async () => {
await initHandler({
dir: testDir,
force: true,
yes: true,
use_variants: true
});
});
it("Should build and upload all package variants", async () => {
const buildResults = await buildHandler({
dir: testDir,
provider: contentProvider,
upload_to: "ipfs",
timeout: "5min",
verbose: true,
all_variants: true
});
const resultEntries = Object.entries(buildResults);
const builtVariants = resultEntries.map(([, { variant }]) => variant);
expect(builtVariants).to.have.lengthOf(defaultVariantsEnvValues.length);
expect(builtVariants).to.have.members(defaultVariantsEnvValues);
resultEntries.forEach(([dnpName, { releaseMultiHash, variant }]) => {
// Check returned hash is correct
expect(releaseMultiHash).to.include("/ipfs/Qm");
expect(dnpName).to.include(variant);
});
});
it("Should build and upload all package variants with custom variants dir", async () => {
const customVariantsDirName = "custom_variants";
// Ensure the directory exists before renaming
const oldPath = path.join(testDir, defaultVariantsDirName);
const newPath = path.join(testDir, customVariantsDirName);
if (fs.existsSync(oldPath)) {
fs.renameSync(oldPath, newPath);
} else {
throw new Error(`Directory ${oldPath} does not exist`);
}
const buildResults = await buildHandler({
dir: testDir,
provider: contentProvider,
upload_to: "ipfs",
timeout: "5min",
verbose: true,
variants: defaultVariantsEnvValues[0],
variants_dir_name: customVariantsDirName
});
const resultEntries = Object.entries(buildResults);
const builtVariants = resultEntries.map(([, { variant }]) => variant);
expect(builtVariants).to.have.lengthOf(1);
const [, { releaseMultiHash }] = resultEntries[0];
expect(releaseMultiHash).to.include("/ipfs/Qm");
});
it("Should throw an error when all specified variants are invalid", async () => {
await buildHandler({
dir: testDir,
provider: contentProvider,
upload_to: "ipfs",
timeout: "5min",
verbose: true,
variants: "invalid_variant",
skip_save: true,
skip_upload: true
}).catch(error => {
expect(error.message).to.include("No valid variants specified");
});
});
it("Should only build valid variants", async () => {
const buildResults = await buildHandler({
dir: testDir,
provider: contentProvider,
upload_to: "ipfs",
timeout: "5min",
verbose: true,
variants: `${defaultVariantsEnvValues[0]},invalid_variant`
});
const resultEntries = Object.entries(buildResults);
const builtVariants = resultEntries.map(([, { variant }]) => variant);
expect(builtVariants).to.have.lengthOf(1);
expect(builtVariants[0]).to.equal(defaultVariantsEnvValues[0]);
});
});