diff --git a/package.json b/package.json index c31fb39..a06381d 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,11 @@ "dependencies": { "@octokit/rest": "^16.28.7", "create-check": "^0.6.40", + "execa": "^1.0.0", "strip-ansi": "^6.0.0" }, "devDependencies": { + "@types/execa": "^0.9.0", "@types/node": "12.12.38", "@typescript-eslint/eslint-plugin": "2.32.0", "@typescript-eslint/parser": "2.32.0", diff --git a/src/create-check.ts b/src/create-check.ts index 6ea9f17..c581522 100644 --- a/src/create-check.ts +++ b/src/create-check.ts @@ -5,6 +5,7 @@ import { TestResult, AggregatedResult } from '@jest/reporters'; import path from 'path'; import stripAnsi from 'strip-ansi'; import createCheck, { Annotation } from 'create-check'; +import execa from 'execa'; const APP_ID = 38833; /** @@ -54,7 +55,9 @@ interface Location { line: number; } -function createAnnotations(results: TestResult[]) { +async function createAnnotations(results: TestResult[]) { + const repoRoot = (await execa('git', ['rev-parse', '--show-toplevel'])).stdout; + const annotations: Annotation[] = []; for (const result of results) { @@ -77,7 +80,7 @@ function createAnnotations(results: TestResult[]) { : location.line || 0; annotations.push({ - path: path.relative(process.cwd(), testFilePath), + path: path.relative(repoRoot, testFilePath), start_line, end_line: start_line, annotation_level: 'failure', @@ -92,11 +95,11 @@ function createAnnotations(results: TestResult[]) { return annotations; } -export default (results: AggregatedResult) => +export default async (results: AggregatedResult) => createCheck({ tool: 'Jest', name: process.env.GH_CHECK_NAME || 'Test', - annotations: createAnnotations(results.testResults), + annotations: await createAnnotations(results.testResults), errorCount: results.numFailedTests, appId: process.env.JEST_APP_ID ? Number(process.env.JEST_APP_ID) : APP_ID, privateKey: process.env.JEST_PRIVATE_KEY || PRIVATE_KEY diff --git a/yarn.lock b/yarn.lock index 4462247..3936f7d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -998,6 +998,13 @@ resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d" integrity sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag== +"@types/execa@^0.9.0": + version "0.9.0" + resolved "https://registry.yarnpkg.com/@types/execa/-/execa-0.9.0.tgz#9b025d2755f17e80beaf9368c3f4f319d8b0fb93" + integrity sha512-mgfd93RhzjYBUHHV532turHC2j4l/qxsF/PbfDmprHDEUHmNZGlDn1CEsulGK3AfsPdhkWzZQT/S/k0UGhLGsA== + dependencies: + "@types/node" "*" + "@types/graceful-fs@^4.1.2": version "4.1.3" resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.3.tgz#039af35fe26bec35003e8d86d2ee9c586354348f"