Skip to content

Commit

Permalink
cover more tests in 3p facades
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Jun 4, 2024
1 parent 7f85f19 commit 6ccb990
Showing 1 changed file with 54 additions and 34 deletions.
88 changes: 54 additions & 34 deletions core/test/audits/third-party-facades-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,17 @@ function youtubeResourceUrl(id) {
return `https://i.ytimg.com/${id}/maxresdefault.jpg`;
}
describe('Third party facades audit', () => {
// TODO(15841): traces needs updating.
if (process.env.INTERNAL_LANTERN_USE_TRACE !== undefined) {
return;
}

it('correctly identifies a third party product with facade alternative', async () => {
const networkRecords = [
{transferSize: 2000, url: 'https://example.com', priority: 'High'},
{transferSize: 4000, url: intercomProductUrl('1')},
{transferSize: 8000, url: intercomResourceUrl('a')},
];
const artifacts = {
devtoolsLogs: {
defaultPass: networkRecordsToDevtoolsLog([
{transferSize: 2000, url: 'https://example.com', priority: 'High'},
{transferSize: 4000, url: intercomProductUrl('1')},
{transferSize: 8000, url: intercomResourceUrl('a')},
]),
defaultPass: networkRecordsToDevtoolsLog(networkRecords),
},
traces: {defaultPass: createTestTrace({timeOrigin: 0, traceEnd: 2000})},
traces: {defaultPass: createTestTrace({timeOrigin: 0, traceEnd: 2000, networkRecords})},
URL: {
requestedUrl: 'https://example.com',
mainDocumentUrl: 'https://example.com',
Expand Down Expand Up @@ -91,17 +87,18 @@ describe('Third party facades audit', () => {
});

it('handles multiple products with facades', async () => {
const networkRecords = [
{transferSize: 2000, url: 'https://example.com', priority: 'High'},
{transferSize: 4000, url: intercomProductUrl('1')},
{transferSize: 3000, url: youtubeProductUrl('2')},
{transferSize: 8000, url: intercomResourceUrl('a')},
{transferSize: 7000, url: youtubeResourceUrl('b')},
];
const artifacts = {
devtoolsLogs: {
defaultPass: networkRecordsToDevtoolsLog([
{transferSize: 2000, url: 'https://example.com', priority: 'High'},
{transferSize: 4000, url: intercomProductUrl('1')},
{transferSize: 3000, url: youtubeProductUrl('2')},
{transferSize: 8000, url: intercomResourceUrl('a')},
{transferSize: 7000, url: youtubeResourceUrl('b')},
]),
defaultPass: networkRecordsToDevtoolsLog(networkRecords),
},
traces: {defaultPass: createTestTrace({timeOrigin: 0, traceEnd: 2000})},
traces: {defaultPass: createTestTrace({timeOrigin: 0, traceEnd: 2000, networkRecords})},
URL: {
requestedUrl: 'https://example.com',
mainDocumentUrl: 'https://example.com',
Expand Down Expand Up @@ -167,16 +164,17 @@ describe('Third party facades audit', () => {
});

it('handle multiple requests to same product resource', async () => {
const networkRecords = [
{transferSize: 2000, url: 'https://example.com', priority: 'High'},
{transferSize: 2000, url: intercomProductUrl('1')},
{transferSize: 8000, url: intercomResourceUrl('a')},
{transferSize: 2000, url: intercomProductUrl('1')},
];
const artifacts = {
devtoolsLogs: {
defaultPass: networkRecordsToDevtoolsLog([
{transferSize: 2000, url: 'https://example.com', priority: 'High'},
{transferSize: 2000, url: intercomProductUrl('1')},
{transferSize: 8000, url: intercomResourceUrl('a')},
{transferSize: 2000, url: intercomProductUrl('1')},
]),
defaultPass: networkRecordsToDevtoolsLog(networkRecords),
},
traces: {defaultPass: createTestTrace({timeOrigin: 0, traceEnd: 2000})},
traces: {defaultPass: createTestTrace({timeOrigin: 0, traceEnd: 2000, networkRecords})},
URL: {
requestedUrl: 'https://example.com',
mainDocumentUrl: 'https://example.com',
Expand Down Expand Up @@ -219,14 +217,15 @@ describe('Third party facades audit', () => {
});

it('does not report first party resources', async () => {
const networkRecords = [
{transferSize: 2000, url: 'https://intercomcdn.com', priority: 'High'},
{transferSize: 4000, url: intercomProductUrl('1')},
];
const artifacts = {
devtoolsLogs: {
defaultPass: networkRecordsToDevtoolsLog([
{transferSize: 2000, url: 'https://intercomcdn.com', priority: 'High'},
{transferSize: 4000, url: intercomProductUrl('1')},
]),
defaultPass: networkRecordsToDevtoolsLog(networkRecords),
},
traces: {defaultPass: createTestTrace({timeOrigin: 0, traceEnd: 2000})},
traces: {defaultPass: createTestTrace({timeOrigin: 0, traceEnd: 2000, networkRecords})},
URL: {
requestedUrl: 'https://intercomcdn.com',
mainDocumentUrl: 'https://intercomcdn.com',
Expand All @@ -246,6 +245,11 @@ describe('Third party facades audit', () => {
});

it('only reports resources which have facade alternatives', async () => {
// TODO(15841): traces needs updating.
if (process.env.INTERNAL_LANTERN_USE_TRACE !== undefined) {
return;
}

const artifacts = {
// This devtools log has third party requests but none have facades
devtoolsLogs: {defaultPass: pwaDevtoolsLog},
Expand All @@ -265,11 +269,17 @@ describe('Third party facades audit', () => {
});

it('not applicable when no third party resources are present', async () => {
// TODO(15841): traces needs updating.
if (process.env.INTERNAL_LANTERN_USE_TRACE !== undefined) {
return;
}

const networkRecords = [
{transferSize: 2000, url: 'https://example.com', priority: 'High'},
];
const artifacts = {
devtoolsLogs: {
defaultPass: networkRecordsToDevtoolsLog([
{transferSize: 2000, url: 'https://example.com', priority: 'High'},
]),
defaultPass: networkRecordsToDevtoolsLog(networkRecords),
},
traces: {defaultPass: noThirdPartyTrace},
URL: {
Expand All @@ -291,6 +301,11 @@ describe('Third party facades audit', () => {
});

it('handles real trace', async () => {
// TODO(15841): traces needs updating.
if (process.env.INTERNAL_LANTERN_USE_TRACE !== undefined) {
return;
}

const artifacts = {
devtoolsLogs: {defaultPass: videoEmbedsDevtolsLog},
traces: {defaultPass: videoEmbedsTrace},
Expand Down Expand Up @@ -439,6 +454,11 @@ Array [
});

it('handles real trace that blocks the main thread', async () => {
// TODO(15841): traces needs updating.
if (process.env.INTERNAL_LANTERN_USE_TRACE !== undefined) {
return;
}

const artifacts = {
devtoolsLogs: {defaultPass: blockingWidgetDevtoolsLog},
traces: {defaultPass: blockingWidgetTrace},
Expand Down

0 comments on commit 6ccb990

Please sign in to comment.