• This repository has been archived on 06/Apr/2018
  • Stars
    star
    222
  • Rank 177,746 (Top 4 %)
  • Language
    Shell
  • License
    Other
  • Created almost 11 years ago
  • Updated over 8 years ago

Reviews

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

Repository Details

Docker Node Tester

DNT: Docker Node Tester

NPM

Use Docker to test code against multiple versions of Node.js and io.js simultaneously

NAN DNT

Docker is a tool that simplifies the use of Linux containers to create lightweight, isolated compute "instances".

DNT contains two tools that work with Docker and Node.js to set-up containers for testing and run your project's tests in those containers.

What incantations does this magic require?

  1. You will need to install Docker on your system, see the installation instructions (don't be afraid, it's pretty simple).
  2. Install DNT from npm: sudo npm install dnt -g
  3. Create a .dntrc file for your project(s) (instructions below).
  4. Run sudo setup-dnt to set up the Docker images required for your project. It will take some time to download, compile and install the required software but once you've done it once your images are re-usable and you'll only need to set up additional images you require in the future.
  5. Run sudo dnt to run your test suite via DNT against all of the Node versions you've specified.

About the images DNT creates

The setup-dnt script sets up the most basic images required to run Node.js applications, nothing extra.

It first creates an image called "dev_base" that uses the default Docker "ubuntu" image and adds the build tools required to compile and install Node.js

Next it creates a "node_dev" image that contains a complete copy of the Node.js source repository. Finally, it creates a series of images that are required by your current project (or the .dntrc file in your current directory).

For each Node version, you will end up with an image named "node_dev-VERSION" where VERSION is the branch or tag in the Node.js repository. Typically this takes the format: "v0.x.y", e.g. "v0.10.22", "v0.8.26", etc. You can also specify "master" if you need the bleeding edge.

.dntrc

Both setup-dnt and dnt read the .dntrc file in the current working directory to load the current configuration. The file is simply read as a Bash script so it can contain arbitrary Bash commands. To configure DNT you need to set some key variables: NODE_VERSIONS and TEST_CMD. Optional variables include COPYDIR, OUTPUT_PREFIX, SIMULTANEOUS, COPY_CMD and LOG_OK_CMD.

A basic .dntrc file for a Node package with a native add-on component might look like this:

## DNT config file
## see https://github.com/rvagg/dnt

NODE_VERSIONS="master v0.12.4 v0.10.38 v3.3.0 v4.0.0"
OUTPUT_PREFIX="libssh-"
TEST_CMD="\
  cd /dnt/ &&                                                    \
  npm install &&                                                 \
  node_modules/.bin/node-gyp --nodedir /usr/src/node/ rebuild && \
  node_modules/.bin/tap test/*-test.js                           \
"

NODE_VERSIONS

Required

A space-separated list of branches or tags in the Node.js repository. For each version listed, the Docker image for that version will be run with a copy of your source code and the TEST_CMD will be executed.

This can also include io.js version numbers.

Note also you can override the list by supplying any number of versions as command-line arguments:

$ sudo dnt master v0.10.20

Updating your list of NODE_VERSIONS

As you add new versions of Node to test against you will need to re-run sudo setup-dnt to make sure you have images set-up properly for these new versions.

Testing against Node master

If you are using "master" as one of your versions then you will need to occasionally remove and rebuild your master image:

$ sudo docker rmi node_dev-master
$ sudo setup-dnt

This removes the Docker image for master and rebuilts it from the latest master in the Node repository.

TEST_CMD

Required

A command, or list of commands to be executed with Bash (/bin/bash -c "${TEST_CMD}") that will invoke your tests and cause them to run. The commands will be executed as root in the container and you may need to install additional software to execute your tests or compile your code.

You should prefer && to ; to separate commands so a failure causes the list of commands to fail.

By default, your entire source directory minus .git/ and build/ are copied into the container; this includes node_modules/. The copy will be located in the /dnt/ directory of the container (this can be configured with COPY_CMD below).

If you are using native-addons as dependencies you may need to purge them from node_modules/ directory prior to running npm install to reinstall them.

Your test output should include some method of verifying a pass or fail. See LOG_OK_CMD for how to parse this if required. You should also make it verbose enough to debug the output from the log files sent to /tmp/.

COPYDIR

Default: current working directory

DNT copies the current working directory into each image prior to test execution. This is done by mounting the directory in the image (read-only) and using rsync to perform a copy. To customise the directory being mounted, change COPYDIR.

