Skip to content

Latest commit

 

History

History
207 lines (129 loc) · 3.67 KB

API.md

File metadata and controls

207 lines (129 loc) · 3.67 KB

Table of Contents

isJSFile

does the file has the extension of JS files (*.js)

Parameters

  • filePath string path to a file

Examples

isJSFile('./index.js')
// true
isJSFile('./package.json')
// false

Returns boolean true if the file has .js extension, false otherwise

listExecutedTests

List all tests that were executed by a mocha test runner

Parameters

Examples

listExecutedTests(runMocha(['./test/main.test.js'], { reporter: 'base' }))
// [ 'test suite test case' ]

Returns Array<string> array of the full test names that were executed (Root suite name + child suite names + test name)

listFiles

List all the files in a given directory, by default in recursive mode

Parameters

  • dir string path to a dir
  • recursive boolean search in nested directories (optional, default true)

Examples

listFiles('./')
// ['main.js', 'package.json', 'README.md', 'test/main.test.js']
listFiles('./', false)
// ['main.js', 'package.json', 'README.md']

Returns Array<string> array of files found in the given directory

patchAfterAll

Patch after() to do nothing

Examples

patchAfterAll()

patchAfterEach

Patch afterEach() to do nothing

Examples

patchAfterEach()

patchBeforeAll

Patch before() to do nothing

Examples

patchBeforeAll()

patchBeforeEach

Patch beforeEach() to do nothing

Examples

patchBeforeEach()

patchTestRunner

Patch the runTest method of the Mocha Test Runner to pass all tests

Examples

patchTestRunner()

runMocha

Run mocha programatically on given test files

Parameters

Examples

To run the tests in ./test/main.test.js with default mocha options

runMocha(['./test/main.test.js'])
//
//    test suite
//    ✓ test case
//
//  1 passing (7ms)

To run the tests in ./test/main.test.js with the nyan mocha reporter

runMocha(['./test/main.test.js'], { reporter: 'nyan' })
//
//  1 -__,------,
//  0 -__|  /\_/\
//  0 -_~|_( ^ .^)
//    -_ ""  ""
//
// 1 passing (11ms)

Returns Mocha.Runner mocha runner instance that ran all the tests

startMocha

Start mocha by requiring the _mocha script

Examples

startMocha()