test-runner-core
Minimal, extensible test runner.
Last updated 5 years ago by 75lb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install test-runner-core 
SYNC missed versions from official npm registry.

view on npm npm module downloads Gihub repo dependents Gihub package dependents Build Status js-standard-style

This documentation is a work in progress.

test-runner-core

Isomophic test runner. Takes a test-object-model instance as input, streaming progress info to the attached view or listener. Used by test-runner and web-runner.

Synopsis

This trivial example creates a test object model containing one passing and one failing test. The model is passed to a TestRunnerCore instance, along with the default view, which then runs the tests printing the result to the console.

import TestRunnerCore from '../index.mjs'
import Tom from 'test-object-model'

/* Define a simple test model */
const tom = new Tom()

tom.test('A successful test', function () {
  return 'This passed'
})

tom.test('A failing test', function () {
  throw new Error('This failed')
})

/* send test-runner output to the default view  */
const view = new DefaultView()

/* run the tests defined in the test model */
const runner = new TestRunnerCore(tom, { view })
runner.start()

Output.

$ nodem tmp/synopsis.mjs

Start: 2 tests loaded

 ✓ tom A successful test [This passed]
 ⨯ tom A failing test

   Error: This failed
       at TestContext.<anonymous> (file:///Users/lloyd/Documents/test-runner-js/test-runner-core/tmp/synopsis.mjs:13:9)
       ...
       at processTimers (internal/timers.js:475:7)


Completed in 11ms. Pass: 1, fail: 1, skip: 0.

Instead of passing a view instance to TestRunnerCore, this example shows how to observe runner events and print your own output.

const runner = new TestRunnerCore(tom)

runner.on('state', (state, prevState) => {
  console.log(`Runner state change: ${prevState} -> ${state}`)
})
runner.on('test-pass', test => {
  console.log(`Test passed: ${test.name}`)
})
runner.on('test-fail', test => {
  console.log(`Test failed: ${test.name}`)
})
runner.start().then(() => {
  console.log(`Test run complete. State: ${runner.state}, passed: ${runner.stats.pass}, failed: ${runner.stats.fail}`)
})

Output.

$ node --experimental-modules synopsis.mjs
Runner state change: pending -> in-progress
Test passed: A successful test
Test failed: A failing test
Runner state change: in-progress -> fail
Test run complete. State: fail, passed: 1, failed: 1

See also


© 2016-21 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.

Current Tags

  • 0.9.0                                ...           latest (4 years ago)

26 Versions

  • 0.9.0                                ...           4 years ago
  • 0.8.6                                ...           5 years ago
  • 0.8.5                                ...           5 years ago
  • 0.8.4                                ...           5 years ago
  • 0.8.3                                ...           5 years ago
  • 0.8.2                                ...           5 years ago
  • 0.8.1                                ...           5 years ago
  • 0.8.0                                ...           5 years ago
  • 0.7.3                                ...           5 years ago
  • 0.7.2                                ...           5 years ago
  • 0.7.1                                ...           5 years ago
  • 0.7.0                                ...           5 years ago
  • 0.6.0                                ...           5 years ago
  • 0.6.0-17                                ...           6 years ago
  • 0.6.0-16                                ...           6 years ago
  • 0.6.0-15                                ...           6 years ago
  • 0.6.0-14                                ...           6 years ago
  • 0.6.0-13                                ...           6 years ago
  • 0.6.0-12                                ...           6 years ago
  • 0.6.0-11                                ...           6 years ago
  • 0.6.0-10                                ...           6 years ago
  • 0.6.0-9                                ...           6 years ago
  • 0.6.0-8                                ...           6 years ago
  • 0.6.0-7                                ...           6 years ago
  • 0.6.0-6                                ...           6 years ago
  • 0.6.0-5                                ...           6 years ago
Maintainers (1)
Downloads
Total 18
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (4)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE