Giter Site home page Giter Site logo

argos-ci / jest-puppeteer Goto Github PK

View Code? Open in Web Editor NEW
3.5K 37.0 291.0 5.84 MB

Run tests using Jest & Puppeteer 🎪✨

License: MIT License

JavaScript 7.37% HTML 2.00% TypeScript 90.63%
jest puppeteer jest-environment chrome chromeless integration-testing

jest-puppeteer's Introduction

Argos

Argos is a visual testing solution that fits in your workflow to avoid visual regression. Takes screenshots on each commit and be notified if something changes.

Argos Visual Testing CI

Links

Contributing

Changes and improvements are more than welcome! Please make your changes in a specific branch and request to pull into main! To learn more about it, have a look at our CONTRIBUTING.md.

jest-puppeteer's People

Contributors

backbone87 avatar brendonbribeiro avatar cancerberosgx avatar colinrotherham avatar dbartholomae avatar dependabot[bot] avatar donovan-graham avatar gidztech avatar gregberge avatar melissachang avatar mohsen1 avatar moredip avatar muka avatar mzedeler avatar nevenq avatar ntwb avatar ohana54 avatar orimarron avatar rkoval avatar ronami avatar rwu823 avatar rzane avatar sorodrigo avatar swissspidy avatar testerez avatar tkrotoff avatar tmilar avatar trysound avatar uzitech avatar xiaoyuhen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jest-puppeteer's Issues

Reset browser state between tests?

Hello, I noticed that the state of the browser/page remains between tests (it).
AFAIK the common practice is to have each it independent so running a single it or all of them are guaranteed to give the same result.

I can imagine though that one could want to execute multiple it to cover a single scenario with a describe. So I'm curious to know if the current behaviour is actually intended.

Cant get local server to load

Great module by the way! Works great on live websites, but I am having a bit of difficulty loading my local web server.

I am using webpack and react. To run my server I usually run:

npm run node_modules/.bin/webpack-dev-server

I have added this to the jest-puppeteer.config.js file:

module.exports = {
  server: {
    command: 'node node_modules/.bin/webpack-dev-server',
    port: 1337,
  },
  launch: {
    headless: false,
    devtools: true,
    timeout:30000
  }
}

But when running the tests it just hangs when trying to load localhost:

describe('Web E2E Test', () => {
  beforeAll(async () => {
    await page.goto('http://localhost:1337/dashboard')
  })

  it('Should load dashboard', async () => {
    await page.waitForSelector('#dashboard');
  })
})

Here is my jest.config.js:

module.exports = {
"verbose": true,
"preset": "jest-puppeteer-preset"
}

Here is the script in the package JSON I used to run the tests:

"e2e-test-web": "jest e2e"

After running this script I get this error when running the tests:

jest e2e

 FAIL  e2e/app.test.js (10.676s)
 Web E2E Test
    ✕ Should load dashboard (5004ms)

  ●Web E2E Test › Should load dashboard

    Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.

      at node_modules/jest-jasmine2/build/queue_runner.js:68:21

  ●Web E2E Test › Should load dashboard

    Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.

      at node_modules/jest-jasmine2/build/queue_runner.js:68:21

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        10.805s, estimated 11s
Ran all test suites matching /e2e/i.
(node:36277) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'addExpectationResult' of undefined
(node:36277) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:36277) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'addExpectationResult' of undefined

Multiple servers

I have tests for a storybook and for the app. I want to run all puppeteer tests at once. But the storybook and the app have different servers and listening ports.

Is it possible to spawn (with server.command) two (or more) servers before running tests?

appMode: true in jest-puppeteer.config.js results in error

Settings appMode to true in jest-puppeteer.config.js

module.exports = {
  launch: {
    headless: false,
    appMode: true,
  },
}

Results in the following error:

 FAIL  src/tests/error.test.js
  ● Test suite failed to run

    wsEndpoint not found

      at PuppeteerEnvironment.setup (node_modules/jest-environment-puppeteer/lib/PuppeteerEnvironment.js:59:13)

Without appMode window area of my webapp only uses a small portion of the viewport during headful tests.

expect-puppeteer: change `toMatch` `text` matcher to check if argument is regex or not to match

First and foremost, I just want to express gratitude for maintaining this project! It's a crucial resource for doing anything with jest and puppeteer.

