chore: More flakey test improvements (#5801)

This commit is contained in:
Tom Moor
2023-09-09 18:30:19 -04:00
committed by GitHub
parent 7270e65f0c
commit 80ef0a38d6
37 changed files with 245 additions and 210 deletions

View File

@@ -101,7 +101,11 @@ export async function getTeamFromContext(ctx: Context) {
let team;
if (!env.isCloudHosted) {
team = await Team.findOne();
if (env.ENVIRONMENT === "test") {
team = await Team.findOne({ where: { domain: env.URL } });
} else {
team = await Team.findOne();
}
} else if (domain.custom) {
team = await Team.findOne({ where: { domain: domain.host } });
} else if (domain.teamSubdomain) {

View File

@@ -1,41 +1,42 @@
import { existsSync } from "fs";
/* eslint-disable @typescript-eslint/no-var-requires */
import path from "path";
import glob from "glob";
import startCase from "lodash/startCase";
import env from "@server/env";
import Logger from "@server/logging/Logger";
import { UnfurlResolver } from "@server/types";
const rootDir = env.ENVIRONMENT === "test" ? "" : "build";
const hasResolver = (plugin: string) => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const config = require(path.join(process.cwd(), plugin, "plugin.json"));
return (
existsSync(resolverPath(plugin)) &&
(config.requiredEnvVars ?? []).every((name: string) => !!env[name])
);
};
const resolverPath = (plugin: string) =>
path.join(plugin, "server", "unfurl.js");
const plugins = glob.sync(path.join(rootDir, "plugins/*"));
const resolvers: Record<string, UnfurlResolver> = plugins
.filter(hasResolver)
.map(resolverPath)
.reduce((resolvers, resolverPath) => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const plugins = glob.sync(path.join(rootDir, "plugins/*/server/unfurl.[jt]s"));
const resolvers: Record<string, UnfurlResolver> = plugins.reduce(
(resolvers, filePath) => {
const resolver: UnfurlResolver = require(path.join(
process.cwd(),
resolverPath
filePath
));
const name = startCase(resolverPath.split("/")[2]);
resolvers[name] = resolver;
Logger.debug("utils", `Registered unfurl resolver ${resolverPath}`);
const id = filePath.replace("build/", "").split("/")[1];
const config = require(path.join(
process.cwd(),
rootDir,
"plugins",
id,
"plugin.json"
));
// Test the all required env vars are set for the resolver
const enabled = (config.requiredEnvVars ?? []).every(
(name: string) => !!env[name]
);
if (!enabled) {
return resolvers;
}
resolvers[config.name] = resolver;
Logger.debug("utils", `Registered unfurl resolver ${filePath}`);
return resolvers;
}, {});
},
{}
);
export default resolvers;