Skip to content

Commit

Permalink
Minor code style improvements. Set correct default value for show-fai…
Browse files Browse the repository at this point in the history
…led-tests-only input
  • Loading branch information
bibipkins committed Feb 7, 2024
1 parent 3886e4e commit 360390b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 46 deletions.
32 changes: 10 additions & 22 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,41 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: |
npm ci
- run: |
npm run build
- run: npm ci
- run: npm run build
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Test Results All
- name: Test - Results All
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-title: Test Results All
results-path: ./files/**/*.trx
allow-failed-tests: true
- name: Test Results Success
- name: Test - Results Success
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-title: Test Results Success
results-path: ./files/success/*
- name: Test Results Fail
- name: Test - Results Fail
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-title: Test Results Fail
results-path: ./files/fail/*
allow-failed-tests: true
- name: Test Coverage OpenCover
- name: Test - Coverage OpenCover
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-title: Test Coverage OpenCover
results-path: ./files/success/*
coverage-path: ./files/success/test_coverage_opencover.xml
coverage-threshold: 44
- name: Test Coverage Cobertura
- name: Test - Coverage Cobertura
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -60,29 +58,19 @@ jobs:
coverage-path: ./files/success/test_coverage_cobertura.xml
coverage-type: cobertura
coverage-threshold: 44
- name: Test Hide Success
- name: Test - Show Failed Tests Only
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-title: Test Hide Success
results-path: ./files/**/*.trx
allow-failed-tests: true
show-failed-tests-only : true
- name: Test Hide Output
show-failed-tests-only: true
- name: Test - Hide Test Output
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-title: Test Hide Output
results-path: ./files/**/test_result.trx
allow-failed-tests: true
show-failed-tests-only: false
show-test-output: false
- name: Test Show Output
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-title: Test Show Output
results-path: ./files/**/test_result.trx
allow-failed-tests: true
show-test-output: true
show-failed-tests-only: false
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Set to `false` or leave blank to fail the job if there are any failed tests (rec

#### `show-failed-tests-only`
**Optional** - Boolean flag.
Set to `true` to show only the failed tests. This is useful if you you have many tests and the results exceed the markdown comment limit in github
Set to `true` to show only the failed tests. This is useful if you have many tests and the results exceed the markdown comment limit in github
Set to `false` or leave blank to show all the test results (recommended).
<br/>Default: `false`

Expand Down
10 changes: 7 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ inputs:
required: false
default: false
show-failed-tests-only:
description: 'Boolean flag. Show only failed tests in summary. Useful for when test count is large and the details are truncated'
description:
'Boolean flag. Show only failed tests in summary. Useful for when test count is large and the details are
truncated'
required: false
default: true
default: false
show-test-output:
description: 'Boolean flag. Show the output of the tests. Useful if there is too much output leading to truncation on the summary'
description:
'Boolean flag. Show the output of the tests. Useful if there is too much output leading to truncation on the
summary'
required: false
default: true
outputs:
Expand Down
13 changes: 4 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,8 @@ const parseSummary = (file) => {
};
};
const parseResults = (file) => {
if (!file.TestRun.Results || !file.TestRun.Results[0].UnitTestResult) {
return [];
}
const results = file.TestRun.Results[0].UnitTestResult;
var _a, _b, _c, _d;
const results = ((_d = (_c = (_b = (_a = file.TestRun) === null || _a === void 0 ? void 0 : _a.Results) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.UnitTestResult) !== null && _d !== void 0 ? _d : []);
return results.map((result) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
return ({
Expand All @@ -582,10 +580,8 @@ const parseResults = (file) => {
});
};
const parseDefinitions = (file) => {
if (!file.TestRun.TestDefinitions || !file.TestRun.TestDefinitions[0].UnitTest) {
return [];
}
const definitions = file.TestRun.TestDefinitions[0].UnitTest;
var _a, _b, _c, _d;
const definitions = ((_d = (_c = (_b = (_a = file.TestRun) === null || _a === void 0 ? void 0 : _a.TestDefinitions) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.UnitTest) !== null && _d !== void 0 ? _d : []);
return definitions.map(definition => {
var _a;
return ({
Expand Down Expand Up @@ -876,7 +872,6 @@ const tryGetUserLogin = (octokit) => __awaiter(void 0, void 0, void 0, function*
}
catch (_b) {
(0, action_1.log)('⚠️ Failed to get username without user scope, will check comment with user type instead');
// when token doesn't have user scope
return undefined;
}
});
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

10 changes: 2 additions & 8 deletions src/parsers/trx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ const parseSummary = (file: any) => {
};

const parseResults = (file: any) => {
if (!file.TestRun.Results || !file.TestRun.Results[0].UnitTestResult) {
return [];
}
const results = file.TestRun.Results[0].UnitTestResult as any[];
const results = (file.TestRun?.Results?.[0]?.UnitTestResult ?? []) as any[];

return results.map((result: any) => ({
executionId: String(result['$'].executionId),
Expand All @@ -65,10 +62,7 @@ const parseResults = (file: any) => {
};

const parseDefinitions = (file: any) => {
if (!file.TestRun.TestDefinitions || !file.TestRun.TestDefinitions[0].UnitTest) {
return [];
}
const definitions = file.TestRun.TestDefinitions[0].UnitTest as any[];
const definitions = (file.TestRun?.TestDefinitions?.[0]?.UnitTest ?? []) as any[];

return definitions.map(definition => ({
id: String(definition['$'].id),
Expand Down
2 changes: 0 additions & 2 deletions src/utils/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ const tryGetUserLogin = async (octokit: Octokit) => {
return username.data?.login;
} catch {
log('⚠️ Failed to get username without user scope, will check comment with user type instead');
// when token doesn't have user scope
return undefined;
}
};
Expand All @@ -73,7 +72,6 @@ const getExistingComment = async (octokit: Octokit, context: IContext, header: s
return comments.data?.find(comment => {
const isBotUserType = comment.user?.type === 'Bot' || comment.user?.login === userLogin;
const startsWithHeader = comment.body?.startsWith(header);

return isBotUserType && startsWithHeader;
});
};

0 comments on commit 360390b

Please sign in to comment.