Merge pull request #1241 from Budibase/feature/test-coverage

Feature/test coverage
This commit is contained in:
Michael Drury 2021-03-03 11:32:07 +00:00 committed by GitHub
commit 2beba28700
9 changed files with 1283 additions and 330 deletions

View File

@ -35,6 +35,12 @@ jobs:
env: env:
CI: true CI: true
name: Budibase CI name: Budibase CI
- uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
files: ./packages/server/coverage/clover.xml
name: codecov-umbrella
verbose: true
- run: yarn test:e2e:ci - run: yarn test:e2e:ci
- name: Build and Push Staging Docker Image - name: Build and Push Staging Docker Image

View File

@ -37,6 +37,9 @@
<img src="https://img.shields.io/twitter/follow/budibase?style=social" alt="Follow @budibase" /> <img src="https://img.shields.io/twitter/follow/budibase?style=social" alt="Follow @budibase" />
</a> </a>
<img src="https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg" alt="Code of conduct" /> <img src="https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg" alt="Code of conduct" />
<a href="https://codecov.io/gh/Budibase/budibase">
<img src="https://codecov.io/gh/Budibase/budibase/branch/master/graph/badge.svg?token=E8W2ZFXQOH"/>
</a>
</p> </p>
<h3 align="center"> <h3 align="center">

View File

@ -8,3 +8,4 @@ myapps/
public/ public/
db/dev.db/ db/dev.db/
dist dist
coverage/

View File

@ -33,7 +33,7 @@
}, },
"scripts": { "scripts": {
"test": "jest --testPathIgnorePatterns=routes && npm run test:integration", "test": "jest --testPathIgnorePatterns=routes && npm run test:integration",
"test:integration": "jest routes --runInBand", "test:integration": "jest routes --runInBand --coverage",
"test:watch": "jest --watch", "test:watch": "jest --watch",
"run:docker": "node src/index", "run:docker": "node src/index",
"dev:builder": "cross-env PORT=4001 nodemon src/index.js", "dev:builder": "cross-env PORT=4001 nodemon src/index.js",
@ -44,6 +44,22 @@
"lint": "eslint --fix src/", "lint": "eslint --fix src/",
"initialise": "node scripts/initialise.js" "initialise": "node scripts/initialise.js"
}, },
"jest": {
"testEnvironment": "node",
"setupFiles": [
"./scripts/jestSetup.js"
],
"collectCoverageFrom": [
"src/**/*.js",
"!**/node_modules/**",
"!src/db/views/*.js"
],
"coverageReporters": [
"lcov",
"json",
"clover"
]
},
"keywords": [ "keywords": [
"budibase" "budibase"
], ],
@ -116,11 +132,5 @@
"pouchdb-adapter-memory": "^7.2.1", "pouchdb-adapter-memory": "^7.2.1",
"supertest": "^4.0.2" "supertest": "^4.0.2"
}, },
"jest": {
"testEnvironment": "node",
"setupFiles": [
"./scripts/jestSetup.js"
]
},
"gitHead": "1a80b09fd093f2599a68f7db72ad639dd50922dd" "gitHead": "1a80b09fd093f2599a68f7db72ad639dd50922dd"
} }

View File

@ -2,6 +2,7 @@ const CouchDB = require("../index")
const Sentry = require("@sentry/node") const Sentry = require("@sentry/node")
const { ViewNames, getQueryIndex } = require("../utils") const { ViewNames, getQueryIndex } = require("../utils")
const { FieldTypes } = require("../../constants") const { FieldTypes } = require("../../constants")
const { createLinkView } = require("../views/staticViews")
/** /**
* Only needed so that boolean parameters are being used for includeDocs * Only needed so that boolean parameters are being used for includeDocs
@ -12,44 +13,7 @@ exports.IncludeDocs = {
EXCLUDE: false, EXCLUDE: false,
} }
/** exports.createLinkView = createLinkView
* 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)
}
/** /**
* Gets the linking documents, not the linked documents themselves. * Gets the linking documents, not the linked documents themselves.

View File

@ -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)
}

View File

@ -1,5 +1,5 @@
const CouchDB = require("../../db") const CouchDB = require("../../db")
const { createRoutingView } = require("./routingUtils") const { createRoutingView } = require("../../db/views/staticViews")
const { ViewNames, getQueryIndex, UNICODE_MAX } = require("../../db/utils") const { ViewNames, getQueryIndex, UNICODE_MAX } = require("../../db/utils")
exports.getRoutingInfo = async appId => { exports.getRoutingInfo = async appId => {

View File

@ -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