Skip to content

bcowgill/javascript-testing-recipes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaScript Testing Recipes

This directory contains the code examples for JavaScript Testing Recipes. Everything you need to run the examples is here, including all third-party libraries. All the examples should run successfully out of the box.

The examples from the book are in the browser/ and node/ directories. Within those directories, any file named test.html can be opened in a web browser and it will run the tests for that example. Similarly, any file named test.js can be run with Node.js.

You can also run any of the browser examples using PhantomJS, using this command, replacing hello_world with the name of the example you want to run:

$ phantomjs phantom.js browser/hello_world/test.html

The node_modules/ and vendor/ directories contain third-party libraries, and package.json contains project meatadata that's used to install all the dependencies the examples rely on. You should not need to modify any of these files.

You can use test-phantom.sh to run all the browser tests using phantomjs.

You can use test-node.sh to run all the node tests using nodejs.

You can change the test output format using FORMAT= variable (spec, xml, html, json etc)

FORMAT=spec ./test-node.sh
FORMAT=spec ./test-phantom.sh

You can run specific tests which match a string.

TEST=PatternMatcher ./test-node.sh  # only runs it/describe suites with PatternMatcher in their descriptive string.
TEST=_only_ ./test-node.sh  # simulate it.only or describe.only by adding _only_ to the test name

You can construct index.html for running the tests in browser:

find browser/ -name '*.html' | sort | perl -pne '
   BEGIN {print "<html>\n<head>\n<title>Browser Based Test Plans</title>\n<style>\nbody {\nbackground: black;\ncolor: yellow;\n}\n</style>\n</head>\n<body>\n<h4>Browser Based Test Plans</h4>\n<ul>\n"; }
   END { print "</ul>\n</body>\n</html>\n"; }
   chomp;
   m{browser/(.+)/(.+)\.html}xms;
   $name = $1;
   $type = $2;
   $type = ($type eq "test") ? "test suite": "$type page";
   $_ = qq{<li><a href="$_">$name $type</a></li>\n}
' > index.html

URL references from the book:

Introduction

Testing Frameworks

Testing Basics

After Blocks

Stub, Mock and Spy

Asyncronous Testing

Event Emission Testing

Event Listening Testing

Node Stream Testing

Form Validation

Modular Interfaces

Talking to the Server

Web Storage

URL Location Testing

Build Tools

Cross-Browser Testing

Basic Node Server Testing

Servers with Databases and Testing them

Extracting Services from Server and Testing more efficiently

Autentication and testing through browsers, real and simulated

About

Source code from book Javascript Testing Recipes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published