• Stars
    star
    1,363
  • Rank 34,478 (Top 0.7 %)
  • Language
    JavaScript
  • Created almost 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A workshop for learning how to test JavaScript applications

Testing Workshop

πŸ‘‹ hi there! My name is Kent C. Dodds! This is a workshop repo to teach you about testing JavaScript applications.

NOTICE: If you're coming here from my Frontend Masters 2017 workshop, I recommend you watch the updated 2018 workshop instead. If you'd rather follow the 2017 workshop, then please go to the fem branch to make sure you're looking at the accurate information for your workshop.

chat-badge Build Status AppVeyor Build Status Code Coverage License All Contributors

PRs Welcome Code of Conduct Watch on GitHub Star on GitHub Tweet

Table of Contents

Topics covered

  1. Unit Testing with Jest
  2. Integration Testing with Jest
  3. End to End (E2E) Testing with Cypress

We'll mention other forms of testing, but these are the types we'll focus on and learn in this workshop. Learn more about the course goals and specific topics covered in the INSTRUCTIONS.md file.

NOTE: This repository is meant for instructional purposes. While you'll probably learn a great deal looking through this project, remember that it's not necessarily a recommendation to test your apps this way. Some code is "over covered" by unit, integration, and end-to-end tests simply to demonstrate the differences. In a real application it would be unnecessary to be this extensive in coverage.

Branches

This project has been used to teach about testing in various settings. You may want to switch to the appropriate branch for this workshop. Otherwise the code you're looking at may not be exactly the same as the code used in the setting you're working with.

  • Frontend Masters 2017 fem

System Requirements

  • git v2.14.1 or greater
  • NodeJS v8.9.4 or greater
  • npm v5.6.0 or greater

All of these must be available in your PATH. To verify things are set up properly, you can run this:

git --version
node --version
npm --version

If you have trouble with any of these, learn more about the PATH environment variable and how to fix it here for windows or mac/linux.

Setup

After you've made sure to have the correct things (and versions) installed, you should be able to just run a few commands to get set up:

git clone https://github.com/kentcdodds/testing-workshop.git
cd testing-workshop
npm run setup --silent

This may take a few minutes. It will ask you for your email. This is optional and just automatically adds your email to the links in the project to make filling out some forms easier If you get any errors, please read through them and see if you can find out what the problem is. You may also want to look at Troubleshooting. If you can't work it out on your own then please file an issue and provide all the output from the commands you ran (even if it's a lot).

Running the app

To get the app up and running (and really see if it worked), run:

npm run dev

This will start the api server, and the client server in development mode at the same time. Your browser should open up automatically to http://localhost:3000 (if it doesn't, just open that yourself) and you should be able to start messing around with the app.

Here's what you should be looking at:

App Screenshot

If this fails at any point for you, please take a minute to read through any error messages you see and try to troubleshoot the issue. If you can't work it out, feel free to open an issue.

About the app

This app is based on the Hashrocket project called Today I Learned. It's a real working application but has been simplified to help us focus on learning testing rather than worrying about distracting ourselves with setting up the project. For example the database is actually just a simple JavaScript file. Every time you start the app, all the data is reset (and in development mode, data is randomly generated).

Continuous Integration

We're using two CI services:

  • Travis (Linux): find config in .travis.yml
  • AppVeyor (Windows): find config in appveyor.yml

Hosting

