Skip to content
This repository has been archived by the owner on Nov 24, 2018. It is now read-only.

Proposal: unit tests #188

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open

Conversation

geoffdutton
Copy link

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, the setViewPort function was calling CDP.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!

@geoffdutton
Copy link
Author

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.

@@ -1,9 +1,14 @@
const { Chromeless } = require('chromeless')
const { Chromeless } = require('../dist/src')
Copy link
Owner

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.

async function run() {
const chromeless = new Chromeless({ remote: true })
async function run () {
const chromeless = await new Chromeless({
Copy link
Owner

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 }.)

@geoffdutton
Copy link
Author

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

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

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

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()

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

@joelgriffith joelgriffith removed their request for review November 19, 2018 23:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants