Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtao25 committed Dec 20, 2024
1 parent 343aa64 commit 1c87336
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 8 additions & 7 deletions tools/canyon-extension/public/interceptor.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// const __canyon__ = ((window.__canyon__||(Object.keys(window.__coverage__||{}).length>0 ? Object.values(window.__coverage__)[0] : undefined))||(Object.keys(window.__coverage__||{}).length>0 ? Object.values(window.__coverage__)[0] : undefined));
window.addEventListener('message', function (e) {
if (e.data.type === '__canyon__event_get_coverage_and_canyon_data_request') {
// 新增逻辑,获取覆盖率数据的时候还可以set reportID,key定为__canyon__report__id__
Expand All @@ -15,10 +16,10 @@ window.addEventListener('message', function (e) {
type: '__canyon__event_get_coverage_and_canyon_data_response',
payload: {
canyon: {
...window.__canyon__,
...(window.__canyon__||(Object.keys(window.__coverage__||{}).length>0 ? Object.values(window.__coverage__)[0] : undefined)),
reportID: localStorage.getItem('__canyon__report__id__') || undefined,
intervalTime: localStorage.getItem('__canyon__interval__time__') || window.__canyon__?.intervalTime,
reporter: localStorage.getItem('__canyon__reporter__') || window.__canyon__?.reporter,
intervalTime: localStorage.getItem('__canyon__interval__time__') || (window.__canyon__||(Object.keys(window.__coverage__||{}).length>0 ? Object.values(window.__coverage__)[0] : undefined))?.intervalTime,
reporter: localStorage.getItem('__canyon__reporter__') || (window.__canyon__||(Object.keys(window.__coverage__||{}).length>0 ? Object.values(window.__coverage__)[0] : undefined))?.reporter,
},
coverage: window.__coverage__,
},
Expand All @@ -36,16 +37,16 @@ setTimeout(()=>{
const num = __canyon__interval__time__;
if (num > 0) {
setInterval(() => {
if (window.__canyon__ && window.__coverage__) {
fetch(window.__canyon__.dsn, {
if ((window.__canyon__||(Object.keys(window.__coverage__||{}).length>0 ? Object.values(window.__coverage__)[0] : undefined)) && window.__coverage__) {
fetch((window.__canyon__||(Object.keys(window.__coverage__||{}).length>0 ? Object.values(window.__coverage__)[0] : undefined)).dsn, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${window.__canyon__.reporter}`,
Authorization: `Bearer ${(window.__canyon__||(Object.keys(window.__coverage__||{}).length>0 ? Object.values(window.__coverage__)[0] : undefined)).reporter}`,
},
body: JSON.stringify({
coverage: window.__coverage__,
...window.__canyon__,
...(window.__canyon__||(Object.keys(window.__coverage__||{}).length>0 ? Object.values(window.__coverage__)[0] : undefined)),
reportID: localStorage.getItem('__canyon__report__id__') || undefined,
}),
}).then(() => {
Expand Down
6 changes: 3 additions & 3 deletions tools/canyon-extension/src/components/app/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const AppMain = () => {
const {
data: { canyon, coverage } = {
canyon: {
commitSha: '-',
sha: '-',
projectID: '-',
branch: '-',
dsn: '-',
Expand Down Expand Up @@ -119,7 +119,7 @@ const AppMain = () => {
<Spin spinning={loading}>
<Space direction={'vertical'}>
<AppDataLayout label={'Project ID'} value={canyon.projectID} />
<AppDataLayout label={'Commit Sha'} value={canyon.commitSha} />
<AppDataLayout label={'Commit Sha'} value={canyon.sha} />
<AppDataLayout label={'Branch'} value={canyon.branch} />
<AppDataLayout label={'DSN'} value={canyon.dsn} />
<AppDataLayout
Expand All @@ -128,7 +128,7 @@ const AppMain = () => {
<div>
<a
onClick={() => {
downJson(JSON.stringify(coverage), canyon.projectID + '-' + canyon.commitSha);
downJson(JSON.stringify(coverage), canyon.projectID + '-' + canyon.sha);
}}
>
{Object.keys(coverage).length}
Expand Down

0 comments on commit 1c87336

Please sign in to comment.