Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration and unit tests using Cypress #1

Merged
merged 10 commits into from
Mar 19, 2018

Conversation

bahmutov
Copy link
Contributor

Here is an example mounting Hyperapp view function as a component and then driving it via Cypress. Also unit testing actions.

  • moved actions and todo item view into separate files for import
  • unit tested actions
  • added Cypress preprocessor that uses current webpack config to bundle test code when importing components
  • mounting view using cypress-hyperapp-unit-test

The integration test checks if TestItem renders class, responds to click.

Also added npm run ci command that can run the tests on CI by starting the server, waiting for it to respond, run Cypress, then shutdown the server.

Copy link
Contributor

@mrozbarry mrozbarry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion for the README, and otherwise just a few questions. The tests themselves are fine, and look good. Thanks for the contribution 😀 🍰 🎉 !

todos: []
}
const result = actions.add()(state)
cy.wrap(result).should('deep.equal', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiousity, why cy.wrap over expect? It looks like cypress bundles with chai's expect, so I'm curious if it's the convention of cypress, support for cy.wrap is better, or just personal preference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing, I changed it to simple expect, no preference

@@ -0,0 +1,39 @@
/// <reference types="cypress" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this turns on IntelliSense for Cypress type in JS specs in VSCode for example

intellisense-vscode

README.md Outdated
To run tests in the interactive mode, start the server and then open Cypress

```
npm start &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer not suggesting running a process in the background, simply because not everyone has a lot of sh experience. Is it possible to use your start-server-and-test package to do something like: start-server-and-test start http://localhost:8080 test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the npm test command and updated the README

@bahmutov
Copy link
Contributor Author

Great feedback, I think I addressed it all in two commits

package.json Outdated
"babel-loader": "^8.0.0-beta.0",
"css-loader": "^0.28.11",
"cypress": "^2.1.0",
"cypress-hyperapp-unit-test": "0.0.0-development",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, this does not look right, the version is incorrect

@mrozbarry mrozbarry merged commit 8f11a15 into LearnHyperapp:master Mar 19, 2018
@mrozbarry
Copy link
Contributor

Awesome @bahmutov thanks for the contribution 👍 💯 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants