From fa290f099e7c33992aefcadbc5bc541ac7f4c064 Mon Sep 17 00:00:00 2001 From: Joshua Goldberg Date: Wed, 4 Apr 2018 17:48:24 -0700 Subject: [PATCH 1/5] Added expect-puppeteer types --- .../expect-puppeteer-tests.ts | 0 types/expect-puppeteer/index.d.ts | 54 +++++++++++++++++++ types/expect-puppeteer/tsconfig.json | 22 ++++++++ types/expect-puppeteer/tslint.json | 1 + 4 files changed, 77 insertions(+) create mode 100644 types/expect-puppeteer/expect-puppeteer-tests.ts create mode 100644 types/expect-puppeteer/index.d.ts create mode 100644 types/expect-puppeteer/tsconfig.json create mode 100644 types/expect-puppeteer/tslint.json diff --git a/types/expect-puppeteer/expect-puppeteer-tests.ts b/types/expect-puppeteer/expect-puppeteer-tests.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/types/expect-puppeteer/index.d.ts b/types/expect-puppeteer/index.d.ts new file mode 100644 index 0000000000..5c96c4cbdf --- /dev/null +++ b/types/expect-puppeteer/index.d.ts @@ -0,0 +1,54 @@ +// Type definitions for expect-puppeteer 2.2 +// Project: https://github.com/smooth-code/jest-puppeteer +// Definitions by: Josh Goldberg +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +/// + +import { ElementHandle, Page } from "puppeteer"; + +/** + * Interval at which pageFunctions may be executed. + */ +type ExpectPolling = number | "mutation" | "raf"; + +/** + * Configures how to poll for an element. + */ +interface ExpectTimingActions { + /** + * An interval at which the pageFunction is executed. Defaults to "raf". + */ + polling?: ExpectPolling; + + /** + * Maximum time to wait for in milliseconds. Defaults to 500. + */ + timeout?: number; +} + +interface ExpectToClickOptions extends ExpectTimingActions { + /** + * A text or a RegExp to match in element textContent. + */ + text?: string | RegExp; +} + +interface ExpectPuppeteer { + toClick(selector: string, options?: ExpectToClickOptions): Promise; + toDisplayDialog(block: () => Promise): Promise; + toFill(selector: string, value: string, options?: ExpectTimingActions): Promise; + toMatch(value: string, options?: ExpectTimingActions): Promise; + toMatchElement(selector: string, value: string, options?: ExpectTimingActions): Promise; + toSelect(selector: string, valueOrText: string, options?: ExpectTimingActions): Promise; + toUploadFile(selector: string, filePath: string, options?: ExpectTimingActions): Promise; +} + +declare global { + namespace jest { + interface Matchers extends ExpectPuppeteer { } + } +} + +export function expectPuppeteer(instance: ElementHandle | Page): ExpectPuppeteer; diff --git a/types/expect-puppeteer/tsconfig.json b/types/expect-puppeteer/tsconfig.json new file mode 100644 index 0000000000..4f88a5ccb3 --- /dev/null +++ b/types/expect-puppeteer/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "expect-puppeteer-tests.ts" + ] +} diff --git a/types/expect-puppeteer/tslint.json b/types/expect-puppeteer/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/expect-puppeteer/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From ae30d384fb5308ba2c0ed4a5fb1878363a9dd8fc Mon Sep 17 00:00:00 2001 From: Joshua Goldberg Date: Wed, 4 Apr 2018 17:54:15 -0700 Subject: [PATCH 2/5] Added missing strictFunctionTypes --- types/expect-puppeteer/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/types/expect-puppeteer/tsconfig.json b/types/expect-puppeteer/tsconfig.json index 4f88a5ccb3..7ca516e3c2 100644 --- a/types/expect-puppeteer/tsconfig.json +++ b/types/expect-puppeteer/tsconfig.json @@ -6,6 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, + "strictFunctionTypes": true, "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ From c64839177085c7d9a46f288a53047621c0c33877 Mon Sep 17 00:00:00 2001 From: Joshua Goldberg Date: Wed, 4 Apr 2018 18:18:47 -0700 Subject: [PATCH 3/5] Added tests; fixed lint issues --- .../expect-puppeteer-tests.ts | 29 +++++++++++++++++++ types/expect-puppeteer/index.d.ts | 4 +-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/types/expect-puppeteer/expect-puppeteer-tests.ts b/types/expect-puppeteer/expect-puppeteer-tests.ts index e69de29bb2..979c34394d 100644 --- a/types/expect-puppeteer/expect-puppeteer-tests.ts +++ b/types/expect-puppeteer/expect-puppeteer-tests.ts @@ -0,0 +1,29 @@ +import { ElementHandle, Page } from "puppeteer"; + +const testGlobal = async (instance: ElementHandle | Page) => { + await expect(instance).toClick("selector"); + await expect(instance).toClick("selector", { polling: "mutation", text: "text" }); + await expect(instance).toClick("selector", { polling: "raf", timeout: 777 }); + + await expect(instance).toDisplayDialog(async () => {}); + + await expect(instance).toFill("selector", "value"); + await expect(instance).toFill("selector", "value", { polling: 777 }); + + await expect(instance).toMatchElement("selector", "value"); + await expect(instance).toMatchElement("selector", "value", { polling: "mutation" }); + + await expect(instance).toSelect("selector", "valueOrText"); + await expect(instance).toSelect("selector", "valueOrText", { polling: "raf" }); + + await expect(instance).toUploadFile("selector", "filePath"); + await expect(instance).toUploadFile("selector", "filePath", { timeout: 777 }); +}; + +const testImported = async (instance: ElementHandle | Page) => { + const expectPuppeteer = await import("expect-puppeteer"); + + await expectPuppeteer(instance).toClick("selector"); + await expect(instance).toClick("selector", { polling: "mutation", text: "text" }); + await expect(instance).toClick("selector", { polling: "raf", timeout: 777 }); +}; diff --git a/types/expect-puppeteer/index.d.ts b/types/expect-puppeteer/index.d.ts index 5c96c4cbdf..ed89a0f709 100644 --- a/types/expect-puppeteer/index.d.ts +++ b/types/expect-puppeteer/index.d.ts @@ -39,7 +39,6 @@ interface ExpectPuppeteer { toClick(selector: string, options?: ExpectToClickOptions): Promise; toDisplayDialog(block: () => Promise): Promise; toFill(selector: string, value: string, options?: ExpectTimingActions): Promise; - toMatch(value: string, options?: ExpectTimingActions): Promise; toMatchElement(selector: string, value: string, options?: ExpectTimingActions): Promise; toSelect(selector: string, valueOrText: string, options?: ExpectTimingActions): Promise; toUploadFile(selector: string, filePath: string, options?: ExpectTimingActions): Promise; @@ -51,4 +50,5 @@ declare global { } } -export function expectPuppeteer(instance: ElementHandle | Page): ExpectPuppeteer; +declare function expectPuppeteer(instance: ElementHandle | Page): ExpectPuppeteer; +export = expectPuppeteer; From 461c0d67dd50c8153d562abf11129648fde1d36e Mon Sep 17 00:00:00 2001 From: Joshua Goldberg Date: Wed, 4 Apr 2018 19:49:49 -0700 Subject: [PATCH 4/5] TS@2.4; lint disablement --- types/expect-puppeteer/index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/expect-puppeteer/index.d.ts b/types/expect-puppeteer/index.d.ts index ed89a0f709..7b33ef686c 100644 --- a/types/expect-puppeteer/index.d.ts +++ b/types/expect-puppeteer/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/smooth-code/jest-puppeteer // Definitions by: Josh Goldberg // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.4 /// @@ -46,6 +46,7 @@ interface ExpectPuppeteer { declare global { namespace jest { + // tslint:disable-next-line no-empty-interface interface Matchers extends ExpectPuppeteer { } } } From 420e69a0c960f0dc2daf7008b4121ccaacdebff4 Mon Sep 17 00:00:00 2001 From: Joshua Goldberg Date: Thu, 5 Apr 2018 12:40:40 -0700 Subject: [PATCH 5/5] Used sub-monorepo link --- types/expect-puppeteer/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/expect-puppeteer/index.d.ts b/types/expect-puppeteer/index.d.ts index 7b33ef686c..12f19c785d 100644 --- a/types/expect-puppeteer/index.d.ts +++ b/types/expect-puppeteer/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for expect-puppeteer 2.2 -// Project: https://github.com/smooth-code/jest-puppeteer +// Project: https://github.com/smooth-code/jest-puppeteer/tree/master/packages/expect-puppeteer // Definitions by: Josh Goldberg // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4