New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

exframe-testing

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

exframe-testing

Framework for unit and contract testing

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6K
increased by33.28%
Maintainers
1
Weekly downloads
 
Created
Source

Exframe testing module

Module that runs unit and contract tests, collects coverage information and stitches it together into a consolidated report. It uses the service's docker-compose.yml file to bring up the necessary environment, then it replaces the service itself with a version that records the code coverage before running the tests.

Use:

The Exframe testing module makes use of exframe-configuration and npm scripts to run tests and collect code coverage. Specifically, exframe-testing uses the following npm scripts:

unit-tests (runs the unit tests)

contract-tests (runs the contract tests)

combine-coverage (merges the coverage.json files output by the above scripts and produces reports of itemized and total code coverage)

In addition, the microservice's configuration must provide a script for running the service with code coverage enabled. This value should be stored in config.default.tests.coverageScript. If not provided, the script defaults to:

./node_modules/.bin/istanbul cover index.js --handle-sigint --dir ./documentation/contract-tests/

The testing framework can be initiated from a service by:

node ./node_modules/exframe-testing/index.js

It is recommended to make the above the npm test script in the package.json of the service.

Executing the above script will run both the unit tests and the contract tests, then merge the coverage objects of both test suites into a single report. You can run either test suite individually with:

node ./node_modules/exframe-testing/index.js unit

or

node ./node_modules/exframe-testing/index.js contract

##Example

package.json:

{
  "name": "my-service",
  "version": "0.0.1",
  "description": "My Service",
  "main": "index.js",
  "repository": {
    "type": "git",
    "url": ""
  },
  "scripts": {
    "start": "node index.js",
    "test": "./node_modules/.bin/exframe-testing",
    "unit-tests": "./node_modules/.bin/istanbul cover --dir ./documentation/unit-tests/ -x index.js -x '**/routing/**' ./node_modules/mocha/bin/_mocha -- -R spec -c",
    "contract-tests": "./node_modules/mocha/bin/_mocha -- -c ./test-contract/tests",
    "combine-coverage": "./node_modules/.bin/istanbul report --dir ./documentation/combined/ --include \"./documentation/**/coverage.json\""
  },
  "author": "Exzeo",
  "license": "ISC",
  "dependencies": {},
  "devDependencies": {
    "istanbul": "^0.4.5",
    "chai": "^3.5.0",
    "mocha": "^3.2.0"
  }
}

./test-contract/tests/mytest.test.js:

/* eslint arrow-body-style: 0 */
/* eslint no-unused-expressions: 0 */
/* eslint no-multi-spaces: 0 */
/* eslint indent: 0 */


'use strict';

const expect = require('chai').expect;
const axios = require('axios');
const framework = require('exframe-testing');

describe('POST /something', () => {
  describe('Basic happy path', () => {
    const fields = ['description',             'data',   'expectedStatus'];
    const values = [
                   ['Does stuff with thing 1', 'thing1', 200]
                   ['Does stuff with thing2',  'thing2', 400]
                   ]
    const testCases = framework.build(fields, values);
    const test = testCase => {
      it(testCase.description, () => {
        const options = {
          method: 'POST',
          url: `${config.default.service.url}:${config.default.service.port}/something`,
          data: testCase.data
        };
        return axios(options)
          .catch(err => err.response)
          .then(response => {
            expect(response.status).to.equal(testCase.expectedStatus);
          });
      });
    };
    testCases.forEach(testCase => test(testCase));
  });
});

FAQs

Package last updated on 09 Jan 2018

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