Commit Graph

1770 Commits

Author SHA1 Message Date
Michael
dc26b8d071
docs(examples): add cucumber-puppeteer-example for integration testing (#5875) 2020-05-18 06:54:53 +02:00
Jack Franklin
3e76554fcb
chore: fix async dialog specs when they fail (#5859)
When this test was failing, it would cause no future tests to run. This
was because the `expect` call within the `page.on` callback would throw
an error, and that would trigger a unhandled promise rejection that
caused the test framework to stop.

The fundamental issue here is making `expect` calls within callbacks.
They are brittle due to the fact that they throw, and the test framework
won't catch it, but also because you have no guarantee that they will
run. If the callback is never executed you dont' know about it.

Although it's slightly more code, using a stub is the way to do this.
Not only can we assert that the stub was called, we can make synchronous
`expect` calls that Mocha will pick up properly if they fail.

Before this change, running the tests (and making it fail on purpose)
would cause all test execution to stop:

```
> puppeteer@3.0.4-post unit /Users/jacktfranklin/src/puppeteer
> mocha --config mocha-config/puppeteer-unit-tests.js

  .(node:69580) UnhandledPromiseRejectionWarning: Error: expect(received).toBe(expected) // Object.is equality

Expected: "yes."
Received: ""
    at Page.<anonymous> (/Users/jacktfranklin/src/puppeteer/test/dialog.spec.js:42:37)
    [snip]
(node:69580) UnhandledPromiseRejectionWarning: Unhandled promise rejection ... [snip]
```

But with this change, the rest of the tests run:

```
> puppeteer@3.0.4-post unit /Users/jacktfranklin/src/puppeteer
> mocha --config mocha-config/puppeteer-unit-tests.js

  Page.Events.Dialog
    ✓ should fire
    1) should allow accepting prompts
    ✓ should dismiss the prompt

  2 passing (2s)
  1 failing

  1) Page.Events.Dialog
       should allow accepting prompts:
     Error: expect(received).toBe(expected) // Object.is equality

Expected: "yes."
Received: ""
      at Context.<anonymous> (test/dialog.spec.js:53:35)
      at processTicksAndRejections (internal/process/task_queues.js:94:5)
```

This is much better because one failing test now doesn't stop the rest
of the test suite.

This probably isn't the only instance of this in the codebase so I
propose as we encounter them we fix them usng this commit as the
template.
2020-05-14 11:34:22 +02:00
Mathias Bynens
b2552e4f7d
chore: restore page.setUserAgent test (#5868)
Ref. #5781.
2020-05-14 10:24:30 +01:00
Christian Bromann
39f1b13449
chore: extract Request and Response into its own module (#5861)
* chore: extract `Request` and `Response` into its own module
2020-05-13 14:57:21 +01:00
Christian Bromann
b510c354c7
chore: fetch Firefox from JSON source instead of RegExp (#5864)
Fetch Firefox from https://product-details.mozilla.org/1.0/firefox_versions.json.

Fixes #5742.
2020-05-13 15:48:39 +02:00
Christian Bromann
69c38fc2d0
chore: extract ConsoleMessage and FileChooser into its own module (#5856)
* chore: extract `ConsoleMessage` and `FileChooser` into its own module
2020-05-13 11:30:29 +01:00
Jack Franklin
0aba6dfddf
chore: force Mocha to exit on CI (#5862)
We have some bug where some test runs will pass but then stall as Mocha
doesn't exit cleanly. This is proving very hard to track down (I've yet
to replicate it or find the test that causes it) and it doesn't happen
consistently.

The `exit` flag forces Mocha to hard exit. This will help with CI
stability. The flag only gets set on CI runs.
2020-05-13 11:10:07 +01:00
Jack Franklin
9368edbac9
chore: upgrade TypeScript to 3.9 (#5860)
Sticking to a specific version of TS rather than a ^ version so we know
everyone is on the exact same version. Think that's preferable for such
an important dependency.
2020-05-13 10:50:51 +01:00
Christian Bromann
5f42547c9d
chore: extract SecurityDetails into its own module (#5858)
* chore: extract `SecurityDetails` into its own module
2020-05-13 10:32:46 +01:00
Jack Franklin
f5d2597bac
chore: add running TSC to test README (#5852) 2020-05-13 09:20:33 +01:00
Jack Franklin
c6d01c950e
chore: extract BrowserRunner into its own module (#5850)
* chore: extract `BrowserRunner` into its own module

`src/Launcher.ts` is large and hard to work in. It has multiple objects
defined in it:

* ChromeLauncher
* FirefoxLauncher
* BrowserRunner
* Launcher

This change moves BrowserRunner into its own module. More refactorings
like this will follow but this is the first step.
2020-05-12 16:30:13 +01:00
Jack Franklin
b38bb4334f
Warn when given unsupported product name. (#5845)
* Warn when given unsupported product name.

Fixes #5844.

This change means when a user launches Puppeteer with a product name
that is not supported (which at the time of this commit means it's not
`firefox` or `chrome) we will warn them about it.

Decided on just a warning vs an error because the current behaviour is
that we fallback to launching Chrome and I don't think this warrants a
breaking change.
2020-05-12 10:30:24 +01:00
Jack Franklin
6099272612
chore: add @types/proxy-from-env (#5831) 2020-05-07 17:26:26 +01:00
Jack Franklin
5343c7a18f
chore: private-ise src/Accessibility.ts (#5832)
Now the first pass of migrating to TypeScript is complete I'm going
through the src files one by one to tidy up the public/private
interfaces.

Puppeteer used an underscore convention to denote privacy but violates
this in some places; we should be strict with TypeScript's `public` and
`private` keywords instead.

This means we'll get nice TS errors if you try to refer to a private
method/variable, and means when we swap to generating our TS docs the
tooling knows what method(s) are public and therefore need to be
documented vs private internals that don't.
2020-05-07 17:26:05 +01:00
Changhao Han
ce097426af
feat: add more options to check_availability script (#5827) 2020-05-07 16:05:39 +02:00
Jack Franklin
510354054f
chore: add command to run eslint with --fix flag (#5829) 2020-05-07 15:54:33 +02:00
Jack Franklin
49ce65943c
chore: remove src/TaskQueue (#5826)
* chore: Remove src/TaskQueue

The only place it's used is in `src/Page.ts` to have a chain of
screenshot promises. Rather than initialize a task queue in `Browser`
and pass it through a chain of constructors we instead move the class
into `src/Page` and define it inline.

In the future we might want to create a helpers folder to contain small
utilities like that (`src/Page.ts` is already far too large) but I'm
leaving that for a future PR.

`TaskQueue` isn't documented in `api.md` so I don't think this is a
breaking change.

I updated the type of `screenshot()` to return `Promise<string | Buffer
| void>` because if a promise rejects it's silently swallowed. I'd like
to change this behaviour but one step at a time. This type only had to
change as now we type the screenshot task queue correctly rather than
using `any` which then exposed the incorrect `screenshot()` types.
2020-05-07 14:49:42 +01:00
Jack Franklin
4fdb1e3cab
chore: add Prettier (#5825) 2020-05-07 12:54:55 +02:00
Jack Franklin
ae576aff61
chore: mark v3.0.4-post (#5824) 2020-05-07 12:04:22 +02:00
Jack Franklin
c214d20d54
chore: mark version v3.0.4 (#5823) 2020-05-07 11:52:59 +02:00
Mathias Bynens
17bb660dd5
chore: remove unused mime-types dependency (#5819) 2020-05-07 11:28:46 +02:00
Jack Franklin
70340de0cc
chore: add Node 12 and Node 14 to CI (#5821) 2020-05-07 10:24:03 +01:00
Avi Vahl
70d5c7ffe9
fix: remove node@14 specific extract timeout (#5816)
closes #5719

Original stream.pipeline issue has been fixed in Node 14.1.0 and above.

Meanwhile, the workaround itself caused timout failures in many CI Node 14 runs, as reported in #5719.

Removed it, as it's no longer needed, and actually blocks consumers from adding CI testing on Node 14.
2020-05-07 09:46:53 +01:00
Jack Franklin
51154824d8
chore: bump version to 3.0.3-post (#5814) 2020-05-06 17:27:31 +02:00
Jack Franklin
dd5bdf1616
chore: mark version v3.0.3 (#5813) 2020-05-06 15:57:04 +01:00
Jack Franklin
ae7483d5cf
chore: remove src/externs.d.ts (#5811)
* chore: remove src/externs.d.ts

It defined global types that we don't want to use, and instead we move
to using interfaces that we import and reference just like with any
other interface.

This means other than Protocol (which I think is fine to leave as is),
there are no other magic global types and you have to import any types
or interfaces that you want.
2020-05-06 14:23:07 +01:00
Jack Franklin
de4f08dc52
chore: migrate src/Page.js to TypeScript (#5809)
* chore: migrate src/Page.js to TypeScript

The final one! This is a huge file and needs to be split up and tidied,
but for now I've left all the definitions in place and converted types
accordingly.

There's some additional tidying we can do now every `src` file is TS,
but I'll leave that for another PR to avoid this one getting any bigger.

Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2020-05-05 13:53:22 +01:00
Mathias Bynens
eed7d94a2b
chore: improve readability for path strings (#5805)
This addresses the feedback from https://github.com/puppeteer/puppeteer/pull/5762#discussion_r416554314.
2020-05-05 14:18:41 +02:00
Jack Franklin
d8d1f6ff7c
chore: migrate src/api.js to TypeScript (#5808) 2020-05-05 10:59:07 +02:00
Jack Franklin
890c215142
chore: migrate src/Puppeteer to TypeScript (#5789)
* chore: migrate src/Puppeteer to TypeScript.

* fix api js
2020-05-05 09:36:44 +01:00
Anderson Aguiar
209e25c0e1
docs(readme): syntax-highlight nested snippets in debugging section (#5799) 2020-05-05 07:45:21 +02:00
Vasilii Artemchuk
53d6fabf80
docs(api.md): improve emulateMediaFeatures section (#5807) 2020-05-05 07:43:14 +02:00
Jack Franklin
ec91ecaf0b
chore: migrate src/Launcher to TypeScript (#5775) 2020-04-30 13:45:58 +01:00
Jack Franklin
5518bac291
chore: update how we track coverage during unit tests (#5779)
* chore: update how we track coverage during unit tests

The old method of tracking coverage was causing issues. If a test failed
on CI, that test's failure would be lost because the test failing would
in turn cause the coverage to fail, but the `process.exit(1)` in the
coverage code caused Mocha to not output anything useful.

Instead the coverage checker now:

* tracks the coverage in memory in a Map (this hasn't changed)
* after all tests, writes that to disk in test/coverage.json (which is
gitignored)
* we then run a single Mocha test that asserts every method was called.

This means if the test run fails, the build will fail and give the error
about that test run, and that output won't be lost when the coverage
then fails too.

Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2020-04-30 13:00:41 +01:00
Paul Lewis
4a47867a24
feat: add support for string-based custom queries (#5753) 2020-04-30 12:45:52 +01:00
Jack Franklin
c212126f6a
chore: turn on Travis retries (#5787)
To enable Travis to retry to work around ECONNRESET and similar that pops up.
2020-04-30 13:38:58 +02:00
Jack Franklin
3116bb9c2d
chore: log product + binary on unit test runs (#5785)
This way it's super clear which product and binary you're testing against.
2020-04-30 13:03:16 +02:00
Mathias Bynens
541281b9f3
chore: fix doclint issues (#5784) 2020-04-30 12:58:51 +02:00
Jack Franklin
32c8c6992c
chore: enable mocha retries (#5782)
We are seeing some CI flakes due to network resets, or issues out of our control. Let's try to avoid some of those by using Mocha's built-in retries.
2020-04-30 12:19:50 +02:00
Jack Franklin
5fb399d55d
docs(contributing): update per recent changes (#5778)
Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2020-04-30 12:16:44 +02:00
Jack Franklin
8654d630ad
chore: migrate src/NetworkManager to TypeScript (#5774) 2020-04-30 11:15:27 +01:00
Mathias Bynens
862eea850e
chore: disable flaky setUserAgent test in Firefox (#5780) 2020-04-30 12:10:28 +02:00
ɯλrv¬
a8908cf3e0
chore: update incorrect link for DeviceDescriptors (#5777) 2020-04-30 09:14:12 +01:00
Jack Franklin
af2e45820f
chore: migrate src/Target to TypeScript (#5771) 2020-04-29 15:18:09 +01:00
Jack Franklin
8a5008e30b
chore: migrate src/FrameManager to TypeScript (#5773) 2020-04-29 13:28:16 +02:00
Jack Franklin
c5c97b07b5
chore: remove DOMWorld definition from externs.d.ts (#5767)
Missed in the initial work to migrate DOMWorld to TypeScript.
2020-04-28 18:45:55 +02:00
Jack Franklin
da6e6c00e5
chore: migrate src/EmulationManager to TypeScript (#5766) 2020-04-28 18:45:34 +02:00
Jack Franklin
01578446fa
chore: migrate src/DOMWorld to TypeScript (#5764) 2020-04-28 15:35:43 +01:00
Jack Franklin
d69fbb9974
chore: Enforce array type styles in TypeScript (#5765)
This change enforces how we type arrays, e.g. choosing between:

* `string[]`
* `Array<string>`

I've gone for the `array-simple` option [1] which enforces that:

* primitive types and type references use `X[]`
* complex types use `Array<X>`

For example, we'd type an array of strings as `string[]`, but an array
of a union type as `Array<SomeUnionType>`.

[1]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/array-type.md
2020-04-28 15:06:43 +01:00
Jack Franklin
1ccfbcb684
chore: enforce naming of errors in catch blocks (#5763) 2020-04-28 15:16:28 +02:00