@centreon/js-config 23.4.22-MON-17552.0 → 23.4.22-MON-17315-platform-update-automation-develop.0

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.
@@ -1,200 +1,386 @@
1
- /* eslint-disable @typescript-eslint/no-namespace */
2
-
3
- const apiBase = `${Cypress.config().baseUrl}/centreon/api`;
4
- const apiActionV1 = `${apiBase}/index.php`;
5
- const apiLoginV2 = '/centreon/authentication/providers/configurations/local';
6
-
7
- Cypress.Commands.add('getIframeBody', (): Cypress.Chainable => {
8
- return cy
9
- .get('iframe#main-content')
10
- .its('0.contentDocument.body')
11
- .should('not.be.empty')
12
- .then(cy.wrap);
13
- });
14
-
15
- Cypress.Commands.add(
16
- 'hoverRootMenuItem',
17
- (rootItemNumber: number): Cypress.Chainable => {
18
- return cy
19
- .get('div[data-testid="sidebar"] li')
20
- .eq(rootItemNumber)
21
- .trigger('mouseover');
22
- }
23
- );
24
-
25
- interface NavigateToProps {
26
- page: string;
27
- rootItemNumber: number;
28
- subMenu?: string;
29
- }
30
-
31
- Cypress.Commands.add(
32
- 'navigateTo',
33
- ({ rootItemNumber, subMenu, page }): void => {
34
- if (subMenu) {
35
- cy.hoverRootMenuItem(rootItemNumber)
36
- .contains(subMenu)
37
- .trigger('mouseover', { force: true });
38
- cy.contains(page).click({ force: true });
39
-
40
- return;
41
- }
42
- cy.hoverRootMenuItem(rootItemNumber).contains(page).click({ force: true });
43
- }
44
- );
45
-
46
- Cypress.Commands.add(
47
- 'moveSortableElement',
48
- {
49
- prevSubject: 'element'
50
- },
51
- (subject, direction): void => {
52
- const key = `{${direction}arrow}`;
53
-
54
- cy.wrap(subject)
55
- .type(' ', {
56
- force: true,
57
- scrollBehavior: false
58
- })
59
- .closest('body')
60
- .type(key, {
61
- scrollBehavior: false
62
- })
63
- .type(' ', {
64
- scrollBehavior: false
65
- });
66
- }
67
- );
68
-
69
- interface CopyOntoContainerProps {
70
- destPath: string;
71
- srcPath: string;
72
- }
73
-
74
- Cypress.Commands.add(
75
- 'copyOntoContainer',
76
- ({ srcPath, destPath }: CopyOntoContainerProps) => {
77
- return cy.exec(
78
- `docker cp ${srcPath} ${Cypress.env('dockerName')}:${destPath}`
79
- );
80
- }
81
- );
82
-
83
- interface LoginByTypeOfUserProps {
84
- jsonName?: string;
85
- preserveToken?: boolean;
86
- }
87
-
88
- Cypress.Commands.add(
89
- 'loginByTypeOfUser',
90
- ({ jsonName, preserveToken }): Cypress.Chainable => {
91
- if (preserveToken) {
92
- return cy
93
- .fixture(`users/${jsonName}.json`)
94
- .then((user) => {
95
- return cy.request({
96
- body: {
97
- login: user.login,
98
- password: user.password
99
- },
100
- method: 'POST',
101
- url: apiLoginV2
102
- });
103
- })
104
- .then(() => {
105
- Cypress.Cookies.defaults({
106
- preserve: 'PHPSESSID'
107
- });
108
- })
109
- .then(() => {
110
- cy.visit(`${Cypress.config().baseUrl}`);
111
- });
112
- }
113
- cy.visit(`${Cypress.config().baseUrl}`)
114
- .fixture(`users/${jsonName}.json`)
115
- .then((credential) => {
116
- cy.getByLabel({ label: 'Alias', tag: 'input' }).type(credential.login);
117
- cy.getByLabel({ label: 'Password', tag: 'input' }).type(
118
- credential.password
119
- );
120
- })
121
- .getByLabel({ label: 'Connect', tag: 'button' })
122
- .click();
123
-
124
- return cy
125
- .get('.SnackbarContent-root > .MuiPaper-root')
126
- .then(($snackbar) => {
127
- if ($snackbar.text().includes('Login succeeded')) {
128
- cy.wait('@getNavigationList');
129
- }
130
- });
131
- }
132
- );
133
-
134
- interface ActionClapi {
135
- action: string;
136
- object?: string;
137
- values: string;
138
- }
139
-
140
- interface ExecuteActionViaClapiProps {
141
- bodyContent: ActionClapi;
142
- method?: string;
143
- }
144
-
145
- Cypress.Commands.add(
146
- 'executeActionViaClapi',
147
- ({
148
- bodyContent,
149
- method = 'POST'
150
- }: ExecuteActionViaClapiProps): Cypress.Chainable => {
151
- return cy.request({
152
- body: bodyContent,
153
- headers: {
154
- 'Content-Type': 'application/json',
155
- 'centreon-auth-token': window.localStorage.getItem('userTokenApiV1')
156
- },
157
- method,
158
- url: `${apiActionV1}?action=action&object=centreon_clapi`
159
- });
160
- }
161
- );
162
-
163
- Cypress.Commands.add(
164
- 'executeCommandsViaClapi',
165
- (fixtureFile: string): Cypress.Chainable => {
166
- return cy.fixture(fixtureFile).then((listRequestConfig) => {
167
- cy.wrap(
168
- Promise.all(
169
- listRequestConfig.map((request: ActionClapi) =>
170
- cy.executeActionViaClapi({ bodyContent: request })
171
- )
172
- )
173
- );
174
- });
175
- }
176
- );
177
-
178
- declare global {
179
- namespace Cypress {
180
- interface Chainable {
181
- copyOntoContainer: (props: CopyOntoContainerProps) => Cypress.Chainable;
182
- executeActionViaClapi: (
183
- props: ExecuteActionViaClapiProps
184
- ) => Cypress.Chainable;
185
- executeCommandsViaClapi: (fixtureFile: string) => Cypress.Chainable;
186
- getIframeBody: () => Cypress.Chainable;
187
- hoverRootMenuItem: (rootItemNumber: number) => Cypress.Chainable;
188
- loginByTypeOfUser: ({
189
- jsonName = 'admin',
190
- preserveToken = false
191
- }: LoginByTypeOfUserProps) => Cypress.Chainable;
192
- moveSortableElement: (direction: string) => Cypress.Chainable;
193
- navigateTo: ({
194
- page,
195
- rootItemNumber,
196
- subMenu
197
- }: NavigateToProps) => Cypress.Chainable;
198
- }
199
- }
200
- }
1
+ /* eslint-disable @typescript-eslint/no-namespace */
2
+
3
+ const apiBase = '/centreon/api';
4
+ const apiActionV1 = `${apiBase}/index.php`;
5
+ const apiLoginV2 = '/centreon/authentication/providers/configurations/local';
6
+
7
+ Cypress.Commands.add('getWebVersion', (): Cypress.Chainable => {
8
+ return cy
9
+ .exec(
10
+ `bash -c "grep version ../../www/install/insertBaseConf.sql | cut -d \\' -f 4 | awk 'NR==2'"`
11
+ )
12
+ .then(({ stdout }) => {
13
+ const found = stdout.match(/(\d+\.\d+)\.(\d+)/);
14
+ if (found) {
15
+ return cy.wrap({ major_version: found[1], minor_version: found[2] });
16
+ }
17
+
18
+ throw new Error('Current web version cannot be parsed.');
19
+ });
20
+ });
21
+
22
+ Cypress.Commands.add('getIframeBody', (): Cypress.Chainable => {
23
+ return cy
24
+ .get('iframe#main-content')
25
+ .its('0.contentDocument.body')
26
+ .should('not.be.empty')
27
+ .then(cy.wrap);
28
+ });
29
+
30
+ Cypress.Commands.add(
31
+ 'hoverRootMenuItem',
32
+ (rootItemNumber: number): Cypress.Chainable => {
33
+ return cy
34
+ .get('div[data-testid="sidebar"] li')
35
+ .eq(rootItemNumber)
36
+ .trigger('mouseover');
37
+ }
38
+ );
39
+
40
+ interface NavigateToProps {
41
+ page: string;
42
+ rootItemNumber: number;
43
+ subMenu?: string;
44
+ }
45
+
46
+ Cypress.Commands.add(
47
+ 'navigateTo',
48
+ ({ rootItemNumber, subMenu, page }): void => {
49
+ if (subMenu) {
50
+ cy.hoverRootMenuItem(rootItemNumber)
51
+ .contains(subMenu)
52
+ .trigger('mouseover', { force: true });
53
+ cy.contains(page).click({ force: true });
54
+
55
+ return;
56
+ }
57
+ cy.hoverRootMenuItem(rootItemNumber).contains(page).click({ force: true });
58
+ }
59
+ );
60
+
61
+ Cypress.Commands.add(
62
+ 'moveSortableElement',
63
+ {
64
+ prevSubject: 'element'
65
+ },
66
+ (subject, direction): void => {
67
+ const key = `{${direction}arrow}`;
68
+
69
+ cy.wrap(subject)
70
+ .type(' ', {
71
+ force: true,
72
+ scrollBehavior: false
73
+ })
74
+ .closest('body')
75
+ .type(key, {
76
+ scrollBehavior: false
77
+ })
78
+ .type(' ', {
79
+ scrollBehavior: false
80
+ });
81
+ }
82
+ );
83
+
84
+ interface CopyFromContainerProps {
85
+ destination: string;
86
+ source: string;
87
+ }
88
+
89
+ Cypress.Commands.add(
90
+ 'copyFromContainer',
91
+ ({ source, destination }: CopyFromContainerProps) => {
92
+ return cy.exec(
93
+ `docker cp ${Cypress.env('dockerName')}:${source} "${destination}"`
94
+ );
95
+ }
96
+ );
97
+
98
+ interface CopyToContainerProps {
99
+ destination: string;
100
+ source: string;
101
+ }
102
+
103
+ Cypress.Commands.add(
104
+ 'copyToContainer',
105
+ ({ source, destination }: CopyToContainerProps) => {
106
+ return cy.exec(
107
+ `docker cp ${source} ${Cypress.env('dockerName')}:${destination}`
108
+ );
109
+ }
110
+ );
111
+
112
+ interface LoginByTypeOfUserProps {
113
+ jsonName?: string;
114
+ loginViaApi?: boolean;
115
+ }
116
+
117
+ Cypress.Commands.add(
118
+ 'loginByTypeOfUser',
119
+ ({ jsonName, loginViaApi }): Cypress.Chainable => {
120
+ if (loginViaApi) {
121
+ return cy
122
+ .fixture(`users/${jsonName}.json`)
123
+ .then((user) => {
124
+ return cy.request({
125
+ body: {
126
+ login: user.login,
127
+ password: user.password
128
+ },
129
+ method: 'POST',
130
+ url: apiLoginV2
131
+ });
132
+ })
133
+ .visit(`${Cypress.config().baseUrl}`)
134
+ .wait('@getNavigationList');
135
+ }
136
+ cy.visit(`${Cypress.config().baseUrl}`)
137
+ .fixture(`users/${jsonName}.json`)
138
+ .then((credential) => {
139
+ cy.getByLabel({ label: 'Alias', tag: 'input' }).type(credential.login);
140
+ cy.getByLabel({ label: 'Password', tag: 'input' }).type(
141
+ credential.password
142
+ );
143
+ })
144
+ .getByLabel({ label: 'Connect', tag: 'button' })
145
+ .click();
146
+
147
+ return cy
148
+ .get('.SnackbarContent-root > .MuiPaper-root')
149
+ .then(($snackbar) => {
150
+ if ($snackbar.text().includes('Login succeeded')) {
151
+ cy.wait('@getNavigationList');
152
+ }
153
+ });
154
+ }
155
+ );
156
+
157
+ Cypress.Commands.add(
158
+ 'visitEmptyPage',
159
+ (): Cypress.Chainable =>
160
+ cy
161
+ .intercept('/waiting-page', {
162
+ headers: { 'content-type': 'text/html' },
163
+ statusCode: 200
164
+ })
165
+ .visit('/waiting-page')
166
+ );
167
+
168
+ interface ActionClapi {
169
+ action: string;
170
+ object?: string;
171
+ values: string;
172
+ }
173
+
174
+ interface ExecuteActionViaClapiProps {
175
+ bodyContent: ActionClapi;
176
+ method?: string;
177
+ }
178
+
179
+ Cypress.Commands.add(
180
+ 'executeActionViaClapi',
181
+ ({
182
+ bodyContent,
183
+ method = 'POST'
184
+ }: ExecuteActionViaClapiProps): Cypress.Chainable => {
185
+ return cy.request({
186
+ body: bodyContent,
187
+ headers: {
188
+ 'Content-Type': 'application/json',
189
+ 'centreon-auth-token': window.localStorage.getItem('userTokenApiV1')
190
+ },
191
+ method,
192
+ url: `${apiActionV1}?action=action&object=centreon_clapi`
193
+ });
194
+ }
195
+ );
196
+
197
+ Cypress.Commands.add(
198
+ 'executeCommandsViaClapi',
199
+ (fixtureFile: string): Cypress.Chainable => {
200
+ return cy.fixture(fixtureFile).then((listRequestConfig) => {
201
+ cy.wrap(
202
+ Promise.all(
203
+ listRequestConfig.map((request: ActionClapi) =>
204
+ cy.executeActionViaClapi({ bodyContent: request })
205
+ )
206
+ )
207
+ );
208
+ });
209
+ }
210
+ );
211
+
212
+ Cypress.Commands.add('waitForContainerAndSetToken', (): Cypress.Chainable => {
213
+ return cy.setUserTokenApiV1();
214
+ });
215
+
216
+ interface ExecInContainerProps {
217
+ command: string;
218
+ name: string;
219
+ }
220
+
221
+ Cypress.Commands.add(
222
+ 'execInContainer',
223
+ ({ command, name }: ExecInContainerProps): Cypress.Chainable => {
224
+ return cy.exec(`docker exec -i ${name} ${command}`);
225
+ }
226
+ );
227
+
228
+ interface PortBinding {
229
+ destination: number;
230
+ source: number;
231
+ }
232
+
233
+ interface StartContainerProps {
234
+ image: string;
235
+ name: string;
236
+ portBindings: Array<PortBinding>;
237
+ }
238
+
239
+ Cypress.Commands.add(
240
+ 'startContainer',
241
+ ({ name, image, portBindings }: StartContainerProps): Cypress.Chainable => {
242
+ return cy
243
+ .exec(`docker image inspect ${image} || docker pull ${image}`)
244
+ .task('startContainer', { image, name, portBindings });
245
+ }
246
+ );
247
+
248
+ interface StartWebContainerProps {
249
+ name?: string;
250
+ os?: string;
251
+ useSlim?: boolean;
252
+ version?: string;
253
+ }
254
+
255
+ Cypress.Commands.add(
256
+ 'startWebContainer',
257
+ ({
258
+ name = Cypress.env('dockerName'),
259
+ os = 'alma9',
260
+ useSlim = true,
261
+ version = Cypress.env('WEB_IMAGE_VERSION')
262
+ }: StartWebContainerProps = {}): Cypress.Chainable => {
263
+ const slimSuffix = useSlim ? '-slim' : '';
264
+
265
+ const image = `docker.centreon.com/centreon/centreon-web${slimSuffix}-${os}:${version}`;
266
+
267
+ return cy
268
+ .startContainer({
269
+ image,
270
+ name,
271
+ portBindings: [{ destination: 4000, source: 80 }]
272
+ })
273
+ .then(() => {
274
+ const baseUrl = 'http://0.0.0.0:4000';
275
+
276
+ Cypress.config('baseUrl', baseUrl);
277
+
278
+ return cy.exec(
279
+ `npx wait-on ${baseUrl}/centreon/api/latest/platform/installation/status`
280
+ );
281
+ })
282
+ .visit('/') // this is necessary to refresh browser cause baseUrl has changed (flash appears in video)
283
+ .setUserTokenApiV1();
284
+ }
285
+ );
286
+
287
+ interface StopWebContainerProps {
288
+ name?: string;
289
+ }
290
+
291
+ Cypress.Commands.add(
292
+ 'stopWebContainer',
293
+ ({
294
+ name = Cypress.env('dockerName')
295
+ }: StopWebContainerProps = {}): Cypress.Chainable => {
296
+ const logDirectory = `cypress/results/logs/${
297
+ Cypress.spec.name
298
+ }/${Cypress.currentTest.title.replace(/,|\s|\//g, '_')}`;
299
+
300
+ return cy
301
+ .visitEmptyPage()
302
+ .exec(`mkdir -p "${logDirectory}"`)
303
+ .copyFromContainer({
304
+ destination: `${logDirectory}/broker`,
305
+ source: '/var/log/centreon-broker'
306
+ })
307
+ .copyFromContainer({
308
+ destination: `${logDirectory}/engine`,
309
+ source: '/var/log/centreon-engine'
310
+ })
311
+ .copyFromContainer({
312
+ destination: `${logDirectory}/centreon`,
313
+ source: '/var/log/centreon'
314
+ })
315
+ .stopContainer({ name });
316
+ }
317
+ );
318
+
319
+ interface StopContainerProps {
320
+ name: string;
321
+ }
322
+
323
+ Cypress.Commands.add(
324
+ 'stopContainer',
325
+ ({ name }: StopContainerProps): Cypress.Chainable => {
326
+ cy.exec(`docker logs ${name}`).then(({ stdout }) => {
327
+ cy.writeFile(
328
+ `cypress/results/logs/${
329
+ Cypress.spec.name
330
+ }/${Cypress.currentTest.title.replace(
331
+ /,|\s|\//g,
332
+ '_'
333
+ )}/container-${name}.log`,
334
+ stdout
335
+ );
336
+ });
337
+
338
+ return cy.task('stopContainer', { name });
339
+ }
340
+ );
341
+
342
+ declare global {
343
+ namespace Cypress {
344
+ interface Chainable {
345
+ copyFromContainer: (props: CopyFromContainerProps) => Cypress.Chainable;
346
+ copyToContainer: (props: CopyToContainerProps) => Cypress.Chainable;
347
+ execInContainer: ({
348
+ command,
349
+ name
350
+ }: ExecInContainerProps) => Cypress.Chainable;
351
+ executeActionViaClapi: (
352
+ props: ExecuteActionViaClapiProps
353
+ ) => Cypress.Chainable;
354
+ executeCommandsViaClapi: (fixtureFile: string) => Cypress.Chainable;
355
+ getIframeBody: () => Cypress.Chainable;
356
+ getWebVersion: () => Cypress.Chainable;
357
+ hoverRootMenuItem: (rootItemNumber: number) => Cypress.Chainable;
358
+ loginByTypeOfUser: ({
359
+ jsonName = 'admin',
360
+ loginViaApi = false
361
+ }: LoginByTypeOfUserProps) => Cypress.Chainable;
362
+ moveSortableElement: (direction: string) => Cypress.Chainable;
363
+ navigateTo: ({
364
+ page,
365
+ rootItemNumber,
366
+ subMenu
367
+ }: NavigateToProps) => Cypress.Chainable;
368
+ startContainer: ({
369
+ name,
370
+ image
371
+ }: StartContainerProps) => Cypress.Chainable;
372
+ startWebContainer: ({
373
+ name,
374
+ os,
375
+ useSlim,
376
+ version
377
+ }?: StartWebContainerProps) => Cypress.Chainable;
378
+ stopContainer: ({ name }: StopContainerProps) => Cypress.Chainable;
379
+ stopWebContainer: ({ name }?: StopWebContainerProps) => Cypress.Chainable;
380
+ visitEmptyPage: () => Cypress.Chainable;
381
+ waitForContainerAndSetToken: () => Cypress.Chainable;
382
+ }
383
+ }
384
+ }
385
+
386
+ export {};
@@ -1,58 +1,62 @@
1
- /* eslint-disable import/extensions */
2
- /* eslint-disable import/no-unresolved */
3
-
4
- import { defineConfig } from 'cypress';
5
-
6
- import setupNodeEvents from './plugins';
7
-
8
- interface ConfigurationOptions {
9
- cypressFolder?: string;
10
- dockerName?: string;
11
- env?: Record<string, unknown>;
12
- isDevelopment?: boolean;
13
- specPattern: string;
14
- }
15
-
16
- export default ({
17
- specPattern,
18
- cypressFolder,
19
- isDevelopment,
20
- dockerName,
21
- env
22
- }: ConfigurationOptions): Cypress.ConfigOptions => {
23
- const resultsFolder = `${cypressFolder || 'cypress'}/results${
24
- isDevelopment ? '/dev' : ''
25
- }`;
26
-
27
- const baseUrlIPAddress = isDevelopment ? '0.0.0.0' : 'localhost';
28
-
29
- return defineConfig({
30
- chromeWebSecurity: false,
31
- defaultCommandTimeout: 6000,
32
- e2e: {
33
- baseUrl: `http://${baseUrlIPAddress}:4000`,
34
- excludeSpecPattern: ['*.js', '*.ts', '*.md'],
35
- experimentalSessionAndOrigin: true,
36
- setupNodeEvents,
37
- specPattern
38
- },
39
- env: {
40
- ...env,
41
- dockerName: dockerName || 'centreon-dev'
42
- },
43
- execTimeout: 60000,
44
- reporter: 'mochawesome',
45
- reporterOptions: {
46
- html: false,
47
- json: true,
48
- overwrite: true,
49
- reportDir: `${resultsFolder}/reports`,
50
- reportFilename: '[name]-report.json'
51
- },
52
- requestTimeout: 10000,
53
- retries: 0,
54
- screenshotsFolder: `${resultsFolder}/screenshots`,
55
- video: true,
56
- videosFolder: `${resultsFolder}/videos`
57
- });
58
- };
1
+ /* eslint-disable import/extensions */
2
+ /* eslint-disable import/no-unresolved */
3
+
4
+ import { execSync } from 'child_process';
5
+
6
+ import { defineConfig } from 'cypress';
7
+
8
+ import setupNodeEvents from './plugins';
9
+
10
+ interface ConfigurationOptions {
11
+ cypressFolder?: string;
12
+ dockerName?: string;
13
+ env?: Record<string, unknown>;
14
+ isDevelopment?: boolean;
15
+ specPattern: string;
16
+ }
17
+
18
+ export default ({
19
+ specPattern,
20
+ cypressFolder,
21
+ isDevelopment,
22
+ dockerName,
23
+ env
24
+ }: ConfigurationOptions): Cypress.ConfigOptions => {
25
+ const resultsFolder = `${cypressFolder || 'cypress'}/results${
26
+ isDevelopment ? '/dev' : ''
27
+ }`;
28
+
29
+ const webImageVersion = execSync('git rev-parse --abbrev-ref HEAD')
30
+ .toString('utf8')
31
+ .replace(/[\n\r\s]+$/, '');
32
+
33
+ return defineConfig({
34
+ chromeWebSecurity: false,
35
+ defaultCommandTimeout: 6000,
36
+ e2e: {
37
+ excludeSpecPattern: ['*.js', '*.ts', '*.md'],
38
+ setupNodeEvents,
39
+ specPattern
40
+ },
41
+ env: {
42
+ ...env,
43
+ OPENID_IMAGE_VERSION: '23.04',
44
+ WEB_IMAGE_VERSION: webImageVersion,
45
+ dockerName: dockerName || 'centreon-dev'
46
+ },
47
+ execTimeout: 60000,
48
+ reporter: 'mochawesome',
49
+ reporterOptions: {
50
+ html: false,
51
+ json: true,
52
+ overwrite: true,
53
+ reportDir: `${resultsFolder}/reports`,
54
+ reportFilename: '[name]-report.json'
55
+ },
56
+ requestTimeout: 10000,
57
+ retries: 0,
58
+ screenshotsFolder: `${resultsFolder}/screenshots`,
59
+ video: true,
60
+ videosFolder: `${resultsFolder}/videos`
61
+ });
62
+ };
@@ -1,61 +1,134 @@
1
- /* eslint-disable default-param-last */
2
- /* eslint-disable global-require */
3
- /* eslint-disable @typescript-eslint/no-var-requires */
4
- /* eslint-disable no-param-reassign */
5
-
6
- import { addCucumberPreprocessorPlugin } from '@badeball/cypress-cucumber-preprocessor';
7
- import webpackPreprocessor from '@cypress/webpack-preprocessor';
8
-
9
- const getWebpackOptions = (config): object => {
10
- return {
11
- module: {
12
- rules: [
13
- {
14
- exclude: [/node_modules/],
15
- test: /\.ts?$/,
16
- use: [
17
- {
18
- loader: 'swc-loader'
19
- }
20
- ]
21
- },
22
- {
23
- test: /\.feature$/,
24
- use: [
25
- {
26
- loader: '@badeball/cypress-cucumber-preprocessor/webpack',
27
- options: config
28
- }
29
- ]
30
- }
31
- ]
32
- },
33
- resolve: {
34
- extensions: ['.ts', '.js']
35
- }
36
- };
37
- };
38
-
39
- export default async (on, config): Promise<void> => {
40
- await addCucumberPreprocessorPlugin(on, config);
41
-
42
- const webpackOptions = await getWebpackOptions(config);
43
- const options = {
44
- webpackOptions
45
- };
46
-
47
- on('file:preprocessor', webpackPreprocessor(options));
48
-
49
- on('before:browser:launch', (browser = {}, launchOptions) => {
50
- if ((browser as { name }).name === 'chrome') {
51
- launchOptions.args.push('--disable-gpu');
52
- launchOptions.args = launchOptions.args.filter(
53
- (element) => element !== '--disable-dev-shm-usage'
54
- );
55
- }
56
-
57
- return launchOptions;
58
- });
59
-
60
- return config;
61
- };
1
+ /* eslint-disable default-param-last */
2
+ /* eslint-disable global-require */
3
+ /* eslint-disable @typescript-eslint/no-var-requires */
4
+ /* eslint-disable no-param-reassign */
5
+
6
+ import Docker from 'dockerode';
7
+ import { addCucumberPreprocessorPlugin } from '@badeball/cypress-cucumber-preprocessor';
8
+ import webpackPreprocessor from '@cypress/webpack-preprocessor';
9
+
10
+ const docker = new Docker();
11
+
12
+ const getWebpackOptions = (config): object => {
13
+ return {
14
+ module: {
15
+ rules: [
16
+ {
17
+ exclude: [/node_modules/],
18
+ test: /\.ts?$/,
19
+ use: [
20
+ {
21
+ loader: 'swc-loader'
22
+ }
23
+ ]
24
+ },
25
+ {
26
+ test: /\.feature$/,
27
+ use: [
28
+ {
29
+ loader: '@badeball/cypress-cucumber-preprocessor/webpack',
30
+ options: config
31
+ }
32
+ ]
33
+ }
34
+ ]
35
+ },
36
+ resolve: {
37
+ extensions: ['.ts', '.js']
38
+ }
39
+ };
40
+ };
41
+
42
+ export default async (on, config): Promise<void> => {
43
+ await addCucumberPreprocessorPlugin(on, config);
44
+
45
+ const webpackOptions = await getWebpackOptions(config);
46
+ const options = {
47
+ webpackOptions
48
+ };
49
+
50
+ on('file:preprocessor', webpackPreprocessor(options));
51
+
52
+ on('before:browser:launch', (browser = {}, launchOptions) => {
53
+ if ((browser as { name }).name === 'chrome') {
54
+ launchOptions.args.push('--disable-gpu');
55
+ launchOptions.args = launchOptions.args.filter(
56
+ (element) => element !== '--disable-dev-shm-usage'
57
+ );
58
+ }
59
+
60
+ return launchOptions;
61
+ });
62
+
63
+ interface PortBinding {
64
+ destination: number;
65
+ source: number;
66
+ }
67
+
68
+ interface StartContainerProps {
69
+ image: string;
70
+ name: string;
71
+ portBindings: Array<PortBinding>;
72
+ }
73
+
74
+ interface StopContainerProps {
75
+ name: string;
76
+ }
77
+
78
+ on('task', {
79
+ startContainer: async ({
80
+ image,
81
+ name,
82
+ portBindings = []
83
+ }: StartContainerProps) => {
84
+ const webContainers = await docker.listContainers({
85
+ all: true,
86
+ filters: { name: [name] }
87
+ });
88
+ if (webContainers.length) {
89
+ return webContainers[0];
90
+ }
91
+
92
+ const container = await docker.createContainer({
93
+ AttachStderr: true,
94
+ AttachStdin: false,
95
+ AttachStdout: true,
96
+ ExposedPorts: portBindings.reduce((accumulator, currentValue) => {
97
+ accumulator[`${currentValue.source}/tcp`] = {};
98
+
99
+ return accumulator;
100
+ }, {}),
101
+ HostConfig: {
102
+ PortBindings: portBindings.reduce((accumulator, currentValue) => {
103
+ accumulator[`${currentValue.source}/tcp`] = [
104
+ {
105
+ HostIP: '0.0.0.0',
106
+ HostPort: `${currentValue.destination}`
107
+ }
108
+ ];
109
+
110
+ return accumulator;
111
+ }, {})
112
+ },
113
+ Image: image,
114
+ OpenStdin: false,
115
+ StdinOnce: false,
116
+ Tty: true,
117
+ name
118
+ });
119
+
120
+ await container.start();
121
+
122
+ return container;
123
+ },
124
+ stopContainer: async ({ name }: StopContainerProps) => {
125
+ const container = await docker.getContainer(name);
126
+ await container.kill();
127
+ await container.remove();
128
+
129
+ return null;
130
+ }
131
+ });
132
+
133
+ return config;
134
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@centreon/js-config",
3
3
  "description": "Centreon Frontend shared build configuration",
4
- "version": "23.4.22-MON-17552.0",
4
+ "version": "23.4.22-MON-17315-platform-update-automation-develop.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/centreon/centreon-frontend.git"
@@ -17,6 +17,8 @@
17
17
  },
18
18
  "devDependencies": {
19
19
  "@badeball/cypress-cucumber-preprocessor": "^14.0.0",
20
+ "@types/dockerode": "^3.3.16",
21
+ "dockerode": "^3.3.5",
20
22
  "eslint": "^8.17.0",
21
23
  "eslint-config-airbnb": "19.0.4",
22
24
  "eslint-config-prettier": "^8.5.0",