@centreon/js-config 23.10.1-wait-on-task.0 → 23.10.1-wait-on-task.2
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/e2e/commands.ts
CHANGED
|
@@ -248,8 +248,6 @@ Cypress.Commands.add(
|
|
|
248
248
|
|
|
249
249
|
const image = `docker.centreon.com/centreon/centreon-web${slimSuffix}-${os}:${version}`;
|
|
250
250
|
|
|
251
|
-
cy.setUserTokenApiV1();
|
|
252
|
-
|
|
253
251
|
return cy
|
|
254
252
|
.startContainer({
|
|
255
253
|
image,
|
|
@@ -257,7 +255,7 @@ Cypress.Commands.add(
|
|
|
257
255
|
portBindings: [{ destination: 4000, source: 80 }]
|
|
258
256
|
})
|
|
259
257
|
.then(() => {
|
|
260
|
-
const baseUrl = 'http://
|
|
258
|
+
const baseUrl = 'http://127.0.0.1:4000';
|
|
261
259
|
|
|
262
260
|
Cypress.config('baseUrl', baseUrl);
|
|
263
261
|
|
|
@@ -5,7 +5,9 @@ import { execSync } from 'child_process';
|
|
|
5
5
|
|
|
6
6
|
import { defineConfig } from 'cypress';
|
|
7
7
|
|
|
8
|
-
import
|
|
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
|
+
};
|
package/cypress/e2e/plugins.ts
CHANGED
|
@@ -3,55 +3,11 @@
|
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
4
4
|
/* eslint-disable no-param-reassign */
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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,95 +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
|
-
waitOn: async (url: string) => {
|
|
159
|
-
execSync(`npx wait-on ${url}`);
|
|
160
|
-
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
|
|
165
31
|
return config;
|
|
166
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.1-wait-on-task.
|
|
4
|
+
"version": "23.10.1-wait-on-task.2",
|
|
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": "^
|
|
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/
|
|
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",
|