• Stars
    star
    119
  • Rank 297,930 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 12 years ago
  • Updated over 2 years ago

Reviews

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

Repository Details

Automated cross-browser JavaScript testing made easy

Testee

Greenkeeper badge NPM Version Build Status Gitter Chat

Automated cross-browser testing made easy.

  • Supports any local browser that supports socket.io
  • Supports BrowserStack, Electron and PhantomJS
  • Supports Mocha, Jasmine and QUnit
  • Code coverage
  • Local and remote file testing

Installation

Node.js >= 4 is required. To install, type this at the command line:

npm install testee

You can choose to install globally with -g if you wish, but it is recommended that you install per-project so that CI environments and all members of your team have instant access to the same dependencies.

Command Line Usage

On the command line, you have the following options available:

  • -h, --help: output usage information
  • -V, --version: output the version number
  • -b, --browsers [name]: A comma separated list of browsers you want to run (default: phantom)
  • -R, --root [path|URL]: The server root path or URL the files are relative to
  • -p, --port [port]: The port to run the server on (default: 3621)
  • -r, --reporter [name]: The name of the reporter to use (default: Dot)
  • --reporter-options [options]: The reporter specific options (separated by a comma)
  • -c, --config [file]: Use this JSON or JS configuration file (can be overridden by command line options)
  • --timeout [seconds]: The per test timeout (in seconds)
  • --delay [ms]: When running multiple tests, the time to wait for the browser to shut down before starting it with a new page.
  • -s, --server: Only run the server
  • --coverage: Enable code coverage

Examples

Test with one or multiple files:

testee test.html
testee test1.html test2.html

Save keystrokes with a base path/URL:

testee test1.html test2.html --root=/var/www/app/
testee test1.html test2.html --root=http://yourapp/

Specify browsers:

testee test.html --browsers=firefox,safari

Use a configuration file:

testee test.html --config=testee.json
testee test.html --config=testee.js

Development Flow

During development it is nice to have tests run when files change. Testee is unique in that you do not need Testee while developing. Test pages can be served locally by something like http-server or live-server and opened/reloaded in the browser at will. This is the recommended way to iterate when using Testee. Testee is better used to test against multiple browsers as part of your build and/or release process, or alongside Git hooks for commits or pushes.

Programmatic Usage

For custom scripts (including gulp):

const testee = require('testee');

const browsers = 'phantom';
const config = { reporter: 'spec' };
const files = ['test/test.html'];

testee.test(files, browsers, config)
  .then(function() {
    console.log('done!')
  });

Grunt Usage

See the Testee Grunt plugin grunt-testee for more information.

Configuration API

A simple, local browser config (JSON) example with mostly default values could look like:

{
  "port": 3621,
  "root": "/var/www/app/",
  "reporter": "dot",
  "timeout": 120,
  "delay": 1000,
  "tunnel": {
    "type": "local"
  },
  "launch": {
    "type": "local"
  },
  "browsers": [
    "firefox",
    {
      "browser": "chrome",
      "args": [
        "--headless",
        "--disable-gpu",
        "--no-sandbox",
        "--remote-debugging-port=9222"
      ]
    }
  ]
}

BrowserStack hosts virtual machines running specific versions of web browsers and is extremely useful for cross-browser testing. It will require a username and password. An advanced config (JS) that runs your tests on an iPad Mini and Samsung Galaxy S3 emulator using BrowserStack in a CI environment (outputting XUnit logs) could look like:

require('dotenv').config();

const pkg = require('./package.json');

module.exports = {
    reporter: 'XUnit',
    coverage: {
      dir: 'coverage/',
      reporters: ['text', 'html'],
      ignore: ['node_modules']
    }
    tunnel: {
      type: 'browserstack',
      key: process.env.BROWSERSTACK_KEY
    },
    launch: {
      type: 'browserstack',
      username: process.env.BROWSERSTACK_USER,
      password: process.env.BROWSERSTACK_KEY,
      version: 4
    },
    browsers: [
      { project:pkg.name, build:pkg.version, os:'ios', device:'iPad Mini', os_version:'6.0' },
      { project:pkg.name, build:pkg.version, os:'android', device:'Samsung Galaxy S III', os_version:'4.1' }
    ]
  }
};

General Settings

delay

Type: Number
Default value: 1000
The delay (in milliseconds) between multiple test pages within a single browser.

port

Type: Number
Default value: 3621
The port of the static fileserver used to serve the tests. This will also be used by Localhost tunneling services.

