@centreon/js-config 25.4.0 → 25.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cypress/e2e/configuration.ts +4 -7
- package/cypress/e2e/tasks.ts +45 -30
- package/package.json +1 -1
|
@@ -50,13 +50,10 @@ export default ({
|
|
|
50
50
|
},
|
|
51
51
|
setupNodeEvents: async (cypressOn, config) => {
|
|
52
52
|
const on = require('cypress-on-fix')(cypressOn)
|
|
53
|
-
installLogsPrinter(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
defaultTrimLength: 5000,
|
|
58
|
-
}
|
|
59
|
-
);
|
|
53
|
+
installLogsPrinter(on, {
|
|
54
|
+
commandTrimLength: 5000,
|
|
55
|
+
defaultTrimLength: 5000,
|
|
56
|
+
});
|
|
60
57
|
await esbuildPreprocessor(on, config);
|
|
61
58
|
tasks(on);
|
|
62
59
|
|
package/cypress/e2e/tasks.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { execSync } from 'child_process';
|
|
3
3
|
import { existsSync, mkdirSync } from 'fs';
|
|
4
4
|
import path from 'path';
|
|
5
|
+
import fs from "fs";
|
|
5
6
|
|
|
6
7
|
import tar from 'tar-fs';
|
|
7
8
|
import {
|
|
@@ -52,7 +53,7 @@ export default (on: Cypress.PluginEvents): void => {
|
|
|
52
53
|
name: string;
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
on(
|
|
56
|
+
on("task", {
|
|
56
57
|
copyFromContainer: async ({ destination, serviceName, source }) => {
|
|
57
58
|
try {
|
|
58
59
|
const container = getContainer(serviceName);
|
|
@@ -63,7 +64,7 @@ export default (on: Cypress.PluginEvents): void => {
|
|
|
63
64
|
return new Promise<void>((resolve) => {
|
|
64
65
|
const dest = tar.extract(destination);
|
|
65
66
|
archiveStream.pipe(dest);
|
|
66
|
-
dest.on(
|
|
67
|
+
dest.on("finish", resolve);
|
|
67
68
|
});
|
|
68
69
|
});
|
|
69
70
|
} catch (error) {
|
|
@@ -75,19 +76,19 @@ export default (on: Cypress.PluginEvents): void => {
|
|
|
75
76
|
copyToContainer: async ({ destination, serviceName, source, type }) => {
|
|
76
77
|
const container = getContainer(serviceName);
|
|
77
78
|
|
|
78
|
-
if (type ===
|
|
79
|
+
if (type === "directory") {
|
|
79
80
|
await container.copyDirectoriesToContainer([
|
|
80
81
|
{
|
|
81
82
|
source,
|
|
82
|
-
target: destination
|
|
83
|
-
}
|
|
83
|
+
target: destination,
|
|
84
|
+
},
|
|
84
85
|
]);
|
|
85
|
-
} else if (type ===
|
|
86
|
+
} else if (type === "file") {
|
|
86
87
|
await container.copyFilesToContainer([
|
|
87
88
|
{
|
|
88
89
|
source,
|
|
89
|
-
target: destination
|
|
90
|
-
}
|
|
90
|
+
target: destination,
|
|
91
|
+
},
|
|
91
92
|
]);
|
|
92
93
|
}
|
|
93
94
|
|
|
@@ -102,9 +103,9 @@ export default (on: Cypress.PluginEvents): void => {
|
|
|
102
103
|
},
|
|
103
104
|
execInContainer: async ({ command, name }) => {
|
|
104
105
|
const { exitCode, output } = await getContainer(name).exec([
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
`${command}${command.match(/[\n\r]/) ?
|
|
106
|
+
"bash",
|
|
107
|
+
"-c",
|
|
108
|
+
`${command}${command.match(/[\n\r]/) ? "" : " 2>&1"}`,
|
|
108
109
|
]);
|
|
109
110
|
|
|
110
111
|
return { exitCode, output };
|
|
@@ -124,15 +125,15 @@ export default (on: Cypress.PluginEvents): void => {
|
|
|
124
125
|
const loggedContainers = await dockerode.listContainers();
|
|
125
126
|
|
|
126
127
|
return loggedContainers.reduce((acc, container) => {
|
|
127
|
-
const containerName = container.Names[0].replace(
|
|
128
|
+
const containerName = container.Names[0].replace("/", "");
|
|
128
129
|
acc[containerName] = execSync(`docker logs -t ${container.Id}`, {
|
|
129
|
-
stdio:
|
|
130
|
-
}).toString(
|
|
130
|
+
stdio: "pipe",
|
|
131
|
+
}).toString("utf8");
|
|
131
132
|
|
|
132
133
|
return acc;
|
|
133
134
|
}, {});
|
|
134
135
|
} catch (error) {
|
|
135
|
-
console.warn(
|
|
136
|
+
console.warn("Cannot get containers logs");
|
|
136
137
|
console.warn(error);
|
|
137
138
|
|
|
138
139
|
return null;
|
|
@@ -142,17 +143,17 @@ export default (on: Cypress.PluginEvents): void => {
|
|
|
142
143
|
let container: StartedTestContainer | null = null;
|
|
143
144
|
|
|
144
145
|
if (dockerEnvironment !== null) {
|
|
145
|
-
container = dockerEnvironment.getContainer(
|
|
146
|
+
container = dockerEnvironment.getContainer("db-1");
|
|
146
147
|
} else {
|
|
147
|
-
container = getContainer(
|
|
148
|
+
container = getContainer("web");
|
|
148
149
|
}
|
|
149
150
|
|
|
150
151
|
const client = await createConnection({
|
|
151
152
|
database,
|
|
152
153
|
host: container.getHost(),
|
|
153
|
-
password:
|
|
154
|
+
password: "centreon",
|
|
154
155
|
port: container.getMappedPort(3306),
|
|
155
|
-
user:
|
|
156
|
+
user: "centreon",
|
|
156
157
|
});
|
|
157
158
|
|
|
158
159
|
const [rows, fields] = await client.query(query);
|
|
@@ -165,21 +166,21 @@ export default (on: Cypress.PluginEvents): void => {
|
|
|
165
166
|
command,
|
|
166
167
|
image,
|
|
167
168
|
name,
|
|
168
|
-
portBindings = []
|
|
169
|
+
portBindings = [],
|
|
169
170
|
}: StartContainerProps) => {
|
|
170
171
|
let container = await new GenericContainer(image).withName(name);
|
|
171
172
|
|
|
172
173
|
portBindings.forEach(({ source, destination }) => {
|
|
173
174
|
container = container.withExposedPorts({
|
|
174
175
|
container: source,
|
|
175
|
-
host: destination
|
|
176
|
+
host: destination,
|
|
176
177
|
});
|
|
177
178
|
});
|
|
178
179
|
|
|
179
180
|
if (command) {
|
|
180
181
|
container
|
|
181
|
-
.withCommand([
|
|
182
|
-
.withWaitStrategy(Wait.forSuccessfulCommand(
|
|
182
|
+
.withCommand(["bash", "-c", command])
|
|
183
|
+
.withWaitStrategy(Wait.forSuccessfulCommand("ls"));
|
|
183
184
|
}
|
|
184
185
|
|
|
185
186
|
containers[name] = await container.start();
|
|
@@ -192,7 +193,7 @@ export default (on: Cypress.PluginEvents): void => {
|
|
|
192
193
|
openidImage,
|
|
193
194
|
profiles,
|
|
194
195
|
samlImage,
|
|
195
|
-
webImage
|
|
196
|
+
webImage,
|
|
196
197
|
}) => {
|
|
197
198
|
try {
|
|
198
199
|
const composeFileDir = path.dirname(composeFile);
|
|
@@ -200,22 +201,22 @@ export default (on: Cypress.PluginEvents): void => {
|
|
|
200
201
|
|
|
201
202
|
dockerEnvironment = await new DockerComposeEnvironment(
|
|
202
203
|
composeFileDir,
|
|
203
|
-
composeFileName
|
|
204
|
+
composeFileName,
|
|
204
205
|
)
|
|
205
206
|
.withEnvironment({
|
|
206
207
|
MYSQL_IMAGE: databaseImage,
|
|
207
208
|
OPENID_IMAGE: openidImage,
|
|
208
209
|
SAML_IMAGE: samlImage,
|
|
209
|
-
WEB_IMAGE: webImage
|
|
210
|
+
WEB_IMAGE: webImage,
|
|
210
211
|
})
|
|
211
212
|
.withProfiles(...profiles)
|
|
212
213
|
.withStartupTimeout(120000)
|
|
213
214
|
.withWaitStrategy(
|
|
214
|
-
|
|
215
|
+
"web-1",
|
|
215
216
|
Wait.forAll([
|
|
216
217
|
Wait.forHealthCheck(),
|
|
217
|
-
Wait.forLogMessage(
|
|
218
|
-
])
|
|
218
|
+
Wait.forLogMessage("Centreon is ready"),
|
|
219
|
+
]),
|
|
219
220
|
)
|
|
220
221
|
.up();
|
|
221
222
|
|
|
@@ -252,6 +253,20 @@ export default (on: Cypress.PluginEvents): void => {
|
|
|
252
253
|
execSync(`npx wait-on ${url}`);
|
|
253
254
|
|
|
254
255
|
return null;
|
|
255
|
-
}
|
|
256
|
+
},
|
|
257
|
+
listFilesInDirectory: async ( directoryPath ) => {
|
|
258
|
+
return new Promise((resolve, reject) => {
|
|
259
|
+
fs.readdir(directoryPath, (err, files) => {
|
|
260
|
+
if (err) {
|
|
261
|
+
reject(err);
|
|
262
|
+
} else {
|
|
263
|
+
resolve(files);
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
},
|
|
268
|
+
fileExists: async ( filePath ) => {
|
|
269
|
+
return fs.existsSync(filePath);
|
|
270
|
+
},
|
|
256
271
|
});
|
|
257
272
|
};
|
package/package.json
CHANGED