- isJSFile
- listExecutedTests
- listFiles
- patchAfterAll
- patchAfterEach
- patchBeforeAll
- patchBeforeEach
- patchTestRunner
- runMocha
- startMocha
does the file has the extension of JS files (*.js)
filePath
string path to a file
isJSFile('./index.js')
// true
isJSFile('./package.json')
// false
Returns boolean true if the file has .js extension, false otherwise
- See: Mocha Runner
List all tests that were executed by a mocha test runner
runner
Mocha.Runner Mocha Runner instance
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)
List all the files in a given directory, by default in recursive mode
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
Patch after() to do nothing
patchAfterAll()
Patch afterEach() to do nothing
patchAfterEach()
Patch before() to do nothing
patchBeforeAll()
Patch beforeEach() to do nothing
patchBeforeEach()
Patch the runTest method of the Mocha Test Runner to pass all tests
patchTestRunner()
Run mocha programatically on given test files
files
Array array of test files (optional, default[]
)mochaOptions
Object mocha options, refer to mocha's api documentation (optional, default{}
)
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
Start mocha by requiring the _mocha script
startMocha()