reporter

Type: String
Default value: 'dot'
See Mocha reporters.

root

Type: String Default value: process.cwd()
The root path (or base URL) of the static fileserver used to serve the tests. Any test file will be relative to this path.

timeout

Type: Number
Default value: 120
The time (in seconds) to wait for a test page to report back before an error is thrown. This timeout might, for example, occurr when the given file doesn't exist, the browser didn't start, or the localhost tunnel wasn't running.

Browser Settings

Choose between locally installed browsers and those provided remotely by BrowserStack.

Note: Depending on your OS, the target browsers should not already be open/running before using this library. Electron and PhantomJS are the exceptions, as they can always be started multiple times.

browsers

Type: Array
Default value: ['phantom']
The browsers that will be used to run tests. For local browsers, use a browser name string (see Launchpad for more info). For a remote/BrowserStack browser, use a browser object. To pass command-line arguments and other browser options to Launchpad, use an object containing the browser name and optional array of arguments and options. This browser object will spawn a Chrome Headless browser:

{
  "browser": "chrome",
  "args": [
    "--headless",
    "--disable-gpu",
    "--no-sandbox",
    "--remote-debugging-port=9222"
  ]
}

launch

Type: Object

launch.password

Type: String
Default value: undefined
Your BrowserStack API key.

launch.type

Type: String
Default value: 'local'
The test environment. Possible values are 'local' and 'browserstack'.

launch.username

Type: String
Default value: undefined
Your BrowserStack username.

launch.version

Type: String
Default value: undefined
The BrowserStack API version you'd like to use. The recommended value is 4.

Code Coverage

These options are used to instrument and report code coverage using Istanbul.

coverage

Type: Object

coverage.dir

Type: String
Default value: './coverage'
The directory where the coverage data should be written. text reports will be written to the console.

coverage.ignore

Type: Array
Default value: ['text']
A list of regex patterns that match files to be ignored by coverage instrumentation and reporting.

Note: When using the --coverage option, coverage.ignore will default to ['node_modules'].

coverage.reporters

Type: Array
Default value: []
The type of reporter(s) to use. Available reporters.

Note: babel-plugin-istanbul instruments ES2015/ES6 code automatically.

Localhost Tunneling

A localhost tunneling service makes your local system available to the outside world. This is great if you want to run tests on another system which can't easily reach your local machine. Such a service is necessary for giving BrowserStack workers an endpoint to communicate with.

tunnel

Type: Object
Default value: { type: 'local' }
See miner documentation for all available tunneling services and options.

Electron & PhantomJS

If you plan to use these, be sure to add electron and/or phantomjs-prebuilt to your list of devDependencies, or have them installed globally on your system.

Chrome Headless

To easily leverage Chrome Headless, you can add puppeteer to your project as a development dependency and the following browser option to your config's browsers array:

const puppeteer = require('puppeteer')
process.env.LAUNCHPAD_CHROMIUM = puppeteer.executablePath()

module.exports = {
  "browser": "chromium",
  "args": [
    "--headless",
    "--disable-gpu",
    "--no-sandbox",
    "--remote-debugging-port=9222"
  ]
}

CI integration

Because different reporters are supported for the test result output, it is easy to obtain XUnit style XML files that integrate with CI servers like Jenkins. Just use the 'XUnit' reporter and write the output into a file. The following example writes the XML result of a Firefox test to "testresults.xml":

testee test.html --browsers=firefox --reporter=XUnit > testresults.xml

See available reporters.

Note: If your CI platform uses Ubuntu to run builds, such as Travis CI, additional configuration is needed for FireFox to run properly. See bellow for more details.

Launching FireFox on Linux

The Linux version of FireFox uses D-Bus which is not preinstalled on all Linux distributions, including Ubuntu, this can cause errors when launching tests, heavily pollute Testee's debug logs with error messages, and make FireFox run slow.

To solve this problem, we recommend installing dbus-x11 via the apt package manager before the build executes.

Here is an example configuration for Travis CI:

language: node_js
node_js:
  - "6"
addons:
  firefox: "latest-esr"
  # Install D-Bus here
  apt:
    packages:
      - "dbus-x11"
before_install:
  - "export DISPLAY=:99.0"
  - "sh -e /etc/init.d/xvfb start"

Capturing console.log and console.error

All calls to console.log and console.error in a test are tracked. To get the output during a test run, set the DEBUG environment variable to testee:console-log:

DEBUG=testee:console-log testee test.html --browsers=canary

