UNPKG

mocha-decaf

Version:
208 lines (129 loc) 3.76 kB
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> ### Table of Contents - [isJSFile][1] - [listExecutedTests][2] - [listFiles][3] - [patchAfterAll][4] - [patchAfterEach][5] - [patchBeforeAll][6] - [patchBeforeEach][7] - [patchTestRunner][8] - [runMocha][9] - [startMocha][10] ## isJSFile does the file has the extension of JS files (\*.js) ### Parameters - `filePath` **[string][11]** path to a file ### Examples ```javascript isJSFile('./index.js') // true isJSFile('./package.json') // false ``` Returns **[boolean][12]** true if the file has .js extension, false otherwise ## listExecutedTests - **See: [Mocha Runner][13]** List all tests that were executed by a mocha test runner ### Parameters - `runner` **Mocha.Runner** [Mocha Runner instance][13] ### Examples ```javascript listExecutedTests(runMocha(['./test/main.test.js'], { reporter: 'base' })) // [ 'test suite test case' ] ``` Returns **[Array][14]&lt;[string][11]>** 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][11]** path to a dir - `recursive` **[boolean][12]** search in nested directories (optional, default `true`) ### Examples ```javascript listFiles('./') // ['main.js', 'package.json', 'README.md', 'test/main.test.js'] listFiles('./', false) // ['main.js', 'package.json', 'README.md'] ``` Returns **[Array][14]&lt;[string][11]>** array of files found in the given directory ## patchAfterAll Patch after() to do nothing ### Examples ```javascript patchAfterAll() ``` ## patchAfterEach Patch afterEach() to do nothing ### Examples ```javascript patchAfterEach() ``` ## patchBeforeAll Patch before() to do nothing ### Examples ```javascript patchBeforeAll() ``` ## patchBeforeEach Patch beforeEach() to do nothing ### Examples ```javascript patchBeforeEach() ``` ## patchTestRunner Patch the runTest method of the Mocha Test Runner to pass all tests ### Examples ```javascript patchTestRunner() ``` ## runMocha - **See: [Mocha API documentation][15]** Run mocha programatically on given test files ### Parameters - `files` **[Array][14]** array of test files (optional, default `[]`) - `mochaOptions` **[Object][16]** mocha options, refer to [mocha's api documentation][17] (optional, default `{}`) ### Examples To run the tests in ./test/main.test.js with default mocha options ```javascript 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 ```javascript runMocha(['./test/main.test.js'], { reporter: 'nyan' }) // // 1 -__,------, // 0 -__| /\_/\ // 0 -_~|_( ^ .^) // -_ "" "" // // 1 passing (11ms) ``` Returns **Mocha.Runner** mocha [runner][13] instance that ran all the tests ## startMocha Start mocha by requiring the \_mocha script ### Examples ```javascript startMocha() ``` [1]: #isjsfile [2]: #listexecutedtests [3]: #listfiles [4]: #patchafterall [5]: #patchaftereach [6]: #patchbeforeall [7]: #patchbeforeeach [8]: #patchtestrunner [9]: #runmocha [10]: #startmocha [11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String [12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean [13]: https://mochajs.org/api/runner [14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array [15]: https://mochajs.org/api/ [16]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object [17]: https://mochajs.org/api/mocha