@centreon/js-config 23.10.66 → 24.4.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.
- package/cypress/component/commands.tsx +203 -174
- package/cypress/component/configuration.js +83 -66
- package/cypress/component/enableVisualTesting.ts +21 -21
- package/cypress/component/excludeNodeModulesFromCoverage.js +36 -0
- package/cypress/e2e/commands/configuration.ts +327 -1
- package/cypress/e2e/commands/monitoring.ts +56 -0
- package/cypress/e2e/commands.ts +433 -160
- package/cypress/e2e/configuration.ts +28 -12
- package/cypress/e2e/plugins.ts +31 -4
- package/cypress/e2e/tasks.ts +204 -53
- package/package.json +64 -58
- package/tsconfig/lambda/node20.tsconfig.json +12 -0
- package/webpack/base/index.js +2 -1
|
@@ -1,174 +1,203 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-namespace */
|
|
2
|
-
import React from 'react';
|
|
3
|
-
|
|
4
|
-
import { mount } from 'cypress/react18';
|
|
5
|
-
import { equals, isNil } from 'ramda';
|
|
6
|
-
|
|
7
|
-
import { Box, CssBaseline } from '@mui/material';
|
|
8
|
-
|
|
9
|
-
import { ThemeProvider } from '@centreon/ui';
|
|
10
|
-
|
|
11
|
-
import '@testing-library/cypress/add-commands';
|
|
12
|
-
import 'cypress-msw-interceptor';
|
|
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
|
-
scrollBehavior: false
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import { mount } from 'cypress/react18';
|
|
5
|
+
import { equals, isNil } from 'ramda';
|
|
6
|
+
|
|
7
|
+
import { Box, CssBaseline } from '@mui/material';
|
|
8
|
+
|
|
9
|
+
import { ThemeProvider } from '@centreon/ui';
|
|
10
|
+
|
|
11
|
+
import '@testing-library/cypress/add-commands';
|
|
12
|
+
import 'cypress-msw-interceptor';
|
|
13
|
+
import 'cypress-real-events';
|
|
14
|
+
|
|
15
|
+
import disableMotion from './disableCssTransitions';
|
|
16
|
+
|
|
17
|
+
interface MountProps {
|
|
18
|
+
Component: React.ReactNode;
|
|
19
|
+
options?: object;
|
|
20
|
+
}
|
|
21
|
+
interface Resolution {
|
|
22
|
+
height: number;
|
|
23
|
+
width: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface MakeSnapshotWithCustomResolution {
|
|
27
|
+
resolution: Resolution;
|
|
28
|
+
title: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export enum Method {
|
|
32
|
+
DELETE = 'DELETE',
|
|
33
|
+
GET = 'GET',
|
|
34
|
+
PATCH = 'PATCH',
|
|
35
|
+
POST = 'POST',
|
|
36
|
+
PUT = 'PUT'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
Cypress.Commands.add('mount', ({ Component, options = {} }) => {
|
|
40
|
+
const wrapped = (
|
|
41
|
+
<ThemeProvider>
|
|
42
|
+
<Box
|
|
43
|
+
sx={{
|
|
44
|
+
backgroundColor: 'background.paper',
|
|
45
|
+
height: '100%',
|
|
46
|
+
width: '100%'
|
|
47
|
+
}}
|
|
48
|
+
>
|
|
49
|
+
{Component}
|
|
50
|
+
</Box>
|
|
51
|
+
<CssBaseline />
|
|
52
|
+
</ThemeProvider>
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
return mount(wrapped, options);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
interface Query {
|
|
59
|
+
name: string;
|
|
60
|
+
value: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface InterceptAPIRequestProps<T> {
|
|
64
|
+
alias: string;
|
|
65
|
+
delay?: number;
|
|
66
|
+
method: Method;
|
|
67
|
+
path: string;
|
|
68
|
+
query?: Query;
|
|
69
|
+
response?: T | Array<T>;
|
|
70
|
+
statusCode?: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
Cypress.Commands.add(
|
|
74
|
+
'interceptAPIRequest',
|
|
75
|
+
<T extends object>({
|
|
76
|
+
method,
|
|
77
|
+
path,
|
|
78
|
+
response,
|
|
79
|
+
alias,
|
|
80
|
+
query,
|
|
81
|
+
statusCode = 200,
|
|
82
|
+
delay = 500
|
|
83
|
+
}: InterceptAPIRequestProps<T>): void => {
|
|
84
|
+
cy.interceptRequest(
|
|
85
|
+
method,
|
|
86
|
+
path.replace('./', '**'),
|
|
87
|
+
(req, res, ctx) => {
|
|
88
|
+
const getQuery = req?.url?.searchParams?.get(query?.name);
|
|
89
|
+
if (query && equals(query.value, getQuery)) {
|
|
90
|
+
return res(
|
|
91
|
+
ctx.delay(delay),
|
|
92
|
+
ctx.json(response),
|
|
93
|
+
ctx.status(statusCode)
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
if (!getQuery && isNil(query)) {
|
|
97
|
+
return res(
|
|
98
|
+
ctx.delay(delay),
|
|
99
|
+
ctx.json(response),
|
|
100
|
+
ctx.status(statusCode)
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return null;
|
|
105
|
+
},
|
|
106
|
+
alias
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
interface MoveSortableElementProps {
|
|
112
|
+
direction: 'up' | 'down' | 'left' | 'right';
|
|
113
|
+
element: Cypress.Chainable<JQuery<HTMLElement>>;
|
|
114
|
+
times?: number;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
Cypress.Commands.add(
|
|
118
|
+
'moveSortableElement',
|
|
119
|
+
({ element, direction, times = 1 }: MoveSortableElementProps): void => {
|
|
120
|
+
const key = `{${direction}arrow}`;
|
|
121
|
+
|
|
122
|
+
element.type(' ', {
|
|
123
|
+
force: true,
|
|
124
|
+
scrollBehavior: false
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
Array.from({ length: times }).forEach(() => {
|
|
128
|
+
element.eq(-1).type(key, {
|
|
129
|
+
scrollBehavior: false
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
element.eq(-1).type(' ', {
|
|
133
|
+
scrollBehavior: false
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
Cypress.Commands.add(
|
|
139
|
+
'moveSortableElementUsingAriaLabel',
|
|
140
|
+
({ ariaLabel, direction }): void => {
|
|
141
|
+
const key = `{${direction}arrow}`;
|
|
142
|
+
|
|
143
|
+
cy.findByLabelText(ariaLabel).type(' ', {
|
|
144
|
+
force: true,
|
|
145
|
+
scrollBehavior: false
|
|
146
|
+
});
|
|
147
|
+
cy.findAllByLabelText(ariaLabel).eq(-1).type(key, {
|
|
148
|
+
scrollBehavior: false
|
|
149
|
+
});
|
|
150
|
+
cy.findAllByLabelText(ariaLabel).eq(-1).type(' ', {
|
|
151
|
+
scrollBehavior: false
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
Cypress.Commands.add('adjustViewport', () => cy.viewport(1280, 590));
|
|
157
|
+
|
|
158
|
+
Cypress.Commands.add('makeSnapshot', (title?: string) => {
|
|
159
|
+
cy.adjustViewport();
|
|
160
|
+
cy.matchImageSnapshot(title);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
Cypress.Commands.add(
|
|
164
|
+
'makeSnapshotWithCustomResolution',
|
|
165
|
+
({ title, resolution }: MakeSnapshotWithCustomResolution) => {
|
|
166
|
+
const { width, height } = resolution;
|
|
167
|
+
cy.viewport(width, height);
|
|
168
|
+
cy.matchImageSnapshot(title);
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
Cypress.Commands.add('cssDisableMotion', (): void => {
|
|
173
|
+
Cypress.on('window:before:load', (cyWindow) => {
|
|
174
|
+
disableMotion(cyWindow);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
declare global {
|
|
179
|
+
namespace Cypress {
|
|
180
|
+
interface Chainable {
|
|
181
|
+
adjustViewport: () => Cypress.Chainable;
|
|
182
|
+
cssDisableMotion: () => Cypress.Chainable;
|
|
183
|
+
getRequestCalls: (alias) => Cypress.Chainable;
|
|
184
|
+
interceptAPIRequest: <T extends object>(
|
|
185
|
+
props: InterceptAPIRequestProps<T>
|
|
186
|
+
) => Cypress.Chainable;
|
|
187
|
+
interceptRequest: (method, path, mock, alias) => Cypress.Chainable;
|
|
188
|
+
makeSnapshot: (title?: string) => void;
|
|
189
|
+
makeSnapshotWithCustomResolution: ({
|
|
190
|
+
title,
|
|
191
|
+
resolution
|
|
192
|
+
}: MakeSnapshotWithCustomResolution) => Cypress.Chainable;
|
|
193
|
+
mount: ({ Component, options }: MountProps) => Cypress.Chainable;
|
|
194
|
+
moveSortableElement: ({
|
|
195
|
+
element,
|
|
196
|
+
direction,
|
|
197
|
+
times
|
|
198
|
+
}: MoveSortableElementProps) => void;
|
|
199
|
+
moveSortableElementUsingAriaLabel: ({ ariaLabel, direction }) => void;
|
|
200
|
+
waitForRequest: (alias) => Cypress.Chainable;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -1,66 +1,83 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
-
const { defineConfig } = require('cypress');
|
|
3
|
-
const {
|
|
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
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
+
const { defineConfig } = require('cypress');
|
|
3
|
+
const { devServer } = require('cypress-rspack-dev-server');
|
|
4
|
+
const {
|
|
5
|
+
addMatchImageSnapshotPlugin
|
|
6
|
+
} = require('@simonsmith/cypress-image-snapshot/plugin');
|
|
7
|
+
const cypressCodeCoverageTask = require('@cypress/code-coverage/task');
|
|
8
|
+
|
|
9
|
+
module.exports = ({
|
|
10
|
+
webpackConfig,
|
|
11
|
+
cypressFolder,
|
|
12
|
+
specPattern,
|
|
13
|
+
env,
|
|
14
|
+
useVite = false,
|
|
15
|
+
excludeSpecPattern
|
|
16
|
+
}) => {
|
|
17
|
+
const mainCypressFolder = cypressFolder || 'cypress';
|
|
18
|
+
|
|
19
|
+
return defineConfig({
|
|
20
|
+
component: {
|
|
21
|
+
devServer: useVite
|
|
22
|
+
? {
|
|
23
|
+
bundler: 'vite',
|
|
24
|
+
framework: 'react',
|
|
25
|
+
webpackConfig
|
|
26
|
+
}
|
|
27
|
+
: (devServerConfig) =>
|
|
28
|
+
devServer({
|
|
29
|
+
...devServerConfig,
|
|
30
|
+
framework: 'react',
|
|
31
|
+
rspackConfig: webpackConfig
|
|
32
|
+
}),
|
|
33
|
+
excludeSpecPattern,
|
|
34
|
+
setupNodeEvents: (on, config) => {
|
|
35
|
+
addMatchImageSnapshotPlugin(on, config);
|
|
36
|
+
|
|
37
|
+
cypressCodeCoverageTask(on, config);
|
|
38
|
+
on('task', {
|
|
39
|
+
coverageReport: () => {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
on('before:browser:launch', (browser, launchOptions) => {
|
|
45
|
+
if (browser.name === 'chrome' && browser.isHeadless) {
|
|
46
|
+
launchOptions.args.push('--headless=new');
|
|
47
|
+
launchOptions.args.push('--force-color-profile=srgb');
|
|
48
|
+
launchOptions.args.push('--window-size=1400,1200');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return launchOptions;
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
specPattern,
|
|
55
|
+
supportFile: `${mainCypressFolder}/support/component.tsx`
|
|
56
|
+
},
|
|
57
|
+
env: {
|
|
58
|
+
baseUrl: 'http://localhost:9092',
|
|
59
|
+
codeCoverage: {
|
|
60
|
+
exclude: [
|
|
61
|
+
'cypress/**/*.*',
|
|
62
|
+
'packages/**',
|
|
63
|
+
'node_modules',
|
|
64
|
+
'**/*.js',
|
|
65
|
+
'**/*.spec.tsx'
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
...env
|
|
69
|
+
},
|
|
70
|
+
reporter: 'mochawesome',
|
|
71
|
+
reporterOptions: {
|
|
72
|
+
html: false,
|
|
73
|
+
json: true,
|
|
74
|
+
overwrite: true,
|
|
75
|
+
reportDir: `${mainCypressFolder}/results`,
|
|
76
|
+
reportFilename: '[name]-report.json'
|
|
77
|
+
},
|
|
78
|
+
video: true,
|
|
79
|
+
videosFolder: `${mainCypressFolder}/results/videos`,
|
|
80
|
+
viewportHeight: 590,
|
|
81
|
+
viewportWidth: 1280
|
|
82
|
+
});
|
|
83
|
+
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { addMatchImageSnapshotCommand } from '@simonsmith/cypress-image-snapshot/command';
|
|
2
|
-
|
|
3
|
-
const enableVisualTesting = (cypressFolder = 'cypress'): void => {
|
|
4
|
-
if (Cypress.config('isInteractive')) {
|
|
5
|
-
Cypress.Commands.add('matchImageSnapshot', () => {
|
|
6
|
-
cy.log('Skipping snapshot');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
addMatchImageSnapshotCommand({
|
|
13
|
-
capture: 'viewport',
|
|
14
|
-
customDiffConfig: { threshold: 0.01 },
|
|
15
|
-
customSnapshotsDir: `${cypressFolder}/visual-testing-snapshots`,
|
|
16
|
-
failureThreshold: 0.07,
|
|
17
|
-
failureThresholdType: 'percent'
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export default enableVisualTesting;
|
|
1
|
+
import { addMatchImageSnapshotCommand } from '@simonsmith/cypress-image-snapshot/command';
|
|
2
|
+
|
|
3
|
+
const enableVisualTesting = (cypressFolder = 'cypress'): void => {
|
|
4
|
+
if (Cypress.config('isInteractive')) {
|
|
5
|
+
Cypress.Commands.add('matchImageSnapshot', () => {
|
|
6
|
+
cy.log('Skipping snapshot');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
addMatchImageSnapshotCommand({
|
|
13
|
+
capture: 'viewport',
|
|
14
|
+
customDiffConfig: { threshold: 0.01 },
|
|
15
|
+
customSnapshotsDir: `${cypressFolder}/visual-testing-snapshots`,
|
|
16
|
+
failureThreshold: 0.07,
|
|
17
|
+
failureThresholdType: 'percent'
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default enableVisualTesting;
|
|
@@ -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
|
+
}
|