Debugging

Detailed debugging information can be enabled in any environment (command line, Grunt, programatically) by setting the DEBUG environment variable to testee:*:

DEBUG=testee:* testee test.html --browsers=canary

Client side configuration

In most cases there is no need to change your actual test code.

One exception is when you load your testing library using an asynchronous client side loader like Steal or RequireJS because Testee won't know which library adapters to attach. In this case, you need to call Testee.init() manually once the test library is loaded:

<script>
  define(['qunit'], function() {
    // Needs to check because it will only be available
    // when running the test with Testee
    if(window.Testee) {
      window.Testee.init();
    }

    QUnit.start();
  });
</script>

In some testing environments, reporting test progress via REST may work better than socket.io:

<script>
  window.Testee = {
    provider: {
      type: 'rest'
    }
  };
</script>

Troubleshooting

Browser caching

On Safari, disable caching by choosing Develop -> Disable Caches and also Develop -> Empty Caches. Without these preferences, updated tests may not load in the browser.

"UnhandledPromiseRejectionWarning" messages

If you see a message which looks like the one below, there is most likely an incorrect assertion somewhere in your tests. Please refer to issue #136 for an example. If the warning is unrelated to your assertions, please open an issue.

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1):
Error: Test `title` should be a "string" but "number" was given instead.

More Repositories

1

jquerypp

jQuery's missing utils and special events
JavaScript
1,220
star
2

react-to-web-component

Convert react components to native Web Components. Works with Preact too!
TypeScript
688
star
3

documentjs

The sophisticated documentation engine
JavaScript
599
star
4

funcunit

A functional test suite based on jQuery
JavaScript
570
star
5

syn

Standalone Synthetic Event Library
JavaScript
444
star
6

checklist

A JavaScript Project Checklist
JavaScript
146
star
7

velocirender

Accelerated server-side rendering.
JavaScript
128
star
8

documentcss

A documentation/guide portal for the Live Style Guide feature of DocumentJS
HTML
72
star
9

hatchify

JavaScript, open source, CRUD app scaffolding that turns schemas into an app quickly, while allowing customization later.
TypeScript
71
star
10

github-actions-deploy-docker-to-ec2

GitHub Action to deploy any docker-composed app to an AWS EC2 VM.
59
star
11

launchpad

NodeJS Browser Launcher
JavaScript
45
star
12

ylem

Add Observable View-Models to React components
JavaScript
42
star
13

bitops

Automate the provisioning and configuration of cloud infrastructure with BitOps docker image
Python
34
star
14

canui

CanJS and jQuerypp
JavaScript
28
star
15

use-simple-reducer

A react state mechanic that supports simple asynchronous reducer functions
TypeScript
27
star
16

github-actions-react-to-github-pages

GitHub Action for hosting a React app on GitHub Pages
22
star
17

training

Bitovi's training material
JavaScript
19
star
18

github-actions-deploy-eks-helm

Shell
19
star
19

canjs.com

The CanJS homepage and distributable files
JavaScript
17
star
20

mutationobserver

JavaScript
15
star
21

academy

Everything we know about frontend, backend, UX, and Devops consulting and management.
TypeScript
14
star
22

landscaper

Apply code mods to projects, awesomely
JavaScript
14
star
23

optimizely-as-code

optimizely-as-code
JavaScript
12
star
24

github-actions-aws-secrets-manager

TypeScript
11
star
25

miner

Localhost tunnelling service wrappers
JavaScript
11
star
26

github-actions-storybook-to-github-pages

Deploy a Storybook build to GitHub Pages
9
star
27

github-actions-deploy-static-site-to-aws

HCL
9
star
28

querystring-parser

JavaScript
8
star
29

github-actions-docker-publish

8
star
30

eslint-config

JavaScript
8
star
31

github-actions-deploy-stackstorm

GitHub Action to deploy StackStorm to AWS (Ξ²eta)
Shell
8
star
32

fluid-text

Tailwind utility class plugin for sizing text smoothly between your breakpoints.
JavaScript
8
star
33

universal.js

Universal library wrappers
JavaScript
7
star
34

stateful-mocks

TypeScript
7
star
35

crawlify

JavaScript
6
star
36

github-actions-deploy-prometheus

Deploy a prometheus and configure it to monitor things
5
star
37

sequelize-create-with-associations

TypeScript
5
star
38

github-actions-docker-to-azure-vm

Stand up an Azure VM and run your Docker Compose on it.
Shell
5
star
39

