@centreon/js-config 24.4.21 → 24.4.22

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.
@@ -18,6 +18,15 @@ interface MountProps {
18
18
  Component: React.ReactNode;
19
19
  options?: object;
20
20
  }
21
+ interface Resolution {
22
+ height: number;
23
+ width: number;
24
+ }
25
+
26
+ interface MakeSnapshotWithCustomResolution {
27
+ resolution: Resolution;
28
+ title: string;
29
+ }
21
30
 
22
31
  export enum Method {
23
32
  DELETE = 'DELETE',
@@ -97,20 +106,32 @@ Cypress.Commands.add(
97
106
  }
98
107
  );
99
108
 
100
- Cypress.Commands.add('moveSortableElement', ({ element, direction }): void => {
101
- const key = `{${direction}arrow}`;
109
+ interface MoveSortableElementProps {
110
+ direction: 'up' | 'down' | 'left' | 'right';
111
+ element: Cypress.Chainable<JQuery<HTMLElement>>;
112
+ times?: number;
113
+ }
102
114
 
103
- element.type(' ', {
104
- force: true,
105
- scrollBehavior: false
106
- });
107
- element.eq(-1).type(key, {
108
- scrollBehavior: false
109
- });
110
- element.eq(-1).type(' ', {
111
- scrollBehavior: false
112
- });
113
- });
115
+ Cypress.Commands.add(
116
+ 'moveSortableElement',
117
+ ({ element, direction, times = 1 }: MoveSortableElementProps): void => {
118
+ const key = `{${direction}arrow}`;
119
+
120
+ element.type(' ', {
121
+ force: true,
122
+ scrollBehavior: false
123
+ });
124
+
125
+ Array.from({ length: times }).forEach(() => {
126
+ element.eq(-1).type(key, {
127
+ scrollBehavior: false
128
+ });
129
+ });
130
+ element.eq(-1).type(' ', {
131
+ scrollBehavior: false
132
+ });
133
+ }
134
+ );
114
135
 
115
136
  Cypress.Commands.add(
116
137
  'moveSortableElementUsingAriaLabel',
@@ -137,6 +158,15 @@ Cypress.Commands.add('makeSnapshot', (title?: string) => {
137
158
  cy.matchImageSnapshot(title);
138
159
  });
139
160
 
161
+ Cypress.Commands.add(
162
+ 'makeSnapshotWithCustomResolution',
163
+ ({ title, resolution }: MakeSnapshotWithCustomResolution) => {
164
+ const { width, height } = resolution;
165
+ cy.viewport(width, height);
166
+ cy.matchImageSnapshot(title);
167
+ }
168
+ );
169
+
140
170
  Cypress.Commands.add('cssDisableMotion', (): void => {
141
171
  Cypress.on('window:before:load', (cyWindow) => {
142
172
  disableMotion(cyWindow);
@@ -148,13 +178,22 @@ declare global {
148
178
  interface Chainable {
149
179
  adjustViewport: () => Cypress.Chainable;
150
180
  cssDisableMotion: () => Cypress.Chainable;
181
+ getRequestCalls: (alias) => Cypress.Chainable;
151
182
  interceptAPIRequest: <T extends object>(
152
183
  props: InterceptAPIRequestProps<T>
153
184
  ) => Cypress.Chainable;
154
185
  interceptRequest: (method, path, mock, alias) => Cypress.Chainable;
155
186
  makeSnapshot: (title?: string) => void;
187
+ makeSnapshotWithCustomResolution: ({
188
+ title,
189
+ resolution
190
+ }: MakeSnapshotWithCustomResolution) => Cypress.Chainable;
156
191
  mount: ({ Component, options }: MountProps) => Cypress.Chainable;
157
- moveSortableElement: ({ element, direction }) => void;
192
+ moveSortableElement: ({
193
+ element,
194
+ direction,
195
+ times
196
+ }: MoveSortableElementProps) => void;
158
197
  moveSortableElementUsingAriaLabel: ({ ariaLabel, direction }) => void;
159
198
  waitForRequest: (alias) => Cypress.Chainable;
160
199
  }
@@ -3,6 +3,7 @@ const { defineConfig } = require('cypress');
3
3
  const {
4
4
  addMatchImageSnapshotPlugin
5
5
  } = require('@simonsmith/cypress-image-snapshot/plugin');
6
+ const cypressCodeCoverageTask = require('@cypress/code-coverage/task');
6
7
 
7
8
  module.exports = ({
8
9
  webpackConfig,
@@ -25,9 +26,12 @@ module.exports = ({
25
26
  setupNodeEvents: (on, config) => {
26
27
  addMatchImageSnapshotPlugin(on, config);
27
28
 
29
+ cypressCodeCoverageTask(on, config);
30
+
28
31
  on('before:browser:launch', (browser, launchOptions) => {
29
32
  if (browser.name === 'chrome' && browser.isHeadless) {
30
33
  launchOptions.args.push('--headless=new');
34
+ launchOptions.args.push('--force-color-profile=srgb');
31
35
  }
32
36
 
33
37
  return launchOptions;
@@ -37,8 +41,17 @@ module.exports = ({
37
41
  supportFile: `${mainCypressFolder}/support/component.tsx`
38
42
  },
39
43
  env: {
40
- ...env,
41
- baseUrl: 'http://localhost:9092'
44
+ baseUrl: 'http://localhost:9092',
45
+ codeCoverage: {
46
+ exclude: [
47
+ 'cypress/**/*.*',
48
+ 'packages/**',
49
+ 'node_modules',
50
+ '**/*.js',
51
+ '**/*.spec.tsx'
52
+ ]
53
+ },
54
+ ...env
42
55
  },
43
56
  reporter: 'mochawesome',
44
57
  reporterOptions: {
@@ -0,0 +1,36 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const filePath = process.argv[2];
5
+
6
+ const { error: logError } = console;
7
+
8
+ try {
9
+ const outFile = fs.readFileSync(path.resolve(filePath)).toString();
10
+ const outFileJson = JSON.parse(outFile);
11
+
12
+ const coveragesWithoutNodeModules = Object.entries(outFileJson)
13
+ .map(([key, value]) => {
14
+ if (key.includes('node_modules')) {
15
+ return undefined;
16
+ }
17
+
18
+ return [key, value];
19
+ })
20
+ .filter((v) => v);
21
+
22
+ const finalOutJson = coveragesWithoutNodeModules.reduce(
23
+ (acc, [key, value]) => ({
24
+ ...acc,
25
+ [key]: value
26
+ }),
27
+ {}
28
+ );
29
+
30
+ fs.writeFileSync(
31
+ path.resolve(filePath),
32
+ JSON.stringify(finalOutJson, null, 2)
33
+ );
34
+ } catch (error) {
35
+ logError(error.message);
36
+ }