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QAAU,OACnC,EAAQ,GAAK,EAAQ,IAAM,GAC3B,EAAQ,QAAU,EAAQ,SAAW,CAAC,EACtC,EAAQ,QAAQ,UAAY,YAC5B,EAAQ,UAAY,EAAQ,YAAa,EACzC,EAAQ,YAA4B,IAAnB,EAAQ,QAA8B,EAAQ,OAC/D,EAAQ,WAAa,EAAQ,YAAc,WAC1C,OAAO,CACR,EACA,EAAQ,gBAAkB,EAAQ,iBAAmB,CAAC,MAAO,OAE7D,EAAQ,SAAS,EAAQ,MAAM,WAC9B,EAAQ,QAAO,SAAU,GAExB,YAAY,QAAQ,EAAQ,UAAU,SAAU,EAAK,GACpD,GAAI,EACH,OAAO,EAAK,GAEb,EAAQ,GAAK,EACb,GACD,GACD,IAGA,KAAK,EAAQ,UAAW,GAAQ,SAAU,GACzC,GAAwB,QAApB,EAAK,QAAQ,IAAgB,EAAQ,WAAW,GAAO,CAC1D,IAAI,EAAO,UAAU,GACjB,EAAQ,QACX,EAAQ,OAAO,GAEhB,EAAK,QAAQ,EACd,CACD,GACD,GACD","file":"/npm/api-test@4.1.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/api-test@4.1.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/*globals describe, before, it*/\r\n'use strict'\r\n\r\nvar parseFile = require('./parseFile'),\r\n\tfs = require('fs'),\r\n\tpath = require('path'),\r\n\tMongoClient = require('mongodb').MongoClient,\r\n\tbaseContext = require('./baseContext'),\r\n\tparseUrl = require('url').parse,\r\n\tcrypto = require('crypto')\r\n\r\n/**\r\n * Execute the tests described by *.md files in a given folder\r\n * @param {string} file The folder path\r\n * @param {Object} options an object with optional keys:\r\n * @param {string} options.mongoUri\r\n * @param {string} options.baseUrl\r\n * @param {string} [options.name='api']\r\n * @param {boolean} [options.recursive=false]\r\n * @param {boolean} [options.strict=true]\r\n * @param {Object} [options.context]\r\n * @param {string[]} [options.ignoredFindKeys=['_id', '__v']]\r\n * @param {Buffer} [options.ca]\r\n * @param {function(string):boolean} [options.filterFile]\r\n * @param {function(Test)} [options.onTest]\r\n * @param {function(Test,Insertion|Clear|Declaration)} [options.onSetup]\r\n * @param {function(Test,Case)} [options.onCase]\r\n * @param {function(Case,*)} [options.onPost]\r\n * @param {function(Case,*)} [options.onOut]\r\n * @param {function(Case,Find)} [options.onFind]\r\n * @param {Function} [options.describe]\r\n * @param {Function} [options.before]\r\n * @param {Function} [options.it]\r\n * @param {Object<String, Object>} [options.defaultDocuments]\r\n */\r\nmodule.exports = function (folder, options) {\r\n\toptions.mongoUri = validateMongoUri(options.mongoUri)\r\n\r\n\t// Save defaultDocuments to baseContext to make it available for the script\r\n\tbaseContext.defaultDocuments = options.defaultDocuments || Object.create(null)\r\n\r\n\t// Prepare options\r\n\toptions.name = options.name || 'api'\r\n\toptions.describe = options.describe || describe\r\n\toptions.before = options.before || before\r\n\toptions.it = options.it || it\r\n\toptions.context = options.context || {}\r\n\toptions.context.__proto__ = baseContext\r\n\toptions.recursive = options.recursive || false\r\n\toptions.strict = options.strict === undefined ? true : options.strict\r\n\toptions.filterFile = options.filterFile || function () {\r\n\t\treturn true\r\n\t}\r\n\toptions.ignoredFindKeys = options.ignoredFindKeys || ['_id', '__v']\r\n\r\n\toptions.describe(options.name, function () {\r\n\t\toptions.before(function (done) {\r\n\t\t\t// Connect to mongo\r\n\t\t\tMongoClient.connect(options.mongoUri, function (err, db) {\r\n\t\t\t\tif (err) {\r\n\t\t\t\t\treturn done(err)\r\n\t\t\t\t}\r\n\t\t\t\toptions.db = db\r\n\t\t\t\tdone()\r\n\t\t\t})\r\n\t\t})\r\n\r\n\t\t// Load files\r\n\t\twalk(options.recursive, folder, function (file) {\r\n\t\t\tif (file.substr(-3) === '.md' && options.filterFile(file)) {\r\n\t\t\t\tvar test = parseFile(file)\r\n\t\t\t\tif (options.onTest) {\r\n\t\t\t\t\toptions.onTest(test)\r\n\t\t\t\t}\r\n\t\t\t\ttest.execute(options)\r\n\t\t\t}\r\n\t\t})\r\n\t})\r\n}\r\n\r\n/**\r\n * Make sure the mongo uri has 'localhost' as hostname and 'test' in the DB name\r\n * @param {string} mongoUri\r\n */\r\nfunction validateMongoUri(mongoUri) {\r\n\tvar tag, rightTag, sha\r\n\tif (mongoUri.match(/^![a-z0-9]{10}!/)) {\r\n\t\t// Extract tag\r\n\t\ttag = mongoUri.substr(1, 10)\r\n\t\tmongoUri = mongoUri.substr(12)\r\n\t}\r\n\r\n\tif (mongoUri.indexOf('test') === -1 || parseUrl(mongoUri).hostname !== 'localhost') {\r\n\t\t// Propably an error, we force the mongoUri to be localhost and the DB/username to be test\r\n\t\tsha = crypto.createHash('sha1')\r\n\t\tsha.end(new Buffer(mongoUri))\r\n\t\trightTag = sha.read().toString('hex').substr(0, 10)\r\n\t}\r\n\r\n\t// Compare tags\r\n\tif (tag !== rightTag) {\r\n\t\tconsole.log('++++++++++')\r\n\t\tif (rightTag) {\r\n\t\t\tconsole.log('The mongoUri \"' + mongoUri.substr(0, 17) + '...\" seems not to be test-safe')\r\n\t\t\tconsole.log('I recommend you to connect to a localhost instance and a database with \"test\" in the name')\r\n\t\t\tconsole.log('Remember that the database is DROPPED before every test!')\r\n\t\t\tconsole.log('If you are really sure, please prepend \"!' + rightTag + '!\" to your mongoUri')\r\n\t\t\tconsole.log('Like this: \"!' + rightTag + '!' + mongoUri.substr(0, 17) + '...\"')\r\n\t\t} else {\r\n\t\t\tconsole.log('Please remove the !tag! from the mongoUri to run the test')\r\n\t\t}\r\n\t\tconsole.log('++++++++++')\r\n\t\tthrow new Error('Invalid protection tag')\r\n\t}\r\n\treturn mongoUri\r\n}\r\n\r\n/**\r\n * Call a function for each file in a given directory\r\n * @param {boolean} recursive\r\n * @param {string} dir\r\n * @param {Function} fn\r\n */\r\nfunction walk(recursive, dir, fn) {\r\n\tfs.readdirSync(dir).forEach(function (item) {\r\n\t\titem = path.join(dir, item)\r\n\t\tif (fs.statSync(item).isDirectory()) {\r\n\t\t\tif (recursive) {\r\n\t\t\t\twalk(recursive, item, fn)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tfn(item)\r\n\t\t}\r\n\t})\r\n}"]}