One pain point though is from usage of text matching option on some of the matchers (e.g., toMatch or toMatchElement). It's confusing (especially for newcomers) that the string you pass to it is actually used as a regex. I realized that it's documented this way, but it would be a lot nicer if the library could do a typeof to check if the argument is a string or object (regex's actual type from what I can tell). Then, it just does a simple includes or an actual match on the textContent respectively. I've run into weird cases where I'm trying to match on money values (e.g., '$1000') and i've found myself beating my head on more than one occasion trying to figure out why text won't match (the $ is not escaped, obviously). Also, sometimes all you really need is a simple string match without needing to remember to escape everything in the regex for what you're matching.

I know that this would bring about a breaking change, so it might not be something you'd be thrilled to add right now. However, I think it could definitely help for readability and usability of this library.

using expect-puppeteer with jest's regular expect

expect(page).not.toContain('Example Title'); throws TypeError: (0 , _expectPuppeteer2.default)(...).not.toContain is not a function

is there a way to use jest expect and puppeteer expect in the same test in create-react-app?

I'm guessing the following jest configurations fix this:

{
"preset": "jest-puppeteer",
"setupTestFrameworkScriptFile": "expect-puppeteer"
}

...but CRA doesn't let me configure this without ejecting. Is there anything I can do?

Spawning and killing browser and dev server in parallel?

The setup and teardown async logics run in series now. Since #66 is a little cleaner to read, code snippets from there:

// setup
browser = await puppeteer.launch(config.launch)
// (couple of other lines)
if (config.server) await setupServer(config.server)
// teardown
await teardownServer()
await browser.close()

These could be done in parallel for speed:

// setup
const tasks = [puppeteer.launch(config.launch)]
if (config.server) tasks.push(setupServer(config.server))
[browser] = await Promise.all(tasks)
// setup
await Promise.all([
    teardownServer(),
    browser.close(),
])

Missing devDependencies?

Trying to run the tests after a fresh install, I ran into:

kytwbs-MacBook-Pro:jest-puppeteer kytwb$ npm test

> @ test /Users/kytwb/Desktop/jest-puppeteer
> jest --runInBand

● Validation Error:

  Test environment jest-environment-puppeteer cannot be found. Make sure the testEnvironment configuration option points to an existing node module.

  Configuration Documentation:
  https://facebook.github.io/jest/docs/configuration.html

npm ERR! Test failed.  See above for more details.

And:

kytwbs-MacBook-Pro:jest-puppeteer kytwb$ npm test

> @ test /Users/kytwb/Desktop/jest-puppeteer
> jest --runInBand

● Validation Error:

  Module expect-puppeteer in the setupTestFrameworkScriptFile option was not found.

  Configuration Documentation:
  https://facebook.github.io/jest/docs/configuration.html

npm ERR! Test failed.  See above for more details.

Should I come up with a PR adding these two in package.json's devDependencies?

TypeError: expect(...).toClick is not a function

I get the above error when I try and click on an element in a page.

screen shot 2018-05-03 at 8 19 19 am

I have added the following config to my package json as instructed:
screen shot 2018-05-03 at 8 20 11 am

I then wrote the following tests:
screen shot 2018-05-03 at 8 21 05 am

The first one passes so I'm set up properly, does anyone know why the toClick function is failing?

Fresh install doesn't work

  • Install jest globally with 'npm install -g jest'
  • Create a directory and cd into it
  • Put into package.json:
{
  "jest": {
    "preset": "jest-puppeteer"
  }
}
  • npm install --save-dev jest-puppeteer puppeteer
    Note this warning is printed:
npm WARN [email protected] requires a peer of jest-environment-node@^22.0.0 but none is installed. You must install peer dependencies yourself.

Also note that node_modules/jest-environment-node doesn't exit.

  • Put sample code into test.js
  • jest test.js gives this error:
~/repro-issues (jest): jest test.js 
 FAIL  ./test.js
  ● Test suite failed to run

    Cannot find module 'jest-environment-node'
      
      at Object.<anonymous> (node_modules/jest-environment-puppeteer/lib/PuppeteerEnvironment.js:9:28)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.05s, estimated 3s
Ran all test suites matching /test.js/i.

This happens because of this peer dependency. With npm, peer dependencies must be manually installed. This SO answer explains when to use peer dependencies.

@neoziro, can these be regular dependencies instead of peer?

Enabling spawned server output (stdout, stderr) for debugging

When a server command is specified in jest-puppeteer.config.js but for some reason e.g. misconfigured port etc. we cannot connect to the spawned server, Jest will just hang forever in a state Determining test suites to run...

screen shot 2018-04-19 at 8 57 09 am

Actually when the ports are not matching this it waits forever for the port to be opened:

    if (config.server.port) {
      await waitPort({ port: config.server.port, output: 'silent' })
    }

Adding e.g. a debug option to the server config could help developers to find out what's causing the issue e.g.

// jest-puppeteer.config.js
module.exports = {
  server: {
    command: 'node server.js',
    port: 4444,
    debug: true
  },
}

The implementation is simple, the spawned child process needs listeners on both stdout and stderr so that we can console.log whatever happens in there:

    server = spawnd(config.server.command, {
      shell: true,
      env: process.env,
      cwd: cwd(),
      ...config.server.options,
    })

    // allow logging the spawned process output to our own shell
    if (config.server.debug) {
      server.stdout.on('data', data => {
        console.log(data)
      })

      server.stderr.on('data', data => {
        console.log(data)
      })
    }

Also the output: 'silent' option of wait-port could be turned off to show that we're actually waiting for the port to be opened.

    if (config.server.port) {
      await waitPort({ port: config.server.port, ...!debug && { output: 'silent' } })
    }

expect-puppeteer: Support XPATH selectors

From what I can see expect-puppeteer does not support XPath selector. XPath could be useful to select elements based on text content for example.
Would you be interested in adding support for XPath?

A possible API could be to accept either a string or a selector object. So for example you could do:

expect(page).toClick('#myId');

// or

expect(page).toClick({value: '#myId', type: 'css'});

// or

expect(page).toClick(
  {value: 'text()[starts-with(., "myText")]]', type: 'xpath'}
);

Does it make sense?

Misleading error message

Somehow our e2e tests suite stopped working and I couldn't figure out why. The toMatch() method was always throwing Text not found when in fact the error catched in here was due to an update of our server CSP:

Error: Evaluation failed: EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' 'unsafe-inline'".

Consider moving config to jest config?

Just an idea, not sure how feasible it is, but it would be great if I could just put my headless configuration inside my jest.config.js file instead of creating a new config file just for that.

However, totally worth it to use this preset!

How to pass process.env to jest-puppeteer.config ?

I tried to launch puppeteer with

PUPPETEER_SLOW=1 ./node_modules/.bin/jest --config ./puppeteer/jest.config.js

But PUPPETEER_SLOW not in process.env in ./jest-puppeteer.config.js. Why?

console.log(process.env.PUPPETEER_SLOW) // undefined

module.exports = {
  server: {
    command: 'node puppeteer/server.js',
    port: 1337,
  },
  launch: {
...

expect-puppeteer readme out of date?

The toMatch docs for expect-puppeteer has a code example saying await expect(page).toMatch('lo.*') will match the string as a RegExp, but the changelog says this is no longer possible, unless I've misunderstood?

Cannot read property 'removeListener' of undefined

Trying to run jest-puppeteer on *.puppeteer.test.js files and JSDom on *.test.js files by using projects. My jest.config.js looks something like:

module.exports = {
  projects: [
    {
      displayName: "jsdom",
      testPathIgnorePatterns: ["puppeteer.test.js$"]
    },
    {
      displayName: "puppeteer",
      preset: "jest-puppeteer",
      setupTestFrameworkScriptFile: "expect-puppeteer",
      testMatch: ["**/*.puppeteer.test.js"]
    }
  ]
};

Run I run Jest, I get the following error:

TypeError: Cannot read property 'removeListener' of undefined

      at PuppeteerEnvironment.teardown (node_modules/jest-environment-puppeteer/lib/PuppeteerEnvironment.js:50:22)
          at Generator.throw (<anonymous>)

Same error occurs if I specify the following docBlock at the top of a .puppeteer.test.js file:

/**
 * @jest-environment puppeteer
 */

Related: jestjs/jest#6026, jestjs/jest#5441

Add an option for a dev server to ignore EADDRINUSE

I have jest-puppeteer set up with a create-react-app project with the config.server option set to start the dev server. This works perfectly in CI 😊.

When locally developing, it's common to separately keep the dev server running in the background to keep a web page open with the latest changes. You then have to remember to close that server before running jest-puppeteer tests. It's not always practical to specify them to run on different ports.

Can the soon-to-be jest-dev-server server startup logic have an option to ignore?:

Error: listen EADDRINUSE 0.0.0.0:3000
    at Server.setupListenHandle [as _listen2] (net.js:1342:14)
    at listenInCluster (net.js:1383:12)
    at doListen (net.js:1498:7)
    at process._tickCallback (internal/process/next_tick.js:114:19)
Emitted 'error' event at:
    at Server.emit (C:\Code\WebClient\node_modules\spdy\lib\spdy\server.js:237:40)
    at emitErrorNT (net.js:1362:8)
    at process._tickCallback (internal/process/next_tick.js:114:19)

Side benefit: setup of tests will be faster for not having to start up the dev server.

Jest's native expect functions are broken by puppeteer-expect

Hi, it looks like puppeteer-expect doesn't actually copy over the old jest expect's matchers. This causes a lot of problems like: TypeError: expect(...).not.toBe is not a function
Code:

const elementHandle = await page.$("input");
expect(elementHandle).not.toBe(null);

Wait for server command

My jest-puppeteer.config.js is

module.exports = {
  server: {
    command: 'node puppeteer/server-storybook.js',
  },
...

And sometimes I have a network error: tests are trying to reach node process, which is launching, but not completely launched.

Is it possible to tell jest-puppeteer wait until ping localhost:3000 will be ok? Or, at least, tell to wait some amount of milliseconds.

Now I have to set await sleep(1000) before each test suit, which is not convenient.

The problem could be critical in case if you are launching something heavy like webpack-dev-server.

slowMo not working

My root jest-puppeteer.config.js:

const isDev = true

module.exports = {
  server: {
    command: 'node puppeteer/server.js',
    port: 1337,
  },
  launch: {
    // dumpio: true,
    slowMo: 1200,
    headless: !isDev,
    executablePath: isDev ? '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' : undefined,
  },
}

But no slowMo detected: tests are executed as fast as possible, nothing can be observed. Is there any secrets on how to switch on the slowMo flag?

Feature Request: Support incognito browser contexts

Puppeteer 1.5.0 introduces a new feature, the support for incognito browser contexts.

Since all the tests seem to run in the same browser instance here, we could leverage this functionality to ensure isolation between all tabs. This could be useful to run multiple tests that require separate user sessions / cookies, etc.

I'm thinking the solution could be implemented here :

https://github.com/smooth-code/jest-puppeteer/blob/d06f58feca62d5ea5225d53a20035db6dd82d750/packages/jest-environment-puppeteer/src/PuppeteerEnvironment.js#L50

My suggestion :

  • Have an "INCOGNITO" env variable (true|false)
  • Based on the existence / value, create a page with or without the incognito browser context

Do you think I need to consider other things or that makes sense ?
If this seems like a reasonable solution, are you open to PRs ? :)

Thanks !

Globals "page" and "browser" are both undefined when using Jest 21

I just tried adding jest-puppeteer to an existing project and I was getting page is undefined when running my tests, even though the preset: 'jest-puppeteer' was set and Jest was launching without any errors.

After a while I tried upgrading Jest from 21 to 22, and it solved the problem. So it seems jest-puppeteer peer-depends on jest >= 22. If so, it would be good to mention this in the readme and/or officially add it to peerDependencies.

Thanks for making this great project btw!

Spinning server environment spawning into a separate module?

The jest-puppeteer preset has been working great for tests with Jest & Puppeteer. However, I'd like to switch to cross-browser Selenium tests. The launching of a server in setup and killing it in teardown is great and it looks like the logic to spawn a server if config.server exists is separate from spinning up a Puppeteer page. Do you think it could be moved into a separate module separate from Puppeteer?

In lib/global.js, it could import { setup, teardown } from "jest-server". setup could await teardown(); after creating the browser and teardown could await teardown(); before closing the browser.

Global: define default timeouts

I see in the documentation in expect-puppeteer :

timeout maximum time to wait for in milliseconds. Defaults to 500.

However, I'd like to be able to set the default value globally, do you think this could be possible ?
I haven't found an official way to set it even in puppeteer :(

Puppeteer has a partial solution with page.setDefaultNavigationTimeout() but it only has effect on a subset of the functions exposed by puppeteer: https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagesetdefaultnavigationtimeouttimeout

It would be amazing if we could have control over a global timeout variable for

  • expect-puppeteer
  • puppeteer

An example to illustrate my point:

describe('A test with login in page objects', () => {

  beforeAll(async () => {
     // Have function attached to page reference ?
      await page.setGlobalTimeout(30000); 
  });

  it('should display "Google" text on page', async () => {
      await page.goto('https://google.com'); // Would use 30 seconds timeout instead of puppeteer default
      await expect(page).toMatch('Google'); // Would use 30 seconds timeout instead of 500ms
  });
});

Expect .toClick() to click innermost div that matches textContent

Assuming I have the following HTML:

    <div>
        <div>
            <div class="box" onclick="console.log('One')">One</div>
            <div class="box" onclick="console.log('Two')">Two</div>
            <div class="box" onclick="console.log('Three')">Three</div>
        </div>
    </div>

And I'm attempting to click the div with textContent matching "One":

await expect(page).toClick('div', { text: 'One' })

I'd expect the div with textContent matching "One" to be clicked, instead, any of the three divs could be clicked.

This seems to be due to the fact .find() returns the first match (always the outermost div) in the following code:
https://github.com/smooth-code/jest-puppeteer/blob/d06f58feca62d5ea5225d53a20035db6dd82d750/packages/expect-puppeteer/src/matchers/toMatchElement.js#L27

To always select the element with the innermost div matching textContent one could use the xpath selector instead of querySelectorAll:

const selector = 'div'
const text = 'One'
await page.$x("//selector[contains(text(), text)]")

If this change makes sense, I'd be happy to make a pull request. If not, please let me know where my assumptions are incorrect.

Thanks for a great utility!

globalSetup and a globalTeardown aren't optional

Hi! I just play around with your lib and it looks like I need to specify a globalSetup and globalTeardown, even though I just use the default behaviour (see https://github.com/Mercateo/e2e-check/blob/master/packages/puppeteer/global-setup.js).

If I don't specify these files I get this error:

TypeError: Cannot read property 'removeListener' of undefined

      at PuppeteerEnvironment.teardown (../../node_modules/jest-environment-puppeteer/lib/PuppeteerEnvironment.js:108:22)
          at Generator.throw (<anonymous>)

Reading the README it sounds to me, that they should be optional...? Thank you for the lib.

jest-puppeteer.config.js ignores headless settings in launch section

I would like to deactivate headless but my config is ignored.

jest-puppeteer.config.js:

module.exports = {
  launch: {
    //dumpio: true,
    headless: false, //process.env.HEADLESS !== 'false',
    devtools: true
  }
};

Directory structure:

/application

package.json
jest-puppeteer.config.js
.babelrc
/src

tests

registration.js

package.json:

{
  "name": "tests",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "babel-core": "^6.26.0",
    "babel-jest": "^22.4.3",
    "babel-preset-env": "^1.6.1",
    "jest": "^22.4.3",
    "jest-puppeteer": "^2.4.0",
    "puppeteer": "^1.3.0"
  },
  "scripts": {
    "start": "jest",
    "test": "jest"
  },
  "jest": {
    "preset": "jest-puppeteer"
  }
}

Timeout - Async callback was not invoked

I try executing the demo code in README and it prompts me ' within the 10000ms timeout specified by jest.setTimeout.'

  beforeAll(async () => {
    await page.goto('https://www.google.com.hk')
  })

  it('should display "google" text on page', async () => {
    await expect(page).toMatch('google')
  })
})```

expect(element).toMatchTextContent?

Here's what I'm doing now:

const textProperty = await element.getProperty("textContent");
const textValue = await textProperty.jsonValue();
expect(textValue).toEqual("MyText");

I'd be nice to have a concise one-liner:

await expect(element).toMatchTextContent("MyText");

Docs around Access globalSetup or globalTeardown incorrect

The docs around Access globalSetup or globalTeardown indicate using:

const {
  setup: setupPuppeteer,
  teardown: teardownPuppeteer,
} = require('jest-puppeteer')

However that throws an error:

Error: Cannot find module 'jest-puppeteer'

Instead using require('jest-environment-puppeteer') works as expected.

Requesting that the docs be updated !

Pretty error messages

Have you thought of incorporating jest-diff and jest-matcher-utils in the expect-puppeteer package? It would be nice to have more descriptive and colorful error messages.

I understand the desire to keep expect-puppeteer non-jest-specific, but I am fairly certain that those utility packages don't depend on Jest.

For example, it would be nice to see what the textContent is on the page when toMatch fails.

How to use with create-react-app

I want to leave the default config CRA comes with for unit tests, and then add puppeteer and have e2e tests in a different directory.

So far I've tried the following:

  1. create jest-e2e.config.js and add "test:e2e": "jest -c jest-e2e.config.js", to package.json
module.exports = {
  preset: 'jest-puppeteer',
  testRegex: "e2e/tests/.*\\.test\\.js$"
};
  1. Add tests inside e2e/tests/ directory

It doesn't work, it says page is not defined.

How can I accomplish this?

Option to check & allow existing port usage in jest-dev-server?

I'm using this with a create-react-app fork and starting the server takes up a bunch of seconds. It'd be useful to allow developers and CI machines to have a local server running that was started before tests run. That way, if we want to run several runs of tests, we don't have to start the server up each time: the tests can run immediately. We also wouldn't have to manually close our servers before running tests

Can the dev server config logic have a flag to check for the existing port being used, and not start the server if so?

I'd be very open to adding this in. :)

expect-puppeteer: trim out redundant whitespace in `textContent` when doing `text` matching

When matching on textContent, a lot of the time, there will be extra whitespace/newlines surrounding the text you're matching based on how the HTML looks within the element you're matching. It could be nice to strip all of the redundant whitespace out when doing the comparison within this library as well such that consumers of it don't need to account for that whitespace in their comparison strings.

For example, a textContent of

'    white  

  space   '

could be stripped to just

'white space'

to allow matching by passing just 'white space' without needing wildcards in the comparison string. This could vastly improve test cases asserting that text exists. This could also perhaps be configurable too in case someone actually needed the textContent as-is in the HTML.

Running tests that match string can cause non-matching suites to fail

Hey, I'm hoping I've just made a mistake somewhere, however I think I might have found a bug.

When I set the -t CLI option to filter what tests are run, if there is a suite that doesn't have any tests that match the string then it fails with:

 ● Test suite failed to run

    Your test suite must contain at least one test.

      at node_modules/jest/node_modules/jest-cli/build/test_scheduler.js:245:22

My expectation would be that it behaves the same as Jest, where any suites that have no matching tests are skipped.

I setup a super simple repo to highlight the problem:
https://github.com/Crispioso/jest-puppeteer-issue

If you run

npm test

...then everything passes fine, but if you run

npm test -- -t=false

... it still tries to run1.test.js but fails because it doesn't think it contains any tests, rather than being skipped.

By the way, I'm running:

  • Node 8.9.3
  • Puppeteer 1.4.0
  • Jest 23.1.0
  • Jest Puppeteer 3.0.1

If this is a bug and not my error then I'd be happy to try and help fix it, but might need some guidance as of where to start looking.

clicking a button is not an assertion

await expect(page).toClick('button', { text: 'Home' }) makes no sense.

what you are trying to do is the action of clicking the Home button.

there is assertion hidden in this, maybe, but it should be separated from the action of clicking:

await expect(page).has('button', { text: 'Home' })
await page.click('button')

Ignore Errors on page.goto(...)

When I'm running the below code, it errors out due to error messages on kohls side that I would like to ignore. For reference, I'm trying to test Chrome extension functionality on other sites so I would need to ignore errors that are not on my own when going to a page.

is there any way to do this?

describe('www.kohls.com user action services', () => {
  beforeEach(async () => {
    await page.goto('https://www.kohls.com');
  });

  it.only('should find nearby stores', async () => {
    const result = await page.evaluate('1 + 2');
    expect(result).toBe(3);
  });
});

Documentation of puppeteer-expect API

Thanks for writing this amazing library! Can you add a simple description for what each method is for? Just one sentence per method would be very helpful. It's not always obvious from the name what the method does. For example I'm not sure what the difference is between toSelect and toMatchElement.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.