Skip to content

Commit

Permalink
fixed wrong duration for shards (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Nov 4, 2024
1 parent d65bdb8 commit 079bbd1
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 83 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changelog

* 2.9.8
- fixed wrong duration for shards (#157)

* 2.9.7
- fixed eol for unix

Expand Down
17 changes: 9 additions & 8 deletions lib/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,16 @@ const Util = {
},

getDuration: (dateRanges, durationStrategy) => {
dateRanges.sort((a, b) => {
if (a.start === b.start) {
return a.end - b.end;
}
return a.start - b.start;
});

if (durationStrategy === 'exclude-idle') {

dateRanges.sort((a, b) => {
if (a.start === b.start) {
return a.end - b.end;
}
return a.start - b.start;
});

dateRanges.reduce((prevRange, range) => {
// same start
if (range.start === prevRange.start) {
Expand Down Expand Up @@ -387,8 +388,8 @@ const Util = {
return duration;
}
// normal
const dateStart = dateRanges[0].start;
const endDate = dateRanges[dateRanges.length - 1].end;
const dateStart = Math.min.apply(null, dateRanges.map((it) => it.start));
const endDate = Math.max.apply(null, dateRanges.map((it) => it.end));
const duration = endDate - dateStart;
return duration;
},
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,27 @@
"lz-utils": "^2.1.0",
"monocart-coverage-reports": "^2.11.1",
"monocart-locator": "^1.0.2",
"nodemailer": "^6.9.15"
"nodemailer": "^6.9.16"
},
"devDependencies": {
"@babel/code-frame": "^7.25.7",
"@playwright/test": "^1.48.0",
"@babel/code-frame": "^7.26.2",
"@playwright/test": "^1.48.2",
"ansi-to-html": "^0.7.2",
"async-tick": "^1.0.0",
"autolinker": "^4.0.0",
"axios": "^1.7.7",
"commander": "^12.1.0",
"dotenv": "^16.4.5",
"eslint": "^9.12.0",
"eslint": "^9.14.0",
"eslint-config-plus": "^2.0.2",
"eslint-plugin-html": "^8.1.2",
"eslint-plugin-vue": "^9.28.0",
"eslint-plugin-vue": "^9.30.0",
"file-saver": "^2.0.5",
"find-up": "^7.0.0",
"github-markdown-css": "^5.7.0",
"glob": "^11.0.0",
"marked": "^14.1.2",
"mermaid": "^11.3.0",
"marked": "^14.1.3",
"mermaid": "^11.4.0",
"mitt": "^3.0.1",
"monocart-code-viewer": "^1.1.4",
"monocart-formatter": "^3.0.0",
Expand All @@ -78,12 +78,12 @@
"open": "8.4.2",
"sanitize-filename": "^1.6.3",
"stack-utils": "^2.0.6",
"stylelint": "^16.9.0",
"stylelint": "^16.10.0",
"stylelint-config-plus": "^1.1.3",
"supports-color": "^9.4.0",
"turbogrid": "^3.2.0",
"vine-ui": "^3.1.16",
"ws": "^8.18.0",
"yazl": "^2.5.1"
"yazl": "^3.2.1"
}
}
49 changes: 26 additions & 23 deletions packages/app/src/components/detail/attachments/audit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,32 @@ watchEffect(() => {
<template>
<div class="mcr-attachment-audit">
<table>
<tr class="mcr-head">
<td class="mcr-column-left">
Name
</td>
<td />
<td>
Score
</td>
</tr>

<tr
v-for="(item, i) of d.list"
:key="i"
:class="item.sub?'mcr-row-sub':''"
>
<td class="mcr-column-left mcr-column-name">
{{ item.name }}
</td>
<td>{{ item.value }}</td>
<td :class="'mcr-'+item.status">
{{ Util.PNF(item.score) }}
</td>
</tr>
<thead>
<tr class="mcr-head">
<td class="mcr-column-left">
Name
</td>
<td />
<td>
Score
</td>
</tr>
</thead>
<tbody>
<tr
v-for="(item, i) of d.list"
:key="i"
:class="item.sub?'mcr-row-sub':''"
>
<td class="mcr-column-left mcr-column-name">
{{ item.name }}
</td>
<td>{{ item.value }}</td>
<td :class="'mcr-'+item.status">
{{ Util.PNF(item.score) }}
</td>
</tr>
</tbody>
</table>
<VuiFlex padding="8px">
<a
Expand Down
90 changes: 47 additions & 43 deletions packages/app/src/components/detail/attachments/coverage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,50 +92,54 @@ watchEffect(() => {
<template>
<div class="mcr-attachment-coverage">
<table>
<tr>
<td class="mcr-column-left">
Name
</td>
<td>Coverage</td>
<td />
<td>Covered</td>
<td>Uncovered</td>
<td>Total</td>
</tr>
<tr
v-for="(item, i) of d.list"
:key="i"
>
<td class="mcr-column-left">
<b>{{ item.name }}</b>
</td>
<td
style="padding: 0 5px;"
:class="'mcr-'+item.status"
<thead>
<tr>
<td class="mcr-column-left">
Name
</td>
<td>Coverage</td>
<td />
<td>Covered</td>
<td>Uncovered</td>
<td>Total</td>
</tr>
</thead>
<tbody>
<tr
v-for="(item, i) of d.list"
:key="i"
>
{{ Util.PF(item.pct, 100, 2) }}
</td>
<td
style="min-width: 100px;"
v-html="item.percentChart"
/>

<td :title="item.coveredTitle">
<span :class="item.coveredClass">{{ Util.NF(item.covered) }}</span>
</td>
<td :title="item.uncoveredTitle">
<span :class="item.uncoveredClass">{{ Util.NF(item.uncovered) }}</span>
</td>
<td :title="item.totalTitle">
{{ Util.NF(item.total) }}
</td>
</tr>
<tr>
<td class="mcr-column-left">
<b>Files</b> <span class="mcr-num">{{ d.files }}</span>
</td>
<td /><td /><td /><td />
</tr>
<td class="mcr-column-left">
<b>{{ item.name }}</b>
</td>
<td
style="padding: 0 5px;"
:class="'mcr-'+item.status"
>
{{ Util.PF(item.pct, 100, 2) }}
</td>
<td
style="min-width: 100px;"
v-html="item.percentChart"
/>

<td :title="item.coveredTitle">
<span :class="item.coveredClass">{{ Util.NF(item.covered) }}</span>
</td>
<td :title="item.uncoveredTitle">
<span :class="item.uncoveredClass">{{ Util.NF(item.uncovered) }}</span>
</td>
<td :title="item.totalTitle">
{{ Util.NF(item.total) }}
</td>
</tr>
<tr>
<td class="mcr-column-left">
<b>Files</b> <span class="mcr-num">{{ d.files }}</span>
</td>
<td /><td /><td /><td />
</tr>
</tbody>
</table>
<VuiFlex padding="8px">
<a
Expand Down
17 changes: 17 additions & 0 deletions tests/example/example.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,23 @@ test.describe('group', () => {
expect(Util.getDuration(ranges)).toBe(15);
expect(Util.getDuration(ranges, 'exclude-idle')).toBe(13);

ranges = [
{
start: 1,
end: 6
},
{
start: 8,
end: 16
},
{
start: 2,
end: 24
}
];
expect(Util.getDuration(ranges)).toBe(23);
expect(Util.getDuration(ranges, 'exclude-idle')).toBe(23);

});
});

Expand Down

0 comments on commit 079bbd1

Please sign in to comment.