Updating package.json to include an option for coverage, had to re-write some stuff to make sure that views were not getting coverage statements inserted (breaking things).
This commit is contained in:
parent
d93cfa73fd
commit
68bb5d5062
|
@ -34,6 +34,7 @@
|
|||
"scripts": {
|
||||
"test": "jest --testPathIgnorePatterns=routes && npm run test:integration",
|
||||
"test:integration": "jest routes --runInBand",
|
||||
"test:coverage": "jest routes --runInBand --coverage",
|
||||
"test:watch": "jest --watch",
|
||||
"run:docker": "node src/index",
|
||||
"dev:builder": "cross-env PORT=4001 nodemon src/index.js",
|
||||
|
@ -44,6 +45,17 @@
|
|||
"lint": "eslint --fix src/",
|
||||
"initialise": "node scripts/initialise.js"
|
||||
},
|
||||
"jest": {
|
||||
"testEnvironment": "node",
|
||||
"setupFiles": [
|
||||
"./scripts/jestSetup.js"
|
||||
],
|
||||
"collectCoverageFrom": [
|
||||
"src/**/*.js",
|
||||
"!**/node_modules/**",
|
||||
"!src/db/views/*.js"
|
||||
]
|
||||
},
|
||||
"keywords": [
|
||||
"budibase"
|
||||
],
|
||||
|
@ -116,11 +128,5 @@
|
|||
"pouchdb-adapter-memory": "^7.2.1",
|
||||
"supertest": "^4.0.2"
|
||||
},
|
||||
"jest": {
|
||||
"testEnvironment": "node",
|
||||
"setupFiles": [
|
||||
"./scripts/jestSetup.js"
|
||||
]
|
||||
},
|
||||
"gitHead": "1a80b09fd093f2599a68f7db72ad639dd50922dd"
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ const CouchDB = require("../index")
|
|||
const Sentry = require("@sentry/node")
|
||||
const { ViewNames, getQueryIndex } = require("../utils")
|
||||
const { FieldTypes } = require("../../constants")
|
||||
const { createLinkView } = require("../views/staticViews")
|
||||
|
||||
/**
|
||||
* Only needed so that boolean parameters are being used for includeDocs
|
||||
|
@ -12,44 +13,7 @@ exports.IncludeDocs = {
|
|||
EXCLUDE: false,
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the link view for the instance, this will overwrite the existing one, but this should only
|
||||
* be called if it is found that the view does not exist.
|
||||
* @param {string} appId The instance to which the view should be added.
|
||||
* @returns {Promise<void>} The view now exists, please note that the next view of this query will actually build it,
|
||||
* so it may be slow.
|
||||
*/
|
||||
exports.createLinkView = async appId => {
|
||||
const db = new CouchDB(appId)
|
||||
const designDoc = await db.get("_design/database")
|
||||
const view = {
|
||||
map: function(doc) {
|
||||
// everything in this must remain constant as its going to Pouch, no external variables
|
||||
if (doc.type === "link") {
|
||||
let doc1 = doc.doc1
|
||||
let doc2 = doc.doc2
|
||||
emit([doc1.tableId, doc1.rowId], {
|
||||
id: doc2.rowId,
|
||||
thisId: doc1.rowId,
|
||||
fieldName: doc1.fieldName,
|
||||
})
|
||||
// if linking to same table can't emit twice
|
||||
if (doc1.tableId !== doc2.tableId) {
|
||||
emit([doc2.tableId, doc2.rowId], {
|
||||
id: doc1.rowId,
|
||||
thisId: doc2.rowId,
|
||||
fieldName: doc2.fieldName,
|
||||
})
|
||||
}
|
||||
}
|
||||
}.toString(),
|
||||
}
|
||||
designDoc.views = {
|
||||
...designDoc.views,
|
||||
[ViewNames.LINK]: view,
|
||||
}
|
||||
await db.put(designDoc)
|
||||
}
|
||||
exports.createLinkView = createLinkView
|
||||
|
||||
/**
|
||||
* Gets the linking documents, not the linked documents themselves.
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
const CouchDB = require("../index")
|
||||
const { DocumentTypes, SEPARATOR, ViewNames } = require("../utils")
|
||||
const SCREEN_PREFIX = DocumentTypes.SCREEN + SEPARATOR
|
||||
|
||||
/**************************************************
|
||||
* INFORMATION *
|
||||
* This file exists purely to keep views separate *
|
||||
* from the rest of the codebase, the reason *
|
||||
* being that they affect coverage and any *
|
||||
* functions written in this file cannot import *
|
||||
* or make use of any constants/variables that *
|
||||
* aren't defined as part of the map function *
|
||||
* itself. *
|
||||
**************************************************/
|
||||
|
||||
/**
|
||||
* Creates the link view for the instance, this will overwrite the existing one, but this should only
|
||||
* be called if it is found that the view does not exist.
|
||||
* @param {string} appId The instance to which the view should be added.
|
||||
* @returns {Promise<void>} The view now exists, please note that the next view of this query will actually build it,
|
||||
* so it may be slow.
|
||||
*/
|
||||
exports.createLinkView = async appId => {
|
||||
const db = new CouchDB(appId)
|
||||
const designDoc = await db.get("_design/database")
|
||||
const view = {
|
||||
map: function(doc) {
|
||||
// everything in this must remain constant as its going to Pouch, no external variables
|
||||
if (doc.type === "link") {
|
||||
let doc1 = doc.doc1
|
||||
let doc2 = doc.doc2
|
||||
emit([doc1.tableId, doc1.rowId], {
|
||||
id: doc2.rowId,
|
||||
thisId: doc1.rowId,
|
||||
fieldName: doc1.fieldName,
|
||||
})
|
||||
// if linking to same table can't emit twice
|
||||
if (doc1.tableId !== doc2.tableId) {
|
||||
emit([doc2.tableId, doc2.rowId], {
|
||||
id: doc1.rowId,
|
||||
thisId: doc2.rowId,
|
||||
fieldName: doc2.fieldName,
|
||||
})
|
||||
}
|
||||
}
|
||||
}.toString(),
|
||||
}
|
||||
designDoc.views = {
|
||||
...designDoc.views,
|
||||
[ViewNames.LINK]: view,
|
||||
}
|
||||
await db.put(designDoc)
|
||||
}
|
||||
|
||||
exports.createRoutingView = async appId => {
|
||||
const db = new CouchDB(appId)
|
||||
const designDoc = await db.get("_design/database")
|
||||
const view = {
|
||||
// if using variables in a map function need to inject them before use
|
||||
map: `function(doc) {
|
||||
if (doc._id.startsWith("${SCREEN_PREFIX}")) {
|
||||
emit(doc._id, {
|
||||
id: doc._id,
|
||||
routing: doc.routing,
|
||||
})
|
||||
}
|
||||
}`,
|
||||
}
|
||||
designDoc.views = {
|
||||
...designDoc.views,
|
||||
[ViewNames.ROUTING]: view,
|
||||
}
|
||||
await db.put(designDoc)
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
const CouchDB = require("../../db")
|
||||
const { createRoutingView } = require("./routingUtils")
|
||||
const { createRoutingView } = require("../../db/views/staticViews")
|
||||
const { ViewNames, getQueryIndex, UNICODE_MAX } = require("../../db/utils")
|
||||
|
||||
exports.getRoutingInfo = async appId => {
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
const CouchDB = require("../../db")
|
||||
const { DocumentTypes, SEPARATOR, ViewNames } = require("../../db/utils")
|
||||
const SCREEN_PREFIX = DocumentTypes.SCREEN + SEPARATOR
|
||||
|
||||
exports.createRoutingView = async appId => {
|
||||
const db = new CouchDB(appId)
|
||||
const designDoc = await db.get("_design/database")
|
||||
const view = {
|
||||
// if using variables in a map function need to inject them before use
|
||||
map: `function(doc) {
|
||||
if (doc._id.startsWith("${SCREEN_PREFIX}")) {
|
||||
emit(doc._id, {
|
||||
id: doc._id,
|
||||
routing: doc.routing,
|
||||
})
|
||||
}
|
||||
}`,
|
||||
}
|
||||
designDoc.views = {
|
||||
...designDoc.views,
|
||||
[ViewNames.ROUTING]: view,
|
||||
}
|
||||
await db.put(designDoc)
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue