Skip to content

Commit

Permalink
test(firefox): add puppeteer-firefox unique evaluation tests (#3891)
Browse files Browse the repository at this point in the history
References #3889
  • Loading branch information
aslushnikov committed Feb 2, 2019
1 parent 6bb0350 commit b5e53fd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion experimental/puppeteer-firefox/test/evaluation.spec.js
Expand Up @@ -132,7 +132,7 @@ module.exports.addTests = function({testRunner, expect, product}) {
await page.goto(server.PREFIX + '/global-var.html');
expect(await page.evaluate('globalVar')).toBe(123);
});
it('should use the same sandbox', async({page}) => {
it('should modify global environment', async({page}) => {
await page.evaluate(() => window.globalVar = 123);
expect(await page.evaluate('globalVar')).toBe(123);
});
Expand Down
3 changes: 3 additions & 0 deletions test/assets/global-var.html
@@ -0,0 +1,3 @@
<script>
var globalVar = 123;
</script>
43 changes: 42 additions & 1 deletion test/evaluation.spec.js
Expand Up @@ -23,7 +23,7 @@ try {
asyncawait = false;
}

module.exports.addTests = function({testRunner, expect}) {
module.exports.addTests = function({testRunner, expect, FFOX}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
Expand All @@ -33,6 +33,41 @@ module.exports.addTests = function({testRunner, expect}) {
const result = await page.evaluate(() => 7 * 3);
expect(result).toBe(21);
});
it('should transfer NaN', async({page, server}) => {
const result = await page.evaluate(a => a, NaN);
expect(Object.is(result, NaN)).toBe(true);
});
it('should transfer -0', async({page, server}) => {
const result = await page.evaluate(a => a, -0);
expect(Object.is(result, -0)).toBe(true);
});
it('should transfer Infinity', async({page, server}) => {
const result = await page.evaluate(a => a, Infinity);
expect(Object.is(result, Infinity)).toBe(true);
});
it('should transfer -Infinity', async({page, server}) => {
const result = await page.evaluate(a => a, -Infinity);
expect(Object.is(result, -Infinity)).toBe(true);
});
it('should transfer arrays', async({page, server}) => {
const result = await page.evaluate(a => a, [1, 2, 3]);
expect(result).toEqual([1,2,3]);
});
it('should transfer arrays as arrays, not objects', async({page, server}) => {
const result = await page.evaluate(a => Array.isArray(a), [1, 2, 3]);
expect(result).toBe(true);
});
it('should modify global environment', async({page}) => {
await page.evaluate(() => window.globalVar = 123);
expect(await page.evaluate('globalVar')).toBe(123);
});
it('should evaluate in the page context', async({page, server}) => {
await page.goto(server.PREFIX + '/global-var.html');
expect(await page.evaluate('globalVar')).toBe(123);
});
(FFOX ? xit : it)('should return undefined for objects with symbols', async({page, server}) => {
expect(await page.evaluate(() => [Symbol('foo4')])).toBe(undefined);
});
(asyncawait ? it : xit)('should work with function shorthands', async({page, server}) => {
// trick node6 transpiler to not touch our object.
// TODO(lushnikov): remove eval once Node6 is dropped.
Expand Down Expand Up @@ -227,6 +262,12 @@ module.exports.addTests = function({testRunner, expect}) {
expect(await page.frames()[0].evaluate(() => window.FOO)).toBe('foo');
expect(await page.frames()[1].evaluate(() => window.FOO)).toBe('bar');
});
it('should have correct execution contexts', async({page, server}) => {
await page.goto(server.PREFIX + '/frames/one-frame.html');
expect(page.frames().length).toBe(2);
expect(await page.frames()[0].evaluate(() => document.body.textContent.trim())).toBe('');
expect(await page.frames()[1].evaluate(() => document.body.textContent.trim())).toBe(`Hi, I'm frame`);
});
it('should execute after cross-site navigation', async({page, server}) => {
await page.goto(server.EMPTY_PAGE);
const mainFrame = page.mainFrame();
Expand Down

0 comments on commit b5e53fd

Please sign in to comment.