How to use
const path = require('path');
const { setup: appSetup } = require('./fake-application/src');
const TestUtils = require('../../src');
const { PathsExtractor, ConfigLoader, Runner } = TestUtils.Mocha;
const { isBrokenAtLeast, printResultPretty } = TestUtils.Utils;
(async () => {
try {
console.log('start setup');
const dir = path.join(__dirname, './fake-application');
const pathExtractor = new PathsExtractor();
const paths = pathExtractor.fromDir(dir);
const mochaConfigs = ConfigLoader.load(paths);
const unitTestResult = await new Runner()
.addConfig(mochaConfigs[0])
.changeReporter('dot')
.run();
printResultPretty(unitTestResult);
await appSetup();
const testResults = await new Runner()
.addConfig(mochaConfigs)
.changeReporter('dot')
.run();
printResultPretty(testResults);
isBrokenAtLeast(unitTestResult, testResults)
? process.exit(1)
: process.exit(0);
} catch (error) {
console.error(error);
}
})();
For typescript
//jsconfig.json
"allowJs": true
const { Mocha } = require('@asfrom30/test-utils');
Package.json
{
"test": "NODE_ENV=test ts-node test.ts",
"tdd": "NODE_ENV=test nodemon --exec 'ts-node' test.ts"
}
{}
Pass argument
$ npm run test -- --y // it may help in CI
$ npm run tdd -- --y
change reporter
.changeReporter();
reporter list
test-wrap
> expected output
[API] users.api.spec.ts
How to develop
scenario testing
$ nodemon tests/scenario1/test.js --mocharc /Volumes/sourcehub/projects/@asfrom30/npm/test-utils/tests/.resources/a/.mocharc
or
$ nodemon tests/scenario1/test.js --mocharc {mocharcPath}