test: test puppeteer-utils using `httpbingo.org` (#11987)

This commit is contained in:
Tony 2023-02-28 07:40:30 -11:00 committed by GitHub
parent 992ab44a3a
commit 6002eb6e11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 11 deletions

View File

@ -65,28 +65,28 @@ describe('puppeteer-utils', () => {
});
});
it('getCookies httpbin', async () => {
it('getCookies httpbingo', async () => {
puppeteer = require('../../lib/utils/puppeteer');
browser = await puppeteer();
const page = await browser.newPage();
await page.goto('https://httpbin.org/cookies/set?foo=bar&baz=qux', {
await page.goto('https://httpbingo.org/cookies/set?foo=bar&baz=qux', {
waitUntil: 'domcontentloaded',
});
expect((await getCookies(page, 'httpbin.org')).split('; ').sort()).toEqual(['foo=bar', 'baz=qux'].sort());
}, 10000);
expect((await getCookies(page, 'httpbingo.org')).split('; ').sort()).toEqual(['foo=bar', 'baz=qux'].sort());
}, 15000);
it('setCookies httpbin', async () => {
it('setCookies httpbingo', async () => {
puppeteer = require('../../lib/utils/puppeteer');
browser = await puppeteer();
const page = await browser.newPage();
// httpbin.org cannot recognize cookies with empty name properly, so we cannot use cookieStrAll here
await setCookies(page, cookieStrExampleCom, 'httpbin.org');
await page.goto('https://httpbin.org/cookies', {
// httpbingo.org cannot recognize cookies with empty name properly, so we cannot use cookieStrAll here
await setCookies(page, cookieStrExampleCom, 'httpbingo.org');
await page.goto('https://httpbingo.org/cookies', {
waitUntil: 'domcontentloaded',
});
const data = await page.evaluate(() => JSON.parse(document.body.innerText));
expect(data.cookies).toEqual(Object.fromEntries(cookieArrayExampleCom.map(({ name, value }) => [name, value])));
}, 10000);
expect(data).toEqual(Object.fromEntries(cookieArrayExampleCom.map(({ name, value }) => [name, value])));
}, 15000);
it('setCookies & getCookies example.org', async () => {
puppeteer = require('../../lib/utils/puppeteer');
@ -98,5 +98,5 @@ describe('puppeteer-utils', () => {
waitUntil: 'domcontentloaded',
});
expect((await getCookies(page, 'example.org')).split('; ').sort()).toEqual(cookieStrAll.split('; ').sort());
}, 10000);
}, 15000);
});