test: cleanup page.waitForRequest/page.waitForResponse tests (#2880)

This patch removes unnecessary regexp tests and unifies all tests
between each other.
This commit is contained in:
Andrey Lushnikov 2018-07-12 15:32:18 -07:00 committed by GitHub
parent 726c8dc046
commit 66fa0d3d53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -790,39 +790,38 @@ module.exports.addTests = function({testRunner, expect, puppeteer, DeviceDescrip
it('should work', async({page, server}) => { it('should work', async({page, server}) => {
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
const [request] = await Promise.all([ const [request] = await Promise.all([
page.waitForRequest(server.PREFIX + '/404'), page.waitForRequest(server.PREFIX + '/digits/2.png'),
page.evaluate(() => fetch('/404', {method: 'GET'})) page.evaluate(() => {
fetch('/digits/1.png');
fetch('/digits/2.png');
fetch('/digits/3.png');
})
]); ]);
expect(request.method()).toBe('GET'); expect(request.url()).toBe(server.PREFIX + '/digits/2.png');
expect(request.url()).toBe(server.PREFIX + '/404');
});
it('should work with regex pattern', async({page, server}) => {
await page.goto(server.EMPTY_PAGE);
const [request] = await Promise.all([
page.waitForRequest(request => new RegExp(`${server.PREFIX}/(200|404)`).test(request.url())),
page.evaluate(() => fetch('/404', {method: 'GET'}))
]);
expect(request.method()).toBe('GET');
expect(request.url()).toBe(server.PREFIX + '/404');
}); });
it('should work with predicate', async({page, server}) => { it('should work with predicate', async({page, server}) => {
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
const [request] = await Promise.all([ const [request] = await Promise.all([
page.waitForRequest(request => request.url() === server.PREFIX + '/404' && request.method() === 'PATCH'), page.waitForRequest(request => request.url() === server.PREFIX + '/digits/2.png'),
page.evaluate(() => fetch('/404', {method: 'PATCH'})) page.evaluate(() => {
fetch('/digits/1.png');
fetch('/digits/2.png');
fetch('/digits/3.png');
})
]); ]);
expect(request.method()).toBe('PATCH'); expect(request.url()).toBe(server.PREFIX + '/digits/2.png');
expect(request.url()).toBe(server.PREFIX + '/404');
}); });
it('should work with no timeout', async({page, server}) => { it('should work with no timeout', async({page, server}) => {
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
const [request] = await Promise.all([ const [request] = await Promise.all([
page.waitForRequest(server.PREFIX + '/404', { timeout: 0}), page.waitForRequest(server.PREFIX + '/digits/2.png', {timeout: 0}),
page.waitFor(50), page.evaluate(() => setTimeout(() => {
page.evaluate(() => fetch('/404', {method: 'GET'})) fetch('/digits/1.png');
fetch('/digits/2.png');
fetch('/digits/3.png');
}, 50))
]); ]);
expect(request.method()).toBe('GET'); expect(request.url()).toBe(server.PREFIX + '/digits/2.png');
expect(request.url()).toBe(server.PREFIX + '/404');
}); });
}); });
@ -830,42 +829,38 @@ module.exports.addTests = function({testRunner, expect, puppeteer, DeviceDescrip
it('should work', async({page, server}) => { it('should work', async({page, server}) => {
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
const [response] = await Promise.all([ const [response] = await Promise.all([
page.waitForResponse(server.PREFIX + '/grid.html'), page.waitForResponse(server.PREFIX + '/digits/2.png'),
page.waitFor(100), page.evaluate(() => {
page.evaluate(() => fetch('/grid.html', {method: 'GET'})) fetch('/digits/1.png');
fetch('/digits/2.png');
fetch('/digits/3.png');
})
]); ]);
expect(response.ok()).toBe(true); expect(response.url()).toBe(server.PREFIX + '/digits/2.png');
expect(response.url()).toBe(server.PREFIX + '/grid.html');
});
it('should work with regex', async({page, server}) => {
await page.goto(server.EMPTY_PAGE);
const [response] = await Promise.all([
page.waitForResponse(response => new RegExp(`${server.PREFIX}/(get|grid.html)`).test(response.url())),
page.waitFor(100),
page.evaluate(() => fetch('/grid.html', {method: 'GET'}))
]);
expect(response.ok()).toBe(true);
expect(response.url()).toBe(server.PREFIX + '/grid.html');
}); });
it('should work with predicate', async({page, server}) => { it('should work with predicate', async({page, server}) => {
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
const [response] = await Promise.all([ const [response] = await Promise.all([
page.waitForResponse(response => response.url() === server.PREFIX + '/grid.html' && response.status() === 200), page.waitForResponse(response => response.url() === server.PREFIX + '/digits/2.png'),
page.waitFor(100), page.evaluate(() => {
page.evaluate(() => fetch('/grid.html', {method: 'PATCH'})) fetch('/digits/1.png');
fetch('/digits/2.png');
fetch('/digits/3.png');
})
]); ]);
expect(response.ok()).toBe(true); expect(response.url()).toBe(server.PREFIX + '/digits/2.png');
expect(response.url()).toBe(server.PREFIX + '/grid.html');
}); });
it('should work with no timeout', async({page, server}) => { it('should work with no timeout', async({page, server}) => {
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
const [response] = await Promise.all([ const [response] = await Promise.all([
page.waitForResponse(server.PREFIX + '/grid.html', { timeout: 0}), page.waitForResponse(server.PREFIX + '/digits/2.png', {timeout: 0}),
page.waitFor(50), page.evaluate(() => setTimeout(() => {
page.evaluate(() => fetch('/grid.html', {method: 'GET'})) fetch('/digits/1.png');
fetch('/digits/2.png');
fetch('/digits/3.png');
}, 50))
]); ]);
expect(response.ok()).toBe(true); expect(response.url()).toBe(server.PREFIX + '/digits/2.png');
expect(response.url()).toBe(server.PREFIX + '/grid.html');
}); });
}); });