Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Dec 17, 2020
1 parent 80da673 commit 2a7a192
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
17 changes: 12 additions & 5 deletions .github/test/inspector-issues-details-uptodate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
'use strict';

const assert = require('assert').strict;
const fs = require('fs');
const fetch = require('node-fetch');

Expand All @@ -24,7 +23,8 @@ describe('issueAdded types', () => {
inspectorIssueDetailsTypes = json.domains
.find(d => d.domain === 'Audits')
.types.find(t => t.id === 'InspectorIssueDetails')
.properties.map(t => t.name);
.properties.map(t => t.name)
.sort();
});

it('should notify us if something changed', () => {
Expand All @@ -40,8 +40,15 @@ describe('issueAdded types', () => {
});

it('are each handled explicitly in the gatherer', () => {
for (const inspectorIssueDetailsType of inspectorIssueDetailsTypes) {
expect(inspectorIssuesGathererSource.includes(inspectorIssueDetailsType)).toBeTruthy();
}
// Regex relies on the typecasts
const sourceTypeMatches = inspectorIssuesGathererSource.matchAll(/LH\.Crdp\.Audits\.(.*?Details)>/g);

const sourceTypeMatchIds = [...sourceTypeMatches]
.map(match => match[1])
// mapping TS type casing (TitleCase) to protocol types (camelCase)
.map(id => `${id.slice(0, 1).toLowerCase()}${id.slice(1)}`)
.sort();

expect(sourceTypeMatchIds).toMatchObject(inspectorIssueDetailsTypes);
});
});
28 changes: 17 additions & 11 deletions .github/test/installability-errors-uptodate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ describe('installabilityErrors', () => {
let chromiumErrorIds;

beforeAll(async () => {
debugger;
const installableLoggingGitTilesUrl =
'https://chromium.googlesource.com/chromium/src/+/master/chrome/browser/installable/installable_logging.cc?format=TEXT';
const base64 = await fetch(installableLoggingGitTilesUrl).then(r => r.text());

let buff = Buffer.from(base64, 'base64');
let text = buff.toString('utf-8');
'https://chromium.googlesource.com/chromium/src/+/master/components/webapps/installable/installable_logging.cc?format=TEXT';
const resp = await fetch(installableLoggingGitTilesUrl);
if (!resp.ok) {
throw new Error(`Chromium source fetch failed: ${resp.status} ${resp.statusText}`);
}
const base64 = await resp.text();
const buff = Buffer.from(base64, 'base64');
const text = buff.toString('utf-8');

// Apply some *beautiful* regexes to parse the C++ of https://chromium.googlesource.com/chromium/src/+/master/chrome/browser/installable/installable_logging.cc
const handledErrorConsts = [...text.matchAll(/error_id = (k.*?);/g)].map(([_, match]) => match);
Expand All @@ -34,11 +38,11 @@ describe('installabilityErrors', () => {
chromiumErrorIds = handledErrorConsts.map(varName => {
if (!errorConstsToIdsDict[varName]) throw new Error(`Error const (${varName}) not found!`);
return errorConstsToIdsDict[varName];
});
}).sort();
});

it('should notify us if something changed', () => {
expect(chromiumErrorIds.sort()).toMatchInlineSnapshot(`
expect(chromiumErrorIds).toMatchInlineSnapshot(`
Array [
"already-installed",
"cannot-download-icon",
Expand All @@ -63,14 +67,16 @@ describe('installabilityErrors', () => {
"prefer-related-applications-only-beta-stable",
"start-url-not-valid",
"url-not-supported-for-webapk",
"warn-not-offline-capable",
]
`);
});

it('are each handled explicitly in the gatherer', () => {
// expect.arrayContaining is semantically great, but the output sucks
for (const chromiumErrorId of chromiumErrorIds) {
expect(Object.keys(InstallableManifestAudit.UIStrings)).toContain(chromiumErrorId);
}
const errorStrings = Object.keys(InstallableManifestAudit.UIStrings)
.filter(key => chromiumErrorIds.includes(key))
.sort();
expect(errorStrings).toEqual(chromiumErrorIds);

});
});
3 changes: 1 addition & 2 deletions .github/workflows/cron-weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ jobs:
node-version: 12.x
- run: yarn --frozen-lockfile

- name: yarn jest .github/test/*-uptodate-test.js
run: yarn jest --testMatch="**/.github/test/**/*-test.js"
- run: yarn jest --testMatch="**/.github/test/**/*-test.js"

0 comments on commit 2a7a192

Please sign in to comment.