Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@asfrom30/test-utils

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asfrom30/test-utils

```js const path = require('path'); const { setup: appSetup } = require('./fake-application/src');

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

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}

FAQs

Package last updated on 08 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc