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

swagger-police

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger-police - npm Package Compare versions

Comparing version 0.0.4-beta to 0.0.5-beta

71

lib/mocha-test-builder.js

@@ -31,27 +31,54 @@ 'use strict';

function createMochaSuite({parentSuite, testCase, hooks, serverBaseUrl}) {
const testCaseHooks = hooks.testCaseHooksMap[testCase.name] || [];
function invokeSuiteHooks({testCases, globalHooks, suite}) {
if (_.isEmpty(testCaseHooks)) {
testCaseHooks.push({});
if (globalHooks.beforeAll) {
suite.beforeAll((done) => globalHooks.beforeAll(testCases, done));
}
if (globalHooks.afterAll) {
suite.afterAll((done) => globalHooks.afterAll(testCases, done));
}
}
function invokeTestcaseHooks({testCase, globalHooks, testCaseHook, suite}) {
if (globalHooks.beforeEach) {
suite.beforeEach((done) => globalHooks.beforeEach(testCase, done));
}
if (globalHooks.afterEach) {
suite.afterEach((done) => globalHooks.afterEach(testCase, done));
}
if (testCaseHook.before) {
suite.beforeEach((done) => testCaseHook.before(testCase, done));
}
if (testCaseHook.after) {
suite.afterEach((done) => testCaseHook.after(testCase, done));
}
}
function createMochaSuite({parentSuite, testCase, hooks, serverBaseUrl}) {
const globalHooks = hooks.globalHooks;
const testCaseHooks = hooks.testCaseHooksMap[testCase.name] || [{}];
const hooksCount = testCaseHooks.length;
testCaseHooks.forEach((hook, index) => {
testCaseHooks.forEach((testCaseHook, index) => {
const suiteName = testCase.name + (hooksCount > 1 ? ` # ${hook.name || (index+1)}`:'');
const mochaSuite = Mocha.Suite.create(parentSuite, suiteName);
const suiteName = testCase.name + (hooksCount > 1 ? ` # ${testCaseHook.name || (index+1)}`:'');
const suite = Mocha.Suite.create(parentSuite, suiteName);
if (hook.before) {
mochaSuite.beforeEach((done) => hook.before(testCase, done));
}
invokeTestcaseHooks({
testCase,
globalHooks,
testCaseHook,
suite
});
if (hook.after) {
mochaSuite.afterEach((done) => hook.after(testCase, done));
}
suite.addTest(new Mocha.Test('Verifying API', (done) => {
mochaSuite.addTest(new Mocha.Test('Verifying API', (done) => {
const request = testCase.request;

@@ -107,10 +134,2 @@

function invokeGlobalHooks({testCases, hooks, parentSuite}) {
_.functions(hooks.globalHooks).forEach((hookName) => {
const setHook = parentSuite[hookName].bind(parentSuite);
setHook((done) => hooks.globalHooks[hookName](testCases, done));
});
}
function buildTestSuite({testCases, hooks, serverBaseUrl}) {

@@ -121,3 +140,7 @@

invokeGlobalHooks({testCases, hooks, parentSuite});
invokeSuiteHooks({
testCases,
globalHooks: hooks.globalHooks,
suite: parentSuite
});
testCases.forEach((testCase) => createMochaSuite({parentSuite, testCase, hooks, serverBaseUrl}));

@@ -124,0 +147,0 @@

{
"name": "swagger-police",
"version": "0.0.4-beta",
"version": "0.0.5-beta",
"description": "Automatically validates the APIs against the published swagger specification",

@@ -5,0 +5,0 @@ "bin": {

@@ -13,3 +13,3 @@ **swagger-police** is a command line tool for validating backend APIs against the published swagger specification. It can

This ensures that the url params, query params, headers and the body defined in the spec is supported by the service.
* Verifies the HTTP response status and headers against the specs.
* Verifies the HTTP response status against the specs.
* Verifies the response body against the schema defined in specs (JSON schema validation).

@@ -131,10 +131,10 @@ * Supports the following hook methods for customising the tests (see Hooks)

These will be executed before and after every test. Note that only one of each type can be specified, there cannot be
more than one beforeEach/afterEach hooks. However, testcase specific hooks can be specified, see below.
more than one beforeEach/afterEach hooks. However, testcase specific before/after hooks can be specified, see below.
```
hooks.beforeEach((testcases, done) => {
hooks.beforeEach((testcase, done) => {
done();
});
hooks.afterEach((testcases, done) => {
hooks.afterEach((testcase, done) => {
done();

@@ -144,4 +144,4 @@ });

* **testcases** - An array of `testcase` objects to be executed. This is generated from the swagger specs. Any
changes made to the testcase objects in the `beforeAll` hook will be reflected in the tests.
* **testcase** - The specific `testcase` this hook is being executed for. Any
changes made to the testcase objects in the `beforeEach` hook will be reflected in the tests.
* **done** - The callback function

@@ -148,0 +148,0 @@

@@ -21,7 +21,7 @@ hooks.add('GET /pet/{petId} -> 200', {

hooks.beforeEach((testcases, done) => {
hooks.beforeEach((testcase, done) => {
done();
});
hooks.afterEach((testcases, done) => {
hooks.afterEach((testcase, done) => {
done();

@@ -28,0 +28,0 @@ });

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