OUTPUT_PREFIX

Default: ""

Logs for each run are sent to /tmp/dnt-VERSION.out where "VERSION" is the Node.js version being used. Supply an OUTPUT_PREFIX to prefix a project name to the beginning of the filenames.

SIMULTANEOUS

Default: number of cores on the current computer

By default, DNT will run parallel tests, up to the number of cores on the current computer. This may be too much for some computers, depending on other system resources and the jobs being executed so you may want to lower this number.

COPY_CMD

Default: rsync -aAXx --delete --exclude .git --exclude build /dnt-src/ /dnt/

Override this command to adjust the way DNT copies the mounted source directory to the required test folder in the image. The source folder will always be mounted as /dnt-src/ but the /dnt/ target directory can be changed if you take this into account in your TEST_CMD.

LOG_OK_CMD

Default: tail -1

DNT is designed to work best with TAP which outputs a single "ok" or "not ok" as the final line of the test execution. The LOG_OK_CMD is a command that will take the complete log file piped to it and return either an "ok" to indicate a pass or something else to indicate a failure. i.e. cat log | ${LOG_OK_CMD}.

If you are not using TAP-output then you can adjust the LOG_OK_CMD to transform the source to return an "ok" when the tests have passed. You may need to resort to a bit of sed depending on your testing framework.

CONSOLE_LOG

Default: false

When set to true standard error is redirected to standard output and then tee sends this standard input to standard output (i.e. the console from which the dnt command was executed) and the normal log file will also be logged too.

Example .dntrc files

  • LevelDOWN: simple requirements, latest 0.8, 0.10, 0.11 and master.
  • NAN: needs to test across many versions of Node, including master. Has tests installed and run in non-root directory.
  • node-ssh: latest 0.10, 0.11 and master only. Needs additional software installed on the image prior to compile.
  • rvagg/node-canvas: latest 0.8, 0.10, 0.11 and master only. Needs Cairo installed and translates the dot reporter for Mocha tests.

Other considerations

  • You should check your logs occasionally to make sure that tests are actually running. node-tap, if run incorrectly can execute zero tests and output an "ok" which will still pass. Your LOG_OK_CMD may also be doing unexpected things.

  • The initial node_dev Docker image you create has a copy of the registry at the time you first run sudo setup-dnt. As this gets older it will take longer to download the latest master or new versions of Node. You may want to sudo docker rmi node_dev to fetch a new copy.

  • If your test environment requires specific fixtures that take a considerable amount of time to set up for each test (for example an installation of a database or other complex software) then you could consider customising the node_dev Docker image to have the environment partially set up so you don't need to repeat the process for each test run. Note though that this is not portable for other people needing to run your tests with DNT without specific additional instructions.

What about Mac, Windows, SOLARIS?

What about them?

Solaris invented containers with "zones" and Solaris users are grown-ups and can take care of themselves.

Mac users can install docker via docmac: npm install -g docmac && docmac or follow these instructions.

The rest of you babies, well... are you really deploying on those toys?

Contributing

Yes please, I'm happy to share ownership with people making significant contributions to the code, you're welcome to help steer the project if you invest enough.

Currently DNT serves my simple needs but I imagine that for a lot of people there will be additional requirements different to my own. Please open an issue or pull request for further discussion!

Contributors / collaborators / maintainers

Licence & copyright

Copyright (c) 2013 Rod Vagg

DNT is licensed under an MIT +no-false-attribs license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.

More Repositories

1

through2

Tiny wrapper around Node streams2 Transform to avoid explicit subclassing noise
JavaScript
1,894
star
2

node-worker-farm

Distribute processing tasks to child processes with an ΓΌber-simple API and baked-in durability & custom concurrency options.
JavaScript
1,747
star
3

github-webhook-handler

Node.js web handler / middleware for processing GitHub Webhooks
JavaScript
783
star
4

bl

Buffer List: collect buffers and access with a standard readable Buffer interface, streamable too!
JavaScript
420
star
5

bole

A tiny JSON logger
JavaScript
265
star
6

nodei.co

nodei.co - Node.js badges, that's all
JavaScript
258
star
7

archived-morkdown

A simple Markdown editor
JavaScript
245
star
8

node-errno

libuv errno details exposed
JavaScript
244
star
9

ghauth

Create and load persistent GitHub authentication tokens for command-line apps
JavaScript
184
star
10

archived-node-libssh

A Low-level Node.js binding for libssh
C++
132
star
11

archived-traversty

Headache-free DOM collection management and traversal
JavaScript
131
star
12

