@centreon/js-config 23.10.1-debug-openid.5 → 23.10.1-debug-e2e-cookies.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.
@@ -11,6 +11,8 @@ import { ThemeProvider } from '@centreon/ui';
11
11
  import '@testing-library/cypress/add-commands';
12
12
  import 'cypress-msw-interceptor';
13
13
 
14
+ import disableMotion from './disableCssTransitions';
15
+
14
16
  interface MountProps {
15
17
  Component: React.ReactNode;
16
18
  options?: object;
@@ -132,9 +134,16 @@ Cypress.Commands.add('makeSnapshot', (title?: string) => {
132
134
  cy.matchImageSnapshot(title);
133
135
  });
134
136
 
137
+ Cypress.Commands.add('cssDisableMotion', (): void => {
138
+ Cypress.on('window:before:load', (cyWindow) => {
139
+ disableMotion(cyWindow);
140
+ });
141
+ });
142
+
135
143
  declare global {
136
144
  namespace Cypress {
137
145
  interface Chainable {
146
+ cssDisableMotion: () => Cypress.Chainable;
138
147
  interceptAPIRequest: <T extends object>(
139
148
  props: InterceptAPIRequestProps<T>
140
149
  ) => Cypress.Chainable;
@@ -0,0 +1,19 @@
1
+ const disableMotion = (win): void => {
2
+ const injectedStyleEl = win.document.getElementById('__cy_disable_motion__');
3
+ if (injectedStyleEl) {
4
+ return;
5
+ }
6
+ win.document.head.insertAdjacentHTML(
7
+ 'beforeend',
8
+ `
9
+ <style id="__cy_disable_motion__">
10
+ /* Disable CSS transitions. */
11
+ *, *::before, *::after { -webkit-transition: none !important; -moz-transition: none !important; -o-transition: none !important; -ms-transition: none !important; transition: none !important; }
12
+ /* Disable CSS animations. */
13
+ *, *::before, *::after { -webkit-animation: none !important; -moz-animation: none !important; -o-animation: none !important; -ms-animation: none !important; animation: none !important; }
14
+ </style>
15
+ `.trim()
16
+ );
17
+ };
18
+
19
+ export default disableMotion;
@@ -5,10 +5,7 @@ import './commands/monitoring';
5
5
 
6
6
  import installLogsCollector from 'cypress-terminal-report/src/installLogsCollector';
7
7
 
8
- installLogsCollector({
9
- enableExtendedCollector: true,
10
- xhr: { printHeaderData: true, printRequestData: true }
11
- });
8
+ installLogsCollector({ enableExtendedCollector: true });
12
9
 
13
10
  const apiLoginV2 = '/centreon/authentication/providers/configurations/local';
14
11
 
@@ -214,7 +211,20 @@ interface ExecInContainerProps {
214
211
  Cypress.Commands.add(
215
212
  'execInContainer',
216
213
  ({ command, name }: ExecInContainerProps): Cypress.Chainable => {
217
- return cy.exec(`docker exec -i ${name} ${command}`);
214
+ return cy
215
+ .exec(`docker exec -i ${name} ${command}`, { failOnNonZeroExit: false })
216
+ .then((result) => {
217
+ if (result.code) {
218
+ // output will not be truncated
219
+ throw new Error(`
220
+ Execution of "${command}" failed
221
+ Exit code: ${result.code}
222
+ Stdout:\n${result.stdout}
223
+ Stderr:\n${result.stderr}`);
224
+ }
225
+
226
+ return cy.wrap(result);
227
+ });
218
228
  }
219
229
  );
220
230
 
@@ -232,7 +242,20 @@ interface StartContainerProps {
232
242
  Cypress.Commands.add(
233
243
  'startContainer',
234
244
  ({ name, image, portBindings }: StartContainerProps): Cypress.Chainable => {
235
- return cy.task('startContainer', { image, name, portBindings });
245
+ cy.log(`Starting container ${name} from image ${image}`);
246
+
247
+ return cy.task(
248
+ 'startContainer',
249
+ { image, name, portBindings },
250
+ { timeout: 600000 } // 10 minutes because docker pull can be very slow
251
+ );
252
+ }
253
+ );
254
+
255
+ Cypress.Commands.add(
256
+ 'createDirectory',
257
+ (directoryPath: string): Cypress.Chainable => {
258
+ return cy.task('createDirectory', directoryPath);
236
259
  }
237
260
  );
238
261
 
@@ -285,7 +308,7 @@ Cypress.Commands.add(
285
308
  ({
286
309
  name = Cypress.env('dockerName')
287
310
  }: StopWebContainerProps = {}): Cypress.Chainable => {
288
- const logDirectory = `cypress/results/logs/${Cypress.spec.name.replace(
311
+ const logDirectory = `results/logs/${Cypress.spec.name.replace(
289
312
  artifactIllegalCharactersMatcher,
290
313
  '_'
291
314
  )}/${Cypress.currentTest.title.replace(
@@ -295,7 +318,7 @@ Cypress.Commands.add(
295
318
 
296
319
  return cy
297
320
  .visitEmptyPage()
298
- .exec(`mkdir -p "${logDirectory}"`)
321
+ .createDirectory(logDirectory)
299
322
  .copyFromContainer({
300
323
  destination: `${logDirectory}/broker`,
301
324
  name,
@@ -311,6 +334,11 @@ Cypress.Commands.add(
311
334
  name,
312
335
  source: '/var/log/centreon'
313
336
  })
337
+ .copyFromContainer({
338
+ destination: `${logDirectory}/centreon-gorgone`,
339
+ name,
340
+ source: '/var/log/centreon-gorgone'
341
+ })
314
342
  .then(() => {
315
343
  if (Cypress.env('WEB_IMAGE_OS').includes('alma')) {
316
344
  return cy.copyFromContainer({
@@ -329,6 +357,24 @@ Cypress.Commands.add(
329
357
  { failOnNonZeroExit: false }
330
358
  );
331
359
  })
360
+ .then(() => {
361
+ if (Cypress.env('WEB_IMAGE_OS').includes('alma')) {
362
+ return cy.copyFromContainer({
363
+ destination: `${logDirectory}/httpd`,
364
+ name,
365
+ source: '/var/log/httpd'
366
+ });
367
+ }
368
+
369
+ return cy.copyFromContainer(
370
+ {
371
+ destination: `${logDirectory}/apache2`,
372
+ name,
373
+ source: '/var/log/apache2'
374
+ },
375
+ { failOnNonZeroExit: false }
376
+ );
377
+ })
332
378
  .exec(`chmod -R 755 "${logDirectory}"`)
333
379
  .stopContainer({ name });
334
380
  }
@@ -341,9 +387,11 @@ interface StopContainerProps {
341
387
  Cypress.Commands.add(
342
388
  'stopContainer',
343
389
  ({ name }: StopContainerProps): Cypress.Chainable => {
390
+ cy.log(`Stopping container ${name}`);
391
+
344
392
  cy.exec(`docker logs ${name}`).then(({ stdout }) => {
345
393
  cy.writeFile(
346
- `cypress/results/logs/${Cypress.spec.name.replace(
394
+ `results/logs/${Cypress.spec.name.replace(
347
395
  artifactIllegalCharactersMatcher,
348
396
  '_'
349
397
  )}/${Cypress.currentTest.title.replace(
@@ -391,6 +439,41 @@ Cypress.Commands.add(
391
439
  }
392
440
  );
393
441
 
442
+ Cypress.Commands.add(
443
+ 'insertDashboardWithWidget',
444
+ (dashboardBody, patchBody) => {
445
+ cy.request({
446
+ body: {
447
+ ...dashboardBody
448
+ },
449
+ method: 'POST',
450
+ url: '/centreon/api/latest/configuration/dashboards'
451
+ }).then((response) => {
452
+ const dashboardId = response.body.id;
453
+ cy.waitUntil(
454
+ () => {
455
+ return cy
456
+ .request({
457
+ method: 'GET',
458
+ url: `/centreon/api/latest/configuration/dashboards/${dashboardId}`
459
+ })
460
+ .then((getResponse) => {
461
+ return getResponse.body && getResponse.body.id === dashboardId;
462
+ });
463
+ },
464
+ {
465
+ timeout: 10000
466
+ }
467
+ );
468
+ cy.request({
469
+ body: patchBody,
470
+ method: 'PATCH',
471
+ url: `/centreon/api/latest/configuration/dashboards/${dashboardId}`
472
+ });
473
+ });
474
+ }
475
+ );
476
+
394
477
  interface ShareDashboardToUserProps {
395
478
  dashboardName: string;
396
479
  role: string;
@@ -405,6 +488,30 @@ interface ListingRequestResult {
405
488
  };
406
489
  }
407
490
 
491
+ interface PatchDashboardBody {
492
+ panels: Array<{
493
+ layout: {
494
+ height: number;
495
+ min_height: number;
496
+ min_width: number;
497
+ width: number;
498
+ x: number;
499
+ y: number;
500
+ };
501
+ name: string;
502
+ widget_settings: {
503
+ options: {
504
+ description: {
505
+ content: string;
506
+ enabled: boolean;
507
+ };
508
+ name: string;
509
+ };
510
+ };
511
+ widget_type: string;
512
+ }>;
513
+ }
514
+
408
515
  Cypress.Commands.add(
409
516
  'shareDashboardToUser',
410
517
  ({ dashboardName, userName, role }: ShareDashboardToUserProps): void => {
@@ -466,6 +573,7 @@ declare global {
466
573
  props: CopyToContainerProps,
467
574
  options?: Partial<Cypress.ExecOptions>
468
575
  ) => Cypress.Chainable;
576
+ createDirectory: (directoryPath: string) => Cypress.Chainable;
469
577
  execInContainer: ({
470
578
  command,
471
579
  name
@@ -476,6 +584,11 @@ declare global {
476
584
  hoverRootMenuItem: (rootItemNumber: number) => Cypress.Chainable;
477
585
  insertDashboard: (dashboard: Dashboard) => Cypress.Chainable;
478
586
  insertDashboardList: (fixtureFile: string) => Cypress.Chainable;
587
+ insertDashboardWithWidget: (
588
+ dashboard: Dashboard,
589
+ patch: PatchDashboardBody
590
+ ) => Cypress.Chainable;
591
+
479
592
  loginByTypeOfUser: ({
480
593
  jsonName,
481
594
  loginViaApi
@@ -5,6 +5,7 @@ import { execSync } from 'child_process';
5
5
 
6
6
  import { defineConfig } from 'cypress';
7
7
  import installLogsPrinter from 'cypress-terminal-report/src/installLogsPrinter';
8
+ import { config as configDotenv } from 'dotenv';
8
9
 
9
10
  import esbuildPreprocessor from './esbuild-preprocessor';
10
11
  import plugins from './plugins';
@@ -14,6 +15,7 @@ interface ConfigurationOptions {
14
15
  cypressFolder?: string;
15
16
  dockerName?: string;
16
17
  env?: Record<string, unknown>;
18
+ envFile?: string;
17
19
  isDevelopment?: boolean;
18
20
  specPattern: string;
19
21
  }
@@ -23,9 +25,14 @@ export default ({
23
25
  cypressFolder,
24
26
  isDevelopment,
25
27
  dockerName,
26
- env
28
+ env,
29
+ envFile
27
30
  }: ConfigurationOptions): Cypress.ConfigOptions => {
28
- const resultsFolder = `${cypressFolder || 'cypress'}/results`;
31
+ if (envFile) {
32
+ configDotenv({ path: envFile });
33
+ }
34
+
35
+ const resultsFolder = `${cypressFolder || '.'}/results`;
29
36
 
30
37
  const webImageVersion = execSync('git rev-parse --abbrev-ref HEAD')
31
38
  .toString('utf8')
@@ -36,6 +43,7 @@ export default ({
36
43
  defaultCommandTimeout: 6000,
37
44
  e2e: {
38
45
  excludeSpecPattern: ['*.js', '*.ts', '*.md'],
46
+ fixturesFolder: 'fixtures',
39
47
  reporter: require.resolve('cypress-multi-reporters'),
40
48
  reporterOptions: {
41
49
  configFile: `${__dirname}/reporter-config.js`
@@ -47,11 +55,12 @@ export default ({
47
55
 
48
56
  return plugins(on, config);
49
57
  },
50
- specPattern
58
+ specPattern,
59
+ supportFile: 'support/e2e.{js,jsx,ts,tsx}'
51
60
  },
52
61
  env: {
53
62
  ...env,
54
- OPENID_IMAGE_VERSION: '23.04',
63
+ OPENID_IMAGE_VERSION: process.env.MAJOR || '24.04',
55
64
  WEB_IMAGE_OS: 'alma9',
56
65
  WEB_IMAGE_VERSION: webImageVersion,
57
66
  dockerName: dockerName || 'centreon-dev'
@@ -4,7 +4,7 @@ module.exports = {
4
4
  html: false,
5
5
  json: true,
6
6
  overwrite: true,
7
- reportDir: 'cypress/results/reports',
7
+ reportDir: 'results/reports',
8
8
  reportFilename: '[name]-report.json'
9
9
  },
10
10
  reporterEnabled: `mochawesome,${require.resolve(
@@ -1,4 +1,5 @@
1
1
  import { execSync } from 'child_process';
2
+ import { existsSync, mkdirSync } from 'fs';
2
3
 
3
4
  import Docker from 'dockerode';
4
5
 
@@ -21,6 +22,13 @@ export default (on: Cypress.PluginEvents): void => {
21
22
  }
22
23
 
23
24
  on('task', {
25
+ createDirectory: async (directoryPath: string) => {
26
+ if (!existsSync(directoryPath)) {
27
+ mkdirSync(directoryPath, { recursive: true });
28
+ }
29
+
30
+ return null;
31
+ },
24
32
  startContainer: async ({
25
33
  image,
26
34
  name,
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.10.1-debug-openid.5",
4
+ "version": "23.10.1-debug-e2e-cookies.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/centreon/centreon-frontend.git"
@@ -44,16 +44,17 @@
44
44
  "cypress"
45
45
  ],
46
46
  "dependencies": {
47
- "@badeball/cypress-cucumber-preprocessor": "^18.0.6",
47
+ "@badeball/cypress-cucumber-preprocessor": "^19.1.0",
48
48
  "@bahmutov/cypress-esbuild-preprocessor": "^2.2.0",
49
49
  "@esbuild-plugins/node-globals-polyfill": "^0.2.3",
50
50
  "@esbuild-plugins/node-modules-polyfill": "^0.2.2",
51
- "@types/cypress-cucumber-preprocessor": "^4.0.2",
52
- "@types/dockerode": "^3.3.19",
53
- "cypress-multi-reporters": "^1.6.3",
54
- "cypress-terminal-report": "^5.3.6",
55
- "dockerode": "^3.3.5",
56
- "esbuild": "^0.19.3",
51
+ "@types/cypress-cucumber-preprocessor": "^4.0.5",
52
+ "@types/dockerode": "^3.3.23",
53
+ "cypress-multi-reporters": "^1.6.4",
54
+ "cypress-terminal-report": "^5.3.9",
55
+ "dockerode": "^4.0.0",
56
+ "dotenv": "^16.3.1",
57
+ "esbuild": "^0.19.5",
57
58
  "mochawesome": "^7.1.3"
58
59
  }
59
60
  }