Skip to content

Commit

Permalink
fix coverage reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdemartini committed Aug 5, 2019
1 parent abea6f3 commit 38f87f1
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 25 deletions.
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ jobs:
if: branch = master
script: yarn test --suite unit
after_success:
- bash <(curl -s https://codecov.io/bash) -cF unit
# verify the ui packages can build
- yarn --cwd=./packages/ui-core build
- yarn --cwd=./packages/ui-data-access build
Expand All @@ -45,21 +44,19 @@ jobs:
name: 'ES Test Suite (elasticsearch 5) (node 10)'
# run only on pull-requests
if: branch = master AND type IN (pull_request) AND fork = false
script: yarn test --suite elasticsearch --elasticsearch-version 5.6 --elasticsearch-api-version 6.5
script: yarn test --suite elasticsearch --elasticsearch-version 5.6 --elasticsearch-api-version 6.5 --report-coverage false

- script:
name: 'ES Test Suite (elasticsearch 6) (node 10)'
# run only on pull-requests and cron
if: branch = master AND type IN (pull_request, cron) AND fork = false
script: yarn test --suite elasticsearch --elasticsearch-version 6.8 --elasticsearch-api-version 6.5
# only report coverage on elasticsearch@6
after_success: bash <(curl -s https://codecov.io/bash) -cF elasticsearch

- script:
name: 'ES Test Suite (elasticsearch 7) (node 10)'
# run only on pull-requests
if: branch = master AND type IN (pull_request) AND fork = false
script: yarn test --suite elasticsearch --elasticsearch-version 7.2 --elasticsearch-api-version 7.0
script: yarn test --suite elasticsearch --elasticsearch-version 7.2 --elasticsearch-api-version 7.0 --report-coverage false

- script:
name: 'End-to-End Test Suite (elasticsearch 6) (node 10)'
Expand Down
19 changes: 5 additions & 14 deletions jest.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = (projectDir) => {
const rootDir = name === 'e2e' ? '../' : '../../';
const packageRoot = name === 'e2e' ? '<rootDir>/e2e' : `<rootDir>/${workspaceName}/${name}`;
const isTypescript = fs.pathExistsSync(path.join(projectDir, 'tsconfig.json'));
const runInPackage = projectDir === process.cwd();

const config = {
rootDir,
Expand Down Expand Up @@ -55,19 +54,11 @@ module.exports = (projectDir) => {
};

if (isTypescript) {
if (runInPackage) {
config.globals['ts-jest'] = {
tsConfig: './tsconfig.json',
diagnostics: true,
pretty: true
};
} else {
config.globals['ts-jest'] = {
tsConfig: `./${workspaceName}/${name}/tsconfig.json`,
diagnostics: true,
pretty: true
};
}
config.globals['ts-jest'] = {
tsConfig: `./${workspaceName}/${name}/tsconfig.json`,
diagnostics: true,
pretty: true
};
} else {
config.globals['ts-jest'] = {
diagnostics: true,
Expand Down
1 change: 1 addition & 0 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@lerna/query-graph": "^3.14.0",
"@terascope/utils": "^0.14.1",
"@types/is-ci": "^2.0.0",
"codecov": "^3.5.0",
"execa": "^2.0.3",
"fs-extra": "^8.1.0",
"got": "^9.6.0",
Expand Down
7 changes: 7 additions & 0 deletions packages/scripts/src/cmds/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Options = {
watch: boolean;
bail: boolean;
suite?: TestSuite;
'report-coverage': boolean;
'elasticsearch-host': string;
'elasticsearch-version': string;
'elasticsearch-api-version': string;
Expand All @@ -37,6 +38,11 @@ const cmd: CommandModule<GlobalCMDOptions, Options> = {
type: 'boolean',
default: isCI,
})
.option('report-coverage', {
description: 'Report the coverage for CI',
type: 'boolean',
default: isCI,
})
.option('watch', {
description: 'Run tests in an interactive watch mode, this will test only the changed files',
type: 'boolean',
Expand Down Expand Up @@ -103,6 +109,7 @@ const cmd: CommandModule<GlobalCMDOptions, Options> = {
kafkaBroker: argv['kafka-broker'],
kafkaVersion: argv['kafka-version'],
all: !argv.packages || !argv.packages.length,
reportCoverage: argv['report-coverage'],
jestArgs,
});
},
Expand Down
13 changes: 9 additions & 4 deletions packages/scripts/src/helpers/test-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@ async function runTestSuite(suite: TestSuite, pkgInfos: PackageInfo[], options:
}

if (!errors.length) {
// unit tests don't have as much as a memory leak so we can run more at a time
// elasticsearch we should limit the number packages at time
const chunkSize = suite === TestSuite.Unit ? 9 : 3;
const chunked = chunk(pkgInfos, options.debug ? 1 : chunkSize);
// jest or our tests have a memory leak, limiting this to 5 seems to help
const chunked = chunk(pkgInfos, options.debug ? 1 : 5);
const timeLabel = `test suite "${suite}"`;
signale.time(timeLabel);

Expand All @@ -115,7 +113,10 @@ async function runTestSuite(suite: TestSuite, pkgInfos: PackageInfo[], options:
signale.debug(`setting env for test suite "${suite}"`, env);
}

let chunkIndex = -1;
for (const pkgs of chunked) {
chunkIndex++;

if (!pkgs.length) continue;
if (pkgs.length === 1) {
writePkgHeader('Running test', pkgs, true);
Expand Down Expand Up @@ -146,6 +147,10 @@ async function runTestSuite(suite: TestSuite, pkgInfos: PackageInfo[], options:
if (options.bail) {
break;
}
} finally {
if (options.reportCoverage) {
await utils.reportCoverage(suite, chunkIndex);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/scripts/src/helpers/test-runner/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type TestOptions = {
debug: boolean;
watch: boolean;
all: boolean;
reportCoverage: boolean;
suite?: TestSuite;
elasticsearchHost: string;
elasticsearchVersion: string;
Expand Down
20 changes: 18 additions & 2 deletions packages/scripts/src/helpers/test-runner/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path';
import isCI from 'is-ci';
import fse from 'fs-extra';
import { debugLogger, get, TSError, isFunction } from '@terascope/utils';
import { ArgsMap, ExecEnv, dockerBuild, dockerPull, exec } from '../scripts';
import { ArgsMap, ExecEnv, dockerBuild, dockerPull, exec, fork } from '../scripts';
import { TestOptions, GroupedPackages } from './interfaces';
import { PackageInfo, TestSuite } from '../interfaces';
import { HOST_IP } from '../config';
Expand Down Expand Up @@ -193,7 +193,7 @@ export async function logE2E(dir: string, failed: boolean): Promise<void> {
RAW_LOGS: 'true',
});

const logFilePath = path.join(dir, './teraslice-test.log');
const logFilePath = path.join(dir, 'teraslice-test.log');
if (!rawLogs) {
await fse.remove(logFilePath);
return;
Expand All @@ -202,3 +202,19 @@ export async function logE2E(dir: string, failed: boolean): Promise<void> {
await fse.writeFile(logFilePath, rawLogs);
signale.debug(`Wrote e2e log files to ${path.relative(process.cwd(), logFilePath)}`);
}

const abc = 'abcdefghijklmnopqrstuvwxyz';

export async function reportCoverage(suite: TestSuite, chunkIndex: number) {
const id = abc[chunkIndex] || 'any';

signale.info('* reporting coverage');
try {
await fork({
cmd: 'codecov',
args: ['--clear', '--flags', `${suite}-${id}`],
});
} catch (err) {
signale.error(err);
}
}
30 changes: 30 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3474,6 +3474,11 @@ argparse@^1.0.7:
dependencies:
sprintf-js "~1.0.2"

argv@^0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/argv/-/argv-0.0.2.tgz#ecbd16f8949b157183711b1bda334f37840185ab"
integrity sha1-7L0W+JSbFXGDcRsb2jNPN4QBhas=

aria-query@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/aria-query/-/aria-query-3.0.0.tgz#65b3fcc1ca1155a8c9ae64d6eee297f15d5133cc"
Expand Down Expand Up @@ -4937,6 +4942,17 @@ code-point-at@^1.0.0:
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=

codecov@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/codecov/-/codecov-3.5.0.tgz#3d0748932f9cb41e1ad7f21fa346ef1b2b1bed47"
integrity sha512-/OsWOfIHaQIr7aeZ4pY0UC1PZT6kimoKFOFYFNb6wxo3iw12nRrh+mNGH72rnXxNsq6SGfesVPizm/6Q3XqcFQ==
dependencies:
argv "^0.0.2"
ignore-walk "^3.0.1"
js-yaml "^3.13.1"
teeny-request "^3.11.3"
urlgrey "^0.4.4"

collection-visit@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/collection-visit/-/collection-visit-1.0.0.tgz#4bc0373c164bc3291b4d368c829cf1a80a59dca0"
Expand Down Expand Up @@ -16241,6 +16257,15 @@ tar@^4.4.10:
safe-buffer "^5.1.2"
yallist "^3.0.3"

teeny-request@^3.11.3:
version "3.11.3"
resolved "https://registry.yarnpkg.com/teeny-request/-/teeny-request-3.11.3.tgz#335c629f7645e5d6599362df2f3230c4cbc23a55"
integrity sha512-CKncqSF7sH6p4rzCgkb/z/Pcos5efl0DmolzvlqRQUNcpRIruOhY9+T1FsIlyEbfWd7MsFpodROOwHYh2BaXzw==
dependencies:
https-proxy-agent "^2.2.1"
node-fetch "^2.2.0"
uuid "^3.3.2"

temp-dir@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/temp-dir/-/temp-dir-1.0.0.tgz#0a7c0ea26d3a39afa7e0ebea9c1fc0bc4daa011d"
Expand Down Expand Up @@ -17100,6 +17125,11 @@ url@^0.11.0:
punycode "1.3.2"
querystring "0.2.0"

urlgrey@^0.4.4:
version "0.4.4"
resolved "https://registry.yarnpkg.com/urlgrey/-/urlgrey-0.4.4.tgz#892fe95960805e85519f1cd4389f2cb4cbb7652f"
integrity sha1-iS/pWWCAXoVRnxzUOJ8stMu3ZS8=

use@^3.1.0:
version "3.1.1"
resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"
Expand Down

0 comments on commit 38f87f1

Please sign in to comment.