Skip to content

Commit

Permalink
WIP Upgrade dependencies for security issues
Browse files Browse the repository at this point in the history
  • Loading branch information
powerivq committed May 29, 2024
1 parent c7d6eae commit 56ac7ed
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/optimizer/spec/assets/validator.json

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions packages/optimizer/spec/end-to-end/EndToEndSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ const fetch = fetchMock
.mock('https://example.com/amp/rtv/123456789000000/v0.css', '/* example.com v0.css */')
.mock('https://cdn.ampproject.org/v0.css', '/* ampproject.org v0.css */');

const nock = require('nock');
nock('https://cdn.ampproject.org')
.get('/v0/validator.json')
.replyWithFile(200, __dirname + '/../assets/validator.json');
const CACHES_JSON = `{
"caches": [
{
"id": "google",
"name": "Google AMP Cache",
"docs": "https://developers.google.com/amp/cache/",
"updateCacheApiDomainSuffix": "cdn.ampproject.org"
}
]
}`;
nock('https://cdn.ampproject.org').get('/caches.json').reply(200, CACHES_JSON);

createSpec({
name: 'End-to-End: AMP First',
testDir: __dirname,
Expand Down
1 change: 0 additions & 1 deletion packages/optimizer/spec/helpers/validatorInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ let instance = null;
module.exports = {
get: () => {
if (!instance) {
console.error('Validator instance created: ' + path.join(__dirname, 'validator.js'));
instance = validator.getInstance(path.join(__dirname, 'validator.js'));
}
return instance;
Expand Down
21 changes: 9 additions & 12 deletions packages/page-experience/lib/PageDataGatherer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,16 @@ class PageAnalyzer {
throw new Error('Puppeteer not running, please call `start` first.');
}
const {page, remoteStyles, responsePromise} = await this.setupPage();
try {
await page.goto(url, {waitUntil: 'load'});
await page.goto(url, {waitUntil: 'load'});

const response = await responsePromise;
if (!response) {
throw new Error('Failed loading url', url);
}
const {html, headers} = response;
return await this.gatherPageData(page, {remoteStyles, html, headers});
} finally {
if (page) {
page.close();
}
const response = await responsePromise;
if (!response) {
throw new Error('Failed loading url', url);
}
const {html, headers} = response;
const data = await this.gatherPageData(page, {remoteStyles, html, headers});
await page.close();
return data;
}

/**
Expand All @@ -80,6 +76,7 @@ class PageAnalyzer {
async shutdown() {
try {
await this.browser.close();
this.browser = null;
} catch (e) {
console.log(e);
}
Expand Down
9 changes: 9 additions & 0 deletions packages/page-experience/lib/PageExperienceGuide.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@
*/
const fileUrl = require('file-url');
const path = require('path');
const nock = require('nock');
const PageExperienceGuide = require('./PageExperienceGuide');

beforeAll(async () => {
nock('https://cdn.ampproject.org').get('/caches.json').reply(200, '{"caches": []}');
});

afterAll(() => {
nock.cleanAll();
});

test('runs amp linter checks', async () => {
const url = fileUrl(path.join(__dirname, '../test-data/pages/hello-world.html'));
const result = await new PageExperienceGuide().analyze(url);
Expand Down
3 changes: 3 additions & 0 deletions packages/page-experience/tests/Checks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
const fs = require('fs');
const path = require('path');
const nock = require('nock');
const fileUrl = require('file-url');

const PageExperienceGuide = require('../lib/PageExperienceGuide');
Expand All @@ -29,6 +30,7 @@ jest.setTimeout(60000);
beforeAll(async () => {
await pageExperienceGuide.setup();
checks = pageExperienceGuide.loadChecks();
nock('https://cdn.ampproject.org').get('/caches.json').reply(200, '{"caches": []}');
});

describe('Checks', () => {
Expand Down Expand Up @@ -64,4 +66,5 @@ describe('Checks', () => {

afterAll(async () => {
await pageExperienceGuide.teardown();
nock.cleanAll();
});

0 comments on commit 56ac7ed

Please sign in to comment.