Some cleanup fixes for tests that makes sure temp directory isn't getting out of control.
This commit is contained in:
parent
7c2ef4d43f
commit
1cf0027c6e
|
@ -1,16 +1,6 @@
|
||||||
const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
||||||
const setup = require("./utilities")
|
const setup = require("./utilities")
|
||||||
|
|
||||||
jest.mock("../../../utilities/fileSystem/utilities", () => ({
|
|
||||||
...jest.requireActual("../../../utilities/fileSystem/utilities"),
|
|
||||||
retrieve: () => {
|
|
||||||
const { join } = require("path")
|
|
||||||
const library = join("@budibase", "standard-components")
|
|
||||||
const path = require.resolve(library).split(join("dist", "index.js"))[0] + "manifest.json"
|
|
||||||
return JSON.stringify(require(path))
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
|
|
||||||
describe("/component", () => {
|
describe("/component", () => {
|
||||||
let request = setup.getRequest()
|
let request = setup.getRequest()
|
||||||
let config = setup.getConfig()
|
let config = setup.getConfig()
|
||||||
|
|
|
@ -14,6 +14,7 @@ const {
|
||||||
} = require("./structures")
|
} = require("./structures")
|
||||||
const controllers = require("./controllers")
|
const controllers = require("./controllers")
|
||||||
const supertest = require("supertest")
|
const supertest = require("supertest")
|
||||||
|
const { cleanup } = require("../../utilities/fileSystem")
|
||||||
|
|
||||||
const EMAIL = "babs@babs.com"
|
const EMAIL = "babs@babs.com"
|
||||||
const PASSWORD = "babs_password"
|
const PASSWORD = "babs_password"
|
||||||
|
@ -63,6 +64,7 @@ class TestConfiguration {
|
||||||
if (this.server) {
|
if (this.server) {
|
||||||
this.server.close()
|
this.server.close()
|
||||||
}
|
}
|
||||||
|
cleanup(this.allApps.map(app => app._id))
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultHeaders() {
|
defaultHeaders() {
|
||||||
|
|
|
@ -157,11 +157,19 @@ exports.downloadTemplate = async (type, name) => {
|
||||||
* Retrieves component libraries from object store (or tmp symlink if in local)
|
* Retrieves component libraries from object store (or tmp symlink if in local)
|
||||||
*/
|
*/
|
||||||
exports.getComponentLibraryManifest = async (appId, library) => {
|
exports.getComponentLibraryManifest = async (appId, library) => {
|
||||||
const devPath = join(budibaseTempDir(), library, "manifest.json")
|
const filename = "manifest.json"
|
||||||
|
/* istanbul ignore next */
|
||||||
|
// when testing in cypress and so on we need to get the package
|
||||||
|
// as the environment may not be fully fleshed out for dev or prod
|
||||||
|
if (env.isTest()) {
|
||||||
|
const paths = await downloadLibraries(appId)
|
||||||
|
return require(join(paths[library], "package", filename))
|
||||||
|
}
|
||||||
|
const devPath = join(budibaseTempDir(), library, filename)
|
||||||
if (env.isDev() && fs.existsSync(devPath)) {
|
if (env.isDev() && fs.existsSync(devPath)) {
|
||||||
return require(devPath)
|
return require(devPath)
|
||||||
}
|
}
|
||||||
const path = join(appId, "node_modules", library, "package", "manifest.json")
|
const path = join(appId, "node_modules", library, "package", filename)
|
||||||
let resp = await retrieve(ObjectStoreBuckets.APPS, path)
|
let resp = await retrieve(ObjectStoreBuckets.APPS, path)
|
||||||
if (typeof resp !== "string") {
|
if (typeof resp !== "string") {
|
||||||
resp = resp.toString("utf8")
|
resp = resp.toString("utf8")
|
||||||
|
@ -201,6 +209,15 @@ exports.readFileSync = (filepath, options = "utf8") => {
|
||||||
return fs.readFileSync(filepath, options)
|
return fs.readFileSync(filepath, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a set of app IDs makes sure file system is cleared of any of their temp info.
|
||||||
|
*/
|
||||||
|
exports.cleanup = appIds => {
|
||||||
|
for (let appId of appIds) {
|
||||||
|
fs.rmdirSync(join(budibaseTempDir(), appId), { recursive: true })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Full function definition for below can be found in the utilities.
|
* Full function definition for below can be found in the utilities.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -11,13 +11,19 @@ const BUCKET_NAME = ObjectStoreBuckets.APPS
|
||||||
exports.downloadLibraries = async appId => {
|
exports.downloadLibraries = async appId => {
|
||||||
const LIBRARIES = ["standard-components"]
|
const LIBRARIES = ["standard-components"]
|
||||||
|
|
||||||
|
const paths = {}
|
||||||
// Need to download tarballs directly from NPM as our users may not have node on their machine
|
// Need to download tarballs directly from NPM as our users may not have node on their machine
|
||||||
for (let lib of LIBRARIES) {
|
for (let lib of LIBRARIES) {
|
||||||
// download tarball
|
// download tarball
|
||||||
const registryUrl = `https://registry.npmjs.org/@budibase/${lib}/-/${lib}-${packageJson.version}.tgz`
|
const registryUrl = `https://registry.npmjs.org/@budibase/${lib}/-/${lib}-${packageJson.version}.tgz`
|
||||||
const path = join(appId, "node_modules", "@budibase", lib)
|
const path = join(appId, "node_modules", "@budibase", lib)
|
||||||
await downloadTarball(registryUrl, BUCKET_NAME, path)
|
paths[`@budibase/${lib}`] = await downloadTarball(
|
||||||
|
registryUrl,
|
||||||
|
BUCKET_NAME,
|
||||||
|
path
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
return paths
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.newAppPublicPath = async appId => {
|
exports.newAppPublicPath = async appId => {
|
||||||
|
|
|
@ -49,8 +49,6 @@ const PUBLIC_BUCKETS = [ObjectStoreBuckets.APPS]
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
exports.ObjectStore = bucket => {
|
exports.ObjectStore = bucket => {
|
||||||
console.log("CREATED OBJECT STORE")
|
|
||||||
console.trace()
|
|
||||||
if (env.SELF_HOSTED) {
|
if (env.SELF_HOSTED) {
|
||||||
AWS.config.update({
|
AWS.config.update({
|
||||||
accessKeyId: env.MINIO_ACCESS_KEY,
|
accessKeyId: env.MINIO_ACCESS_KEY,
|
||||||
|
@ -217,7 +215,9 @@ exports.downloadTarball = async (url, bucket, path) => {
|
||||||
|
|
||||||
const tmpPath = join(budibaseTempDir(), path)
|
const tmpPath = join(budibaseTempDir(), path)
|
||||||
await streamPipeline(response.body, zlib.Unzip(), tar.extract(tmpPath))
|
await streamPipeline(response.body, zlib.Unzip(), tar.extract(tmpPath))
|
||||||
await exports.uploadDirectory(bucket, tmpPath, path)
|
if (!env.isTest()) {
|
||||||
|
await exports.uploadDirectory(bucket, tmpPath, path)
|
||||||
|
}
|
||||||
// return the temporary path incase there is a use for it
|
// return the temporary path incase there is a use for it
|
||||||
return tmpPath
|
return tmpPath
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue