Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: remove more mock computed artifacts #6195

Merged
merged 1 commit into from
Oct 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 58 additions & 61 deletions lighthouse-core/test/audits/critical-request-chains-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,105 +10,102 @@
const Runner = require('../../runner.js');
const CriticalRequestChains = require('../../audits/critical-request-chains.js');
const assert = require('assert');
const networkRecordsToDevtoolsLog = require('../network-records-to-devtools-log.js');

const FAILING_REQUEST_CHAIN = {
0: {
request: {
endTime: 1,
responseReceivedTime: 5,
startTime: 0,
const FAILING_CHAIN_RECORDS = [
{
endTime: 5,
responseReceivedTime: 5,
startTime: 0,
url: 'https://example.com/',
priority: 'VeryHigh',
}, {
endTime: 16,
responseReceivedTime: 14,
startTime: 11,
url: 'https://example.com/b.js',
priority: 'VeryHigh',
initiator: {
type: 'parser',
url: 'https://example.com/',
},
children: {
1: {
request: {
endTime: 16,
responseReceivedTime: 14,
startTime: 11,
url: 'https://example.com/b.js',
},
children: {
},
},
2: {
request: {
endTime: 17,
responseReceivedTime: 15,
startTime: 12,
url: 'https://example.com/c.js',
},
children: {},
},
}, {
endTime: 17,
responseReceivedTime: 15,
startTime: 12,
url: 'https://example.com/c.js',
priority: 'VeryHigh',
initiator: {
type: 'parser',
url: 'https://example.com/',
},
},
};
];

const PASSING_REQUEST_CHAIN = {
0: {
request: {
endTime: 1,
responseReceivedTime: 5,
startTime: 0,
url: 'https://example.com/',
},
children: {},
const PASSING_CHAIN_RECORDS = [
{
endTime: 1,
responseReceivedTime: 1,
startTime: 0,
url: 'https://example.com/',
priority: 'VeryHigh',
},
};
];

const PASSING_REQUEST_CHAIN_2 = {
13653.1: {
request: {
url: 'http://localhost:10503/offline-ready.html',
startTime: 33552.036878,
endTime: 33552.285438,
responseReceivedTime: 33552.275677,
transferSize: 1849,
},
children: {},
const PASSING_CHAIN_RECORDS_2 = [
{
url: 'http://localhost:10503/offline-ready.html',
startTime: 33552.036878,
endTime: 33552.285438,
responseReceivedTime: 33552.275677,
transferSize: 1849,
priority: 'VeryHigh',
},
};
];

const EMPTY_CHAIN_RECORDS = [];

const EMPTY_REQUEST_CHAIN = {};
const mockArtifacts = (chainNetworkRecords) => {
const devtoolsLog = networkRecordsToDevtoolsLog(chainNetworkRecords);
const finalUrl = chainNetworkRecords[0] ? chainNetworkRecords[0].url : 'https://example.com';

const mockArtifacts = (mockChain) => {
return Object.assign(Runner.instantiateComputedArtifacts(), {
devtoolsLogs: {
[CriticalRequestChains.DEFAULT_PASS]: [],
},
requestCriticalRequestChains: function() {
return Promise.resolve(mockChain);
[CriticalRequestChains.DEFAULT_PASS]: devtoolsLog,
},
URL: {finalUrl},
});
};

describe('Performance: critical-request-chains audit', () => {
it('calculates the correct chain result for failing example', () => {
return CriticalRequestChains.audit(mockArtifacts(FAILING_REQUEST_CHAIN)).then(output => {
return CriticalRequestChains.audit(mockArtifacts(FAILING_CHAIN_RECORDS)).then(output => {
expect(output.displayValue).toBeDisplayString('2 chains found');
assert.equal(output.rawValue, false);
assert.ok(output.details);
});
});

it('calculates the correct chain result for passing example', () => {
return CriticalRequestChains.audit(mockArtifacts(PASSING_REQUEST_CHAIN)).then(output => {
return CriticalRequestChains.audit(mockArtifacts(PASSING_CHAIN_RECORDS)).then(output => {
assert.equal(output.details.longestChain.duration, 1000);
assert.equal(output.displayValue, '');
assert.equal(output.rawValue, true);
});
});

it('calculates the correct chain result for passing example (no 2.)', () => {
return CriticalRequestChains.audit(mockArtifacts(PASSING_REQUEST_CHAIN_2)).then(output => {
return CriticalRequestChains.audit(mockArtifacts(PASSING_CHAIN_RECORDS_2)).then(output => {
assert.equal(output.displayValue, '');
assert.equal(output.rawValue, true);
});
});

it('calculates the correct chain result for empty example', () => {
return CriticalRequestChains.audit(mockArtifacts(EMPTY_REQUEST_CHAIN)).then(output => {
assert.equal(output.displayValue, '');
assert.equal(output.rawValue, true);
it('throws an error for no main resource found for empty example', () => {
return CriticalRequestChains.audit(mockArtifacts(EMPTY_CHAIN_RECORDS)).then(_ => {
throw new Error('should have failed');
}).catch(err => {
assert.ok(err.message.includes('Unable to identify the main resource'));
});
});
});
15 changes: 0 additions & 15 deletions lighthouse-core/test/audits/metrics/speed-index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,4 @@ describe('Performance: speed-index audit', () => {
assert.equal(result.rawValue, 605);
});
}, 10000);

it('scores speed index of 845 as 100', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test above already tests that a score of 605 yields a passing score. This seemed redundant (and difficult to fake)

const artifacts = {
traces: {},
devtoolsLogs: {},
requestSpeedIndex() {
return Promise.resolve({timing: 845});
},
};

return Audit.audit(artifacts, {options}).then(result => {
assert.equal(result.score, 1);
assert.equal(result.rawValue, 845);
});
});
});
16 changes: 10 additions & 6 deletions lighthouse-core/test/audits/screenshot-thumbnails-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ describe('Screenshot thumbnails', () => {
const artifacts = Object.assign({
traces: {defaultPass: pwaTrace},
}, computedArtifacts);
computedArtifacts.requestInteractive = () => ({timing: 20000});

return ScreenshotThumbnailsAudit.audit(artifacts, {settings, options}).then(results => {
assert.equal(results.details.items[0].timing, 82);
Expand All @@ -93,12 +92,17 @@ describe('Screenshot thumbnails', () => {
});

it('should handle nonsense times', async () => {
const infiniteTrace = JSON.parse(JSON.stringify(pwaTrace));
infiniteTrace.traceEvents.forEach(event => {
if (event.name === 'Screenshot') {
event.ts = Infinity;
}
});

const settings = {throttlingMethod: 'simulate'};
const artifacts = {
traces: {},
requestSpeedline: () => ({frames: [], complete: false, beginning: -1}),
requestInteractive: () => ({timing: NaN}),
};
const artifacts = Object.assign({
traces: {defaultPass: infiniteTrace},
}, computedArtifacts);

try {
await ScreenshotThumbnailsAudit.audit(artifacts, {settings, options: {}});
Expand Down
Loading