0.1.1 • Published 3 years ago
@asfrom30/test-utils v0.1.1
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');
// 1. FindMocharc
// const paths = pathExtractor.fromPaths();
const dir = path.join(__dirname, './fake-application');
const pathExtractor = new PathsExtractor();
const paths = pathExtractor.fromDir(dir);
// 2. Ask which mocharc to run using cli
// TODO: 찾아낸 mocharc를 cli로 선택하도록 물어본다.
// 만약 -y옵션이 true이면 그냥 다 선택하고 넘어간다.
// 3. convert mocharcPath to Config
const mochaConfigs = ConfigLoader.load(paths);
// 4. Run Unit Test
const unitTestResult = await new Runner()
.addConfig(mochaConfigs[0])
.changeReporter('dot')
.run();
printResultPretty(unitTestResult);
// 5. Application Setup
await appSetup();
// 6. Run integration and Scenario
const testResults = await new Runner()
.addConfig(mochaConfigs)
.changeReporter('dot')
.run();
printResultPretty(testResults);
// 7. sketch
isBrokenAtLeast(unitTestResult, testResults)
? process.exit(1)
: process.exit(0);
} catch (error) {
console.error(error); // prevent to uncaught error
}
})();
For typescript
//jsconfig.json
"allowJs": true
const { Mocha } = require('@asfrom30/test-utils');
Package.json
- typescript
{
"test": "NODE_ENV=test ts-node test.ts",
"tdd": "NODE_ENV=test nodemon --exec 'ts-node' test.ts"
}
- javascript
{}
Pass argument
$ npm run test -- --y // it may help in CI
$ npm run tdd -- --y
change reporter
.changeReporter();
reporter list
- progress
- spec
- min
- json
- and more : https://mochajs.org/api/mocha.reporters.html
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}