diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 03ffba6b9b..fc226cf1c7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -81,7 +81,7 @@ unit-cbt: image: $CI_IMAGE script: - yarn - - ./ci-cbt.sh test:unit + - ./scripts/ci-cbt.sh test:unit e2e-cbt: except: @@ -93,7 +93,7 @@ e2e-cbt: image: $CI_IMAGE script: - yarn - - ./ci-cbt.sh test:e2e + - ./scripts/ci-cbt.sh test:e2e deploy-staging: only: @@ -105,9 +105,9 @@ deploy-staging: script: - yarn - TARGET_DATACENTER=eu TARGET_ENV=staging VERSION=staging yarn build:bundle - - ./deploy.sh staging eu + - ./scripts/deploy.sh staging eu - TARGET_DATACENTER=us TARGET_ENV=staging VERSION=staging yarn build:bundle - - ./deploy.sh staging us + - ./scripts/deploy.sh staging us deploy-release: only: @@ -121,9 +121,9 @@ deploy-release: script: - yarn - TARGET_DATACENTER=eu TARGET_ENV=production VERSION=release yarn build:bundle - - ./deploy.sh prod eu + - ./scripts/deploy.sh prod eu - TARGET_DATACENTER=us TARGET_ENV=production VERSION=release yarn build:bundle - - ./deploy.sh prod us + - ./scripts/deploy.sh prod us ######################################################################################################################## # Notify diff --git a/package.json b/package.json index d1d61de324..3a122d3f09 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "dev": "ENV=development node test/server/server.js", "test": "yarn test:unit", "test:unit": "karma start ./test/unit/karma.local.conf.js", - "test:unit:cbt": "karma start ./test/unit/karma.cbt.conf.js", + "test:unit:cbt": "node ./scripts/karma-cbt-with-retry.js", "test:e2e": "yarn run test:e2e:bundle", "test:e2e:bundle": "TARGET_ENV=e2e-test yarn build && E2E_MODE=bundle wdio test/e2e/wdio.local.conf.js", "test:e2e:npm": "TARGET_ENV=e2e-test yarn build && (cd test/app && rm -rf node_modules && yarn) && E2E_MODE=npm wdio test/e2e/wdio.local.conf.js", diff --git a/packages/logs/package.json b/packages/logs/package.json index 62db4de4f6..06d2ed645f 100644 --- a/packages/logs/package.json +++ b/packages/logs/package.json @@ -10,7 +10,7 @@ "build:bundle": "rm -rf bundle && webpack --config webpack.config.js --mode=production && yarn replace-build-env bundle", "build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json && yarn replace-build-env cjs", "build:esm": "rm -rf esm && tsc -p tsconfig.esm.json && yarn replace-build-env esm", - "replace-build-env": "node ../../replace-build-env.js" + "replace-build-env": "node ../../scripts/replace-build-env.js" }, "dependencies": { "@browser-sdk/core": "^1.1.0", diff --git a/packages/rum/package.json b/packages/rum/package.json index b1ebc920d1..5ef318674c 100644 --- a/packages/rum/package.json +++ b/packages/rum/package.json @@ -10,7 +10,7 @@ "build:bundle": "rm -rf bundle && webpack --config webpack.config.js --mode=production && yarn replace-build-env bundle", "build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json && yarn replace-build-env cjs", "build:esm": "rm -rf esm && tsc -p tsconfig.esm.json && yarn replace-build-env esm", - "replace-build-env": "node ../../replace-build-env.js" + "replace-build-env": "node ../../scripts/replace-build-env.js" }, "dependencies": { "@browser-sdk/core": "^1.1.0", diff --git a/build-env.js b/scripts/build-env.js similarity index 92% rename from build-env.js rename to scripts/build-env.js index 0f4edcc77c..5fd6c87c66 100644 --- a/build-env.js +++ b/scripts/build-env.js @@ -1,5 +1,5 @@ const execSync = require('child_process').execSync -const lernaJson = require('./lerna.json') +const lernaJson = require('../lerna.json') let version switch (process.env.VERSION) { diff --git a/ci-cbt.sh b/scripts/ci-cbt.sh similarity index 100% rename from ci-cbt.sh rename to scripts/ci-cbt.sh diff --git a/deploy.sh b/scripts/deploy.sh similarity index 100% rename from deploy.sh rename to scripts/deploy.sh diff --git a/scripts/karma-cbt-with-retry.js b/scripts/karma-cbt-with-retry.js new file mode 100644 index 0000000000..dc765b6c18 --- /dev/null +++ b/scripts/karma-cbt-with-retry.js @@ -0,0 +1,33 @@ +'use strict' + +const path = require('path') +const exec = require('child_process').exec + +const rootDirectory = path.join(__dirname, '..') +const COMMAND = `${rootDirectory}/node_modules/.bin/karma start ${rootDirectory}/test/unit/karma.cbt.conf.js` +const MAX_RETRY_COUNT = 3 +let retryCount = 0 + +function executeWithRetry() { + let logs = '' + const current = exec(COMMAND) + current.stdout.pipe(process.stdout) + current.stdout.on('data', (data) => (logs += data)) + current.on('exit', (code) => { + if (code !== 0 && isRetryAllowed(logs)) { + if (retryCount < MAX_RETRY_COUNT) { + retryCount += 1 + console.log(`\n${COMMAND} (Retry ${retryCount}/${MAX_RETRY_COUNT})\n\n`) + executeWithRetry() + } + } else { + process.exit(code) + } + }) +} + +function isRetryAllowed(logs) { + return logs.indexOf('UnhandledRejection') !== -1 +} + +executeWithRetry() diff --git a/replace-build-env.js b/scripts/replace-build-env.js similarity index 100% rename from replace-build-env.js rename to scripts/replace-build-env.js diff --git a/test/server/server.js b/test/server/server.js index 4d024984de..d483ba97f2 100644 --- a/test/server/server.js +++ b/test/server/server.js @@ -8,7 +8,7 @@ const webpack = require('webpack') const logsConfig = require('../../packages/logs/webpack.config') const rumConfig = require('../../packages/rum/webpack.config') const fakeBackend = require('./fake-backend') -const buildEnv = require('.././../build-env') +const buildEnv = require('../../scripts/build-env') let port = 3000 const app = express()