Skip to content

Commit

Permalink
ci: collect code coverage from e2e (wix#1317)
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph authored Apr 30, 2019
1 parent b291df2 commit caf9d6e
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 21 deletions.
34 changes: 16 additions & 18 deletions detox/local-cli/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,15 @@ module.exports.handler = async function test(program) {
const platform = currentConfiguration.type.split('.')[0];

function run() {
switch (runner) {
case 'mocha':
runMocha();
break;
case 'jest':
runJest();
break;
default:
throw new Error(`${runner} is not supported in detox cli tools. You can still run your tests with the runner's own cli tool`);
if (runner.includes('jest')) {
return runJest();
}

if (runner.includes('mocha')) {
return runMocha();
}

throw new Error(`${runner} is not supported in detox cli tools. You can still run your tests with the runner's own cli tool`);
}

function getConfigFor(...keys) {
Expand Down Expand Up @@ -206,7 +205,7 @@ module.exports.handler = async function test(program) {
}

const command = _.compact([
(path.join('node_modules', '.bin', 'mocha')),
(path.join('node_modules', '.bin', runner)),
(runnerConfig ? `--opts ${runnerConfig}` : ''),
(program.configuration ? `--configuration ${program.configuration}` : ''),
(program.loglevel ? `--loglevel ${program.loglevel}` : ''),
Expand Down Expand Up @@ -237,7 +236,7 @@ module.exports.handler = async function test(program) {
}

const command = _.compact([
path.join('node_modules', '.bin', 'jest'),
path.join('node_modules', '.bin', runner),
(runnerConfig ? `--config=${runnerConfig}` : ''),
(program.noColor ? ' --no-color' : ''),
`--maxWorkers=${program.workers}`,
Expand Down Expand Up @@ -282,13 +281,12 @@ module.exports.handler = async function test(program) {
}

function getDefaultRunnerConfig() {
switch (runner) {
case 'mocha':
return 'e2e/mocha.opts';
case 'jest':
return 'e2e/config.json';
default:
return undefined;
if (runner.includes('jest')) {
return 'e2e/config.json';
}

if (runner.includes('mocha')) {
return 'e2e/mocha.opts';
}
}

Expand Down
1 change: 1 addition & 0 deletions detox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"unit": "jest --coverage --verbose",
"pretest": "npm run lint",
"test": "npm run unit",
"posttest": "cp coverage/lcov.info coverage/unit.lcov",
"unit:watch": "jest --watch",
"prepublish": "npm run build",
"postinstall": "node scripts/postinstall.js"
Expand Down
23 changes: 21 additions & 2 deletions detox/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
"detox": "^12.6.0",
"express": "^4.15.3",
"lodash": "^4.14.1",
"mocha": "^6.1.3"
"mocha": "^6.1.3",
"nyc": "^14.0.0"
},
"detox": {
"test-runner": "mocha",
"test-runner": "nyc mocha",
"__session": {
"server": "ws://localhost:8099",
"sessionId": "test"
Expand Down Expand Up @@ -71,5 +72,23 @@
"name": "Nexus_5X_API_26"
}
}
},
"nyc": {
"reporter": [
"lcov",
"html"
],
"all": true,
"cwd": "..",
"include": [
"src/**/*.js"
],
"report-dir": "test/coverage",
"exclude": [
"**/__test/**",
"**/__mocks__/**",
"**/*.mock.js",
"**/*.test.js"
]
}
}
23 changes: 23 additions & 0 deletions scripts/aggregate_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

if [ -d aggregated-coverage ]; then
npm install --no-save --no-package-lock "[email protected]" "[email protected]"

rm -f "aggregated-coverage/merged.lcov"
{
for lcov in aggregated-coverage/**/*.lcov; do
echo "Forcing relative paths in: $lcov"
sed -i 's/^SF:.*\(detox-ios-51-pr\|detox-ios-56-pr\|detox-android-56-pr\)\//SF:/g' $lcov
done

echo "Merging LCOV files"
node_modules/.bin/lcov-result-merger 'aggregated-coverage/**/*.lcov' "aggregated-coverage/merged.lcov"
} && {
echo "Uploading to coveralls"
cat "aggregated-coverage/merged.lcov" | node_modules/.bin/coveralls
} || {
echo "Failed to aggregate the test coverage, skipping."
}
else
echo "Aggregated coverage directory was not found, skipping."
fi
1 change: 1 addition & 0 deletions scripts/ci.android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ cp extras/release.gradle node_modules/react-native/ReactAndroid/

run_f "npm run build:android"
run_f "npm run e2e:android -- --headless --loglevel verbose"
cp coverage/lcov.info coverage/e2e.lcov
# run_f "npm run verify-artifacts:android"
popd
2 changes: 1 addition & 1 deletion scripts/ci.ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ run_f "$(dirname "$0")/unit.ios.sh"
pushd detox/test
run_f "npm run build:ios"
run_f "npm run e2e:ios"
cp coverage/lcov.info coverage/e2e.lcov
# run_f "npm run verify-artifacts:ios"
popd

0 comments on commit caf9d6e

Please sign in to comment.