@centreon/js-config 24.10.3 → 24.10.5
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/biome/base.json +224 -0
- package/cypress/component/commands.tsx +82 -22
- package/cypress/component/configuration.js +39 -16
- package/cypress/component/disableCssTransitions.ts +19 -0
- package/cypress/component/enableVisualTesting.ts +1 -1
- package/cypress/component/excludeNodeModulesFromCoverage.js +36 -0
- package/cypress/e2e/commands/configuration.ts +330 -1
- package/cypress/e2e/commands/monitoring.ts +225 -0
- package/cypress/e2e/commands.ts +751 -173
- package/cypress/e2e/configuration.ts +57 -40
- package/cypress/e2e/esbuild-preprocessor.ts +26 -0
- package/cypress/e2e/plugins.ts +43 -114
- package/cypress/e2e/reporter-config.js +13 -0
- package/cypress/e2e/tasks.ts +273 -0
- package/eslint/base.typescript.eslintrc.js +15 -3
- package/eslint/lambda/typescript.eslintrc.js +48 -0
- package/jest/index.js +5 -2
- package/jest/lambda/typescript.js +49 -0
- package/package.json +57 -45
- package/rspack/base/globalConfig.js +75 -0
- package/rspack/base/index.js +89 -0
- package/rspack/patch/dev.js +12 -0
- package/{webpack → rspack}/patch/devServer.js +3 -5
- package/rspack/patch/module.js +13 -0
- package/rspack/plugins/TransformPreloadScript.js +37 -0
- package/rspack/plugins/WriteRemoteEntryNameToModuleFederation.js +30 -0
- package/tsconfig/index.json +5 -4
- package/tsconfig/lambda/node20.tsconfig.json +12 -0
- package/tsconfig/lambda/tsconfig.json +14 -0
- package/tsconfig.json +21 -0
- package/webpack/base/index.js +0 -130
- package/webpack/patch/dev.js +0 -24
- package/webpack/patch/module.js +0 -46
|
@@ -1,16 +1,21 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
1
2
|
/* eslint-disable import/extensions */
|
|
2
3
|
/* eslint-disable import/no-unresolved */
|
|
3
4
|
|
|
4
5
|
import { execSync } from 'child_process';
|
|
5
6
|
|
|
6
7
|
import { defineConfig } from 'cypress';
|
|
8
|
+
import installLogsPrinter from 'cypress-terminal-report/src/installLogsPrinter';
|
|
9
|
+
import { config as configDotenv } from 'dotenv';
|
|
7
10
|
|
|
8
|
-
import
|
|
11
|
+
import esbuildPreprocessor from './esbuild-preprocessor';
|
|
12
|
+
import plugins from './plugins';
|
|
13
|
+
import tasks from './tasks';
|
|
9
14
|
|
|
10
15
|
interface ConfigurationOptions {
|
|
11
16
|
cypressFolder?: string;
|
|
12
|
-
dockerName?: string;
|
|
13
17
|
env?: Record<string, unknown>;
|
|
18
|
+
envFile?: string;
|
|
14
19
|
isDevelopment?: boolean;
|
|
15
20
|
specPattern: string;
|
|
16
21
|
}
|
|
@@ -19,12 +24,14 @@ export default ({
|
|
|
19
24
|
specPattern,
|
|
20
25
|
cypressFolder,
|
|
21
26
|
isDevelopment,
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
env,
|
|
28
|
+
envFile
|
|
24
29
|
}: ConfigurationOptions): Cypress.ConfigOptions => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
30
|
+
if (envFile) {
|
|
31
|
+
configDotenv({ path: envFile });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const resultsFolder = `${cypressFolder || '.'}/results`;
|
|
28
35
|
|
|
29
36
|
const webImageVersion = execSync('git rev-parse --abbrev-ref HEAD')
|
|
30
37
|
.toString('utf8')
|
|
@@ -32,47 +39,57 @@ export default ({
|
|
|
32
39
|
|
|
33
40
|
return defineConfig({
|
|
34
41
|
chromeWebSecurity: false,
|
|
35
|
-
defaultCommandTimeout:
|
|
42
|
+
defaultCommandTimeout: 20000,
|
|
43
|
+
downloadsFolder: `${resultsFolder}/downloads`,
|
|
36
44
|
e2e: {
|
|
37
45
|
excludeSpecPattern: ['*.js', '*.ts', '*.md'],
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
fixturesFolder: 'fixtures',
|
|
47
|
+
reporter: require.resolve('cypress-multi-reporters'),
|
|
48
|
+
reporterOptions: {
|
|
49
|
+
configFile: `${__dirname}/reporter-config.js`
|
|
50
|
+
},
|
|
51
|
+
setupNodeEvents: async (cypressOn, config) => {
|
|
52
|
+
const on = require('cypress-on-fix')(cypressOn)
|
|
53
|
+
installLogsPrinter(on, {
|
|
54
|
+
commandTrimLength: 5000,
|
|
55
|
+
defaultTrimLength: 5000,
|
|
56
|
+
});
|
|
57
|
+
on('task', {
|
|
58
|
+
logVersion(message) {
|
|
59
|
+
console.log(`[LOG]: ${message}`);
|
|
60
|
+
return null;
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
await esbuildPreprocessor(on, config);
|
|
64
|
+
tasks(on);
|
|
65
|
+
|
|
66
|
+
return plugins(on, config);
|
|
67
|
+
},
|
|
68
|
+
specPattern,
|
|
69
|
+
supportFile: 'support/e2e.{js,jsx,ts,tsx}',
|
|
70
|
+
testIsolation: true,
|
|
40
71
|
},
|
|
41
72
|
env: {
|
|
42
73
|
...env,
|
|
43
|
-
|
|
74
|
+
DATABASE_IMAGE: 'bitnami/mariadb:10.11',
|
|
75
|
+
OPENID_IMAGE_VERSION: process.env.MAJOR || '24.04',
|
|
76
|
+
SAML_IMAGE_VERSION: process.env.MAJOR || '24.04',
|
|
77
|
+
STABILITY: 'unstable',
|
|
78
|
+
TARGET_STABILITY: 'unstable',
|
|
44
79
|
WEB_IMAGE_OS: 'alma9',
|
|
45
|
-
WEB_IMAGE_VERSION: webImageVersion
|
|
46
|
-
dockerName: dockerName || 'centreon-dev'
|
|
80
|
+
WEB_IMAGE_VERSION: webImageVersion
|
|
47
81
|
},
|
|
48
|
-
execTimeout:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
overwrite: true,
|
|
54
|
-
reportDir: `${resultsFolder}/reports`,
|
|
55
|
-
reportFilename: '[name]-report.json'
|
|
82
|
+
execTimeout: 60000,
|
|
83
|
+
requestTimeout: 20000,
|
|
84
|
+
retries: {
|
|
85
|
+
openMode: 0,
|
|
86
|
+
runMode: 2
|
|
56
87
|
},
|
|
57
|
-
requestTimeout: 10000,
|
|
58
|
-
retries: 0,
|
|
59
88
|
screenshotsFolder: `${resultsFolder}/screenshots`,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return '--headless=new';
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return arg;
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return launchOptions;
|
|
73
|
-
});
|
|
74
|
-
},
|
|
75
|
-
video: true,
|
|
76
|
-
videosFolder: `${resultsFolder}/videos`
|
|
89
|
+
video: isDevelopment,
|
|
90
|
+
videoCompression: 0,
|
|
91
|
+
videosFolder: `${resultsFolder}/videos`,
|
|
92
|
+
viewportHeight: 1080,
|
|
93
|
+
viewportWidth: 1920
|
|
77
94
|
});
|
|
78
95
|
};
|
|
@@ -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,131 +3,60 @@
|
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
4
4
|
/* eslint-disable no-param-reassign */
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
loader: 'swc-loader'
|
|
22
|
-
}
|
|
23
|
-
]
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
test: /\.feature$/,
|
|
27
|
-
use: [
|
|
28
|
-
{
|
|
29
|
-
loader: '@badeball/cypress-cucumber-preprocessor/webpack',
|
|
30
|
-
options: config
|
|
31
|
-
}
|
|
32
|
-
]
|
|
33
|
-
}
|
|
34
|
-
]
|
|
35
|
-
},
|
|
36
|
-
resolve: {
|
|
37
|
-
extensions: ['.ts', '.js']
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export default async (on, config): Promise<void> => {
|
|
43
|
-
await addCucumberPreprocessorPlugin(on, config);
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
|
|
9
|
+
export default (
|
|
10
|
+
on: Cypress.PluginEvents,
|
|
11
|
+
config: Cypress.PluginConfigOptions
|
|
12
|
+
): Cypress.PluginConfigOptions => {
|
|
13
|
+
on('before:browser:launch', (browser, launchOptions) => {
|
|
14
|
+
const width = 1920;
|
|
15
|
+
const height = 1080;
|
|
16
|
+
|
|
17
|
+
if (browser.family === 'chromium' && browser.name !== 'electron') {
|
|
18
|
+
if (browser.isHeadless) {
|
|
19
|
+
launchOptions.args.push('--headless=new');
|
|
20
|
+
}
|
|
44
21
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
22
|
+
// flags description : https://github.com/GoogleChrome/chrome-launcher/blob/main/docs/chrome-flags-for-tools.md
|
|
23
|
+
launchOptions.args.push('--disable-gpu');
|
|
24
|
+
launchOptions.args.push('--auto-open-devtools-for-tabs');
|
|
25
|
+
launchOptions.args.push('--disable-extensions');
|
|
26
|
+
launchOptions.args.push('--hide-scrollbars');
|
|
27
|
+
launchOptions.args.push('--mute-audio');
|
|
49
28
|
|
|
50
|
-
|
|
29
|
+
// force screen to be non-retina and just use our given resolution
|
|
30
|
+
launchOptions.args.push('--force-device-scale-factor=1');
|
|
51
31
|
|
|
52
|
-
|
|
53
|
-
if ((browser as { name }).name === 'chrome') {
|
|
54
|
-
launchOptions.args.push('--disable-gpu');
|
|
55
|
-
launchOptions.args = launchOptions.args.filter(
|
|
56
|
-
(element) => element !== '--disable-dev-shm-usage'
|
|
57
|
-
);
|
|
32
|
+
launchOptions.args.push(`--window-size=${width},${height}`);
|
|
58
33
|
}
|
|
59
34
|
|
|
60
35
|
return launchOptions;
|
|
61
36
|
});
|
|
62
37
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
interface StopContainerProps {
|
|
75
|
-
name: string;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
on('task', {
|
|
79
|
-
startContainer: async ({
|
|
80
|
-
image,
|
|
81
|
-
name,
|
|
82
|
-
portBindings = []
|
|
83
|
-
}: StartContainerProps) => {
|
|
84
|
-
const webContainers = await docker.listContainers({
|
|
85
|
-
all: true,
|
|
86
|
-
filters: { name: [name] }
|
|
38
|
+
on('after:run', (results) => {
|
|
39
|
+
const testRetries: { [key: string]: Number } = {};
|
|
40
|
+
if ('runs' in results) {
|
|
41
|
+
results.runs.forEach((run) => {
|
|
42
|
+
run.tests.forEach((test) => {
|
|
43
|
+
console.log(test)
|
|
44
|
+
if (test.attempts && test.attempts.length > 1 && test.state === 'passed') {
|
|
45
|
+
const testTitle = test.title.join(' > '); // Convert the array to a string
|
|
46
|
+
testRetries[testTitle] = test.attempts.length - 1;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
87
49
|
});
|
|
88
|
-
|
|
89
|
-
return webContainers[0];
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const container = await docker.createContainer({
|
|
93
|
-
AttachStderr: true,
|
|
94
|
-
AttachStdin: false,
|
|
95
|
-
AttachStdout: true,
|
|
96
|
-
ExposedPorts: portBindings.reduce((accumulator, currentValue) => {
|
|
97
|
-
accumulator[`${currentValue.source}/tcp`] = {};
|
|
98
|
-
|
|
99
|
-
return accumulator;
|
|
100
|
-
}, {}),
|
|
101
|
-
HostConfig: {
|
|
102
|
-
PortBindings: portBindings.reduce((accumulator, currentValue) => {
|
|
103
|
-
accumulator[`${currentValue.source}/tcp`] = [
|
|
104
|
-
{
|
|
105
|
-
HostIP: '0.0.0.0',
|
|
106
|
-
HostPort: `${currentValue.destination}`
|
|
107
|
-
}
|
|
108
|
-
];
|
|
109
|
-
|
|
110
|
-
return accumulator;
|
|
111
|
-
}, {})
|
|
112
|
-
},
|
|
113
|
-
Image: image,
|
|
114
|
-
OpenStdin: false,
|
|
115
|
-
StdinOnce: false,
|
|
116
|
-
Tty: true,
|
|
117
|
-
name
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
await container.start();
|
|
50
|
+
}
|
|
121
51
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
52
|
+
// Save the testRetries object to a file in the e2e/results directory
|
|
53
|
+
const resultFilePath = path.join(
|
|
54
|
+
__dirname,
|
|
55
|
+
'../../../../tests/e2e/results',
|
|
56
|
+
'retries.json'
|
|
57
|
+
);
|
|
128
58
|
|
|
129
|
-
|
|
130
|
-
}
|
|
59
|
+
fs.writeFileSync(resultFilePath, JSON.stringify(testRetries, null, 2));
|
|
131
60
|
});
|
|
132
61
|
|
|
133
62
|
return config;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
mochawesomeReporterOptions: {
|
|
3
|
+
consoleReporter: 'none',
|
|
4
|
+
html: false,
|
|
5
|
+
json: true,
|
|
6
|
+
overwrite: true,
|
|
7
|
+
reportDir: 'results/reports',
|
|
8
|
+
reportFilename: '[name]-report.json'
|
|
9
|
+
},
|
|
10
|
+
reporterEnabled: `mochawesome,${require.resolve(
|
|
11
|
+
'@badeball/cypress-cucumber-preprocessor/pretty-reporter'
|
|
12
|
+
)}`
|
|
13
|
+
};
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { execSync } from 'child_process';
|
|
3
|
+
import { existsSync, mkdirSync } from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
|
|
6
|
+
import tar from 'tar-fs';
|
|
7
|
+
import {
|
|
8
|
+
DockerComposeEnvironment,
|
|
9
|
+
GenericContainer,
|
|
10
|
+
StartedDockerComposeEnvironment,
|
|
11
|
+
StartedTestContainer,
|
|
12
|
+
Wait,
|
|
13
|
+
getContainerRuntimeClient
|
|
14
|
+
} from 'testcontainers';
|
|
15
|
+
import { createConnection } from 'mysql2/promise';
|
|
16
|
+
|
|
17
|
+
interface Containers {
|
|
18
|
+
[key: string]: StartedTestContainer;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
class NotFoundContainerError extends Error {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = 'NotFoundContainerError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default (on: Cypress.PluginEvents): void => {
|
|
29
|
+
let dockerEnvironment: StartedDockerComposeEnvironment | null = null;
|
|
30
|
+
const containers: Containers = {};
|
|
31
|
+
|
|
32
|
+
const getContainer = (containerName): StartedTestContainer => {
|
|
33
|
+
let container;
|
|
34
|
+
|
|
35
|
+
if (dockerEnvironment !== null) {
|
|
36
|
+
container = dockerEnvironment.getContainer(`${containerName}-1`);
|
|
37
|
+
} else if (containers[containerName]) {
|
|
38
|
+
container = containers[containerName];
|
|
39
|
+
} else {
|
|
40
|
+
throw new NotFoundContainerError(`Cannot get container ${containerName}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return container;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
interface PortBinding {
|
|
47
|
+
destination: number;
|
|
48
|
+
source: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface StartContainerProps {
|
|
52
|
+
command?: string;
|
|
53
|
+
image: string;
|
|
54
|
+
name: string;
|
|
55
|
+
portBindings: Array<PortBinding>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface StopContainerProps {
|
|
59
|
+
name: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
on('task', {
|
|
63
|
+
copyFromContainer: async ({ destination, serviceName, source }) => {
|
|
64
|
+
try {
|
|
65
|
+
const container = getContainer(serviceName);
|
|
66
|
+
|
|
67
|
+
await container
|
|
68
|
+
.copyArchiveFromContainer(source)
|
|
69
|
+
.then((archiveStream) => {
|
|
70
|
+
return new Promise<void>((resolve) => {
|
|
71
|
+
const dest = tar.extract(destination);
|
|
72
|
+
archiveStream.pipe(dest);
|
|
73
|
+
dest.on('finish', resolve);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (error instanceof NotFoundContainerError) {
|
|
78
|
+
console.log(`Cannot get ${source} from container ${serviceName} because it doesn't exist.`);
|
|
79
|
+
} else {
|
|
80
|
+
console.error(error);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return null;
|
|
85
|
+
},
|
|
86
|
+
copyToContainer: async ({ destination, serviceName, source, type }) => {
|
|
87
|
+
const container = getContainer(serviceName);
|
|
88
|
+
|
|
89
|
+
if (type === 'directory') {
|
|
90
|
+
await container.copyDirectoriesToContainer([
|
|
91
|
+
{
|
|
92
|
+
source,
|
|
93
|
+
target: destination
|
|
94
|
+
}
|
|
95
|
+
]);
|
|
96
|
+
} else if (type === 'file') {
|
|
97
|
+
await container.copyFilesToContainer([
|
|
98
|
+
{
|
|
99
|
+
source,
|
|
100
|
+
target: destination
|
|
101
|
+
}
|
|
102
|
+
]);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return null;
|
|
106
|
+
},
|
|
107
|
+
createDirectory: async (directoryPath: string) => {
|
|
108
|
+
if (!existsSync(directoryPath)) {
|
|
109
|
+
mkdirSync(directoryPath, { recursive: true });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return null;
|
|
113
|
+
},
|
|
114
|
+
execInContainer: async ({ command, name }) => {
|
|
115
|
+
const { exitCode, output } = await getContainer(name).exec([
|
|
116
|
+
'bash',
|
|
117
|
+
'-c',
|
|
118
|
+
`${command}${command.match(/[\n\r]/) ? '' : ' 2>&1'}`
|
|
119
|
+
]);
|
|
120
|
+
|
|
121
|
+
return { exitCode, output };
|
|
122
|
+
},
|
|
123
|
+
getContainerId: (containerName: string) =>
|
|
124
|
+
getContainer(containerName).getId(),
|
|
125
|
+
getContainerIpAddress: (containerName: string) => {
|
|
126
|
+
const container = getContainer(containerName);
|
|
127
|
+
|
|
128
|
+
const networkNames = container.getNetworkNames();
|
|
129
|
+
|
|
130
|
+
return container.getIpAddress(networkNames[0]);
|
|
131
|
+
},
|
|
132
|
+
getContainersLogs: async () => {
|
|
133
|
+
try {
|
|
134
|
+
const { dockerode } = (await getContainerRuntimeClient()).container;
|
|
135
|
+
const loggedContainers = await dockerode.listContainers();
|
|
136
|
+
|
|
137
|
+
return loggedContainers.reduce((acc, container) => {
|
|
138
|
+
const containerName = container.Names[0].replace('/', '');
|
|
139
|
+
acc[containerName] = execSync(`docker logs -t ${container.Id}`, {
|
|
140
|
+
stdio: 'pipe'
|
|
141
|
+
}).toString('utf8');
|
|
142
|
+
|
|
143
|
+
return acc;
|
|
144
|
+
}, {});
|
|
145
|
+
} catch (error) {
|
|
146
|
+
console.warn('Cannot get containers logs');
|
|
147
|
+
console.warn(error);
|
|
148
|
+
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
getContainerMappedPort: async ({ containerName, containerPort }) => {
|
|
153
|
+
const container = getContainer(containerName);
|
|
154
|
+
|
|
155
|
+
return container.getMappedPort(containerPort);
|
|
156
|
+
},
|
|
157
|
+
requestOnDatabase: async ({ database, query }) => {
|
|
158
|
+
let container: StartedTestContainer | null = null;
|
|
159
|
+
|
|
160
|
+
if (dockerEnvironment !== null) {
|
|
161
|
+
container = dockerEnvironment.getContainer('db-1');
|
|
162
|
+
} else {
|
|
163
|
+
container = getContainer('web');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const client = await createConnection({
|
|
167
|
+
database,
|
|
168
|
+
host: container.getHost(),
|
|
169
|
+
password: 'centreon',
|
|
170
|
+
port: container.getMappedPort(3306),
|
|
171
|
+
user: 'centreon'
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const [rows, fields] = await client.query(query);
|
|
175
|
+
|
|
176
|
+
await client.end();
|
|
177
|
+
|
|
178
|
+
return [rows, fields];
|
|
179
|
+
},
|
|
180
|
+
startContainer: async ({
|
|
181
|
+
command,
|
|
182
|
+
image,
|
|
183
|
+
name,
|
|
184
|
+
portBindings = []
|
|
185
|
+
}: StartContainerProps) => {
|
|
186
|
+
let container = await new GenericContainer(image).withName(name);
|
|
187
|
+
|
|
188
|
+
portBindings.forEach(({ source, destination }) => {
|
|
189
|
+
container = container.withExposedPorts({
|
|
190
|
+
container: source,
|
|
191
|
+
host: destination
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
if (command) {
|
|
196
|
+
container
|
|
197
|
+
.withCommand(['bash', '-c', command])
|
|
198
|
+
.withWaitStrategy(Wait.forSuccessfulCommand('ls'));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
containers[name] = await container.start();
|
|
202
|
+
|
|
203
|
+
return container;
|
|
204
|
+
},
|
|
205
|
+
startContainers: async ({
|
|
206
|
+
composeFile,
|
|
207
|
+
databaseImage,
|
|
208
|
+
openidImage,
|
|
209
|
+
profiles,
|
|
210
|
+
samlImage,
|
|
211
|
+
webImage
|
|
212
|
+
}) => {
|
|
213
|
+
try {
|
|
214
|
+
const composeFileDir = path.dirname(composeFile);
|
|
215
|
+
const composeFileName = path.basename(composeFile);
|
|
216
|
+
|
|
217
|
+
dockerEnvironment = await new DockerComposeEnvironment(
|
|
218
|
+
composeFileDir,
|
|
219
|
+
composeFileName
|
|
220
|
+
)
|
|
221
|
+
.withEnvironment({
|
|
222
|
+
MYSQL_IMAGE: databaseImage,
|
|
223
|
+
OPENID_IMAGE: openidImage,
|
|
224
|
+
SAML_IMAGE: samlImage,
|
|
225
|
+
WEB_IMAGE: webImage
|
|
226
|
+
})
|
|
227
|
+
.withProfiles(...profiles)
|
|
228
|
+
.withStartupTimeout(120000)
|
|
229
|
+
.withWaitStrategy(
|
|
230
|
+
'web-1',
|
|
231
|
+
Wait.forAll([
|
|
232
|
+
Wait.forHealthCheck(),
|
|
233
|
+
Wait.forLogMessage('Centreon is ready')
|
|
234
|
+
])
|
|
235
|
+
)
|
|
236
|
+
.up();
|
|
237
|
+
|
|
238
|
+
return null;
|
|
239
|
+
} catch (error) {
|
|
240
|
+
if (error instanceof Error) {
|
|
241
|
+
console.error(error.message);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
throw error;
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
stopContainer: async ({ name }: StopContainerProps) => {
|
|
248
|
+
if (containers[name]) {
|
|
249
|
+
const container = containers[name];
|
|
250
|
+
|
|
251
|
+
await container.stop();
|
|
252
|
+
|
|
253
|
+
delete containers[name];
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return null;
|
|
257
|
+
},
|
|
258
|
+
stopContainers: async () => {
|
|
259
|
+
if (dockerEnvironment !== null) {
|
|
260
|
+
await dockerEnvironment.down();
|
|
261
|
+
|
|
262
|
+
dockerEnvironment = null;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return null;
|
|
266
|
+
},
|
|
267
|
+
waitOn: async (url: string) => {
|
|
268
|
+
execSync(`npx wait-on ${url}`);
|
|
269
|
+
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
};
|
|
@@ -21,11 +21,15 @@ module.exports = {
|
|
|
21
21
|
}
|
|
22
22
|
],
|
|
23
23
|
'@typescript-eslint/camelcase': 'off',
|
|
24
|
-
'@typescript-eslint/consistent-type-definitions': [
|
|
24
|
+
'@typescript-eslint/consistent-type-definitions': ['off', 'interface'],
|
|
25
|
+
'@typescript-eslint/explicit-function-return-type': [
|
|
25
26
|
'error',
|
|
26
|
-
|
|
27
|
+
{
|
|
28
|
+
allowExpressions: true,
|
|
29
|
+
allowHigherOrderFunctions: true,
|
|
30
|
+
allowTypedFunctionExpressions: true
|
|
31
|
+
}
|
|
27
32
|
],
|
|
28
|
-
'@typescript-eslint/explicit-function-return-type': ['error'],
|
|
29
33
|
'@typescript-eslint/explicit-member-accessibility': [
|
|
30
34
|
'error',
|
|
31
35
|
{
|
|
@@ -76,13 +80,21 @@ module.exports = {
|
|
|
76
80
|
}
|
|
77
81
|
],
|
|
78
82
|
camelcase: 'off',
|
|
83
|
+
'import/no-cycle': 'off',
|
|
84
|
+
'import/no-named-as-default': 'warn',
|
|
79
85
|
'no-shadow': 'off',
|
|
80
86
|
'no-unused-expressions': 'off'
|
|
81
87
|
},
|
|
82
88
|
settings: {
|
|
89
|
+
'import/parsers': {
|
|
90
|
+
'@typescript-eslint/parser': ['.ts', '.tsx']
|
|
91
|
+
},
|
|
83
92
|
'import/resolver': {
|
|
84
93
|
alias: {
|
|
85
94
|
extensions: ['.ts', '.tsx', '.js', '.jsx']
|
|
95
|
+
},
|
|
96
|
+
typescript: {
|
|
97
|
+
alwaysTryTypes: true
|
|
86
98
|
}
|
|
87
99
|
}
|
|
88
100
|
}
|