github-webhook

A flexible web server for reacting GitHub Webhooks
JavaScript
114
star
13

archived-node-pygmentize-bundled

A simple wrapper around Python's Pygments code formatter, with Pygments bundled
HTML
95
star
14

archived-lmdb

C++
85
star
15

jsonist

JSON over HTTP: A simple wrapper around hyperquest for dealing with JSON web APIs
JavaScript
66
star
16

isstream

Determine if an object is a Node.js Stream
JavaScript
63
star
17

polendina

Non-UI browser testing for JavaScript libraries from the command-line
JavaScript
63
star
18

archived-CAPSLOCKSCRIPT

JAVASCRIPT: T-H-E L-O-U-D P-A-R-T-S
JavaScript
60
star
19

archived-gfm2html

Convert a GitHub style Markdown file to HTML, complete with inline CSS
CSS
49
star
20

archived-node-level-session

A very fast and persistent web server session manager backed by LevelDB
JavaScript
49
star
21

cborg

fast CBOR with a focus on strictness
JavaScript
44
star
22

csv2

A Node Streams2 CSV parser
JavaScript
38
star
23

archived-pangyp

Node.js and io.js native addon build tool a (hopefully temporary) fork of TooTallNate/node-gyp
Python
38
star
24

archived-tsml

ES6 template string tag for multi-line cleaning - squash multi-line strings into a single line
JavaScript
37
star
25

archived-node-level-mapped-index

JavaScript
35
star
26

archived-node-rsz

An image resizer for Node.js
JavaScript
34
star
27

iamap

An Immutable Asynchronous Map
JavaScript
31
star
28

archived-servertest

A simple HTTP server testing tool
JavaScript
30
star
29

node-du

A simple JavaScript implementation of `du -sb`
JavaScript
29
star
30

archived-node-brucedown

A near-perfect GitHub style Markdown to HTML converter
JavaScript
29
star
31

rpi-newer-crosstools

Newer cross-compiler toolchains than are available @ https://github.com/raspberrypi/tools
C++
28
star
32

list-stream

Collect chunks / objects from a readable stream, write obejcts / chunks to a writable stream
JavaScript
27
star
33

archived-prr

JavaScript
26
star
34

archived-npm-explicit-deps

Say goodbye to fickle `~` and `^` semver ranges
JavaScript
26
star
35

ghissues

A node library to interact with the GitHub issues API
JavaScript
25
star
36

archived-string_decoder

Moved to https://github.com/nodejs/string_decoder
23
star
37

archived-node-sz

A Node.js utility for determining the dimensions of an image
JavaScript
23
star
38

js-ipld-hashmap

An associative array Map-type data structure for very large, distributed data sets built on IPLD
JavaScript
23
star
39

delayed

A collection of JavaScript helper functions for your functions, using setTimeout() to delay and defer.
JavaScript
22
star
40

archived-npm-publish-stream

A Node.js ReadableStream that emits data for each module published to npm
JavaScript
21
star
41

ghutils

A collection of utility functions for dealing with the GitHub API
JavaScript
20
star
42

archived-node-require-subvert

Yet another `require()` subversion library for mocking & stubbing
JavaScript
19
star
43

archived-level-ttl-cache

A pass-through cache for arbitrary objects or binary data using LevelDB, expired by a TTL
JavaScript
18
star
44

archived-level-spaces

Namespaced LevelUP instances
JavaScript
18
star
45

archived-node-generic-session

A generic web server session manager for use with any storage back-end
JavaScript
18
star
46

node-boganipsum

Node.js Lorem Ipsum ... Bogan Style!
JavaScript
17
star
47

archived-externr

Provide a plug-in mechanism for your JavaScript objects, exposing their inmost secrets
JavaScript
17
star
48

archived-npm-publish-notify

Desktop notifications on npm publish events
JavaScript
15
star
49

archived-new-contributors

Check a GitHub repository for new contributors
JavaScript
15
star
50

archived-blorg

Flexible static blog generator
JavaScript
15
star
51

archived-iojs-tools

A collection of utilities I use to help with managing io.js business
HTML
15
star
52

archived-node-simple-bufferstream

Turn a Node.js Buffer into a ReadableStream
JavaScript
14
star
53

archived-node-slow-stream

A throttleable stream, for working in the slow-lane
JavaScript
13
star
54

archived-node-crp

An image cropper for Node.js
JavaScript
13
star
55

archived-brtapsauce

