diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c6c8b36 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..89c2c00 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,314 @@ +{ + "env": { + "browser": true, + "es2021": true, + "node": true, + "mocha": true + }, + "extends": ["eslint:recommended", "plugin:chai-expect/recommended"], + "parserOptions": { + "ecmaVersion": 12, + "sourceType": "module" + }, + "plugins": [ + "chai-expect" + ], + "rules": { + "accessor-pairs": "error", + "array-bracket-newline": "error", + "array-bracket-spacing": [ + "error", + "never" + ], + "array-callback-return": "error", + "array-element-newline": "off", + "arrow-body-style": "off", + "arrow-parens": [ + "error", + "always" + ], + "arrow-spacing": [ + "error", + { + "after": true, + "before": true + } + ], + "block-scoped-var": "error", + "block-spacing": "error", + "brace-style": [ + "error", + "1tbs" + ], + "callback-return": "off", + "capitalized-comments": "off", + "class-methods-use-this": "error", + "comma-dangle": "off", + "comma-spacing": [ + "error", + { + "after": true, + "before": false + } + ], + "comma-style": [ + "error", + "last" + ], + "complexity": "error", + "computed-property-spacing": [ + "error", + "never" + ], + "consistent-return": "off", + "consistent-this": "error", + "curly": "off", + "default-case": "error", + "default-case-last": "error", + "default-param-last": "error", + "dot-notation": "error", + "eol-last": "off", + "eqeqeq": "off", + "func-call-spacing": "error", + "func-name-matching": "error", + "func-names": "off", + "func-style": [ + "error", + "expression" + ], + "function-call-argument-newline": [ + "error", + "consistent" + ], + "function-paren-newline": "off", + "generator-star-spacing": "error", + "global-require": "error", + "grouped-accessor-pairs": "error", + "guard-for-in": "error", + "handle-callback-err": "error", + "id-blacklist": "error", + "id-denylist": "error", + "id-length": "off", + "id-match": "error", + "implicit-arrow-linebreak": "error", + "indent": "off", + "indent-legacy": "off", + "init-declarations": "error", + "jsx-quotes": "error", + "key-spacing": "error", + "keyword-spacing": "off", + "line-comment-position": "error", + "linebreak-style": [ + "error", + "unix" + ], + "lines-around-comment": "error", + "lines-around-directive": "error", + "lines-between-class-members": [ + "error", + "always" + ], + "max-classes-per-file": "error", + "max-depth": "error", + "max-len": "off", + "max-lines": "error", + "max-lines-per-function": "off", + "max-nested-callbacks": "error", + "max-params": "off", + "max-statements": "off", + "max-statements-per-line": "error", + "multiline-comment-style": [ + "error", + "separate-lines" + ], + "multiline-ternary": "error", + "new-cap": "error", + "new-parens": "error", + "newline-after-var": "off", + "newline-before-return": "off", + "newline-per-chained-call": "error", + "no-alert": "error", + "no-array-constructor": "error", + "no-await-in-loop": "error", + "no-bitwise": "off", + "no-buffer-constructor": "error", + "no-caller": "error", + "no-catch-shadow": "error", + "no-confusing-arrow": "error", + "no-console": "error", + "no-constructor-return": "error", + "no-continue": "error", + "no-div-regex": "error", + "no-duplicate-imports": "error", + "no-else-return": "error", + "no-empty-function": "error", + "no-eq-null": "error", + "no-eval": "error", + "no-extend-native": "error", + "no-extra-bind": "error", + "no-extra-label": "error", + "no-extra-parens": "error", + "no-floating-decimal": "error", + "no-implicit-coercion": "error", + "no-implicit-globals": "error", + "no-implied-eval": "error", + "no-inline-comments": "error", + "no-inner-declarations": [ + "error", + "functions" + ], + "no-invalid-this": "error", + "no-iterator": "error", + "no-label-var": "error", + "no-labels": "error", + "no-lone-blocks": "error", + "no-lonely-if": "off", + "no-loop-func": "error", + "no-loss-of-precision": "error", + "no-magic-numbers": "off", + "no-mixed-operators": "error", + "no-mixed-requires": "error", + "no-multi-assign": "error", + "no-multi-spaces": "error", + "no-multi-str": "error", + "no-multiple-empty-lines": "error", + "no-native-reassign": "error", + "no-negated-condition": "error", + "no-negated-in-lhs": "error", + "no-nested-ternary": "error", + "no-new": "error", + "no-new-func": "error", + "no-new-object": "error", + "no-new-require": "error", + "no-new-wrappers": "error", + "no-nonoctal-decimal-escape": "error", + "no-octal-escape": "error", + "no-param-reassign": "error", + "no-path-concat": "error", + "no-plusplus": "error", + "no-process-env": "error", + "no-process-exit": "error", + "no-promise-executor-return": "error", + "no-proto": "error", + "no-restricted-exports": "error", + "no-restricted-globals": "error", + "no-restricted-imports": "error", + "no-restricted-modules": "error", + "no-restricted-properties": "error", + "no-restricted-syntax": "error", + "no-return-assign": "error", + "no-return-await": "error", + "no-script-url": "error", + "no-self-compare": "error", + "no-sequences": "error", + "no-shadow": "off", + "no-spaced-func": "error", + "no-sync": "off", + "no-tabs": "error", + "no-template-curly-in-string": "error", + "no-ternary": "error", + "no-throw-literal": "error", + "no-trailing-spaces": "off", + "no-undef-init": "error", + "no-undefined": "off", + "no-underscore-dangle": "error", + "no-unmodified-loop-condition": "error", + "no-unneeded-ternary": "error", + "no-unreachable-loop": "error", + "no-unused-expressions": "error", + "no-use-before-define": "error", + "no-useless-backreference": "error", + "no-useless-call": "error", + "no-useless-computed-key": "error", + "no-useless-concat": "error", + "no-useless-constructor": "error", + "no-useless-rename": "error", + "no-useless-return": "error", + "no-var": "off", + "no-void": "error", + "no-warning-comments": "error", + "no-whitespace-before-property": "error", + "nonblock-statement-body-position": "error", + "object-curly-newline": "off", + "object-curly-spacing": "off", + "object-shorthand": "off", + "one-var": "off", + "one-var-declaration-per-line": "error", + "operator-assignment": [ + "error", + "always" + ], + "operator-linebreak": "error", + "padded-blocks": "off", + "padding-line-between-statements": "error", + "prefer-arrow-callback": "off", + "prefer-const": "off", + "prefer-destructuring": "off", + "prefer-exponentiation-operator": "error", + "prefer-named-capture-group": "error", + "prefer-numeric-literals": "error", + "prefer-object-spread": "error", + "prefer-promise-reject-errors": "error", + "prefer-reflect": "off", + "prefer-regex-literals": "error", + "prefer-rest-params": "error", + "prefer-spread": "error", + "prefer-template": "off", + "quote-props": "off", + "quotes": "off", + "radix": [ + "error", + "always" + ], + "require-atomic-updates": "error", + "require-await": "error", + "require-jsdoc": "error", + "require-unicode-regexp": "off", + "rest-spread-spacing": [ + "error", + "never" + ], + "semi": "off", + "semi-spacing": "error", + "semi-style": [ + "error", + "last" + ], + "sort-imports": "error", + "sort-keys": "off", + "sort-vars": "error", + "space-before-blocks": "off", + "space-before-function-paren": "off", + "space-in-parens": [ + "error", + "never" + ], + "space-infix-ops": "error", + "space-unary-ops": "error", + "spaced-comment": [ + "error", + "always" + ], + "strict": "error", + "switch-colon-spacing": "error", + "symbol-description": "error", + "template-curly-spacing": [ + "error", + "never" + ], + "template-tag-spacing": "error", + "unicode-bom": [ + "error", + "never" + ], + "valid-jsdoc": "off", + "vars-on-top": "off", + "wrap-iife": "error", + "wrap-regex": "error", + "yield-star-spacing": "error", + "yoda": [ + "error", + "never" + ] + } +} diff --git a/.github/workflows/merge-master.yaml b/.github/workflows/merge-master.yaml new file mode 100644 index 0000000..a380f5a --- /dev/null +++ b/.github/workflows/merge-master.yaml @@ -0,0 +1,20 @@ +name: Node.js Package +on: + release: + types: [created] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + # Setup .npmrc file to publish to GitHub Packages + - uses: actions/setup-node@v1 + with: + node-version: '14.x' + registry-url: 'https://npm.pkg.github.com' + scope: '@devaway' + - run: npm install + # Publish to GitHub Packages + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/on-push.yaml b/.github/workflows/on-push.yaml new file mode 100644 index 0000000..87809ce --- /dev/null +++ b/.github/workflows/on-push.yaml @@ -0,0 +1,23 @@ +name: Node.js CI + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [14.x, 15.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm run build --if-present + - run: npm test + env: + CI: true diff --git a/.gitignore b/.gitignore index 1fd04da..df1f80c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ node_modules coverage .nyc_output +.envrc + +# IDEs +.vscode diff --git a/.husky/.gitignore b/.husky/.gitignore new file mode 100644 index 0000000..31354ec --- /dev/null +++ b/.husky/.gitignore @@ -0,0 +1 @@ +_ diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000..be14622 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname $0)/_/husky.sh" + +npm run prettier:check && npm run lint diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100755 index 0000000..c878c73 --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname $0)/_/husky.sh" + +npm run test diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ + diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..e2e1071 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,8 @@ +{ + "printWidth": 80, + "tabWidth": 2, + "trailingComma": "all", + "singleQuote": true, + "jsxBracketSameLine": true, + "semi": true +} diff --git a/lib/ajv-manager.js b/lib/ajv-manager.js index a0db2f4..48c3870 100644 --- a/lib/ajv-manager.js +++ b/lib/ajv-manager.js @@ -1,79 +1,74 @@ -const ajv = require("ajv"); -const path = require("path"); -const fs = require("fs"); -const walkSyncJson = require("./walk-sync-json"); +import ajv from 'ajv'; +import chokidar from 'chokidar'; +import fs from 'fs'; +import path from 'path'; + +import walkSyncJson from './walk-sync-json'; class AjvValidator { constructor(schemaDirectory, logger) { - this.ajv = ajv({ allErrors: true, schemaId: "auto" }); + this.ajv = ajv({ allErrors: true, schemaId: 'auto' }); this.schemas = new Map(); this.logger = logger; - if (fs.existsSync(schemaDirectory) && fs.statSync(schemaDirectory).isDirectory()) { + if ( + fs.existsSync(schemaDirectory) && + fs.statSync(schemaDirectory).isDirectory() + ) { let mappingFiles = walkSyncJson(schemaDirectory); mappingFiles.forEach((file) => { - let filename = path.normalize(file).replace(schemaDirectory, ""); + let filename = path.normalize(file).replace(schemaDirectory, ''); try { - const schema = JSON.parse(fs.readFileSync(file, "utf8")); + const schema = JSON.parse(fs.readFileSync(file, 'utf8')); this.schemas.set(path.normalize(filename), schema); this.ajv.addSchema(schema); logger.log({ - level: "debug", - message: `Schema "${filename}" loaded.` - }) + level: 'debug', + message: `Schema "${filename}" loaded.`, + }); } catch (e) { logger.log({ - level: "error", + level: 'error', message: `ERROR: invalid schema from: ${filename}`, }); } }); - fs.watch( - schemaDirectory, - { - recursive: true, - }, - (eventType, filename) => { - let filePath = path.normalize(schemaDirectory + filename); - if ( - filename && - fs.existsSync(filePath) && - fs.statSync(filePath).isFile() - ) { - logger.log({ - level: "info", - message: `Realoading: ${filename}`}); - try { - const schema = - JSON.parse(fs.readFileSync(filePath, "utf8")); - if(this.schemas.has(filename)){ - this.ajv.removeSchema(schema); - } - this.schemas.set( - path.normalize(filename), - schema - ); - this.ajv.addSchema(schema); - - } catch (e) { - logger.log({ - level: "error", - message: `invalid json from: ${filename}` - }); + chokidar.watch(schemaDirectory).on('all', (eventType, filename) => { + let filePath = path.normalize(schemaDirectory + filename); + if ( + filename && + fs.existsSync(filePath) && + fs.statSync(filePath).isFile() + ) { + logger.log({ + level: 'info', + message: `Realoading: ${filename}`, + }); + try { + const schema = JSON.parse(fs.readFileSync(filePath, 'utf8')); + if (this.schemas.has(filename)) { + this.ajv.removeSchema(schema); } - } else { + this.schemas.set(path.normalize(filename), schema); + this.ajv.addSchema(schema); + } catch (e) { logger.log({ - level: "error", - message: "filename not provided" + level: 'error', + message: `invalid json from: ${filename}`, }); } + } else { + logger.log({ + level: 'error', + message: 'filename not provided', + }); } - ); + }); } } - validate(fileName, body) { + validate(fileName, body) { if (this.schemas.has(fileName)) { const validator = this.ajv.getSchema(this.schemas.get(fileName).id); const validated = validator(body); @@ -82,16 +77,15 @@ class AjvValidator { return () => { return false; }; - }; - + } + compile(schema) { return this.ajv.compile(schema); - }; - + } + removeSchema(schema) { return this.ajv.removeSchema(schema); - }; - + } } -module.exports = AjvValidator; +export default AjvValidator; diff --git a/lib/logger.js b/lib/logger.js index 3e26875..b319bbf 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -1,4 +1,5 @@ -const { createLogger, transports, format, transport } = require("winston"); +import { createLogger, format, transports } from 'winston'; + const { Console } = transports; const { printf, combine, timestamp } = format; @@ -22,23 +23,28 @@ const setLabel = format((info, label) => { return info; }); -const loggerFilters = ["match-body", "match-headers", "match-method", "match-query", "match-url"]; +const loggerFilters = [ + 'match-body', + 'match-headers', + 'match-method', + 'match-query', + 'match-url', +]; const initLogger = ({ config, filters, appLabel }) => { - let customFilters = loggerFilters; - if(Array.isArray(filters)){ - customFilters = filters; + if (Array.isArray(filters)) { + customFilters = filters; } const intialConfig = { format: combine( - setLabel(appLabel), + setLabel(appLabel), timestamp({ - format: "YYYY-MM-DD HH:mm:ss", + format: 'YYYY-MM-DD HH:mm:ss', }), - filterMessageType(customFilters), - messageFormat + filterMessageType(customFilters), + messageFormat, ), transports: [ new Console({ @@ -47,11 +53,11 @@ const initLogger = ({ config, filters, appLabel }) => { ], exitOnError: false, }; - + return createLogger({ ...intialConfig, ...config, }); }; -module.exports.initLogger = initLogger; +export default initLogger; diff --git a/lib/mappings-sort.js b/lib/mappings-sort.js index 1d87985..7b17966 100644 --- a/lib/mappings-sort.js +++ b/lib/mappings-sort.js @@ -1,14 +1,21 @@ const sortMappings = (mappings) => { - let sortedMappings = new Map([...mappings.entries()].sort((a, b) => { - let order = -1; - if (a[1].request && a[1].request.priority && b[1].request && b[1].request.priority) { - order = a[1].request.priority - b[1].request.priority; - } else if (b[1].request && b[1].request.priority) { - order = 1; - } - return order; - })); + let sortedMappings = new Map( + [...mappings.entries()].sort((a, b) => { + let order = -1; + if ( + a[1].request && + a[1].request.priority && + b[1].request && + b[1].request.priority + ) { + order = a[1].request.priority - b[1].request.priority; + } else if (b[1].request && b[1].request.priority) { + order = 1; + } + return order; + }), + ); return sortedMappings; -} +}; -module.exports = sortMappings; \ No newline at end of file +export default sortMappings; diff --git a/lib/request-matching/body.js b/lib/request-matching/body.js index b885ae0..18f86b6 100644 --- a/lib/request-matching/body.js +++ b/lib/request-matching/body.js @@ -1,7 +1,7 @@ -const equal = require("node-json-equal"); -const jsonpath = require("jsonpath"); +import equal from 'node-json-equal'; +import jsonpath from 'jsonpath'; -const bodyCheck = function (logger, request, req, ajv) { +export const bodyRequestMatching = function (logger, request, req, ajv) { let bodyMatch = true; if (request.bodyPatterns) { if (request.bodyPatterns.equalToJson) { @@ -20,7 +20,7 @@ const bodyCheck = function (logger, request, req, ajv) { if (request.bodyPatterns.matchesJsonPath) { var result = jsonpath.query( req.body, - request.bodyPatterns.matchesJsonPath + request.bodyPatterns.matchesJsonPath, ); if (result.length <= 0) { bodyMatch = false; @@ -36,8 +36,8 @@ const bodyCheck = function (logger, request, req, ajv) { const validator = ajv.compile(schema); result = validator(req.body); logger.log({ - level: "debug", - type: "match-schema", + level: 'debug', + type: 'match-schema', message: JSON.stringify(validator.errors, null, 2), }); ajv.removeSchema(schema); @@ -45,16 +45,16 @@ const bodyCheck = function (logger, request, req, ajv) { const fileName = request.bodyPatterns.matchesSchema.schemaFile; const v = ajv.validate(fileName, req.body); logger.log({ - level: "debug", - type: "match-schema", + level: 'debug', + type: 'match-schema', message: JSON.stringify(v.errors, null, 2), }); result = v.validated; } } catch (e) { logger.log({ - level: "error", - type: "match-schema", + level: 'error', + type: 'match-schema', message: JSON.stringify(e, null, 2), }); result = false; @@ -66,24 +66,22 @@ const bodyCheck = function (logger, request, req, ajv) { } logger.log({ - level: "debug", - type: "match-body", + level: 'debug', + type: 'match-body', message: `Body matching:\nRequest =>\n${JSON.stringify( { body: req.body, }, null, - 2 + 2, )}\nMatching config =>\n${JSON.stringify( { bodyPatterns: request.bodyPatterns, }, null, - 2 + 2, )}\nMatched: ${bodyMatch}`, }); } return bodyMatch; }; - -module.exports = bodyCheck; diff --git a/lib/request-matching/headers.js b/lib/request-matching/headers.js index 48cf0cc..840c44f 100644 --- a/lib/request-matching/headers.js +++ b/lib/request-matching/headers.js @@ -1,4 +1,4 @@ -const headersCheck = function (request, req) { +export const headersRequestMatching = function (logger, request, req) { let headersMatch = true; if (request.headers) { Object.getOwnPropertyNames(request.headers).forEach((name) => { @@ -15,25 +15,23 @@ const headersCheck = function (request, req) { }); logger.log({ - level: "debug", - type: "match-headers", + level: 'debug', + type: 'match-headers', message: `Header matching:\nRequest =>\n${JSON.stringify( { headers: req.headers, }, null, - 2 + 2, )}\nMatching config =>\n${JSON.stringify( { headers: request.headers, }, null, - 2 + 2, )}\nMatched: ${headersMatch}`, }); } return headersMatch; }; - -module.exports = headersCheck; diff --git a/lib/request-matching/index.js b/lib/request-matching/index.js index 9e6d9ca..5e5ef50 100644 --- a/lib/request-matching/index.js +++ b/lib/request-matching/index.js @@ -1,11 +1,5 @@ -const url = require('./url'); -const method = require('./method'); -const headers = require('./headers'); -const queryParameters = require('./query-parameters'); -const body = require('./body'); - -module.exports.url = url; -module.exports.method = method; -module.exports.headers = headers; -module.exports.queryParameters = queryParameters; -module.exports.body = body; \ No newline at end of file +export * from './url'; +export * from './method'; +export * from './headers'; +export * from './query-parameters'; +export * from './body'; diff --git a/lib/request-matching/method.js b/lib/request-matching/method.js index 5d2f1b7..60e606b 100644 --- a/lib/request-matching/method.js +++ b/lib/request-matching/method.js @@ -1,28 +1,30 @@ -const methodcheck = function(request, req) { +export const methodRequestMatching = function (logger, request, req) { let methodMatch = false; - if (!request.method || request.method.toUpperCase() === "ANY" || request.method.toUpperCase() === req.method) { + if ( + !request.method || + request.method.toUpperCase() === 'ANY' || + request.method.toUpperCase() === req.method + ) { methodMatch = true; } - + logger.log({ - level: "debug", - type: "match-method", + level: 'debug', + type: 'match-method', message: `Method matching:\nRequest =>\n${JSON.stringify( { method: req.method, }, null, - 2 + 2, )}\nMatching config =>\n${JSON.stringify( { method: request.method, }, null, - 2 + 2, )}\nMatched: ${methodMatch}`, }); return methodMatch; -} - -module.exports = methodcheck; \ No newline at end of file +}; diff --git a/lib/request-matching/query-parameters.js b/lib/request-matching/query-parameters.js index e219a07..a2b3613 100644 --- a/lib/request-matching/query-parameters.js +++ b/lib/request-matching/query-parameters.js @@ -1,7 +1,7 @@ /** * function that match the check the query parameters and */ -const queryParametersCheck = function (request, req) { +export const queryRequestMatching = function (logger, request, req) { // if no queryParameters then this check match let paramsMatch = true; // if there are query parameters seach for one that doesn't match. @@ -15,25 +15,23 @@ const queryParametersCheck = function (request, req) { }); logger.log({ - level: "debug", - type: "match-query", + level: 'debug', + type: 'match-query', message: `Query matching:\nRequest =>\n${JSON.stringify( { query: req.query, }, null, - 2 + 2, )}\nMatching config =>\n${JSON.stringify( { queryParameters: request.queryParameters, }, null, - 2 + 2, )}\nMatched: ${paramsMatch}`, }); } return paramsMatch; }; - -module.exports = queryParametersCheck; diff --git a/lib/request-matching/url.js b/lib/request-matching/url.js index 7cba580..bffbf5e 100644 --- a/lib/request-matching/url.js +++ b/lib/request-matching/url.js @@ -1,6 +1,4 @@ -const { url } = require("."); - -const urlCheck = function (logger, request, req) { +export const urlRequestMatching = function (logger, request, req) { let urlMatch = false; if ( @@ -26,17 +24,17 @@ const urlCheck = function (logger, request, req) { ) { urlMatch = true; } - + logger.log({ - level: "debug", - type: "match-url", + level: 'debug', + type: 'match-url', message: `Url matching:\nRequest =>\n${JSON.stringify( { originalUrl: req.originalUrl, path: req.path, }, null, - 2 + 2, )}\nMatching config =>\n${JSON.stringify( { url: request.url, @@ -45,12 +43,9 @@ const urlCheck = function (logger, request, req) { urlPathPattern: request.urlPathPattern, }, null, - 2 + 2, )}\nMatched: ${urlMatch}`, }); - } return urlMatch; }; - -module.exports = urlCheck; diff --git a/lib/rest-mock-middleware.js b/lib/rest-mock-middleware.js index ffa1e1b..a98e445 100644 --- a/lib/rest-mock-middleware.js +++ b/lib/rest-mock-middleware.js @@ -1,13 +1,21 @@ -const fs = require("fs"); -const path = require("path"); -const bodyParser = require("body-parser"); -const walkSyncJson = require("./walk-sync-json"); -const sortMappings = require("./mappings-sort"); -const requestMachings = require("./request-matching/index"); -const { initLogger } = require("./logger"); -const AjvValidator = require("./ajv-manager"); - -const mockIdentifier = "Mock"; +import { + bodyRequestMatching, + headersRequestMatching, + methodRequestMatching, + queryRequestMatching, + urlRequestMatching, +} from './request-matching'; + +import AjvValidator from './ajv-manager'; +import bodyParser from 'body-parser'; +import chokidar from 'chokidar'; +import fs from 'fs'; +import initLogger from './logger'; +import path from 'path'; +import sortMappings from './mappings-sort'; +import walkSyncJson from './walk-sync-json'; + +const mockIdentifier = 'Mock'; const isNumber = function (n) { return !isNaN(parseFloat(n)) && isFinite(n); @@ -19,7 +27,7 @@ const mocksMiddleware = function (mocksConfiguration) { const appLabel = (mocksConfiguration || {}).appLabel || mockIdentifier; // initialize - logger = initLogger({ + const logger = initLogger({ config, filters, appLabel, @@ -32,8 +40,8 @@ const mocksMiddleware = function (mocksConfiguration) { mocksConfiguration.disabled === true ) { logger.log({ - level: "error", - message: " Mock middleware not configured, passthrough enabled.", + level: 'error', + message: ' Mock middleware not configured, passthrough enabled.', }); // return passthrough return function (req, res, next) { @@ -43,7 +51,7 @@ const mocksMiddleware = function (mocksConfiguration) { // chek is the directory attribute is configured. if (mocksConfiguration && mocksConfiguration.root_dir === undefined) { throw new Error( - `[${mockIdentifier}] Mock middleware directory is not configured.` + `[${mockIdentifier}] Mock middleware directory is not configured.`, ); } // check is the directory exists @@ -51,7 +59,7 @@ const mocksMiddleware = function (mocksConfiguration) { let directory = path.resolve(__dirname, mocksConfiguration.root_dir); if (!fs.existsSync(directory) || !fs.statSync(directory).isDirectory()) { throw new Error( - `[${mockIdentifier}] Mock middleware directory doesn't exists.` + `[${mockIdentifier}] Mock middleware directory doesn't exists.`, ); } } @@ -60,30 +68,30 @@ const mocksMiddleware = function (mocksConfiguration) { if (mocksConfiguration && mocksConfiguration.root_dir) { let directory = path.resolve( __dirname, - mocksConfiguration.root_dir + "/mappings" + mocksConfiguration.root_dir + '/mappings', ); if (!fs.existsSync(directory) || !fs.statSync(directory).isDirectory()) { throw new Error( - `[${mockIdentifier}] Mock middleware mappings directory doesn't exists.` + `[${mockIdentifier}] Mock middleware mappings directory doesn't exists.`, ); } } let watchDirectory = path.normalize( - path.resolve(__dirname, mocksConfiguration.root_dir + "/mappings") + "/" + path.resolve(__dirname, mocksConfiguration.root_dir + '/mappings') + '/', ); let mappingFiles = walkSyncJson(watchDirectory); let mappings = new Map(); mappingFiles.forEach((file) => { - let filename = path.normalize(file).replace(watchDirectory, ""); + let filename = path.normalize(file).replace(watchDirectory, ''); try { mappings.set( path.normalize(filename), - JSON.parse(fs.readFileSync(file, "utf8")) + JSON.parse(fs.readFileSync(file, 'utf8')), ); } catch (e) { logger.log({ - type: "error", + type: 'error', message: `ERROR: invalid json from: ${filename}`, }); } @@ -91,50 +99,43 @@ const mocksMiddleware = function (mocksConfiguration) { mappings = sortMappings(mappings); - fs.watch( - watchDirectory, - { - recursive: true, - }, - (eventType, filename) => { - let filePath = path.normalize(watchDirectory + filename); - if ( - filename && - fs.existsSync(filePath) && - fs.statSync(filePath).isFile() - ) { - logger.log({ - level: "info", - message: `Realoading: ${filename}`, - }); - try { - mappings.set( - path.normalize(filename), - JSON.parse(fs.readFileSync(filePath, "utf8")) - ); - mappings = sortMappings(mappings); - } catch (e) { - logger.log({ - level: "info", - message: `invalid json from: ${filename}`, - }); - } - } else { + chokidar.watch(watchDirectory).on('all', (eventType, filename) => { + let filePath = path.normalize(watchDirectory + filename); + if (filename && fs.existsSync(filePath) && fs.statSync(filePath).isFile()) { + logger.log({ + level: 'info', + message: `Realoading: ${filename}`, + }); + try { + mappings.set( + path.normalize(filename), + JSON.parse(fs.readFileSync(filePath, 'utf8')), + ); + mappings = sortMappings(mappings); + } catch (e) { logger.log({ - level: "info", - message: `filename not provided`, + level: 'info', + message: `invalid json from: ${filename}`, }); } + } else { + logger.log({ + level: 'info', + message: `filename not provided`, + }); } - ); + }); let schemasWatchDirectory = path.normalize( - path.resolve(__dirname, mocksConfiguration.root_dir + "/schemas") + "/" + path.resolve(__dirname, mocksConfiguration.root_dir + '/schemas') + '/', ); const validator = new AjvValidator(schemasWatchDirectory, logger); - logger.log({ level: "info", message: " Mock middleware started correctly." }); + logger.log({ + level: 'info', + message: ' Mock middleware started correctly.', + }); // Return mock middleware let parser = bodyParser.json(); @@ -145,33 +146,33 @@ const mocksMiddleware = function (mocksConfiguration) { let route = Array.from(mappings.values()).find((route) => { let routeMatch = true; // URL checks - routeMatch = requestMachings.url(logger, route.request, req); + routeMatch = urlRequestMatching(logger, route.request, req); if (routeMatch) { // METHOD checks - routeMatch &= requestMachings.method(route.request, req); + routeMatch &= methodRequestMatching(logger, route.request, req); } if (routeMatch) { // HEADERS checks - routeMatch &= requestMachings.headers(route.request, req); + routeMatch &= headersRequestMatching(logger, route.request, req); } if (routeMatch) { // Query Parameters checks - routeMatch &= requestMachings.queryParameters(route.request, req); + routeMatch &= queryRequestMatching(logger, route.request, req); } if (routeMatch) { // Body checks - routeMatch &= requestMachings.body( + routeMatch &= bodyRequestMatching( logger, route.request, req, - validator + validator, ); } return routeMatch; }); if (route) { - res.set("Content-Type", "application/json"); + res.set('Content-Type', 'application/json'); if (route.response.headers) { res.set(route.response.headers); } @@ -187,19 +188,19 @@ const mocksMiddleware = function (mocksConfiguration) { path.resolve( __dirname, mocksConfiguration.root_dir + - "/responses/" + - route.response.bodyFileName - ) + '/responses/' + + route.response.bodyFileName, + ), ); - body = fs.readFileSync(filePath, "utf8"); + body = fs.readFileSync(filePath, 'utf8'); } catch (e) { res.status(404); - res.set("Content-Type", "text/plain"); + res.set('Content-Type', 'text/plain'); body = mockIdentifier + - "ERROR: file not found: " + + 'ERROR: file not found: ' + route.response.bodyFileName; - body += "\n" + e.message; + body += '\n' + e.message; flagError = true; } if (flagError === false) { @@ -207,12 +208,12 @@ const mocksMiddleware = function (mocksConfiguration) { body = JSON.parse(body); } catch (e) { res.status(500); - res.set("Content-Type", "text/plain"); + res.set('Content-Type', 'text/plain'); body = mockIdentifier + - "ERROR: invalid json from: " + + 'ERROR: invalid json from: ' + route.response.bodyFileName; - body += "\n" + e.message; + body += '\n' + e.message; } } if (route.delay && isNumber(route.delay) && route.delay > 0) { @@ -233,15 +234,15 @@ const mocksMiddleware = function (mocksConfiguration) { } } logger.log({ - level: "info", + level: 'info', message: `${req.method} ${req.originalUrl} -> \n${JSON.stringify( { - status: res.statusCode + " ( " + res.statusMessage + " ) ", + status: res.statusCode + ' ( ' + res.statusMessage + ' ) ', headers: res.headers, body: body, }, null, - 2 + 2, )}`, }); } else { @@ -251,4 +252,4 @@ const mocksMiddleware = function (mocksConfiguration) { }; }; -module.exports = mocksMiddleware; +export default mocksMiddleware; diff --git a/lib/walk-sync-json.js b/lib/walk-sync-json.js index fb84e3c..dad9c01 100644 --- a/lib/walk-sync-json.js +++ b/lib/walk-sync-json.js @@ -1,16 +1,16 @@ -const fs = require('fs'); -const path = require('path'); +import fs from 'fs'; +import path from 'path'; -const walkSyncJson = function(dir) { +const walkSyncJson = (dir) => { let newFileList = []; - files = fs.readdirSync(dir); - files.forEach(function(file) { + const files = fs.readdirSync(dir); + files.forEach(function (file) { let stat = fs.statSync(dir + file); if (stat.isDirectory()) { newFileList = newFileList.concat(walkSyncJson(dir + file + '/')); } else { - if (stat.isFile() && path.extname(dir + file).toLowerCase() === ".json") { + if (stat.isFile() && path.extname(dir + file).toLowerCase() === '.json') { newFileList.push(path.normalize(dir + file)); } } @@ -18,4 +18,4 @@ const walkSyncJson = function(dir) { return newFileList; }; -module.exports = walkSyncJson; \ No newline at end of file +export default walkSyncJson; diff --git a/package-lock.json b/package-lock.json index 565ca5b..587ee38 100644 --- a/package-lock.json +++ b/package-lock.json @@ -337,6 +337,50 @@ "kuler": "^2.0.0" } }, + "@eslint/eslintrc": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.2.1.tgz", + "integrity": "sha512-XRUeBZ5zBWLYgSANMpThFddrZZkEbGHgUdt5UJjZfnlN9BGCiUBrf+nvbRupSjMvqzwnQN0qwCmOxITt1cfywA==", + "dev": true, + "requires": { + "ajv": "^6.12.4", + "debug": "^4.1.1", + "espree": "^7.3.0", + "globals": "^12.1.0", + "ignore": "^4.0.6", + "import-fresh": "^3.2.1", + "js-yaml": "^3.13.1", + "lodash": "^4.17.19", + "minimatch": "^3.0.4", + "strip-json-comments": "^3.1.1" + }, + "dependencies": { + "debug": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", + "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", + "dev": true, + "requires": { + "ms": "2.1.2" + } + }, + "globals": { + "version": "12.4.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-12.4.0.tgz", + "integrity": "sha512-BWICuzzDvDoH54NHKCseDanAhE3CeDorgDL5MT6LMXXj2WCnd9UC2szdk4AWLfjdgNBCXLUanXYcpBBKOSWGwg==", + "dev": true, + "requires": { + "type-fest": "^0.8.1" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + } + } + }, "@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -452,12 +496,24 @@ "integrity": "sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog==", "dev": true }, + "@types/minimist": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.1.tgz", + "integrity": "sha512-fZQQafSREFyuZcdWFAExYjBiCL7AUCdgsk80iO0q4yihYYdcIiH28CcuPTGFgLOCC8RlW49GSQxdHwZP+I7CNg==", + "dev": true + }, "@types/node": { "version": "14.14.10", "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.10.tgz", "integrity": "sha512-J32dgx2hw8vXrSbu4ZlVhn1Nm3GbeCFNw2FWL8S5QKucHGY0cyNwjdQdO+KMBZ4wpmC7KhLCiNsdk1RFRIYUQQ==", "dev": true }, + "@types/normalize-package-data": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz", + "integrity": "sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA==", + "dev": true + }, "@types/superagent": { "version": "3.8.7", "resolved": "https://registry.npmjs.org/@types/superagent/-/superagent-3.8.7.tgz", @@ -484,6 +540,18 @@ "negotiator": "0.6.2" } }, + "acorn": { + "version": "7.4.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", + "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", + "dev": true + }, + "acorn-jsx": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.1.tgz", + "integrity": "sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng==", + "dev": true + }, "aggregate-error": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", @@ -530,7 +598,6 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.1.tgz", "integrity": "sha512-mM8522psRCqzV+6LhomX5wgp25YVibjh8Wj23I5RPkPppSVSjyKD2A2mBJmWGa+KN7f2D6LNh9jkBCeyLktzjg==", - "dev": true, "requires": { "normalize-path": "^3.0.0", "picomatch": "^2.0.4" @@ -566,12 +633,24 @@ "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=", "dev": true }, + "arrify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", + "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", + "dev": true + }, "assertion-error": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", "dev": true }, + "astral-regex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz", + "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", + "dev": true + }, "async": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz", @@ -592,8 +671,7 @@ "binary-extensions": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.1.0.tgz", - "integrity": "sha512-1Yj8h9Q+QDF5FzhMs/c9+6UntbD5MkRfRwac8DoEm9ZfUBZ7tZ55YcGVAzEe4bXsdQHEk+s9S5wsOKVdZrw0tQ==", - "dev": true + "integrity": "sha512-1Yj8h9Q+QDF5FzhMs/c9+6UntbD5MkRfRwac8DoEm9ZfUBZ7tZ55YcGVAzEe4bXsdQHEk+s9S5wsOKVdZrw0tQ==" }, "body-parser": { "version": "1.19.0", @@ -626,7 +704,6 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", - "dev": true, "requires": { "fill-range": "^7.0.1" } @@ -654,12 +731,29 @@ "write-file-atomic": "^3.0.0" } }, + "callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true + }, "camelcase": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", "dev": true }, + "camelcase-keys": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/camelcase-keys/-/camelcase-keys-6.2.2.tgz", + "integrity": "sha512-YrwaA0vEKazPBkn0ipTiMpSajYDSe+KjQfrjhcBMxJt/znbvlHd8Pw/Vamaz5EB4Wfhs3SUR3Z9mwRu/P3s3Yg==", + "dev": true, + "requires": { + "camelcase": "^5.3.1", + "map-obj": "^4.0.0", + "quick-lru": "^4.0.1" + } + }, "chai": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", @@ -709,7 +803,6 @@ "version": "3.4.3", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.4.3.tgz", "integrity": "sha512-DtM3g7juCXQxFVSNPNByEC2+NImtBuxQQvWlHunpJIS5Ocr0lG306cC7FCi7cEA0fzmybPUIl4txBIobk1gGOQ==", - "dev": true, "requires": { "anymatch": "~3.1.1", "braces": "~3.0.2", @@ -911,17 +1004,6 @@ "which": "^2.0.1" } }, - "cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", - "dev": true, - "requires": { - "path-key": "^3.1.0", - "shebang-command": "^2.0.0", - "which": "^2.0.1" - } - }, "debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -936,6 +1018,24 @@ "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", "dev": true }, + "decamelize-keys": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/decamelize-keys/-/decamelize-keys-1.1.0.tgz", + "integrity": "sha1-0XGoeTMlKAfrPLYdwcFEXQeN8tk=", + "dev": true, + "requires": { + "decamelize": "^1.1.0", + "map-obj": "^1.0.0" + }, + "dependencies": { + "map-obj": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/map-obj/-/map-obj-1.0.1.tgz", + "integrity": "sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0=", + "dev": true + } + } + }, "deep-eql": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", @@ -976,12 +1076,27 @@ "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=", "dev": true }, + "detect-indent": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-6.0.0.tgz", + "integrity": "sha512-oSyFlqaTHCItVRGK5RmrmjB+CmaMOW7IaNA/kdxqhoa6d17j/5ce9O9eWXmV/KEdRwqpQA+Vqe8a8Bsybu4YnA==", + "dev": true + }, "diff": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", "dev": true }, + "doctrine": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", + "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", + "dev": true, + "requires": { + "esutils": "^2.0.2" + } + }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -1004,6 +1119,32 @@ "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=", "dev": true }, + "enquirer": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz", + "integrity": "sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==", + "dev": true, + "requires": { + "ansi-colors": "^4.1.1" + } + }, + "error-ex": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", + "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", + "dev": true, + "requires": { + "is-arrayish": "^0.2.1" + }, + "dependencies": { + "is-arrayish": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", + "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=", + "dev": true + } + } + }, "es6-error": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/es6-error/-/es6-error-4.1.1.tgz", @@ -1041,11 +1182,243 @@ } } }, + "eslint": { + "version": "7.14.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.14.0.tgz", + "integrity": "sha512-5YubdnPXrlrYAFCKybPuHIAH++PINe1pmKNc5wQRB9HSbqIK1ywAnntE3Wwua4giKu0bjligf1gLF6qxMGOYRA==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "@eslint/eslintrc": "^0.2.1", + "ajv": "^6.10.0", + "chalk": "^4.0.0", + "cross-spawn": "^7.0.2", + "debug": "^4.0.1", + "doctrine": "^3.0.0", + "enquirer": "^2.3.5", + "eslint-scope": "^5.1.1", + "eslint-utils": "^2.1.0", + "eslint-visitor-keys": "^2.0.0", + "espree": "^7.3.0", + "esquery": "^1.2.0", + "esutils": "^2.0.2", + "file-entry-cache": "^5.0.1", + "functional-red-black-tree": "^1.0.1", + "glob-parent": "^5.0.0", + "globals": "^12.1.0", + "ignore": "^4.0.6", + "import-fresh": "^3.0.0", + "imurmurhash": "^0.1.4", + "is-glob": "^4.0.0", + "js-yaml": "^3.13.1", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.4.1", + "lodash": "^4.17.19", + "minimatch": "^3.0.4", + "natural-compare": "^1.4.0", + "optionator": "^0.9.1", + "progress": "^2.0.0", + "regexpp": "^3.1.0", + "semver": "^7.2.1", + "strip-ansi": "^6.0.0", + "strip-json-comments": "^3.1.0", + "table": "^5.2.3", + "text-table": "^0.2.0", + "v8-compile-cache": "^2.0.3" + }, + "dependencies": { + "ansi-regex": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "dev": true + }, + "debug": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", + "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", + "dev": true, + "requires": { + "ms": "2.1.2" + } + }, + "globals": { + "version": "12.4.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-12.4.0.tgz", + "integrity": "sha512-BWICuzzDvDoH54NHKCseDanAhE3CeDorgDL5MT6LMXXj2WCnd9UC2szdk4AWLfjdgNBCXLUanXYcpBBKOSWGwg==", + "dev": true, + "requires": { + "type-fest": "^0.8.1" + } + }, + "levn": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", + "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "dev": true, + "requires": { + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, + "optionator": { + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz", + "integrity": "sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==", + "dev": true, + "requires": { + "deep-is": "^0.1.3", + "fast-levenshtein": "^2.0.6", + "levn": "^0.4.1", + "prelude-ls": "^1.2.1", + "type-check": "^0.4.0", + "word-wrap": "^1.2.3" + } + }, + "prelude-ls": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", + "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", + "dev": true + }, + "semver": { + "version": "7.3.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.3.tgz", + "integrity": "sha512-kBGrn+sE2tyi6f4c9aFrrYRSTTF5yNOEVRBCdpcgykFp3jt2ZGlBwzIwWER9J9HZnQa9IF1TrR8Xy2UU+eaUhQ==", + "dev": true, + "requires": { + "lru-cache": "^4.1.5" + } + }, + "strip-ansi": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", + "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", + "dev": true, + "requires": { + "ansi-regex": "^5.0.0" + } + }, + "type-check": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", + "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", + "dev": true, + "requires": { + "prelude-ls": "^1.2.1" + } + } + } + }, + "eslint-plugin-chai-expect": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-chai-expect/-/eslint-plugin-chai-expect-2.2.0.tgz", + "integrity": "sha512-ExTJKhgeYMfY8wDj3UiZmgpMKJOUHGNHmWMlxT49JUDB1vTnw0sSNfXJSxnX+LcebyBD/gudXzjzD136WqPJrQ==", + "dev": true + }, + "eslint-scope": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", + "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", + "dev": true, + "requires": { + "esrecurse": "^4.3.0", + "estraverse": "^4.1.1" + } + }, + "eslint-utils": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.1.0.tgz", + "integrity": "sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg==", + "dev": true, + "requires": { + "eslint-visitor-keys": "^1.1.0" + }, + "dependencies": { + "eslint-visitor-keys": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz", + "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==", + "dev": true + } + } + }, + "eslint-visitor-keys": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.0.0.tgz", + "integrity": "sha512-QudtT6av5WXels9WjIM7qz1XD1cWGvX4gGXvp/zBn9nXG02D0utdU3Em2m/QjTnrsk6bBjmCygl3rmj118msQQ==", + "dev": true + }, + "esm": { + "version": "3.2.25", + "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz", + "integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==", + "dev": true + }, + "espree": { + "version": "7.3.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-7.3.0.tgz", + "integrity": "sha512-dksIWsvKCixn1yrEXO8UosNSxaDoSYpq9reEjZSbHLpT5hpaCAKTLBwq0RHtLrIr+c0ByiYzWT8KTMRzoRCNlw==", + "dev": true, + "requires": { + "acorn": "^7.4.0", + "acorn-jsx": "^5.2.0", + "eslint-visitor-keys": "^1.3.0" + }, + "dependencies": { + "eslint-visitor-keys": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz", + "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==", + "dev": true + } + } + }, "esprima": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/esprima/-/esprima-1.2.2.tgz", "integrity": "sha1-dqD9Zvz+FU/SkmZ9wmQBl1CxZXs=" }, + "esquery": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.3.1.tgz", + "integrity": "sha512-olpvt9QG0vniUBZspVRN6lwB7hOZoTRtT+jzR+tS4ffYx2mzbw+z0XCOk44aaLYKApNX5nMm+E+P6o25ip/DHQ==", + "dev": true, + "requires": { + "estraverse": "^5.1.0" + }, + "dependencies": { + "estraverse": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.2.0.tgz", + "integrity": "sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ==", + "dev": true + } + } + }, + "esrecurse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", + "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", + "dev": true, + "requires": { + "estraverse": "^5.2.0" + }, + "dependencies": { + "estraverse": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.2.0.tgz", + "integrity": "sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ==", + "dev": true + } + } + }, "estraverse": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", @@ -1131,11 +1504,19 @@ "resolved": "https://registry.npmjs.org/fecha/-/fecha-4.2.0.tgz", "integrity": "sha512-aN3pcx/DSmtyoovUudctc8+6Hl4T+hI9GBBHLjA76jdZl7+b1sgh5g4k+u/GL3dTy1/pnYzKp69FpJ0OicE3Wg==" }, + "file-entry-cache": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-5.0.1.tgz", + "integrity": "sha512-bCg29ictuBaKUwwArK4ouCaqDgLZcysCFLmM/Yn/FDoqndh/9vNuQfXRDvTuXKLxfD/JtZQGKFT8MGcJBK644g==", + "dev": true, + "requires": { + "flat-cache": "^2.0.1" + } + }, "fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", - "dev": true, "requires": { "to-regex-range": "^5.0.1" } @@ -1182,6 +1563,34 @@ "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", "dev": true }, + "flat-cache": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-2.0.1.tgz", + "integrity": "sha512-LoQe6yDuUMDzQAEH8sgmh4Md6oZnc/7PjtwjNFSzveXqSHt6ka9fPBuso7IGf9Rz4uqnSnWiFH2B/zj24a5ReA==", + "dev": true, + "requires": { + "flatted": "^2.0.0", + "rimraf": "2.6.3", + "write": "1.0.3" + }, + "dependencies": { + "rimraf": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", + "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + } + } + }, + "flatted": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.2.tgz", + "integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==", + "dev": true + }, "fn.name": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/fn.name/-/fn.name-1.1.0.tgz", @@ -1242,7 +1651,6 @@ "version": "2.1.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz", "integrity": "sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==", - "dev": true, "optional": true }, "function-bind": { @@ -1251,6 +1659,12 @@ "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", "dev": true }, + "functional-red-black-tree": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", + "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", + "dev": true + }, "gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", @@ -1293,7 +1707,6 @@ "version": "5.1.1", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz", "integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==", - "dev": true, "requires": { "is-glob": "^4.0.1" } @@ -1316,6 +1729,12 @@ "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", "dev": true }, + "hard-rejection": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/hard-rejection/-/hard-rejection-2.1.0.tgz", + "integrity": "sha512-VIZB+ibDhx7ObhAe7OVtoEbuP4h/MuOTHJ+J8h/eBXotJYl0fBgR72xDFCKgIh22OJZIOVNxBMWuhAr10r8HdA==", + "dev": true + }, "has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -1347,6 +1766,32 @@ "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", "dev": true }, + "hosted-git-info": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-3.0.7.tgz", + "integrity": "sha512-fWqc0IcuXs+BmE9orLDyVykAG9GJtGLGuZAAqgcckPgv5xad4AcXGIv8galtQvlwutxSlaMcdw7BUtq2EIvqCQ==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + }, + "dependencies": { + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "requires": { + "yallist": "^4.0.0" + } + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + } + } + }, "html-escaper": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", @@ -1365,6 +1810,12 @@ "toidentifier": "1.0.0" } }, + "husky": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/husky/-/husky-5.0.4.tgz", + "integrity": "sha512-35tdr4zrmJrpMconZggELF8zzNuddp2NEpPc4AjplPoYJauPZU6WuvCCrJYOTZv5UUj9C15ikQWCcTXk4jJj9Q==", + "dev": true + }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -1373,6 +1824,30 @@ "safer-buffer": ">= 2.1.2 < 3" } }, + "ignore": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", + "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", + "dev": true + }, + "import-fresh": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.2.2.tgz", + "integrity": "sha512-cTPNrlvJT6twpYy+YmKUKrTSjWFs3bjYjAhCwm+z4EOCubZxAuO+hHpRN64TqjEaYSHs7tJAE0w1CKMGmsG/lw==", + "dev": true, + "requires": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + }, + "dependencies": { + "resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true + } + } + }, "imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", @@ -1421,7 +1896,6 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", - "dev": true, "requires": { "binary-extensions": "^2.0.0" } @@ -1438,8 +1912,7 @@ "is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", - "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", - "dev": true + "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=" }, "is-fullwidth-code-point": { "version": "2.0.0", @@ -1451,7 +1924,6 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==", - "dev": true, "requires": { "is-extglob": "^2.1.1" } @@ -1468,8 +1940,7 @@ "is-number": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", - "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "dev": true + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==" }, "is-plain-obj": { "version": "2.1.0", @@ -1505,12 +1976,6 @@ "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", "dev": true }, - "isexe": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", - "dev": true - }, "istanbul-lib-coverage": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.0.0.tgz", @@ -1632,11 +2097,23 @@ "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==", "dev": true }, + "json-parse-even-better-errors": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz", + "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==", + "dev": true + }, "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" }, + "json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", + "dev": true + }, "json5": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/json5/-/json5-2.1.3.tgz", @@ -1662,6 +2139,12 @@ "integrity": "sha512-aWgeGFW67BP3e5181Ep1Fv2v8z//iBJfrvyTnq8wG86vEESwmonn1zPBJ0VfmT9CJq2FIT0VsETtrNFm2a+SHA==", "dev": true }, + "kind-of": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", + "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==", + "dev": true + }, "kuler": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/kuler/-/kuler-2.0.0.tgz", @@ -1676,6 +2159,32 @@ "type-check": "~0.3.2" } }, + "lines-and-columns": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.1.6.tgz", + "integrity": "sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=", + "dev": true + }, + "load-json-file": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-6.2.0.tgz", + "integrity": "sha512-gUD/epcRms75Cw8RT1pUdHugZYM5ce64ucs2GEISABwkRsOQr0q2wm/MV2TKThycIe5e0ytRweW2RZxclogCdQ==", + "dev": true, + "requires": { + "graceful-fs": "^4.1.15", + "parse-json": "^5.0.0", + "strip-bom": "^4.0.0", + "type-fest": "^0.6.0" + }, + "dependencies": { + "type-fest": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.6.0.tgz", + "integrity": "sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg==", + "dev": true + } + } + }, "locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", @@ -1703,6 +2212,12 @@ "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=", "dev": true }, + "lodash.mapkeys": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/lodash.mapkeys/-/lodash.mapkeys-4.6.0.tgz", + "integrity": "sha1-3yz6Ix18V8eorQA6va1dc9PqUZU=", + "dev": true + }, "log-symbols": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.0.0.tgz", @@ -1731,6 +2246,16 @@ } } }, + "lru-cache": { + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", + "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", + "dev": true, + "requires": { + "pseudomap": "^1.0.2", + "yallist": "^2.1.2" + } + }, "make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -1740,11 +2265,50 @@ "semver": "^6.0.0" } }, + "map-obj": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/map-obj/-/map-obj-4.1.0.tgz", + "integrity": "sha512-glc9y00wgtwcDmp7GaE/0b0OnxpNJsVf3ael/An6Fe2Q51LLwN1er6sdomLRzz5h0+yMpiYLhWYF5R7HeqVd4g==", + "dev": true + }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" }, + "meow": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/meow/-/meow-8.0.0.tgz", + "integrity": "sha512-nbsTRz2fwniJBFgUkcdISq8y/q9n9VbiHYbfwklFh5V4V2uAcxtKQkDc0yCLPM/kP0d+inZBewn3zJqewHE7kg==", + "dev": true, + "requires": { + "@types/minimist": "^1.2.0", + "camelcase-keys": "^6.2.2", + "decamelize-keys": "^1.1.0", + "hard-rejection": "^2.1.0", + "minimist-options": "4.1.0", + "normalize-package-data": "^3.0.0", + "read-pkg-up": "^7.0.1", + "redent": "^3.0.0", + "trim-newlines": "^3.0.0", + "type-fest": "^0.18.0", + "yargs-parser": "^20.2.3" + }, + "dependencies": { + "type-fest": { + "version": "0.18.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.18.1.tgz", + "integrity": "sha512-OIAYXk8+ISY+qTOwkHtKqzAuxchoMiD9Udx+FSGQDuiRR+PJKJHc2NJAXlbhkGwTt/4/nKZxELY1w3ReWOL8mw==", + "dev": true + }, + "yargs-parser": { + "version": "20.2.4", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.4.tgz", + "integrity": "sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==", + "dev": true + } + } + }, "merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", @@ -1776,6 +2340,12 @@ "mime-db": "1.44.0" } }, + "min-indent": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz", + "integrity": "sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==", + "dev": true + }, "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", @@ -1791,6 +2361,34 @@ "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", "dev": true }, + "minimist-options": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/minimist-options/-/minimist-options-4.1.0.tgz", + "integrity": "sha512-Q4r8ghd80yhO/0j1O3B2BjweX3fiHg9cdOwjJd2J76Q135c+NDxGCqdYKQ1SKBuFfgWbAUzBfvYjPUEeNgqN1A==", + "dev": true, + "requires": { + "arrify": "^1.0.1", + "is-plain-obj": "^1.1.0", + "kind-of": "^6.0.3" + }, + "dependencies": { + "is-plain-obj": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz", + "integrity": "sha1-caUMhCnfync8kqOQpKA7OfzVHT4=", + "dev": true + } + } + }, + "mkdirp": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", + "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "dev": true, + "requires": { + "minimist": "^1.2.5" + } + }, "mocha": { "version": "8.2.1", "resolved": "https://registry.npmjs.org/mocha/-/mocha-8.2.1.tgz", @@ -1858,6 +2456,12 @@ "integrity": "sha512-1qstj9z5+x491jfiC4Nelk+f8XBad7LN20PmyWINJEMRSf3wcAjAWysw1qaA8z6NSKe2sjq1hRSDpBH5paCb6A==", "dev": true }, + "natural-compare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", + "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", + "dev": true + }, "negotiator": { "version": "0.6.2", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", @@ -1908,11 +2512,48 @@ "process-on-spawn": "^1.0.0" } }, + "normalize-package-data": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-3.0.0.tgz", + "integrity": "sha512-6lUjEI0d3v6kFrtgA/lOx4zHCWULXsFNIjHolnZCKCTLA6m/G625cdn3O7eNmT0iD3jfo6HZ9cdImGZwf21prw==", + "dev": true, + "requires": { + "hosted-git-info": "^3.0.6", + "resolve": "^1.17.0", + "semver": "^7.3.2", + "validate-npm-package-license": "^3.0.1" + }, + "dependencies": { + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "requires": { + "yallist": "^4.0.0" + } + }, + "semver": { + "version": "7.3.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.4.tgz", + "integrity": "sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + } + } + }, "normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", - "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", - "dev": true + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==" }, "nyc": { "version": "15.1.0", @@ -2160,6 +2801,27 @@ "release-zalgo": "^1.0.0" } }, + "parent-module": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", + "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "dev": true, + "requires": { + "callsites": "^3.0.0" + } + }, + "parse-json": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.1.0.tgz", + "integrity": "sha512-+mi/lmVVNKFNVyLXV31ERiy2CY5E1/F6QtJFEzoChPRwwngMNXRDQ9GJ5WdE2Z2P4AujsOi0/+2qHID68KwfIQ==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "error-ex": "^1.3.1", + "json-parse-even-better-errors": "^2.3.0", + "lines-and-columns": "^1.1.6" + } + }, "parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", @@ -2205,8 +2867,19 @@ "picomatch": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz", - "integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==", - "dev": true + "integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==" + }, + "pinst": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/pinst/-/pinst-2.1.1.tgz", + "integrity": "sha512-n8P1bTw2B3Ff/wkG2yP7HN3wBIkobfkuNS5WNhsUrM+/QTSJUZc2n/WPUSxONRjaXMffmjCNDTjwDy0ptVHlbw==", + "dev": true, + "requires": { + "load-json-file": "^6.2.0", + "lodash.mapkeys": "^4.6.0", + "meow": "^8.0.0", + "write-json-file": "^4.3.0" + } }, "pkg-dir": { "version": "4.2.0", @@ -2261,6 +2934,12 @@ "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=" }, + "prettier": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.2.1.tgz", + "integrity": "sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==", + "dev": true + }, "process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", @@ -2275,14 +2954,11 @@ "fromentries": "^1.2.0" } }, - "process-on-spawn": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/process-on-spawn/-/process-on-spawn-1.0.0.tgz", - "integrity": "sha512-1WsPDsUSMmZH5LeMLegqkPDrsGgsWwk1Exipy2hvB0o/F0ASzbpIctSCcZIK1ykJvtTJULEH+20WOFjMvGnCTg==", - "dev": true, - "requires": { - "fromentries": "^1.2.0" - } + "progress": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", + "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", + "dev": true }, "proxy-addr": { "version": "2.0.6", @@ -2294,6 +2970,12 @@ "ipaddr.js": "1.9.1" } }, + "pseudomap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", + "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=", + "dev": true + }, "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", @@ -2304,6 +2986,12 @@ "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==" }, + "quick-lru": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-4.0.1.tgz", + "integrity": "sha512-ARhCpm70fzdcvNQfPoy49IaanKkTlRWF2JMzqhcJbhSFRZv7nPTvZJdcY7301IPmvW+/p0RgIWnQDLJxifsQ7g==", + "dev": true + }, "randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -2330,6 +3018,100 @@ "unpipe": "1.0.0" } }, + "read-pkg": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-5.2.0.tgz", + "integrity": "sha512-Ug69mNOpfvKDAc2Q8DRpMjjzdtrnv9HcSMX+4VsZxD1aZ6ZzrIE7rlzXBtWTyhULSMKg076AW6WR5iZpD0JiOg==", + "dev": true, + "requires": { + "@types/normalize-package-data": "^2.4.0", + "normalize-package-data": "^2.5.0", + "parse-json": "^5.0.0", + "type-fest": "^0.6.0" + }, + "dependencies": { + "hosted-git-info": { + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz", + "integrity": "sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==", + "dev": true + }, + "normalize-package-data": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", + "integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==", + "dev": true, + "requires": { + "hosted-git-info": "^2.1.4", + "resolve": "^1.10.0", + "semver": "2 || 3 || 4 || 5", + "validate-npm-package-license": "^3.0.1" + } + }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + }, + "type-fest": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.6.0.tgz", + "integrity": "sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg==", + "dev": true + } + } + }, + "read-pkg-up": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-7.0.1.tgz", + "integrity": "sha512-zK0TB7Xd6JpCLmlLmufqykGE+/TlOePD6qKClNW7hHDKFh/J7/7gCWGR7joEQEW1bKq3a3yUZSObOoWLFQ4ohg==", + "dev": true, + "requires": { + "find-up": "^4.1.0", + "read-pkg": "^5.2.0", + "type-fest": "^0.8.1" + }, + "dependencies": { + "find-up": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "dev": true, + "requires": { + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" + } + }, + "locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "dev": true, + "requires": { + "p-locate": "^4.1.0" + } + }, + "p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "dev": true, + "requires": { + "p-try": "^2.0.0" + } + }, + "p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "dev": true, + "requires": { + "p-limit": "^2.2.0" + } + } + } + }, "readable-stream": { "version": "2.3.7", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", @@ -2348,11 +3130,26 @@ "version": "3.5.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.5.0.tgz", "integrity": "sha512-cMhu7c/8rdhkHXWsY+osBhfSy0JikwpHK/5+imo+LpeasTF8ouErHrlYkwT0++njiyuDvc7OFY5T3ukvZ8qmFQ==", - "dev": true, "requires": { "picomatch": "^2.2.1" } }, + "redent": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz", + "integrity": "sha512-6tDA8g98We0zd0GvVeMT9arEOnTw9qM03L9cJXaCjrip1OO764RDBLBfrB4cwzNGDj5OA5ioymC9GkizgWJDUg==", + "dev": true, + "requires": { + "indent-string": "^4.0.0", + "strip-indent": "^3.0.0" + } + }, + "regexpp": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.1.0.tgz", + "integrity": "sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q==", + "dev": true + }, "release-zalgo": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/release-zalgo/-/release-zalgo-1.0.0.tgz", @@ -2520,6 +3317,52 @@ "supports-color": "^7.1.0" } }, + "slice-ansi": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz", + "integrity": "sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.0", + "astral-regex": "^1.0.0", + "is-fullwidth-code-point": "^2.0.0" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "dev": true + } + } + }, + "sort-keys": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/sort-keys/-/sort-keys-4.1.0.tgz", + "integrity": "sha512-/sRdxzkkPFUYiCrTr/2t+104nDc9AgDmEpeVYuvOWYQe3Djk1GWO6lVw3Vx2jfh1SsR0eehhd1nvFYlzt5e99w==", + "dev": true, + "requires": { + "is-plain-obj": "^2.0.0" + } + }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -2539,6 +3382,38 @@ "which": "^2.0.1" } }, + "spdx-correct": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.1.tgz", + "integrity": "sha512-cOYcUWwhCuHCXi49RhFRCyJEK3iPj1Ziz9DpViV3tbZOwXD49QzIN3MpOLJNxh2qwq2lJJZaKMVw9qNi4jTC0w==", + "dev": true, + "requires": { + "spdx-expression-parse": "^3.0.0", + "spdx-license-ids": "^3.0.0" + } + }, + "spdx-exceptions": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.3.0.tgz", + "integrity": "sha512-/tTrYOC7PPI1nUAgx34hUpqXuyJG+DTHJTnIULG4rDygi4xu/tfgmq1e1cIRwRzwZgo4NLySi+ricLkZkw4i5A==", + "dev": true + }, + "spdx-expression-parse": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.1.tgz", + "integrity": "sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q==", + "dev": true, + "requires": { + "spdx-exceptions": "^2.1.0", + "spdx-license-ids": "^3.0.0" + } + }, + "spdx-license-ids": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.7.tgz", + "integrity": "sha512-U+MTEOO0AiDzxwFvoa4JVnMV6mZlJKk2sBLt90s7G0Gd0Mlknc7kxEn3nuDPNZRta7O2uy8oLcZLVT+4sqNZHQ==", + "dev": true + }, "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", @@ -2596,6 +3471,15 @@ "integrity": "sha512-3xurFv5tEgii33Zi8Jtp55wEIILR9eh34FAW00PZf+JnSsTmV/ioewSgQl97JHvgjoRGwPShsWm+IdrxB35d0w==", "dev": true }, + "strip-indent": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-3.0.0.tgz", + "integrity": "sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ==", + "dev": true, + "requires": { + "min-indent": "^1.0.0" + } + }, "strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -2646,6 +3530,46 @@ "has-flag": "^4.0.0" } }, + "table": { + "version": "5.4.6", + "resolved": "https://registry.npmjs.org/table/-/table-5.4.6.tgz", + "integrity": "sha512-wmEc8m4fjnob4gt5riFRtTu/6+4rSe12TpAELNSqHMfF3IqnA+CH37USM6/YR3qRZv7e56kAEAtd6nKZaxe0Ug==", + "dev": true, + "requires": { + "ajv": "^6.10.2", + "lodash": "^4.17.14", + "slice-ansi": "^2.1.0", + "string-width": "^3.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "dev": true + }, + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "dev": true, + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + } + }, + "strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "dev": true, + "requires": { + "ansi-regex": "^4.1.0" + } + } + } + }, "test-exclude": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", @@ -2662,6 +3586,12 @@ "resolved": "https://registry.npmjs.org/text-hex/-/text-hex-1.0.0.tgz", "integrity": "sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg==" }, + "text-table": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", + "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", + "dev": true + }, "to-fast-properties": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", @@ -2672,7 +3602,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", - "dev": true, "requires": { "is-number": "^7.0.0" } @@ -2682,6 +3611,12 @@ "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==" }, + "trim-newlines": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-3.0.0.tgz", + "integrity": "sha512-C4+gOpvmxaSMKuEf9Qc134F1ZuOHVXKRbtEflf4NTtuuJDEIJ9p5PXsalL8SkeRw+qit1Mo+yuvMPAKwWg/1hA==", + "dev": true + }, "triple-beam": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.3.0.tgz", @@ -2760,6 +3695,22 @@ "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==", "dev": true }, + "v8-compile-cache": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.2.0.tgz", + "integrity": "sha512-gTpR5XQNKFwOd4clxfnhaqvfqMpqEwr4tOtCyz4MtYZX2JYhfr1JvBFKdS+7K/9rfpZR3VLX+YWBbKoxCgS43Q==", + "dev": true + }, + "validate-npm-package-license": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", + "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==", + "dev": true, + "requires": { + "spdx-correct": "^3.0.0", + "spdx-expression-parse": "^3.0.0" + } + }, "vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -2907,6 +3858,15 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true }, + "write": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/write/-/write-1.0.3.tgz", + "integrity": "sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig==", + "dev": true, + "requires": { + "mkdirp": "^0.5.1" + } + }, "write-file-atomic": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-3.0.3.tgz", @@ -2919,12 +3879,32 @@ "typedarray-to-buffer": "^3.1.5" } }, + "write-json-file": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/write-json-file/-/write-json-file-4.3.0.tgz", + "integrity": "sha512-PxiShnxf0IlnQuMYOPPhPkhExoCQuTUNPOa/2JWCYTmBquU9njyyDuwRKN26IZBlp4yn1nt+Agh2HOOBl+55HQ==", + "dev": true, + "requires": { + "detect-indent": "^6.0.0", + "graceful-fs": "^4.1.15", + "is-plain-obj": "^2.0.0", + "make-dir": "^3.0.0", + "sort-keys": "^4.0.0", + "write-file-atomic": "^3.0.0" + } + }, "y18n": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", "dev": true }, + "yallist": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", + "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=", + "dev": true + }, "yargs": { "version": "13.3.2", "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.3.2.tgz", diff --git a/package.json b/package.json index 0113fe7..c7dc52d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "rest-mock-middleware", - "version": "0.0.3", - "private": true, + "name": "@devaway/rest-mock-middleware", + "version": "0.1.0", + "private": false, "repository": { "type": "git", "url": "https://github.com/devaway/rest-mock-middleware.git" @@ -12,6 +12,7 @@ "dependencies": { "ajv": "^6.12.6", "body-parser": "^1.19.0", + "chokidar": "^3.4.3", "jsonpath": "^1.0.2", "node-json-equal": "0.1.0", "winston": "^3.3.3" @@ -19,15 +20,27 @@ "devDependencies": { "chai": "^4.2.0", "chai-http": "^4.3.0", + "eslint": "^7.14.0", + "eslint-plugin-chai-expect": "^2.2.0", + "esm": "^3.2.25", "express": "^4.17.1", + "husky": "^5.0.4", "mocha": "^8.2.1", "mocha-lcov-reporter": "*", "nyc": "^15.1.0", + "pinst": "^2.1.1", + "prettier": "2.2.1", "sinon": "^9.2.1" }, "scripts": { - "test": "mocha --exit test/**/*.spec.js", - "cover": "nyc --reporter=html mocha test/**/*.spec.js --exit" + "test": "mocha --exit --require esm test/**/*.spec.js", + "cover": "nyc --reporter=html mocha test/**/*.spec.js --exit", + "lint": "eslint ./lib ./test", + "prettier:format": "prettier --write ./lib ./test", + "prettier:check": "prettier --check ./lib ./test", + "postinstall": "husky install", + "prepublish": "pinst --disable", + "postpublish": "pinst --enable" }, "engines": { "node": ">=8.0.0" diff --git a/test/mocksHeaders/mappings/One-Header.json b/test/mocksHeaders/mappings/One-Header.json index 45676b5..808442e 100644 --- a/test/mocksHeaders/mappings/One-Header.json +++ b/test/mocksHeaders/mappings/One-Header.json @@ -12,4 +12,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksHeaders/mappings/Two-Headers.json b/test/mocksHeaders/mappings/Two-Headers.json index 45c00c6..79566e4 100644 --- a/test/mocksHeaders/mappings/Two-Headers.json +++ b/test/mocksHeaders/mappings/Two-Headers.json @@ -13,4 +13,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksJson/mappings/POST-json-equals-arrayOrder.json b/test/mocksJson/mappings/POST-json-equals-arrayOrder.json index aa50ead..5819842 100644 --- a/test/mocksJson/mappings/POST-json-equals-arrayOrder.json +++ b/test/mocksJson/mappings/POST-json-equals-arrayOrder.json @@ -7,10 +7,12 @@ "equalToJson": [ { "total_results": 5 - },{ - "total_results": 4 - }], - "ignoreArrayOrder":false + }, + { + "total_results": 4 + } + ], + "ignoreArrayOrder": false } }, "response": { diff --git a/test/mocksJson/mappings/POST-json-equals.json b/test/mocksJson/mappings/POST-json-equals.json index eefe1fa..0871c6f 100644 --- a/test/mocksJson/mappings/POST-json-equals.json +++ b/test/mocksJson/mappings/POST-json-equals.json @@ -15,4 +15,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksJson/mappings/POST-json-match-path-with-array.json b/test/mocksJson/mappings/POST-json-match-path-with-array.json index 89d2aba..6bf4a82 100644 --- a/test/mocksJson/mappings/POST-json-match-path-with-array.json +++ b/test/mocksJson/mappings/POST-json-match-path-with-array.json @@ -13,4 +13,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksJson/mappings/POST-json-match-path-with-nested-array.json b/test/mocksJson/mappings/POST-json-match-path-with-nested-array.json index 56a69ab..c506709 100644 --- a/test/mocksJson/mappings/POST-json-match-path-with-nested-array.json +++ b/test/mocksJson/mappings/POST-json-match-path-with-nested-array.json @@ -13,4 +13,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksJson/mappings/POST-json-match-path.json b/test/mocksJson/mappings/POST-json-match-path.json index e41157d..b84b8a6 100644 --- a/test/mocksJson/mappings/POST-json-match-path.json +++ b/test/mocksJson/mappings/POST-json-match-path.json @@ -13,4 +13,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksMethod/mappings/ANY-lowercase.json b/test/mocksMethod/mappings/ANY-lowercase.json index 15b339f..ffb4d4f 100644 --- a/test/mocksMethod/mappings/ANY-lowercase.json +++ b/test/mocksMethod/mappings/ANY-lowercase.json @@ -10,4 +10,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksMethod/mappings/ANY.json b/test/mocksMethod/mappings/ANY.json index b30369d..f95be97 100644 --- a/test/mocksMethod/mappings/ANY.json +++ b/test/mocksMethod/mappings/ANY.json @@ -10,4 +10,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksMethod/mappings/DELETE-lowercase.json b/test/mocksMethod/mappings/DELETE-lowercase.json index b1f43f2..3053f8a 100644 --- a/test/mocksMethod/mappings/DELETE-lowercase.json +++ b/test/mocksMethod/mappings/DELETE-lowercase.json @@ -10,4 +10,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksMethod/mappings/DELETE.json b/test/mocksMethod/mappings/DELETE.json index 8f76c3c..58c665e 100644 --- a/test/mocksMethod/mappings/DELETE.json +++ b/test/mocksMethod/mappings/DELETE.json @@ -10,4 +10,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksMethod/mappings/GET-lowercase.json b/test/mocksMethod/mappings/GET-lowercase.json index b947362..e4c2f44 100644 --- a/test/mocksMethod/mappings/GET-lowercase.json +++ b/test/mocksMethod/mappings/GET-lowercase.json @@ -10,4 +10,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksMethod/mappings/GET.json b/test/mocksMethod/mappings/GET.json index 1412750..f328767 100644 --- a/test/mocksMethod/mappings/GET.json +++ b/test/mocksMethod/mappings/GET.json @@ -10,4 +10,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksMethod/mappings/NoMethod-url.json b/test/mocksMethod/mappings/NoMethod-url.json index 59906e4..f7e4098 100644 --- a/test/mocksMethod/mappings/NoMethod-url.json +++ b/test/mocksMethod/mappings/NoMethod-url.json @@ -9,4 +9,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksMethod/mappings/OPTIONS-lowercase.json b/test/mocksMethod/mappings/OPTIONS-lowercase.json index e71f427..ecda5f0 100644 --- a/test/mocksMethod/mappings/OPTIONS-lowercase.json +++ b/test/mocksMethod/mappings/OPTIONS-lowercase.json @@ -10,4 +10,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksMethod/mappings/OPTIONS.json b/test/mocksMethod/mappings/OPTIONS.json index 8d1af94..3d95383 100644 --- a/test/mocksMethod/mappings/OPTIONS.json +++ b/test/mocksMethod/mappings/OPTIONS.json @@ -10,4 +10,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksMethod/mappings/POST-lowercase.json b/test/mocksMethod/mappings/POST-lowercase.json index c9f57f0..14ddb02 100644 --- a/test/mocksMethod/mappings/POST-lowercase.json +++ b/test/mocksMethod/mappings/POST-lowercase.json @@ -10,4 +10,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksMethod/mappings/POST.json b/test/mocksMethod/mappings/POST.json index 1230b4a..42ab7c8 100644 --- a/test/mocksMethod/mappings/POST.json +++ b/test/mocksMethod/mappings/POST.json @@ -10,4 +10,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksMethod/mappings/PUT-lowercase.json b/test/mocksMethod/mappings/PUT-lowercase.json index 466bcbe..bb4df00 100644 --- a/test/mocksMethod/mappings/PUT-lowercase.json +++ b/test/mocksMethod/mappings/PUT-lowercase.json @@ -10,4 +10,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksMethod/mappings/PUT.json b/test/mocksMethod/mappings/PUT.json index 13bc812..b0f947c 100644 --- a/test/mocksMethod/mappings/PUT.json +++ b/test/mocksMethod/mappings/PUT.json @@ -10,4 +10,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksQuery/mappings/One-query-parameter.json b/test/mocksQuery/mappings/One-query-parameter.json index 1f5d946..2f5f69b 100644 --- a/test/mocksQuery/mappings/One-query-parameter.json +++ b/test/mocksQuery/mappings/One-query-parameter.json @@ -12,4 +12,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksQuery/mappings/Two-query-parameter.json b/test/mocksQuery/mappings/Two-query-parameter.json index 4a37b0e..d3d1e83 100644 --- a/test/mocksQuery/mappings/Two-query-parameter.json +++ b/test/mocksQuery/mappings/Two-query-parameter.json @@ -6,7 +6,6 @@ "search": "hello", "name": "Peter" } - }, "response": { "status": 200, @@ -14,4 +13,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksSchema/mappings/POST-json-schema-ref-file.json b/test/mocksSchema/mappings/POST-json-schema-ref-file.json index e9b9cab..2b48707 100644 --- a/test/mocksSchema/mappings/POST-json-schema-ref-file.json +++ b/test/mocksSchema/mappings/POST-json-schema-ref-file.json @@ -11,7 +11,7 @@ "user": { "$ref": "/schemas/user-schema.json" }, "total_results": { "type": "number" } }, - "required":["user", "total_results"], + "required": ["user", "total_results"], "additionalProperties": false } } diff --git a/test/mocksSchema/schemas/login-schema.json b/test/mocksSchema/schemas/login-schema.json index deed339..814163c 100644 --- a/test/mocksSchema/schemas/login-schema.json +++ b/test/mocksSchema/schemas/login-schema.json @@ -2,7 +2,7 @@ "id": "/schemas/login-schema.json", "type": "object", "properties": { - "user": { "$ref": "/schemas/user-schema.json" } + "user": { "$ref": "/schemas/user-schema.json" } }, "required": ["user"], "additionalProperties": false diff --git a/test/mocksUrl/mappings/GET-url.json b/test/mocksUrl/mappings/GET-url.json index 1230b4a..42ab7c8 100644 --- a/test/mocksUrl/mappings/GET-url.json +++ b/test/mocksUrl/mappings/GET-url.json @@ -10,4 +10,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksUrl/mappings/GET-urlPath.json b/test/mocksUrl/mappings/GET-urlPath.json index d62afff..f6ac1b7 100644 --- a/test/mocksUrl/mappings/GET-urlPath.json +++ b/test/mocksUrl/mappings/GET-urlPath.json @@ -10,4 +10,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksUrl/mappings/GET-urlPathPattern.json b/test/mocksUrl/mappings/GET-urlPathPattern.json index cfac2f2..a55399f 100644 --- a/test/mocksUrl/mappings/GET-urlPathPattern.json +++ b/test/mocksUrl/mappings/GET-urlPathPattern.json @@ -10,4 +10,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/mocksUrl/mappings/GET-urlPattern.json b/test/mocksUrl/mappings/GET-urlPattern.json index 1b2398d..bbd4cd5 100644 --- a/test/mocksUrl/mappings/GET-urlPattern.json +++ b/test/mocksUrl/mappings/GET-urlPattern.json @@ -10,4 +10,4 @@ "result": "ok" } } -} \ No newline at end of file +} diff --git a/test/server.js b/test/server.js index adf0737..4d94911 100644 --- a/test/server.js +++ b/test/server.js @@ -1,18 +1,20 @@ -const express = require('express'); -const restMockMiddleware = require('../index'); -const { - resolve -} = require('path'); +import express from 'express'; +import { resolve } from 'path'; -function createServer(options) { +import restMockMiddleware from '../index'; + +const createServer = (options) => { var app = express(); - app.use('/app', restMockMiddleware({ - root_dir: resolve(__dirname, options.root_dir), - logger: options.logger, - loggerDebugFilters: options.loggerDebugFilters, - })); + app.use( + '/app', + restMockMiddleware({ + root_dir: resolve(__dirname, options.root_dir), + logger: options.logger, + loggerDebugFilters: options.loggerDebugFilters, + }), + ); return app; -} +}; -module.exports = createServer; +export default createServer; diff --git a/test/unit-test/lib/logger.spec.js b/test/unit-test/lib/logger.spec.js index 35f8967..d759cf7 100644 --- a/test/unit-test/lib/logger.spec.js +++ b/test/unit-test/lib/logger.spec.js @@ -1,30 +1,25 @@ -const chai = require("chai"); -const expect = chai.expect; -const sinon = require("sinon"); -const { - resolve -} = require('path'); +import { expect } from 'chai'; +import { resolve } from 'path'; +import restMockMiddleware from '../../../lib/rest-mock-middleware'; +import sinon from 'sinon'; +import { transports } from 'winston'; -let rest_mock_middleware = require("../../../lib/rest-mock-middleware"); +const { Console } = transports; -const { - transports: { Console }, -} = require("winston"); +describe('Test logger', () => { + it('Check logs on starting', (done) => { + const consoleLogger = new Console({ handleExceptions: true }); -describe("Test logger", function () { - it("Check logs on starting", function testSlash(done) { - const consoleLogger = new Console({handleExceptions: true}); + const spy = sinon.spy(consoleLogger, 'log'); - const spy = sinon.spy(consoleLogger, "log"); - - rest_mock_middleware({ - root_dir: resolve(__dirname, "../../mocksSchema"), + restMockMiddleware({ + root_dir: resolve(__dirname, '../../mocksSchema'), logger: { - transports: [ consoleLogger ] - } + transports: [consoleLogger], + }, }); - - expect(spy.calledOnce).to.be.ok; + + expect(spy.calledOnce).to.be.ok; // eslint-disable-line no-unused-expressions done(); }); }); diff --git a/test/unit-test/lib/mappings-sort.spec.js b/test/unit-test/lib/mappings-sort.spec.js index 6008415..a4ebbdb 100644 --- a/test/unit-test/lib/mappings-sort.spec.js +++ b/test/unit-test/lib/mappings-sort.spec.js @@ -1,35 +1,36 @@ -let expect = require('chai').expect; -let mapping_sort = require('../../../lib/mappings-sort'); +import { expect } from 'chai'; -describe('Test for the mapping sort', function() { - it('Sort correctly', function(done) { +import mapping_sort from '../../../lib/mappings-sort'; + +describe('Test for the mapping sort', () => { + it('Sort correctly', (done) => { let mappings = [ { - "request": { - "priority": 2, - "method": "POST", - "url": "/app/url" + request: { + priority: 2, + method: 'POST', + url: '/app/url', + }, + response: { + status: 200, + jsonBody: { + result: 'ok', + }, }, - "response": { - "status": 200, - "jsonBody": { - "result": "ok" - } - } }, { - "request": { - "priority": 1, - "method": "POST", - "url": "/app/url" + request: { + priority: 1, + method: 'POST', + url: '/app/url', + }, + response: { + status: 200, + jsonBody: { + result: 'ok', + }, }, - "response": { - "status": 200, - "jsonBody": { - "result": "ok" - } - } - } + }, ]; let mapping_result = Array.from(mapping_sort(mappings).values()); expect(mapping_result[0].request.priority).to.equal(1); @@ -37,50 +38,51 @@ describe('Test for the mapping sort', function() { done(); }); - it('Sort correctly', function(done) { + it('Sort correctly', (done) => { let mappings = [ { - "request": { - "priority": 2, - "method": "POST", - "url": "/app/url" + request: { + priority: 2, + method: 'POST', + url: '/app/url', + }, + response: { + status: 200, + jsonBody: { + result: 'ok', + }, }, - "response": { - "status": 200, - "jsonBody": { - "result": "ok" - } - } }, { - "request": { - "method": "POST", - "url": "/app/url" + request: { + method: 'POST', + url: '/app/url', }, - "response": { - "status": 200, - "jsonBody": { - "result": "ok" - } - } - }, { - "request": { - "priority": 1, - "method": "POST", - "url": "/app/url" + response: { + status: 200, + jsonBody: { + result: 'ok', }, - "response": { - "status": 200, - "jsonBody": { - "result": "ok" - } - } - } + }, + }, + { + request: { + priority: 1, + method: 'POST', + url: '/app/url', + }, + response: { + status: 200, + jsonBody: { + result: 'ok', + }, + }, + }, ]; let mapping_result = Array.from(mapping_sort(mappings).values()); expect(mapping_result[0].request.priority).to.equal(1); expect(mapping_result[1].request.priority).to.equal(2); - expect(mapping_result[2].request.priority).to.be.undefined; + expect(mapping_result[2].request.priority).to.be.undefined; // eslint-disable-line no-unused-expressions done(); }); }); diff --git a/test/unit-test/lib/request-matching/body.spec.js b/test/unit-test/lib/request-matching/body.spec.js index 1634865..4eb204e 100644 --- a/test/unit-test/lib/request-matching/body.spec.js +++ b/test/unit-test/lib/request-matching/body.spec.js @@ -1,135 +1,180 @@ -let chai = require('chai'); -var expect = chai.expect; -let chaiHttp = require('chai-http'); +import chai, { expect } from 'chai'; +import chaiHttp from 'chai-http'; + +import createServer from '../../../server'; chai.use(chaiHttp); -describe('Test for the Body equalToJson request mapping', function() { +describe('Test for the Body equalToJson request mapping', () => { let app = null; - before(function(){ - app = require('../../../server')({ - root_dir: "./mocksJson" + before(function () { + app = createServer({ + root_dir: './mocksJson', }); }); - - it('Check body json equals request mapping', function testSlash(done) { - chai.request(app) + + it('Check body json equals request mapping', (done) => { + chai + .request(app) .post('/app/login') .type('application/json') .send({ - total_results: 4 + total_results: 4, }) - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check body json equals arrayOrder request mapping', function testSlash(done) { - chai.request(app) + it('Check body json equals arrayOrder request mapping', (done) => { + chai + .request(app) .post('/app/login') .type('application/json') - .send([{ - total_results: 4 - },{ - total_results: 5 - }]) - .end(function(err, res) { - done(); + .send([ + { + total_results: 4, + }, + { + total_results: 5, + }, + ]) + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check body json equals request mapping with too mach attributes', function testSlash(done) { - chai.request(app) - .post('/app/login').type('application/json') + it('Check body json equals request mapping with too mach attributes', (done) => { + chai + .request(app) + .post('/app/login') + .type('application/json') .send({ total_results: 4, - error: true + error: true, }) - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(404); + done(); }); }); - it('Check body json equals request mapping with incorrect attribute', function testSlash(done) { - chai.request(app) + it('Check body json equals request mapping with incorrect attribute', (done) => { + chai + .request(app) .post('/app/login') .type('application/json') .send({ - total_results_error: 4 + total_results_error: 4, }) - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(404); + done(); }); }); - it('404 everything else', function testPath(done) { - chai.request(app) + it('404 everything else', (done) => { + chai + .request(app) .get('/foo/bar') - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(404); + done(); }); }); }); -describe('Test for the Body matchesJsonPath request mapping', function() { +describe('Test for the Body matchesJsonPath request mapping', () => { let app = null; - before(function(){ - app = require('../../../server')({ - root_dir: "./mocksJson" + before(function () { + app = createServer({ + root_dir: './mocksJson', }); }); - - it('Check body json match path request mapping', function testSlash(done) { - chai.request(app) + + it('Check body json match path request mapping', (done) => { + chai + .request(app) .post('/app/path') .type('application/json') .send({ - name: 4 + name: 4, }) - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check body json match path request mapping with select a condition to array', function testSlash(done) { - chai.request(app) + it('Check body json match path request mapping with select a condition to array', (done) => { + chai + .request(app) .post('/app/path') .type('application/json') - .send([{ - times: 4 - }]) - .end(function(err, res) { - done(); + .send([ + { + times: 4, + }, + ]) + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check body json match path request mapping with select a condition to nested array', function testSlash(done) { - chai.request(app) + it('Check body json match path request mapping with select a condition to nested array', (done) => { + chai + .request(app) .post('/app/path') .type('application/json') .send({ - book: [{ - times: 4 - }] + book: [ + { + times: 4, + }, + ], }) - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check body json match path mapping with incorrect path', function testSlash(done) { - chai.request(app) + it('Check body json match path mapping with incorrect path', (done) => { + chai + .request(app) .post('/app/path') .type('application/json') .send({ - total_results: 4 + total_results: 4, }) - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(404); + done(); }); }); }); diff --git a/test/unit-test/lib/request-matching/headers.spec.js b/test/unit-test/lib/request-matching/headers.spec.js index 8edccf9..699752a 100644 --- a/test/unit-test/lib/request-matching/headers.spec.js +++ b/test/unit-test/lib/request-matching/headers.spec.js @@ -1,74 +1,99 @@ -let chai = require('chai'); -var expect = chai.expect; -let chaiHttp = require('chai-http'); +import chai, { expect } from 'chai'; +import chaiHttp from 'chai-http'; + +import createServer from '../../../server'; chai.use(chaiHttp); -describe('Test for the Headers request mapping', function() { +describe('Test for the Headers request mapping', () => { let app = null; - before(function(){ - app = require('../../../server')({ - root_dir: "./mocksHeaders" + before(() => { + app = createServer({ + root_dir: './mocksHeaders', }); }); - it('Check the one header request mapping', function testSlash(done) { - chai.request(app) + it('Check the one header request mapping', (done) => { + chai + .request(app) .get('/app/url/one') - .set("Content-type", "application/json") - .end(function(err, res) { - done(); + .set('Content-type', 'application/json') + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check the two headers request mapping', function testSlash(done) { - chai.request(app) + it('Check the two headers request mapping', (done) => { + chai + .request(app) .get('/app/url/two') - .set("Content-type", "application/json") - .set("Accept-Language", "en-US") - .end(function(err, res) { - done(); + .set('Content-type', 'application/json') + .set('Accept-Language', 'en-US') + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check the one header name incorrect request mapping', function testSlash(done) { - chai.request(app) + it('Check the one header name incorrect request mapping', (done) => { + chai + .request(app) .get('/app/url/one') - .set("no-type", "application/json") - .end(function(err, res) { - done(); + .set('no-type', 'application/json') + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(404); + done(); }); }); - it('Check the one header value incorrect request mapping', function testSlash(done) { - chai.request(app) + it('Check the one header value incorrect request mapping', (done) => { + chai + .request(app) .get('/app/url/one') - .set("Content-type", "application") - .end(function(err, res) { - done(); + .set('Content-type', 'application') + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(404); + done(); }); }); - it('Check the two headers with one incorrect request mapping', function testSlash(done) { - chai.request(app) + it('Check the two headers with one incorrect request mapping', (done) => { + chai + .request(app) .get('/app/url/two') - .set("no-type", "application/json") - .set("Accept-Language", "en-US") - .end(function(err, res) { - done(); + .set('no-type', 'application/json') + .set('Accept-Language', 'en-US') + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(404); + done(); }); }); - it('Check the two headers incorrect request mapping', function testSlash(done) { - chai.request(app) + it('Check the two headers incorrect request mapping', (done) => { + chai + .request(app) .get('/app/url/two') - .set("no-type", "application/json") - .set("no-Language", "en-US") - .end(function(err, res) { - done(); + .set('no-type', 'application/json') + .set('no-Language', 'en-US') + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(404); + done(); }); }); }); diff --git a/test/unit-test/lib/request-matching/method.spec.js b/test/unit-test/lib/request-matching/method.spec.js index a5e10ea..7978d67 100644 --- a/test/unit-test/lib/request-matching/method.spec.js +++ b/test/unit-test/lib/request-matching/method.spec.js @@ -1,120 +1,173 @@ -let chai = require('chai'); -var expect = chai.expect; -let chaiHttp = require('chai-http'); +import chai, { expect } from 'chai'; +import chaiHttp from 'chai-http'; + +import createServer from '../../../server'; chai.use(chaiHttp); -describe('Test for the Method request mapping', function() { +describe('Test for the Method request mapping', () => { let app = null; - before(function(){ - app = require('../../../server')({ - root_dir: "./mocksMethod", + before(() => { + app = createServer({ + root_dir: './mocksMethod', }); }); - it('Check the without method', function testSlash(done) { - chai.request(app) + it('Check the without method', (done) => { + chai + .request(app) .post('/app/url/nomethod') - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check ANY method', function testSlash(done) { - chai.request(app) + it('Check ANY method', (done) => { + chai + .request(app) .get('/app/url/any') - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check ANY method lowercase', function testSlash(done) { - chai.request(app) + it('Check ANY method lowercase', (done) => { + chai + .request(app) .get('/app/url/any/lowercase') - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check GET method', function testSlash(done) { - chai.request(app) + it('Check GET method', (done) => { + chai + .request(app) .get('/app/url') - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check GET method lowercase', function testSlash(done) { - chai.request(app) + it('Check GET method lowercase', (done) => { + chai + .request(app) .get('/app/url/lowercase') - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check POST method', function testSlash(done) { - chai.request(app) + it('Check POST method', (done) => { + chai + .request(app) .post('/app/url') - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check POST method lowercase', function testSlash(done) { - chai.request(app) + it('Check POST method lowercase', (done) => { + chai + .request(app) .post('/app/url/lowercase') - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check PUT method', function testSlash(done) { - chai.request(app) + it('Check PUT method', (done) => { + chai + .request(app) .put('/app/url') - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check PUT method lowercase', function testSlash(done) { - chai.request(app) + it('Check PUT method lowercase', (done) => { + chai + .request(app) .put('/app/url/lowercase') - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check DELETE method', function testSlash(done) { - chai.request(app) + it('Check DELETE method', (done) => { + chai + .request(app) .delete('/app/url') - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check DELETE method lowercase', function testSlash(done) { - chai.request(app) + it('Check DELETE method lowercase', (done) => { + chai + .request(app) .delete('/app/url/lowercase') - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check OPTIONS method', function testSlash(done) { - chai.request(app) + it('Check OPTIONS method', (done) => { + chai + .request(app) .options('/app/url') - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check OPTIONS method lowercase', function testSlash(done) { - chai.request(app) + it('Check OPTIONS method lowercase', (done) => { + chai + .request(app) .options('/app/url/lowercase') - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); }); diff --git a/test/unit-test/lib/request-matching/query-parameters.spec.js b/test/unit-test/lib/request-matching/query-parameters.spec.js index be2a91f..b57e9e5 100644 --- a/test/unit-test/lib/request-matching/query-parameters.spec.js +++ b/test/unit-test/lib/request-matching/query-parameters.spec.js @@ -1,100 +1,129 @@ -let chai = require('chai'); -var expect = chai.expect; -let chaiHttp = require('chai-http'); +import chai, { expect } from 'chai'; +import chaiHttp from 'chai-http'; + +import createServer from '../../../server'; chai.use(chaiHttp); -describe('Test for the Query Parameters request mapping', function() { +describe('Test for the Query Parameters request mapping', () => { let app = null; - before(function(){ - app = require('../../../server')({ - root_dir: "./mocksQuery" + before(() => { + app = createServer({ + root_dir: './mocksQuery', }); }); - - it('Check the no query parametes request mapping', function testSlash(done) { - chai.request(app) + + it('Check the no query parametes request mapping', (done) => { + chai + .request(app) .get('/app/url/one') - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(404); + done(); }); }); - it('Check the one query parametes request mapping', function testSlash(done) { - chai.request(app) + it('Check the one query parametes request mapping', (done) => { + chai + .request(app) .get('/app/url/one') .query({ - search: 'hello' + search: 'hello', }) - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check the two query parametes request mapping', function testSlash(done) { - chai.request(app) + it('Check the two query parametes request mapping', (done) => { + chai + .request(app) .get('/app/url/two') .query({ - search: 'hello' + search: 'hello', }) .query({ - name: 'Peter' + name: 'Peter', }) - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it('Check the one query parameter name incorrect request mapping', function testSlash(done) { - chai.request(app) + it('Check the one query parameter name incorrect request mapping', (done) => { + chai + .request(app) .get('/app/url/one') .query({ - no: 'hello' + no: 'hello', }) - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(404); + done(); }); }); - it('Check the one query parameter value incorrect request mapping', function testSlash(done) { - chai.request(app) + it('Check the one query parameter value incorrect request mapping', (done) => { + chai + .request(app) .get('/app/url/one') .query({ - search: 'json' + search: 'json', }) - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(404); + done(); }); }); - it('Check the two query parameter with one incorrect request mapping', function testSlash(done) { - chai.request(app) + it('Check the two query parameter with one incorrect request mapping', (done) => { + chai + .request(app) .get('/app/url/two') .query({ - search: 'hello' + search: 'hello', }) .query({ - dest: '/login' + dest: '/login', }) - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(404); + done(); }); }); - it('Check the two query parameter incorrect request mapping', function testSlash(done) { - chai.request(app) + it('Check the two query parameter incorrect request mapping', (done) => { + chai + .request(app) .get('/app/url/two') .query({ - format: 'json' + format: 'json', }) .query({ - dest: '/login' + dest: '/login', }) - .end(function(err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(404); + done(); }); }); }); diff --git a/test/unit-test/lib/request-matching/schems.spec.js b/test/unit-test/lib/request-matching/schems.spec.js index 9d4dc70..3ccc713 100644 --- a/test/unit-test/lib/request-matching/schems.spec.js +++ b/test/unit-test/lib/request-matching/schems.spec.js @@ -1,134 +1,153 @@ -let chai = require("chai"); -var expect = chai.expect; -let chaiHttp = require("chai-http"); +import chai, { expect } from 'chai'; +import chaiHttp from 'chai-http'; + +import createServer from '../../../server'; chai.use(chaiHttp); -describe("Test for the Schema matching request mapping", function () { +describe('Test for the Schema matching request mapping', () => { let app = null; - before(function(){ - app = require('../../../server')({ - root_dir: "./mocksSchema" + before(() => { + app = createServer({ + root_dir: './mocksSchema', }); }); - it("Check body json match request schema", function testSlash(done) { + it('Check body json match request schema', (done) => { chai .request(app) - .post("/app/results") - .type("application/json") + .post('/app/results') + .type('application/json') .send({ total_results: 4, }) - .end(function (err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it("Check body json not match request schema because too mach attributes", function testSlash(done) { + it('Check body json not match request schema because too mach attributes', (done) => { chai .request(app) - .post("/app/results") - .type("application/json") + .post('/app/results') + .type('application/json') .send({ total_results: 4, error: true, }) - .end(function (err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(404); + done(); }); }); - it("Check body json match request schema file", function testSlash(done) { + it('Check body json match request schema file', (done) => { chai .request(app) - .post("/app/login") - .type("application/json") + .post('/app/login') + .type('application/json') .send({ user: { - first_name: "Peter", - last_name: "Smith", - password: "12345", - email: "peter.smith@ps.com", + first_name: 'Peter', + last_name: 'Smith', + password: '12345', + email: 'peter.smith@ps.com', address: { - street: "Morningside Road", - number: 24 - } + street: 'Morningside Road', + number: 24, + }, }, }) - .end(function (err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it("Check body json not match request schema file because too mach attributes", function testSlash(done) { + it('Check body json not match request schema file because too mach attributes', (done) => { chai .request(app) - .post("/app/login") - .type("application/json") + .post('/app/login') + .type('application/json') .send({ user: { - first_name: "Peter", - last_name: "Smith", - password: "12345", - email: "peter.smith@ps.com", + first_name: 'Peter', + last_name: 'Smith', + password: '12345', + email: 'peter.smith@ps.com', address: { - street: "Morningside Road", - number: 24 - } + street: 'Morningside Road', + number: 24, + }, }, error: true, }) - .end(function (err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(404); + done(); }); }); - it("Check body json match request schema that refs a file", function testSlash(done) { + it('Check body json match request schema that refs a file', (done) => { chai .request(app) - .post("/app/user-results") - .type("application/json") + .post('/app/user-results') + .type('application/json') .send({ user: { - first_name: "Peter", - last_name: "Smith", - password: "12345", - email: "peter.smith@ps.com", + first_name: 'Peter', + last_name: 'Smith', + password: '12345', + email: 'peter.smith@ps.com', address: { - street: "Morningside Road", - number: 24 - } + street: 'Morningside Road', + number: 24, + }, }, total_results: 4, }) - .end(function (err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); + done(); }); }); - it("Check body json equals request schema with too mach attributes", function testSlash(done) { + it('Check body json equals request schema with too mach attributes', (done) => { chai .request(app) - .post("/app/user-results") - .type("application/json") + .post('/app/user-results') + .type('application/json') .send({ user: { - first_name: "Peter", - second_name: "Smith", - password: "12345", - email: "peter.smith@ps.com", + first_name: 'Peter', + second_name: 'Smith', + password: '12345', + email: 'peter.smith@ps.com', address: { - street: "Morningside Road", - number: 24 - } + street: 'Morningside Road', + number: 24, + }, }, error: true, }) - .end(function (err, res) { - done(); + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(404); + done(); }); }); }); diff --git a/test/unit-test/lib/request-matching/url.spec.js b/test/unit-test/lib/request-matching/url.spec.js index d2c63a2..22afec7 100644 --- a/test/unit-test/lib/request-matching/url.spec.js +++ b/test/unit-test/lib/request-matching/url.spec.js @@ -1,59 +1,64 @@ -let chai = require("chai"); -var expect = chai.expect; -let chaiHttp = require("chai-http"); -const sinon = require("sinon"); -const { - transports: { Console }, -} = require("winston"); +import chai, { expect } from 'chai'; +import chaiHttp from 'chai-http'; + +import createServer from '../../../server'; chai.use(chaiHttp); -describe("Test for the URL request mapping", function () { +describe('Test for the URL request mapping', () => { let app = null; - before(function () { - app = require("../../../server")({ - root_dir: "./mocksUrl", + before(() => { + app = createServer({ + root_dir: './mocksUrl', }); }); - after(function(){ - delete app; - }); - - it('Check the "url" request mapping', function testSlash(done) { + it('Check the "url" request mapping', (done) => { chai .request(app) - .post("/app/url") - .end(function (err, res) { + .post('/app/url') + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); done(); }); }); - it('Check the "urlPattern" request mapping', function testSlash(done) { + it('Check the "urlPattern" request mapping', (done) => { chai .request(app) - .post("/app/urlPattern") - .end(function (err, res) { + .post('/app/urlPattern') + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); done(); }); }); - it('Check the "urlPath" request mapping', function testSlash(done) { + it('Check the "urlPath" request mapping', (done) => { chai .request(app) - .post("/app/path") - .end(function (err, res) { + .post('/app/path') + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); done(); }); }); - it('Check the "urlPathPattern" request mapping', function testSlash(done) { + it('Check the "urlPathPattern" request mapping', (done) => { chai .request(app) - .post("/app/pathPattern") - .end(function (err, res) { + .post('/app/pathPattern') + .end((err, res) => { + if (err) { + done(err); + } expect(res).to.have.status(200); done(); }); diff --git a/test/unit-test/lib/rest-mock-middleware.spec.js b/test/unit-test/lib/rest-mock-middleware.spec.js index 82a67ae..9834078 100644 --- a/test/unit-test/lib/rest-mock-middleware.spec.js +++ b/test/unit-test/lib/rest-mock-middleware.spec.js @@ -1,25 +1,25 @@ -let expect = require("chai").expect; -let sinon = require("sinon"); -let rest_mock_middleware = require("../../../lib/rest-mock-middleware"); +import { expect } from 'chai'; +import restMockMiddleware from '../../../lib/rest-mock-middleware'; +import sinon from 'sinon'; -describe("Test for the rest-mock-middleware sort", function () { - it("No config", function (done) { - let directories = rest_mock_middleware(); +describe('Test for the rest-mock-middleware sort', () => { + it('No config', (done) => { + let directories = restMockMiddleware(); var next = sinon.stub(); directories(null, null, next); - expect(next.calledOnce).to.be.ok; + expect(next.calledOnce).to.be.ok; // eslint-disable-line no-unused-expressions done(); }); - it("Disabled", function (done) { - let directories = rest_mock_middleware({ disabled: true }); + it('Disabled', (done) => { + let directories = restMockMiddleware({ disabled: true }); var next = sinon.stub(); directories(null, null, next); - expect(next.calledOnce).to.be.ok; + expect(next.calledOnce).to.be.ok; // eslint-disable-line no-unused-expressions done(); }); - it("wrong configuration", function (done) { - expect(rest_mock_middleware.bind({}, { disabled: false })).to.throw( - "[Mock] Mock middleware directory is not configured." + it('wrong configuration', (done) => { + expect(restMockMiddleware.bind({}, { disabled: false })).to.throw( + '[Mock] Mock middleware directory is not configured.', ); done(); }); diff --git a/test/unit-test/lib/walk-sync.spec.js b/test/unit-test/lib/walk-sync.spec.js index f3e0aca..a0edc6a 100644 --- a/test/unit-test/lib/walk-sync.spec.js +++ b/test/unit-test/lib/walk-sync.spec.js @@ -1,16 +1,17 @@ -const path = require("path"); -let expect = require('chai').expect; -let walk_sync = require('../../../lib/walk-sync-json'); +import { expect } from 'chai'; +import path from 'path'; -describe('Test for the walk sync json sort', function() { - it('Read json file,, read old file, and read directory', function(done) { +import walk_sync from '../../../lib/walk-sync-json'; +describe('Test for the walk sync json sort', () => { + it('Read json file,, read old file, and read directory', (done) => { let directories = walk_sync('test/mocksWalkSync/'); - let expectedResult = [ - `test${path.sep}mocksWalkSync${path.sep}folder${path.sep}jsonResponse.json`, - `test${path.sep}mocksWalkSync${path.sep}jsonResponse.json`]; - expect(directories[0]).to.equal(expectedResult[0]); - expect(directories[1]).to.equal(expectedResult[1]); + let expectedResult = [ + `test${path.sep}mocksWalkSync${path.sep}folder${path.sep}jsonResponse.json`, + `test${path.sep}mocksWalkSync${path.sep}jsonResponse.json`, + ]; + expect(directories[0]).to.equal(expectedResult[0]); + expect(directories[1]).to.equal(expectedResult[1]); done(); }); });