1
0
Fork 0
mirror of synced 2024-06-03 02:55:14 +12:00

Some cleanup fixes for tests that makes sure temp directory isn't getting out of control.

This commit is contained in:
mike12345567 2021-03-25 14:46:32 +00:00
parent 7c2ef4d43f
commit 1cf0027c6e
5 changed files with 31 additions and 16 deletions

View file

@ -1,16 +1,6 @@
const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
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", () => {
let request = setup.getRequest()
let config = setup.getConfig()

View file

@ -14,6 +14,7 @@ const {
} = require("./structures")
const controllers = require("./controllers")
const supertest = require("supertest")
const { cleanup } = require("../../utilities/fileSystem")
const EMAIL = "babs@babs.com"
const PASSWORD = "babs_password"
@ -63,6 +64,7 @@ class TestConfiguration {
if (this.server) {
this.server.close()
}
cleanup(this.allApps.map(app => app._id))
}
defaultHeaders() {

View file

@ -157,11 +157,19 @@ exports.downloadTemplate = async (type, name) => {
* Retrieves component libraries from object store (or tmp symlink if in local)
*/
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)) {
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)
if (typeof resp !== "string") {
resp = resp.toString("utf8")
@ -201,6 +209,15 @@ exports.readFileSync = (filepath, options = "utf8") => {
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.
*/

View file

@ -11,13 +11,19 @@ const BUCKET_NAME = ObjectStoreBuckets.APPS
exports.downloadLibraries = async appId => {
const LIBRARIES = ["standard-components"]
const paths = {}
// Need to download tarballs directly from NPM as our users may not have node on their machine
for (let lib of LIBRARIES) {
// download tarball
const registryUrl = `https://registry.npmjs.org/@budibase/${lib}/-/${lib}-${packageJson.version}.tgz`
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 => {

View file

@ -49,8 +49,6 @@ const PUBLIC_BUCKETS = [ObjectStoreBuckets.APPS]
* @constructor
*/
exports.ObjectStore = bucket => {
console.log("CREATED OBJECT STORE")
console.trace()
if (env.SELF_HOSTED) {
AWS.config.update({
accessKeyId: env.MINIO_ACCESS_KEY,
@ -217,7 +215,9 @@ exports.downloadTarball = async (url, bucket, path) => {
const tmpPath = join(budibaseTempDir(), path)
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 tmpPath
}