Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-26 12:08:47 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-26 12:08:47 +0300
commit66d4203791a01fdedf668a78818a229ea2c07aad (patch)
tree374fc9f6c5e709cf6ab48e257e6bfe4a504d6bbb /scripts
parenta496f41f60e12a0a5c31482b7594ad547e0ade42 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'scripts')
-rw-r--r--scripts/frontend/merge_coverage_frontend.js31
-rw-r--r--scripts/frontend/parallel_ci_sequencer.js41
2 files changed, 72 insertions, 0 deletions
diff --git a/scripts/frontend/merge_coverage_frontend.js b/scripts/frontend/merge_coverage_frontend.js
new file mode 100644
index 00000000000..507695b45e5
--- /dev/null
+++ b/scripts/frontend/merge_coverage_frontend.js
@@ -0,0 +1,31 @@
+const { create } = require('istanbul-reports');
+const { createCoverageMap } = require('istanbul-lib-coverage');
+const { createContext } = require('istanbul-lib-report');
+const { resolve } = require('path');
+const { sync } = require('glob');
+
+const coverageMap = createCoverageMap();
+
+const coverageDir = resolve(__dirname, '../../coverage-frontend');
+const reportFiles = sync(`${coverageDir}/*/coverage-final.json`);
+
+// Normalize coverage report generated by jest that has additional "data" key
+// https://github.com/facebook/jest/issues/2418#issuecomment-423806659
+const normalizeReport = report => {
+ const normalizedReport = Object.assign({}, report);
+ Object.entries(normalizedReport).forEach(([k, v]) => {
+ if (v.data) normalizedReport[k] = v.data;
+ });
+ return normalizedReport;
+};
+
+reportFiles
+ .map(reportFile => require(reportFile))
+ .map(normalizeReport)
+ .forEach(report => coverageMap.merge(report));
+
+const context = createContext({ coverageMap: coverageMap, dir: 'coverage-frontend' });
+
+['json', 'lcov', 'text-summary', 'clover'].forEach(reporter => {
+ create(reporter, {}).execute(context);
+});
diff --git a/scripts/frontend/parallel_ci_sequencer.js b/scripts/frontend/parallel_ci_sequencer.js
new file mode 100644
index 00000000000..d7a674535a6
--- /dev/null
+++ b/scripts/frontend/parallel_ci_sequencer.js
@@ -0,0 +1,41 @@
+const Sequencer = require('@jest/test-sequencer').default;
+
+class ParallelCISequencer extends Sequencer {
+ constructor() {
+ super();
+ this.ciNodeIndex = Number(process.env.CI_NODE_INDEX || '1');
+ this.ciNodeTotal = Number(process.env.CI_NODE_TOTAL || '1');
+ }
+
+ sort(tests) {
+ const sortedTests = this.sortByPath(tests);
+ const testsForThisRunner = this.distributeAcrossCINodes(sortedTests);
+
+ console.log(`CI_NODE_INDEX: ${this.ciNodeIndex}`);
+ console.log(`CI_NODE_TOTAL: ${this.ciNodeTotal}`);
+ console.log(`Total number of tests: ${tests.length}`);
+ console.log(`Total number of tests for this runner: ${testsForThisRunner.length}`);
+
+ return testsForThisRunner;
+ }
+
+ sortByPath(tests) {
+ return tests.sort((test1, test2) => {
+ if (test1.path < test2.path) {
+ return -1;
+ }
+ if (test1.path > test2.path) {
+ return 1;
+ }
+ return 0;
+ });
+ }
+
+ distributeAcrossCINodes(tests) {
+ return tests.filter((test, index) => {
+ return index % this.ciNodeTotal === this.ciNodeIndex - 1;
+ });
+ }
+}
+
+module.exports = ParallelCISequencer;