Skip to content

Commit

Permalink
test: flatten tests (#2337)
Browse files Browse the repository at this point in the history
Today, we have tests split into multiple files, with files pulling
tests from some other files.

This patch starts explicitly gathering all tests from the same
`test.js` file.

Drive-By: move one test from `browser.spec.js` into `puppeteer.spec.js`
since it starts browser itself.
  • Loading branch information
aslushnikov committed Apr 9, 2018
1 parent 06d6191 commit 5d106f7
Show file tree
Hide file tree
Showing 9 changed files with 1,750 additions and 1,773 deletions.
40 changes: 1 addition & 39 deletions test/browser.spec.js
Expand Up @@ -14,13 +14,10 @@
* limitations under the License.
*/

const utils = require('./utils.js');

module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, puppeteer}) {
module.exports.addTests = function({testRunner, expect, puppeteer, headless}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
const headless = defaultBrowserOptions.headless;

describe('Browser.version', function() {
it('should return whether we are in headless', async({browser}) => {
Expand Down Expand Up @@ -48,39 +45,4 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p
await remoteBrowser.disconnect();
});
});

describe('Browser.Events.disconnected', function() {
it('should emitted when: browser gets closed, disconnected or underlying websocket gets closed', async() => {
const originalBrowser = await puppeteer.launch(defaultBrowserOptions);
const browserWSEndpoint = originalBrowser.wsEndpoint();
const remoteBrowser1 = await puppeteer.connect({browserWSEndpoint});
const remoteBrowser2 = await puppeteer.connect({browserWSEndpoint});

let disconnectedOriginal = 0;
let disconnectedRemote1 = 0;
let disconnectedRemote2 = 0;
originalBrowser.on('disconnected', () => ++disconnectedOriginal);
remoteBrowser1.on('disconnected', () => ++disconnectedRemote1);
remoteBrowser2.on('disconnected', () => ++disconnectedRemote2);

await Promise.all([
utils.waitEvent(remoteBrowser2, 'disconnected'),
remoteBrowser2.disconnect(),
]);

expect(disconnectedOriginal).toBe(0);
expect(disconnectedRemote1).toBe(0);
expect(disconnectedRemote2).toBe(1);

await Promise.all([
utils.waitEvent(remoteBrowser1, 'disconnected'),
utils.waitEvent(originalBrowser, 'disconnected'),
originalBrowser.close(),
]);

expect(disconnectedOriginal).toBe(1);
expect(disconnectedRemote1).toBe(1);
expect(disconnectedRemote2).toBe(1);
});
});
};
2 changes: 1 addition & 1 deletion test/cookies.spec.js
Expand Up @@ -230,4 +230,4 @@ module.exports.addTests = function({testRunner, expect}) {

});
});
};
};
2 changes: 1 addition & 1 deletion test/coverage.spec.js
Expand Up @@ -176,4 +176,4 @@ module.exports.addTests = function({testRunner, expect}) {
});
});
});
};
};
5 changes: 2 additions & 3 deletions test/input.spec.js
Expand Up @@ -17,11 +17,10 @@
const path = require('path');
const utils = require('./utils');

module.exports.addTests = function({testRunner, expect, PROJECT_ROOT}) {
module.exports.addTests = function({testRunner, expect, DeviceDescriptors}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
const DeviceDescriptors = require(path.join(PROJECT_ROOT, 'DeviceDescriptors'));
const iPhone = DeviceDescriptors['iPhone 6'];
describe('input', function() {
it('should click the button', async({page, server}) => {
Expand Down Expand Up @@ -441,4 +440,4 @@ module.exports.addTests = function({testRunner, expect, PROJECT_ROOT}) {
};
}
});
};
};
2 changes: 1 addition & 1 deletion test/jshandle.spec.js
Expand Up @@ -113,4 +113,4 @@ module.exports.addTests = function({testRunner, expect}) {
expect(aHandle.toString()).toBe('JSHandle@object');
});
});
};
};

0 comments on commit 5d106f7

Please sign in to comment.