-
Notifications
You must be signed in to change notification settings - Fork 574
Proposal: unit tests #188
base: master
Are you sure you want to change the base?
Proposal: unit tests #188
Conversation
I'm working on the merge conflicts for the latest master branch (1.2.0). I should've updated it before I opened this PR--my bad. |
examples/extract-google-results.js
Outdated
@@ -1,9 +1,14 @@ | |||
const { Chromeless } = require('chromeless') | |||
const { Chromeless } = require('../dist/src') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep chromeless
here so other people have an easier time trying it.
examples/extract-google-results.js
Outdated
async function run() { | ||
const chromeless = new Chromeless({ remote: true }) | ||
async function run () { | ||
const chromeless = await new Chromeless({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove any chromeless arguments here. (There also shouldn't have been a { remote: true }
.)
I have it up to 98% coverage now: https://coveralls.io/github/geoffdutton/chromeless?branch=jest-tests Any thoughts around this? Should I create some more functional tests? |
@@ -178,13 +145,12 @@ export async function evaluate<T>( | |||
fn: string, | |||
...args: any[] | |||
): Promise<T> { | |||
const { Runtime } = client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
@@ -291,10 +254,7 @@ export async function scrollTo( | |||
y: number, | |||
): Promise<void> { | |||
const { Runtime } = client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Above in the file you've removed destructuring
|
||
const links = await chromeless |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect, did you mean to commit this one?
@@ -130,7 +134,7 @@ export default class LocalRuntime { | |||
|
|||
private async clearCache(): Promise<void> { | |||
const { Network } = this.client | |||
const canClearCache = await Network.canClearBrowserCache | |||
const canClearCache = await Network.canClearBrowserCache() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alot of good catches in this file
I'm proposing this unit testing setup which replaces Ava and NYC with Jest. I'm proposing Jest over Ava/NYC due to the mocking features and built in coverage. Jest also supports a preprocessor (using ts-jest), which was smoother than running
tsc -w & ava -w
. I also selfishly have more experience with Jest testing. Is anyone opposed to using Jest?With regards to debugging, especially when unit testing, with Node 8 I could not get break points to hit in Webstorm. Switching to Node 7 fixed that.
The only major changes are a few spots where the CDP port wasn't being passed, rather it was defaulting to 9222. For example, in
utils.ts
, thesetViewPort
function was callingCDP.Version()
without passing any CDP options.Otherwise, I've mainly added unit tests. There shouldn't be any breaking changes.
This is the first time I've worked with TypeScript, so I'd welcome any feedback of my changes.
Let me know your thoughts. Thanks!