eslint-plugin

TypeScript
4
star
40

cordovaboilerplate

A starter app for Cordova projects
JavaScript
4
star
41

bootdocs

Bootstrap documentation generated with DocumentJS
CSS
4
star
42

slack-bot-gptchat

App to manage a gpt chat bot server
Python
4
star
43

github-actions-gcp-bucket

Shell
3
star
44

eslint-plugin-nx-glue

Allows local ESLint Rules written in TypeScript to be available within a Nx workspace or any project
TypeScript
3
star
45

test-saucelabs

Runs test pages on Saucelabs
JavaScript
3
star
46

statistical-software-estimator

A statistical estimator for software projects.
JavaScript
3
star
47

opensource-analytics-dashboard

TypeScript
3
star
48

engine-dependencies

Install npm dependencies based on what version of Node you are using
JavaScript
3
star
49

web-locks-polyfill

A polyfill for the web-locks api
JavaScript
3
star
50

jira-auto-scheduler

A JIRA auto-scheduling application for product management.
JavaScript
3
star
51

github-actions-commons

Common things for GitHub Actions
HCL
3
star
52

shadow

Shadow-DOM for everyone
JavaScript
3
star
53

cqrs-example

TypeScript
3
star
54

signalr-chat

JavaScript
3
star
55

github-actions-deploy-docker-to-gcp

Deploy an app or service to GCP Compute Engine
Shell
3
star
56

dog-things-react

A React version of the Dog Things app with Velocirender
JavaScript
3
star
57

github-actions-deploy-aws-ecr-registry

Repo to deploy an AWS ECR Registry
2
star
58

calendar-events-component

Show events from a google calendar
HTML
2
star
59

signalr-hub

JavaScript
2
star
60

app-staffing

TypeScript
2
star
61

grunt-testee

Grunt task for Testee
JavaScript
2
star
62

vintage-shop

An example app for learning style guide driven development
CSS
2
star
63

devops-training-ec2-gha-example

Example repo to deploy an app to an EC2 instance with a GitHub Action
2
star
64

fast-react-static-renderer

Fast react static render framework
2
star
65

nx-cucumber-plugin

TypeScript
2
star
66

bithub-embed

Embed code for Bithub.com
CSS
2
star
67

github-actions-deploy-github-runner-to-ec2

Deploys a GitHub runner to an EC2 instance
Shell
2
star
68

github-actions-deploy-rds

Deploys an AWS RDS Database instance
2
star
69

testee-client

Testee client adapters for QUnit, Jasmine and Mocha
JavaScript
1
star
70

operations-example-deno-ec2

deploy a simple deno app to EC2
Dockerfile
1
star
71

github-actions-npm-publish

Github Action for NPM Publish
1
star
72

github-actions-deploy-ecs

1
star
73

github-actions-deploy-eks

github action to deploy AWS eks cluster
1
star
74

bitops-operations-repo-generator

JavaScript
1
star
75

github-actions-apply-sql-files-to-postgres

Iterate through .sql files inside a folder using psql to initialize a database
1
star
76

steal.js

JavaScript
1
star
77

dog-things-vue

Example app of using Velocirender in a Vue app
Vue
1
star
78

jmvc-generators

Generators for JavaScriptMVC
HTML
1
star
79

bitovi-tools

Tasks for building Bitovi projects(eg: CanJS, jQuery++)
JavaScript
1
star
80

book

Book
JavaScript
1
star
81

steal-build

StealJS and build tools for NodeJS
JavaScript
1
star
82

n8n-getting-started

Bitovi's getting started guide for N8N
Dockerfile
1
star
83

learn-typescript

Learn TypeScript with small examples
TypeScript
1
star
84

devops-streaming-examples

Examples for Bitovi DevOps Streaming
JavaScript
1
star
85

snapshot-test

Visual snapshot testing in the browser for any test framework.
JavaScript
1
star
86

temporal-publish-sample

TypeScript
1
star
87

scrolling-nav

JavaScript
1
star
88

bitscaffold

TypeScript
1
star
89

voice-guided-interview

Example app using voice to fill out an interview.
JavaScript
1
star
90

github-actions-deploy-kubernetes

GitHub Action to deploy Kubernetes
1
star
91

github-actions-deploy-aurora

GitHub action to deploy an Aurora DB Instance
1
star
92

github-actions-docker-ecr-publish

1
star
93

github-actions-deploy-redis-db

Deploys a Redis database cluster group. From one to multiple nodes.
1
star