The backend code is deployed to now.sh: til.now.sh. Try hitting one of the unauthenticated endpoints like /api/posts (note: it's using the open source free tier, so it may take a while to respond as it warms up). The Travis build is responsible for deploying the backend to now.sh.

The frontend code is deployed using netlify: til.netlify.com. We could host the frontend code on now as well, except Netlify has some pretty awesome features with GitHub integration, and I want to show those off (and benefit from them as well). The frontend code is deployed to netlify using Netlify's integration with GitHub.

Register and Login

If you want to login, go ahead and register a new account and login with that one.

To stop all the servers, hit Ctrl + C.

Troubleshooting

"npm run setup" command not working

Here's what the setup script does. If it fails, try doing each of these things individually yourself:

# verify your environment will work with the project
node ./scripts/verify

# install dependencies in the root of the repo
npm install

# install dependencies in the shared directory
npm install --prefix shared

# install dependencies in the server directory
npm install --prefix server

# install dependencies in the client directory
npm install --prefix client

# verify the project is ready to run
npm run lint
npm run test:coverage
npm run test:e2e:run

If any of those scripts fail, please try to work out what went wrong by the error message you get. If you still can't work it out, feel free to open an issue with all the output from that script. I will try to help if I can.

"npm run dev" command not working

If it doesn't work for you, you can start each of these individually yourself (in separate terminals):

cd server
npm run dev
cd client
npm run dev

If any of those scripts fail, please try to work out what went wrong by the error message you get. If you still can't work it out, feel free to open an issue with all the output from that script. I will try to help if I can.

"npm test" command not working; "./jest" command not working

When attempting to run Jest in watch mode, you may encounter an error that says something like:

`fsevents` unavailable (this watcher can only be used on Darwin)'

Jest watch mode has a dependency on a tool called watchman, which needs to be installed globally on your machine.

To fix this error, please make sure you have watchman installed for your preferred operating system.

NOTE: installing watchman via npm installs an outdated version of the package. To get the latest version of watchman, it is preferred that you install through your operating system's package manager instead.

Structure

This project has a bit of a unique setup. Normally you'll have just a single package.json at the root of your repository, but to simplify setup I've included both the server and client projects in a single repository. The root of the project has a package.json as does server, and client. While you'll be working in the source code and tests in these folders, you should be able to leave you command line in the root directory for the whole workshop.

Contributors

Thanks goes to these wonderful people (emoji key):


Kent C. Dodds

πŸ’» πŸ“– πŸš‡ ⚠️

Osama Jandali

πŸ’» 🎨

Stefan Ivic

πŸ›

Nick Klepinger

πŸ›

Abinav Seelan

πŸ›

Philip Sotirov

πŸ›

Austin Wood

πŸ“–

WK

πŸ›

Richard Perkins

⚠️

This project follows the all-contributors specification. Contributions of any kind welcome!

LICENSE

This material is available for private, non-commercial use under the GPL version 3. If you would like to use this material to conduct your own workshop, please contact me at [email protected]

More Repositories

1

cross-env

πŸ”€ Cross platform setting of environment scripts
JavaScript
6,313
star
2

match-sorter

Simple, expected, and deterministic best-match sorting of an array in JavaScript
TypeScript
3,719
star
3

advanced-react-patterns

This is the latest advanced react patterns workshop
JavaScript
2,885
star
4

babel-plugin-macros

🎣 Allows you to build simple compile-time libraries
JavaScript
2,622
star
5

react-hooks

Learn React Hooks! 🎣 βš›
JavaScript
2,550
star
6

bookshelf

Build a ReactJS App workshop
JavaScript
2,533
star
7

kentcdodds.com

My personal website
MDX
2,143
star
8

use-deep-compare-effect

πŸ‹ It's react's useEffect hook, except using deep comparison on the inputs, not reference equality
TypeScript
1,726
star
9

mdx-bundler

🦀 Give me MDX/TSX strings and I'll give you back a component you can render. Supports imports!
JavaScript
1,702
star
10

react-performance

Let's make our apps fast ⚑
JavaScript
1,557
star
11

advanced-react-patterns-v2

Created with CodeSandbox
JavaScript
1,499
star
12

babel-plugin-preval

🐣 Pre-evaluate code at build-time
TypeScript
1,357
star
13

advanced-react-patterns-v1

The course material for my advanced react patterns course on Egghead.io
HTML
1,092
star
14

react-testing-library-course

Test React Components with Jest and React Testing Library on TestingJavaScript.com
JavaScript
1,004
star
15

testing-react-apps

A workshop for testing react applications
JavaScript
977
star
16

kcd-scripts

CLI toolbox for common scripts for my projects
JavaScript
870
star
17

stop-runaway-react-effects

πŸƒ Catches situations when a react use(Layout)Effect runs repeatedly in rapid succession
JavaScript
788
star
18

netlify-shortener

Your own free URL shortener with Netlify
JavaScript
778
star
19

beginners-guide-to-react

The Beginner's Guide To ReactJS
HTML
757
star
20

react-suspense

React Suspense workshop
JavaScript
746
star
21

old-kentcdodds.com

Kent's Homepage
JavaScript
736
star
22

ng-stats

Little utility to show stats about your page's angular digest/watches.
JavaScript
657
star
23

dotfiles

Shell
510
star
24

js-testing-fundamentals

Fundamentals of Testing in JavaScript on TestingJavaScript.com
JavaScript
500
star
25

react-toggled

Component to build simple, flexible, and accessible toggle components
JavaScript
453
star
26

jest-cypress-react-babel-webpack

Configure Jest for Testing JavaScript Applications and Install, Configure, and Script Cypress for JavaScript Web Applications on TestingJavaScript.com
JavaScript
442
star
27

advanced-remix

TypeScript
393
star
28

react-testing-library-examples

Created with CodeSandbox
HTML
380
star
29

testing-node-apps

Test Node.js Backends on TestingJavaScript.com
JavaScript
365
star
30

es6-workshop

A very hands on πŸ‘ workshop πŸ’» about ES6 and beyond.
JavaScript
362
star
31

es6-todomvc

The vanillajs example converted to es6
JavaScript
353
star
32

babel-plugin-codegen

πŸ’₯ Generate code at build-time
TypeScript
347
star
33

eslint-config-kentcdodds

ESLint configuration for projects that I do... Feel free to use this!
JavaScript
338
star
34

cloc

An npm module for distributing cloc by Al Danial
JavaScript
325
star
35

asts-workshop

Improved productivity πŸ’― with the practical πŸ€“ use of the power πŸ’ͺ of Abstract Syntax Trees 🌳 to lint ⚠️ and transform πŸ”€ your code
JavaScript
295
star
36

how-jest-mocking-works

JavaScript
294
star
37

js-mocking-fundamentals

JavaScript Mocking Fundamentals on TestingJavaScript.com
JavaScript
281
star
38

webpack-config-utils

Utilities to help your webpack config be easier to read
JavaScript
262
star
39

express-app-example

How I structure Express Apps (example repo)
JavaScript
261
star
40

dom-testing-library-with-anything

Use DOM Testing Library to test any JS framework on TestingJavaScript.com
JavaScript
217
star
41

learn-react

Learn React with a laser focused, guided approach.
JavaScript
213
star
42

the-webs-next-transition

TypeScript
211
star
43

modern-react

workshop about React's hottest new features in 16.7.0
JavaScript
207
star
44

react-jest-workshop

JavaScript
199
star
45

react-github-profile

JavaScript
199
star
46

react-ava-workshop

🐯 A workshop repository for testing React βš› with AVA πŸš€ --> slides
JavaScript
192
star
47

api-check

VanillaJS version of ReactJS propTypes
JavaScript
191
star
48

starwars-names

Get a random Star Wars name
JavaScript
185
star
49

import-all.macro

A babel-macro that allows you to import all files that match a glob
JavaScript
177
star
50

remix-todomvc

An Implementation of TodoMVC with Remix
TypeScript
172
star
51

rtl-css-js

RTL for CSS in JS
JavaScript
162
star
52

react-workshop-app

An abstraction for all my React workshops
TypeScript
144
star
53

generator-kcd-oss

A yeoman generator for my open source modules
JavaScript
140
star
54

remix-workshop

TypeScript
133
star
55

issue-template

A way for github projects to make templates for github issues.
JavaScript
131
star
56

react-hooks-and-suspense-egghead-playlist

This is the code for the egghead playlist "React Hooks and Suspense"
JavaScript
128
star
57

modern-javascript

Get up to speed on the latest, most useful JavaScript features to level up your programming
JavaScript
123
star
58

kcd-discord-bot-v1

The bot for the KCD discord community
TypeScript
123
star
59

app-dev-tools

An example of how to create and hook up App DevTools to improve your development productivity of your application
JavaScript
122
star
60

preval.macro

Pre-evaluate code at build-time with babel-macros
JavaScript
120
star
61

split-guide

A tool to help generate code for workshop repositories
JavaScript
108
star
62

kcd-learning-clubs-ideas

πŸ“ Ideas for curriculum and schedule templates for KCD Learning Clubs
106
star
63

simply-react

JavaScript
104
star
64

nps-utils

Utilities for http://npm.im/nps (npm-package-scripts)
JavaScript
101
star
65

glamorous-website

This is still a work in progress
JavaScript
98
star
66

jest-glamor-react

Jest utilities for Glamor and React
JavaScript
98
star
67

react-hooks-pitfalls

The slides and code examples for my talk "React Hook Pitfalls"
JavaScript
94
star
68

webpack-validator-DEPRECATED

Use this to save yourself some time when working on a webpack configuration.
JavaScript
93
star
69

onewheel-blog

TypeScript
90
star
70

remix-tutorial-walkthrough

I live streamed working through the Remix Jokes App Tutorial
TypeScript
87
star
71

rebase-and-merge

Making this a reality ☞
JavaScript
82
star
72

managing-state-management-slides

79
star
73

css-in-js-precompiler

WORK IN PROGRESS: Precompiles CSS-in-JS objects to CSS strings
JavaScript
72
star
74

create-react-app-react-testing-library-example

JavaScript
67
star
75

10-practical-js-features

JavaScript
67
star
76

rename-gh-to-main

JavaScript
67
star
77

full-stack-components

TypeScript
66
star
78

fakebooks-remix

The Remix version of the fakebooks app demonstrated on https://remix.run. Check out the CRA version: https://github.com/kentcdodds/fakebooks-cra
TypeScript
66
star
79

cypress-testing-workshop

A workshop for learning how to write cypress tests
JavaScript
65
star
80

prettier-eslint-atom

DEPRECATED IN FAVOR OF prettier-atom + ESLint integration
JavaScript
64
star
81

repeat-todo

A simple app I made for my wife
JavaScript
63
star
82

why-react-hooks

Talk about React hooks
JavaScript
62
star
83

codegen.macro

JavaScript
61
star
84

talks

A repo with links to talks that I've given
59
star
85

quick-stack

TypeScript
57
star
86

binode

JavaScript
57
star
87

airtable-netlify-short-urls

There's a simpler version using Netlify redirects instead of Airtable here
JavaScript
57
star
88

fully-typed-web-apps-demo

TypeScript
53
star
89

argv-set-env

Set environment variables in npm scripts
JavaScript
52
star
90

react-test-context-provider

A function that allows you to specify context to pass to a child component (intended for testing only).
JavaScript
48
star
91

concurrent-react

React Suspense Egghead course
JavaScript
47
star
92

incremental-react-router-to-remix-upgrade-path

JavaScript
46
star
93

remix-mdx

JavaScript
45
star
94

setup-prettier

JavaScript
44
star
95

podcastify-dir

Take a directory of audio files and syndicate them with an rss feed
JavaScript
42
star
96

aha-programming-slides

JavaScript
42
star
97

workshop-setup

Verify and setup a repository for workshop attendees
JavaScript
42
star
98

jest-esmodules

JavaScript
40
star
99

typing-for-kids

A little app I made for my kids for Christmas :)
JavaScript
40
star
100

react-suspense-simple-example

JavaScript
39
star