@centreon/js-config 23.10.1-wait-on-task.1 → 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
|
@@ -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,26 +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
|
-
import createEsbuildPlugin from '@badeball/cypress-cucumber-preprocessor/esbuild';
|
|
12
|
-
|
|
13
|
-
const docker = new Docker();
|
|
14
|
-
|
|
15
|
-
export default async (on, config): Promise<void> => {
|
|
16
|
-
await addCucumberPreprocessorPlugin(on, config);
|
|
17
|
-
|
|
18
|
-
on(
|
|
19
|
-
'file:preprocessor',
|
|
20
|
-
createBundler({
|
|
21
|
-
plugins: [createEsbuildPlugin(config)]
|
|
22
|
-
})
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
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) => {
|
|
26
11
|
const width = 1920;
|
|
27
12
|
const height = 1080;
|
|
28
13
|
|
|
@@ -43,95 +28,5 @@ export default async (on, config): Promise<void> => {
|
|
|
43
28
|
return launchOptions;
|
|
44
29
|
});
|
|
45
30
|
|
|
46
|
-
interface PortBinding {
|
|
47
|
-
destination: number;
|
|
48
|
-
source: number;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
interface StartContainerProps {
|
|
52
|
-
image: string;
|
|
53
|
-
name: string;
|
|
54
|
-
portBindings: Array<PortBinding>;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
interface StopContainerProps {
|
|
58
|
-
name: string;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
on('task', {
|
|
62
|
-
startContainer: async ({
|
|
63
|
-
image,
|
|
64
|
-
name,
|
|
65
|
-
portBindings = []
|
|
66
|
-
}: StartContainerProps) => {
|
|
67
|
-
const imageList = execSync(
|
|
68
|
-
'docker image list --format "{{.Repository}}:{{.Tag}}"'
|
|
69
|
-
).toString('utf8');
|
|
70
|
-
|
|
71
|
-
if (
|
|
72
|
-
!imageList.match(
|
|
73
|
-
new RegExp(
|
|
74
|
-
`^${image.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')}`,
|
|
75
|
-
'm'
|
|
76
|
-
)
|
|
77
|
-
)
|
|
78
|
-
) {
|
|
79
|
-
execSync(`docker pull ${image}`);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const webContainers = await docker.listContainers({
|
|
83
|
-
all: true,
|
|
84
|
-
filters: { name: [name] }
|
|
85
|
-
});
|
|
86
|
-
if (webContainers.length) {
|
|
87
|
-
return webContainers[0];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const container = await docker.createContainer({
|
|
91
|
-
AttachStderr: true,
|
|
92
|
-
AttachStdin: false,
|
|
93
|
-
AttachStdout: true,
|
|
94
|
-
ExposedPorts: portBindings.reduce((accumulator, currentValue) => {
|
|
95
|
-
accumulator[`${currentValue.source}/tcp`] = {};
|
|
96
|
-
|
|
97
|
-
return accumulator;
|
|
98
|
-
}, {}),
|
|
99
|
-
HostConfig: {
|
|
100
|
-
PortBindings: portBindings.reduce((accumulator, currentValue) => {
|
|
101
|
-
accumulator[`${currentValue.source}/tcp`] = [
|
|
102
|
-
{
|
|
103
|
-
HostIP: '0.0.0.0',
|
|
104
|
-
HostPort: `${currentValue.destination}`
|
|
105
|
-
}
|
|
106
|
-
];
|
|
107
|
-
|
|
108
|
-
return accumulator;
|
|
109
|
-
}, {})
|
|
110
|
-
},
|
|
111
|
-
Image: image,
|
|
112
|
-
OpenStdin: false,
|
|
113
|
-
StdinOnce: false,
|
|
114
|
-
Tty: true,
|
|
115
|
-
name
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
await container.start();
|
|
119
|
-
|
|
120
|
-
return container;
|
|
121
|
-
},
|
|
122
|
-
stopContainer: async ({ name }: StopContainerProps) => {
|
|
123
|
-
const container = await docker.getContainer(name);
|
|
124
|
-
await container.kill();
|
|
125
|
-
await container.remove();
|
|
126
|
-
|
|
127
|
-
return null;
|
|
128
|
-
},
|
|
129
|
-
waitOn: async (url: string) => {
|
|
130
|
-
execSync(`npx wait-on ${url}`);
|
|
131
|
-
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
|
|
136
31
|
return config;
|
|
137
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"
|
|
@@ -18,10 +18,13 @@
|
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@badeball/cypress-cucumber-preprocessor": "^18.0.5",
|
|
20
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",
|
|
21
23
|
"@tsconfig/node16": "^1.0.4",
|
|
22
24
|
"@types/cypress-cucumber-preprocessor": "^4.0.2",
|
|
23
25
|
"@types/dockerode": "^3.3.19",
|
|
24
26
|
"dockerode": "^3.3.5",
|
|
27
|
+
"esbuild": "^0.19.2",
|
|
25
28
|
"eslint": "^8.17.0",
|
|
26
29
|
"eslint-config-airbnb": "19.0.4",
|
|
27
30
|
"eslint-config-prettier": "^8.5.0",
|