Skip to content

Commit

Permalink
chore(tests): add types for tests (#915)
Browse files Browse the repository at this point in the history
I enabled vscode autocomplete in our test files. Typechecking had too many errors to enable, but it caught some real bugs that I will fix in a follow up.

This patch contains:
* `test/types.d.ts` - d.ts file for our test runner.
* `test/tsconfig.json` - typescript project for our tests.
* JSDoc header in all specs to mark the describe as a TestSuite
* Drive-by fix of a launcher test that was using `if` instead of `it`
* Some drive-by fixes of unimpactful typos in tests.
  • Loading branch information
JoelEinbinder committed Feb 10, 2020
1 parent 9da0229 commit c03e8b7
Show file tree
Hide file tree
Showing 45 changed files with 246 additions and 6 deletions.
3 changes: 3 additions & 0 deletions test/accessibility.spec.js
Expand Up @@ -15,6 +15,9 @@
* limitations under the License.
*/

/**
* @type {PageTestSuite}
*/
module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT, MAC}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/browser.spec.js
Expand Up @@ -16,6 +16,9 @@

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

/**
* @type {BrowserTestSuite}
*/
module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/browsercontext.spec.js
Expand Up @@ -17,6 +17,9 @@

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

/**
* @type {BrowserTestSuite}
*/
module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/capabilities.spec.js
Expand Up @@ -17,6 +17,9 @@
const utils = require('./utils');
const { waitEvent } = utils;