Browserify TAP test runner for SauceLabs
JavaScript
12
star
56

npm-download-counts

Fetch package download counts for packages from the npm registry
JavaScript
12
star
57

archived-node-thmb

An image thumbnailer for Node.js
JavaScript
12
star
58

archived-nodei.co-chrome

Chrome extension to display nodei.co npm badges on GitHub README files for Node.js packages
JavaScript
11
star
59

ghrepos

A node library to interact with the GitHub repos API
JavaScript
11
star
60

archived-level-updown

LevelDOWN backed by LevelUP
JavaScript
11
star
61

archived-node-level-multiply

Make your LevelUP get(), put() and del() accept multiples keys & values.
JavaScript
11
star
62

ghteams

Node library to interact with the GitHub teams API
JavaScript
10
star
63

ghusers

A node library to interact with the GitHub users API
JavaScript
10
star
64

js-datastore-zipcar

An implementation of a Datastore (https://github.com/ipfs/interface-datastore) for IPLD blocks that operates on ZIP files
JavaScript
9
star
65

archived-bustermove

JavaScript
9
star
66

node-version-data

Load all Node.js and io.js versions and metadata about them
JavaScript
8
star
67

node-fd

File descriptor manager
JavaScript
8
star
68

archived-sanever

A saner semver parser
JavaScript
7
star
69

js-bitcoin-block

A Bitcoin block interface and decoder for JavaScript
JavaScript
7
star
70

ghpulls

A node library to interact with the GitHub pull requests API
JavaScript
7
star
71

testmark.js

Language-agnostic test fixtures in Markdown
JavaScript
6
star
72

campjs-2013-learn-you-node

CSS
5
star
73

archived-package-use

Use the nodei.co Node.js package download count API to create CSV data on package use
JavaScript
5
star
74

jsdoc4readme

Generate an API section for a README.md from inline JSDocs
JavaScript
5
star
75

archived-node-ssbl

Super-simple blog loader. Load markdown formatted blog files from a folder as a handy data structure for rendering
JavaScript
5
star
76

archived-quantities

JavaScript library for physical quantity representation and conversion
JavaScript
5
star
77

mkfiletree

Make a tree of files and directories by from data defined in an object
JavaScript
5
star
78

readfiletree

Deserialize an file/directory tree into object form
JavaScript
4
star
79

archived-check-python

Check for Python on the current system and return the value
JavaScript
4
star
80

archived-colors-tmpl

Simple templating for applying colors.js to strings
JavaScript
4
star
81

bit-sequence

Turn an arbitrary sequence of bits from a byte array and turn it into an integer
JavaScript
4
star
82

archived-node-downer-rangedel

A native LevelDOWN plugin providing a rangeDel() method
JavaScript
3
star
83

blake2-node

Node.js BLAKE2 addon
C
3
star
84

js-ipld-schema-describer

Provide an object that suits the Data Model and get a naive IPLD Schema description of it.
JavaScript
3
star
85

nodei.co-pkginfo-api

API server to manage the npm package info data for nodei.co
JavaScript
3
star
86

bsplit2

A Node.js binary transform stream splitting chunks by newline characters
JavaScript
3
star
87

archived-npm-download-db

A local store containing npm download counts for all packages, able to provide rankings
JavaScript
3
star
88

gitexec

A specialised child process spawn for `git` commands
JavaScript
3
star
89

js-fil-utils

Miscellaneous JavaScript Filecoin proofs utilities
JavaScript
3
star
90

nodei.co-npm-dl-api

API server to manage the npm downloads counts and rankings for nodei.co
JavaScript
3
star
91

archived-kappa-bridge

A bridge for certificate-authenticated npm connections to Kappa registries
JavaScript
3
star
92

spacemon

Tool to monitor Filecoin storage space onboarding πŸΆπŸ–
JavaScript
3
star
93

node-ci-containers

Dockerfile
2
star
94

r.va.gg

HTML
2
star
95

lxjs2013

JavaScript Databases II
CSS
2
star
96

archived-simpledb2level

Extract complete (or partial / incremental) SimpleDB data to a local LevelDB
JavaScript
2
star
97

iavector

An Immutable Asynchronous Vector
JavaScript
2
star
98

js-bitcoin-extract

Tools to work with the Bitcoin blockchain (and IPLD)
JavaScript
2
star
99

kasm

A WASM thing in Rust that's probably not what you're looking for
Rust
2
star
100

js-ipld-vector

A JavaScript implementation of the IPLD Vetor specification
JavaScript
2
star