Skip to content

Commit

Permalink
feat: add isolation resource error test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoushaw committed Aug 6, 2021
1 parent 37867e2 commit 11725e0
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/// <reference types="cypress" />
import { findMultiAndMatch } from '../common';

describe('monitoring the isolation', () => {
beforeEach(() => {
Cypress.env({
garfishRunConfig: {
basename: '/garfish-app',
},
});
cy.on('uncaught:exception', () => {
return false;
});
cy.visit('http://localhost:2333/garfish-app/react/monitoring');
cy.intercept('POST', '/monitor_browser/collect/batch/', {}).as('post');
});

const MonitoringTitle = 'React sub App Monitoring';

const resourceRequest = (msg) => {
return {
payload: {
url: msg,
},
};
};

const resourcePatch = {
ev_type: 'resource_error',
};

const resourceMessageMap = {
mainJsResource: 'http://localhost:1111/monitoring/xxxxx.js',
subAppJsResource: 'http://localhost:0000/monitoring/xxxxx.js',
};

it('subApp resource error isolation', () => {
cy.window().then((win) => {
cy.contains('[data-test=title]', MonitoringTitle);
cy.get('[data-test=click-resource-error]').click();

findMultiAndMatch(
1,
resourcePatch,
resourceRequest(resourceMessageMap.subAppJsResource),
{
'payload.url': resourceMessageMap.subAppJsResource,
},
);
});
});

it('mainApp resource error isolation', () => {
cy.window().then((win) => {
cy.contains('[data-test=title]', MonitoringTitle);
cy.get('[data-test=main-click-resource-error]').click();

findMultiAndMatch(
1,
resourcePatch,
resourceRequest(resourceMessageMap.mainJsResource),
{
'payload.url': resourceMessageMap.mainJsResource,
},
);
});
});
});
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified cypress/videos/1-the-whole-process/popstate.spec.js.mp4
Binary file not shown.
Binary file modified cypress/videos/1-the-whole-process/visitSubApp.spec.js.mp4
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added cypress/videos/common.js.mp4
Binary file not shown.
1 change: 1 addition & 0 deletions dev/main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ <h3> main App content</h3>
<a data-test="main-click-fetch" onclick="window.fetchM()">fetch</a>
<a data-test="main-click-normal-error" onclick="window.normalError()">error</a>
<a data-test="main-click-unhandledrejection-error" onclick="window.unhandledrejectionError()">unhandledrejectionError</a>
<a data-test="main-click-resource-error" onclick="window.resourceError()">resourceError</a>
<a data-test="main-click-dynamic-resource" onclick="window.DynamicResource()">DynamicResource</a>
</div>
<h2 align="center">
Expand Down
8 changes: 8 additions & 0 deletions dev/main/src/monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ declare global {
unhandledrejectionError: Function;
normalError: Function;
DynamicResource: Function;
resourceError: Function;
}
}

Expand Down Expand Up @@ -47,3 +48,10 @@ window.DynamicResource = function DynamicResource() {
link.href = `http://localhost:${ConfigCommon.mainPort}/monitoring/dynamicLink.css`;
document.body.appendChild(link);
};

window.resourceError = function resourceError() {
// resource error
const sc = document.createElement('script');
sc.src = `http://localhost:1111/monitoring/xxxxx.js`;
document.body.appendChild(sc);
};
17 changes: 17 additions & 0 deletions dev/react/src/components/monitoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ export default function () {
throw Error('subApp: normal error');
}

function resourceError() {
// resource error
const sc = document.createElement('script');
sc.src = `http://localhost:0000/monitoring/xxxxx.js`;
document.body.appendChild(sc);
}

function DynamicResource() {
const sc = document.createElement('script');
sc.src = `http://localhost:${reactPort}/monitoring/dynamicScript.js`;
Expand Down Expand Up @@ -80,6 +87,16 @@ export default function () {
unhandledrejection error
</Button>
<br />
<Button
data-test="click-resource-error"
type="primary"
danger
onClick={() => resourceError()}
style={{ marginBottom: '30px' }}
>
resource error
</Button>
<br />
</div>
);
}
1 change: 1 addition & 0 deletions packages/runtime/browser-vm/src/dynamicNode/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class DynamicNodeProcessor {
event.garfish = true;
Object.defineProperty(event, 'target', { value: this.el });
this.el.dispatchEvent(event);
type === 'error' && window.dispatchEvent(event);
});
}

Expand Down

0 comments on commit 11725e0

Please sign in to comment.