@centreon/js-config 23.10.29 → 23.10.30

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.
@@ -143,7 +143,7 @@ interface LoginByTypeOfUserProps {
143
143
 
144
144
  Cypress.Commands.add(
145
145
  'loginByTypeOfUser',
146
- ({ jsonName, loginViaApi }): Cypress.Chainable => {
146
+ ({ jsonName = 'admin', loginViaApi = false }): Cypress.Chainable => {
147
147
  if (loginViaApi) {
148
148
  return cy
149
149
  .fixture(`users/${jsonName}.json`)
@@ -255,12 +255,13 @@ Cypress.Commands.add(
255
255
  portBindings: [{ destination: 4000, source: 80 }]
256
256
  })
257
257
  .then(() => {
258
- const baseUrl = 'http://0.0.0.0:4000';
258
+ const baseUrl = 'http://127.0.0.1:4000';
259
259
 
260
260
  Cypress.config('baseUrl', baseUrl);
261
261
 
262
- return cy.exec(
263
- `npx wait-on ${baseUrl}/centreon/api/latest/platform/installation/status`
262
+ return cy.task(
263
+ 'waitOn',
264
+ `${baseUrl}/centreon/api/latest/platform/installation/status`
264
265
  );
265
266
  })
266
267
  .visit('/') // this is necessary to refresh browser cause baseUrl has changed (flash appears in video)
@@ -469,8 +470,8 @@ declare global {
469
470
  insertDashboard: (dashboard: Dashboard) => Cypress.Chainable;
470
471
  insertDashboardList: (fixtureFile: string) => Cypress.Chainable;
471
472
  loginByTypeOfUser: ({
472
- jsonName = 'admin',
473
- loginViaApi = false
473
+ jsonName,
474
+ loginViaApi
474
475
  }: LoginByTypeOfUserProps) => Cypress.Chainable;
475
476
  moveSortableElement: (direction: string) => Cypress.Chainable;
476
477
  navigateTo: ({
@@ -5,7 +5,9 @@ import { execSync } from 'child_process';
5
5
 
6
6
  import { defineConfig } from 'cypress';
7
7
 
8
- import setupNodeEvents from './plugins';
8
+ import esbuildPreprocessor from './esbuild-preprocessor';
9
+ import plugins from './plugins';
10
+ import tasks from './tasks';
9
11
 
10
12
  interface ConfigurationOptions {
11
13
  cypressFolder?: string;
@@ -33,7 +35,12 @@ export default ({
33
35
  defaultCommandTimeout: 6000,
34
36
  e2e: {
35
37
  excludeSpecPattern: ['*.js', '*.ts', '*.md'],
36
- setupNodeEvents,
38
+ setupNodeEvents: async (on, config) => {
39
+ await esbuildPreprocessor(on, config);
40
+ tasks(on);
41
+
42
+ return plugins(on, config);
43
+ },
37
44
  specPattern
38
45
  },
39
46
  env: {
@@ -0,0 +1,26 @@
1
+ import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
2
+ import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill';
3
+ import { addCucumberPreprocessorPlugin } from '@badeball/cypress-cucumber-preprocessor';
4
+ import createBundler from '@bahmutov/cypress-esbuild-preprocessor';
5
+ import createEsbuildPlugin from '@badeball/cypress-cucumber-preprocessor/esbuild';
6
+
7
+ export default async (
8
+ on: Cypress.PluginEvents,
9
+ config: Cypress.PluginConfigOptions
10
+ ): Promise<void> => {
11
+ await addCucumberPreprocessorPlugin(on, config);
12
+
13
+ on(
14
+ 'file:preprocessor',
15
+ createBundler({
16
+ plugins: [
17
+ createEsbuildPlugin(config),
18
+ NodeModulesPolyfillPlugin(),
19
+ NodeGlobalsPolyfillPlugin({
20
+ buffer: true,
21
+ process: true
22
+ })
23
+ ]
24
+ })
25
+ );
26
+ };
@@ -3,55 +3,11 @@
3
3
  /* eslint-disable @typescript-eslint/no-var-requires */
4
4
  /* eslint-disable no-param-reassign */
5
5
 
6
- import { execSync } from 'child_process';
7
-
8
- import Docker from 'dockerode';
9
- import { addCucumberPreprocessorPlugin } from '@badeball/cypress-cucumber-preprocessor';
10
- import webpackPreprocessor from '@cypress/webpack-preprocessor';
11
-
12
- const docker = new Docker();
13
-
14
- const getWebpackOptions = (config): object => {
15
- return {
16
- module: {
17
- rules: [
18
- {
19
- exclude: [/node_modules/],
20
- test: /\.ts?$/,
21
- use: [
22
- {
23
- loader: 'swc-loader'
24
- }
25
- ]
26
- },
27
- {
28
- test: /\.feature$/,
29
- use: [
30
- {
31
- loader: '@badeball/cypress-cucumber-preprocessor/webpack',
32
- options: config
33
- }
34
- ]
35
- }
36
- ]
37
- },
38
- resolve: {
39
- extensions: ['.ts', '.js']
40
- }
41
- };
42
- };
43
-
44
- export default async (on, config): Promise<void> => {
45
- await addCucumberPreprocessorPlugin(on, config);
46
-
47
- const webpackOptions = await getWebpackOptions(config);
48
- const options = {
49
- webpackOptions
50
- };
51
-
52
- on('file:preprocessor', webpackPreprocessor(options));
53
-
54
- on('before:browser:launch', (browser = {}, launchOptions) => {
6
+ export default (
7
+ on: Cypress.PluginEvents,
8
+ config: Cypress.PluginConfigOptions
9
+ ): Cypress.PluginConfigOptions => {
10
+ on('before:browser:launch', (browser, launchOptions) => {
55
11
  const width = 1920;
56
12
  const height = 1080;
57
13
 
@@ -72,90 +28,5 @@ export default async (on, config): Promise<void> => {
72
28
  return launchOptions;
73
29
  });
74
30
 
75
- interface PortBinding {
76
- destination: number;
77
- source: number;
78
- }
79
-
80
- interface StartContainerProps {
81
- image: string;
82
- name: string;
83
- portBindings: Array<PortBinding>;
84
- }
85
-
86
- interface StopContainerProps {
87
- name: string;
88
- }
89
-
90
- on('task', {
91
- startContainer: async ({
92
- image,
93
- name,
94
- portBindings = []
95
- }: StartContainerProps) => {
96
- const imageList = execSync(
97
- 'docker image list --format "{{.Repository}}:{{.Tag}}"'
98
- ).toString('utf8');
99
-
100
- if (
101
- !imageList.match(
102
- new RegExp(
103
- `^${image.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')}`,
104
- 'm'
105
- )
106
- )
107
- ) {
108
- execSync(`docker pull ${image}`);
109
- }
110
-
111
- const webContainers = await docker.listContainers({
112
- all: true,
113
- filters: { name: [name] }
114
- });
115
- if (webContainers.length) {
116
- return webContainers[0];
117
- }
118
-
119
- const container = await docker.createContainer({
120
- AttachStderr: true,
121
- AttachStdin: false,
122
- AttachStdout: true,
123
- ExposedPorts: portBindings.reduce((accumulator, currentValue) => {
124
- accumulator[`${currentValue.source}/tcp`] = {};
125
-
126
- return accumulator;
127
- }, {}),
128
- HostConfig: {
129
- PortBindings: portBindings.reduce((accumulator, currentValue) => {
130
- accumulator[`${currentValue.source}/tcp`] = [
131
- {
132
- HostIP: '0.0.0.0',
133
- HostPort: `${currentValue.destination}`
134
- }
135
- ];
136
-
137
- return accumulator;
138
- }, {})
139
- },
140
- Image: image,
141
- OpenStdin: false,
142
- StdinOnce: false,
143
- Tty: true,
144
- name
145
- });
146
-
147
- await container.start();
148
-
149
- return container;
150
- },
151
- stopContainer: async ({ name }: StopContainerProps) => {
152
- const container = await docker.getContainer(name);
153
- await container.kill();
154
- await container.remove();
155
-
156
- return null;
157
- }
158
- });
159
-
160
31
  return config;
161
32
  };
@@ -0,0 +1,97 @@
1
+ import { execSync } from 'child_process';
2
+
3
+ import Docker from 'dockerode';
4
+
5
+ export default (on: Cypress.PluginEvents): void => {
6
+ const docker = new Docker();
7
+
8
+ interface PortBinding {
9
+ destination: number;
10
+ source: number;
11
+ }
12
+
13
+ interface StartContainerProps {
14
+ image: string;
15
+ name: string;
16
+ portBindings: Array<PortBinding>;
17
+ }
18
+
19
+ interface StopContainerProps {
20
+ name: string;
21
+ }
22
+
23
+ on('task', {
24
+ startContainer: async ({
25
+ image,
26
+ name,
27
+ portBindings = []
28
+ }: StartContainerProps) => {
29
+ const imageList = execSync(
30
+ 'docker image list --format "{{.Repository}}:{{.Tag}}"'
31
+ ).toString('utf8');
32
+
33
+ if (
34
+ !imageList.match(
35
+ new RegExp(
36
+ `^${image.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')}`,
37
+ 'm'
38
+ )
39
+ )
40
+ ) {
41
+ execSync(`docker pull ${image}`);
42
+ }
43
+
44
+ const webContainers = await docker.listContainers({
45
+ all: true,
46
+ filters: { name: [name] }
47
+ });
48
+ if (webContainers.length) {
49
+ return webContainers[0];
50
+ }
51
+
52
+ const container = await docker.createContainer({
53
+ AttachStderr: true,
54
+ AttachStdin: false,
55
+ AttachStdout: true,
56
+ ExposedPorts: portBindings.reduce((accumulator, currentValue) => {
57
+ accumulator[`${currentValue.source}/tcp`] = {};
58
+
59
+ return accumulator;
60
+ }, {}),
61
+ HostConfig: {
62
+ PortBindings: portBindings.reduce((accumulator, currentValue) => {
63
+ accumulator[`${currentValue.source}/tcp`] = [
64
+ {
65
+ HostIP: '127.0.0.1',
66
+ HostPort: `${currentValue.destination}`
67
+ }
68
+ ];
69
+
70
+ return accumulator;
71
+ }, {})
72
+ },
73
+ Image: image,
74
+ OpenStdin: false,
75
+ StdinOnce: false,
76
+ Tty: true,
77
+ name
78
+ });
79
+
80
+ await container.start();
81
+
82
+ return container;
83
+ },
84
+ stopContainer: async ({ name }: StopContainerProps) => {
85
+ const container = await docker.getContainer(name);
86
+ await container.kill();
87
+ await container.remove();
88
+
89
+ return null;
90
+ },
91
+ waitOn: async (url: string) => {
92
+ execSync(`npx wait-on ${url}`);
93
+
94
+ return null;
95
+ }
96
+ });
97
+ };
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.29",
4
+ "version": "23.10.30",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/centreon/centreon-frontend.git"
@@ -16,10 +16,15 @@
16
16
  "url": "https://github.com/centreon/centreon-frontend/issues"
17
17
  },
18
18
  "devDependencies": {
19
- "@badeball/cypress-cucumber-preprocessor": "^14.0.0",
19
+ "@badeball/cypress-cucumber-preprocessor": "^18.0.5",
20
+ "@bahmutov/cypress-esbuild-preprocessor": "^2.2.0",
21
+ "@esbuild-plugins/node-globals-polyfill": "^0.2.3",
22
+ "@esbuild-plugins/node-modules-polyfill": "^0.2.2",
20
23
  "@tsconfig/node16": "^1.0.4",
21
- "@types/dockerode": "^3.3.16",
24
+ "@types/cypress-cucumber-preprocessor": "^4.0.2",
25
+ "@types/dockerode": "^3.3.19",
22
26
  "dockerode": "^3.3.5",
27
+ "esbuild": "^0.19.2",
23
28
  "eslint": "^8.17.0",
24
29
  "eslint-config-airbnb": "19.0.4",
25
30
  "eslint-config-prettier": "^8.5.0",
@@ -6,6 +6,7 @@
6
6
  "target": "es2018",
7
7
  "jsx": "react-jsx",
8
8
  "strict": true,
9
+ "moduleResolution": "node",
9
10
  "noImplicitAny": false,
10
11
  "skipLibCheck": true,
11
12
  "esModuleInterop": true,