/**
* @type {PageTestSuite}
*/
module.exports.describe = function({testRunner, expect, WIN, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/chromium/chromium.spec.js
Expand Up @@ -16,6 +16,9 @@

const { waitEvent } = require('../utils');

/**
* @type {ChromiumTestSuite}
*/
module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/chromium/coverage.spec.js
Expand Up @@ -14,6 +14,9 @@
* limitations under the License.
*/

/**
* @type {ChromiumTestSuite}
*/
module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/chromium/headful.spec.js
Expand Up @@ -24,6 +24,9 @@ const mkdtempAsync = util.promisify(fs.mkdtemp);

const TMP_FOLDER = path.join(os.tmpdir(), 'pw_tmp_folder-');

/**
* @type {TestSuite}
*/
module.exports.describe = function({testRunner, expect, playwright, defaultBrowserOptions, FFOX, CHROMIUM, WEBKIT, WIN}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/chromium/launcher.spec.js
Expand Up @@ -25,6 +25,9 @@ const statAsync = util.promisify(fs.stat);

const TMP_FOLDER = path.join(os.tmpdir(), 'pw_tmp_folder-');

/**
* @type {TestSuite}
*/
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, WIN}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/chromium/oopif.spec.js
Expand Up @@ -14,6 +14,9 @@
* limitations under the License.
*/

/**
* @type {ChromiumTestSuite}
*/
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/chromium/pdf.spec.js
Expand Up @@ -17,6 +17,9 @@
const fs = require('fs');
const path = require('path');

/**
* @type {ChromiumTestSuite}
*/
module.exports.describe = function({testRunner, expect, headless, ASSETS_DIR}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/chromium/session.spec.js
Expand Up @@ -16,6 +16,9 @@

const { waitEvent } = require('../utils');

/**
* @type {ChromiumTestSuite}
*/
module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/chromium/tracing.spec.js
Expand Up @@ -17,6 +17,9 @@
const fs = require('fs');
const path = require('path');

/**
* @type {ChromiumTestSuite}
*/
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, ASSETS_DIR}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/click.spec.js
Expand Up @@ -17,6 +17,9 @@

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

/**
* @type {PageTestSuite}
*/
module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/cookies.spec.js
Expand Up @@ -15,6 +15,9 @@
* limitations under the License.
*/

/**
* @type {PageTestSuite}
*/
module.exports.describe = function({testRunner, expect, playwright, defaultBrowserOptions, MAC, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/defaultbrowsercontext.spec.js
Expand Up @@ -17,6 +17,9 @@

const { makeUserDataDir, removeUserDataDir } = require('./utils');

/**
* @type {PageTestSuite}
*/
module.exports.describe = function ({ testRunner, expect, defaultBrowserOptions, playwright }) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/dialog.spec.js
Expand Up @@ -15,6 +15,9 @@
* limitations under the License.
*/

/**
* @type {PageTestSuite}
*/
module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/elementhandle.spec.js
Expand Up @@ -17,6 +17,9 @@

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

/**
* @type {PageTestSuite}
*/
module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/emulation.spec.js
Expand Up @@ -15,6 +15,9 @@
* limitations under the License.
*/

/**
* @type {PageTestSuite}
*/
module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/evaluation.spec.js
Expand Up @@ -19,6 +19,9 @@ const utils = require('./utils');

const bigint = typeof BigInt !== 'undefined';

/**
* @type {PageTestSuite}
*/
module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/features/permissions.spec.js
Expand Up @@ -18,6 +18,9 @@
const fs = require('fs');
const path = require('path');

/**
* @type {PageTestSuite}
*/
module.exports.describe = function({testRunner, expect, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures.spec.js
Expand Up @@ -18,6 +18,9 @@
const path = require('path');
const {spawn, execSync} = require('child_process');

/**
* @type {TestSuite}
*/
module.exports.describe = function({testRunner, expect, product, playwright, playwrightPath, defaultBrowserOptions, WIN, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/frame.spec.js
Expand Up @@ -17,6 +17,9 @@

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

/**
* @type {PageTestSuite}
*/
module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/geolocation.spec.js
Expand Up @@ -15,6 +15,9 @@
* limitations under the License.
*/

/**
* @type {PageTestSuite}
*/
module.exports.describe = function ({ testRunner, expect, FFOX, WEBKIT }) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/headful.spec.js
Expand Up @@ -16,6 +16,9 @@

const { makeUserDataDir, removeUserDataDir } = require('./utils');

/**
* @type {TestSuite}
*/
module.exports.describe = function({testRunner, expect, playwright, defaultBrowserOptions, FFOX, CHROMIUM, WEBKIT, WIN}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/ignorehttpserrors.spec.js
Expand Up @@ -15,6 +15,9 @@
* limitations under the License.
*/

/**
* @type {BrowserTestSuite}
*/
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/input.spec.js
Expand Up @@ -21,6 +21,9 @@ const formidable = require('formidable');

const FILE_TO_UPLOAD = path.join(__dirname, '/assets/file-to-upload.txt');

/**
* @type {PageTestSuite}
*/
module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/interception.spec.js
Expand Up @@ -20,6 +20,9 @@ const path = require('path');
const { helper } = require('../lib/helper');
const utils = require('./utils');

/**
* @type {PageTestSuite}
*/
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/jshandle.spec.js
Expand Up @@ -15,6 +15,9 @@
* limitations under the License.
*/

/**
* @type {PageTestSuite}
*/
module.exports.describe = function({testRunner, expect, CHROMIUM, FFOX, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/keyboard.spec.js
Expand Up @@ -18,6 +18,9 @@
const utils = require('./utils');
const os = require('os');

/**
* @type {PageTestSuite}
*/
module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT, MAC}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
7 changes: 5 additions & 2 deletions test/launcher.spec.js
Expand Up @@ -20,6 +20,9 @@ const fs = require('fs');
const utils = require('./utils');
const { makeUserDataDir, removeUserDataDir } = require('./utils');

/**
* @type {TestSuite}
*/
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, playwrightPath, product, CHROMIUM, FFOX, WEBKIT, WIN}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand All @@ -42,7 +45,7 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
await playwright.launch(options).catch(e => waitError = e);
expect(waitError.message).toContain('Failed to launch');
});
if('should have default URL when launching browser', async function() {
it('should have default URL when launching browser', async function() {
const userDataDir = await makeUserDataDir();
const browserContext = await playwright.launchPersistent(userDataDir, defaultBrowserOptions);
const pages = (await browserContext.pages()).map(page => page.url());
Expand Down Expand Up @@ -172,7 +175,7 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
});

describe('Browser.close', function() {
it('should terminate network waiters', async({context, server}) => {
it('should terminate network waiters', async({server}) => {
const browserServer = await playwright.launchServer({...defaultBrowserOptions });
const remote = await playwright.connect({ wsEndpoint: browserServer.wsEndpoint() });
const newPage = await remote.newPage();
Expand Down
3 changes: 3 additions & 0 deletions test/mouse.spec.js
Expand Up @@ -26,6 +26,9 @@ function dimensions() {
};
}

/**
* @type {PageTestSuite}
*/
module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT, MAC}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/multiclient.spec.js
Expand Up @@ -17,6 +17,9 @@

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

/**
* @type {TestSuite}
*/
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/navigation.spec.js
Expand Up @@ -18,6 +18,9 @@
const utils = require('./utils');
const { performance } = require('perf_hooks');

/**
* @type {PageTestSuite}
*/
module.exports.describe = function({testRunner, expect, playwright, MAC, WIN, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/network.spec.js
Expand Up @@ -19,6 +19,9 @@ const fs = require('fs');
const path = require('path');
const utils = require('./utils');

/**
* @type {PageTestSuite}
*/
module.exports.describe = function({testRunner, expect, MAC, WIN, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/page.spec.js
Expand Up @@ -19,6 +19,9 @@ const path = require('path');
const utils = require('./utils');
const {waitEvent} = utils;

/**
* @type {PageTestSuite}
*/
module.exports.describe = function({testRunner, expect, headless, playwright, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
3 changes: 3 additions & 0 deletions test/playwright.spec.js
Expand Up @@ -24,6 +24,9 @@ const {Matchers} = require('../utils/testrunner/');
const YELLOW_COLOR = '\x1b[33m';
const RESET_COLOR = '\x1b[0m';

/**
* @type {TestSuite}
*/
module.exports.describe = ({testRunner, product, playwrightPath}) => {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down
5 changes: 4 additions & 1 deletion test/queryselector.spec.js
Expand Up @@ -17,6 +17,9 @@

const zsSelectorEngineSource = require('../lib/generated/zsSelectorEngineSource');

/**
* @type {PageTestSuite}
*/
module.exports.describe = function({testRunner, expect, selectors, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
Expand Down Expand Up @@ -236,7 +239,7 @@ module.exports.describe = function({testRunner, expect, selectors, FFOX, CHROMIU
const element = await page.$$('//html/body/non-existing-element');
expect(element).toEqual([]);
});
it('should return multiple elements', async({page, sever}) => {
it('should return multiple elements', async({page, server}) => {
await page.setContent('<div></div><div></div>');
const elements = await page.$$('xpath=/html/body/div');
expect(elements.length).toBe(2);
Expand Down

0 comments on commit c03e8b7

Please sign in to comment.