Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

chore(tests): Fix sidekick timeouts #686

Merged
merged 2 commits into from
Feb 11, 2021
Merged
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
75 changes: 58 additions & 17 deletions test/unit/sidekick.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ describe('Test sidekick bookmarklet', () => {

const mockCustomPlugins = async (p, js, check = () => true) => {
await p.setRequestInterception(true);
p.on('request', async (req) => {
p.on('request', (req) => {
if (req.url().endsWith('/tools/sidekick/plugins.js')
&& check(req)) {
await req.respond({
req.respond({
status: 200,
body: js || '',
});
Expand Down Expand Up @@ -306,7 +306,8 @@ describe('Test sidekick bookmarklet', () => {
);
}).timeout(IT_DEFAULT_TIMEOUT);

it('Preview plugin opens a new tab with staging lookup URL from gdrive URL', async () => {
// TODO: unskip when https://github.com/puppeteer/puppeteer/issues/3667 is fixed
it.skip('Preview plugin opens a new tab with staging lookup URL from gdrive URL', async () => {
await mockCustomPlugins(page);
await new Promise((resolve, reject) => {
// watch for new browser window
Expand All @@ -330,7 +331,8 @@ describe('Test sidekick bookmarklet', () => {
});
}).timeout(IT_DEFAULT_TIMEOUT);

it('Preview plugin opens a new tab with staging lookup URL from onedrive URL', async () => {
// TODO: unskip when https://github.com/puppeteer/puppeteer/issues/3667 is fixed
it.skip('Preview plugin opens a new tab with staging lookup URL from onedrive URL', async () => {
await mockCustomPlugins(page);
await new Promise((resolve, reject) => {
// watch for new browser window
Expand All @@ -354,8 +356,27 @@ describe('Test sidekick bookmarklet', () => {
});
}).timeout(IT_DEFAULT_TIMEOUT);

it('Preview plugin opens a new tab with staging URL from production URL', async () => {
await mockCustomPlugins(page);
// TODO: unskip when https://github.com/puppeteer/puppeteer/issues/3667 is fixed
it.skip('Preview plugin opens a new tab with staging URL from production URL', async () => {
await page.setRequestInterception(true);

page.on('request', (req) => {
const url = req.url();
if (url.endsWith('/tools/sidekick/plugins.js')) {
req.respond({
status: 200,
body: '',
});
} else if (url.startsWith('https://blog.adobe.com') || url.startsWith('https://theblog--adobe.hlx.page')) {
req.respond({
status: 200,
body: 'dummy html',
});
} else {
req.continue();
}
});

await new Promise((resolve, reject) => {
// watch for new browser window
browser.on('targetcreated', async (target) => {
Expand All @@ -378,7 +399,8 @@ describe('Test sidekick bookmarklet', () => {
});
}).timeout(IT_DEFAULT_TIMEOUT);

it('Edit plugin opens a new tab with editor lookup URL from staging URL', async () => {
// TODO: unskip when https://github.com/puppeteer/puppeteer/issues/3667 is fixed
it.skip('Edit plugin opens a new tab with editor lookup URL from staging URL', async () => {
await mockCustomPlugins(page);
await new Promise((resolve, reject) => {
// watch for new browser window
Expand All @@ -402,7 +424,8 @@ describe('Test sidekick bookmarklet', () => {
});
}).timeout(IT_DEFAULT_TIMEOUT);

it('Edit plugin opens a new tab with editor lookup URL from production URL', async () => {
// TODO: unskip when https://github.com/puppeteer/puppeteer/issues/3667 is fixed
it.skip('Edit plugin opens a new tab with editor lookup URL from production URL', async () => {
await mockCustomPlugins(page);
await new Promise((resolve, reject) => {
// watch for new browser window
Expand Down Expand Up @@ -430,15 +453,20 @@ describe('Test sidekick bookmarklet', () => {
const actionHost = 'https://adobeioruntime.net';
const purgePath = '/en/topics/bla.html';
let purged = false;
await mockCustomPlugins(page);
await page.setRequestInterception(true);
const redirected = await new Promise((resolve, reject) => {
browser.on('targetchanged', (target) => {
if (target.url() === `https://blog.adobe.com${purgePath}`) {
resolve(purged);
}
});
page.on('request', async (req) => {
if (req.url().startsWith(actionHost)) {
page.on('request', (req) => {
if (req.url().endsWith('/tools/sidekick/plugins.js')) {
req.respond({
status: 200,
body: '',
});
} else if (req.url().startsWith(actionHost)) {
// intercept purge request
const params = new URL(req.url()).searchParams;
purged = params.get('path') === purgePath
Expand All @@ -447,6 +475,11 @@ describe('Test sidekick bookmarklet', () => {
status: 200,
body: JSON.stringify([{ status: 'ok' }]),
});
} else if (req.url().startsWith('https://blog.adobe.com')) {
req.respond({
status: 200,
body: 'dummy html',
});
} else {
req.continue();
}
Expand All @@ -469,15 +502,17 @@ describe('Test sidekick bookmarklet', () => {
const allPurged = [];
// open test page and click publish button
await page.goto(`${fixturesPrefix}/publish-staging.html`, { waitUntil: 'load' });
await page.setRequestInterception(true);
page.on('request', (req) => {
if (req.url().startsWith(actionHost)) {
const url = req.url();
if (url.startsWith(actionHost)) {
// intercept purge requests
allPurged.push(new URL(req.url()).searchParams.get('path'));
allPurged.push(new URL(url).searchParams.get('path'));
req.respond({
status: 200,
body: JSON.stringify([{ status: 'ok' }]),
});
} else if (req.url().startsWith('https://blog.adobe.com/')) {
} else if (url.startsWith('https://blog.adobe.com/')) {
// intercept redirect
req.respond({ status: 200, body: '' });
} else {
Expand All @@ -501,6 +536,7 @@ describe('Test sidekick bookmarklet', () => {
const actionHost = 'https://adobeioruntime.net';
const purgePath = '/en/topics/foo.html';
let purged = false;
await page.setRequestInterception(true);
await new Promise((resolve, reject) => {
page.on('request', async (req) => {
// intercept purge request
Expand Down Expand Up @@ -537,11 +573,16 @@ describe('Test sidekick bookmarklet', () => {

it('Publish plugin does not purge without production host', async () => {
const actionHost = 'https://adobeioruntime.net';
await mockCustomPlugins(page);
await page.setRequestInterception(true);
const noPurge = await new Promise((resolve) => {
page.on('request', async (req) => {
// intercept purge request
if (req.url().startsWith(actionHost)) {
if (req.url().endsWith('/tools/sidekick/plugins.js')) {
req.respond({
status: 200,
body: '',
});
} else if (req.url().startsWith(actionHost)) {
// intercept purge request
req.respond({
status: 200,
body: JSON.stringify([{ status: 'ok' }]),
Expand Down