Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import isDocker from 'is-docker' // eslint-disable-line import/default
import { DockerComposeFile } from '../@types'
import { DOCKEST_ATTACH_TO_PROCESS, DOCKEST_HOST_ADDRESS, DEFAULT_HOST_NAME } from '../constants'
import { DockestError } from '../Errors'
const isInsideDockerContainer = isDocker()
const dockestConfig = process.env[DOCKEST_ATTACH_TO_PROCESS]
if (!dockestConfig) {
throw new DockestError('Config not attached to process: Not executed inside dockest context')
}
const config: DockerComposeFile = JSON.parse(dockestConfig)
export const getHostAddress = () => {
if (!isInsideDockerContainer) {
return DEFAULT_HOST_NAME
}
return DOCKEST_HOST_ADDRESS
}
}
const cpus = os.cpus() || []
const { NOW_REGION } = process.env
traits = {
// Software information
systemPlatform: os.platform(),
systemRelease: os.release(),
systemArchitecture: os.arch(),
// Machine information
cpuCount: cpus.length,
cpuModel: cpus.length ? cpus[0].model : null,
cpuSpeed: cpus.length ? cpus[0].speed : null,
memoryInMb: Math.trunc(os.totalmem() / Math.pow(1024, 2)),
// Environment information
isDocker: isDockerFunction(),
isNowDev: NOW_REGION === 'dev1',
isWsl: isWslBoolean,
isCI: ciEnvironment.isCI,
ciName: (ciEnvironment.isCI && ciEnvironment.name) || null,
nextVersion: process.env.__NEXT_VERSION as string,
}
return traits
}
constructor(
options: {
port?: number;
mode?: "default" | "local" | "docker";
} = {}
) {
this.server = new ReactComponentServer(options.port || 3037);
switch (options.mode || "default") {
case "local":
this.mode = "local";
break;
case "docker":
this.mode = "docker";
break;
default:
this.mode = isDocker() ? "local" : "docker";
}
this.browser =
this.mode === "local" ? new LocalChromeRenderer() : new DockerRenderer();
}
function getScreenshotMode(): "local" | "docker" | "percy" {
if (process.env.SCREENSHOT_MODE) {
switch (process.env.SCREENSHOT_MODE) {
case "local":
case "docker":
case "percy":
return process.env.SCREENSHOT_MODE;
default:
throw new Error(
`Valid values for SCREENSHOT_MODE are 'local', 'docker' and 'percy'. Received '${process.env.SCREENSHOT_MODE}'.`
);
}
}
return isDocker() ? "local" : "docker";
}
public run = async (dockestServices: DockestService[]) => {
this.config.$.perfStart = Date.now()
this.config.$.isInsideDockerContainer = isDocker()
this.config.$.dockestServices = dockestServices
await bootstrap(this.config)
await startServices(this.config)
await waitForServices(this.config)
await debugMode(this.config)
const { success } = await runJest(this.config)
await teardown(this.config)
success ? process.exit(0) : process.exit(1)
}
}
export function getConfigDir () {
if (isDocker()) return '/config'
switch (process.platform) {
case 'win32':
return path.join(process.env.APPDATA!!, 'Miscord')
case 'linux':
return path.join(os.homedir(), '.config', 'Miscord')
case 'darwin':
return path.join(os.homedir(), 'Library', 'Application Support', 'Miscord')
default:
return path.join(os.homedir(), '.miscord')
}
}
import timezonedDate from './timezonedDate'
import util from 'util'
import chalk from 'chalk'
import is_docker from 'is-docker'
const isDocker = is_docker()
export type Level = 'fatal' | 'error' | 'warn' | 'info' | 'start' | 'success' | 'debug' | 'trace'
const levelBadges = {
fatal: chalk.bgWhite.red(' FATAL '),
error: chalk.bgRed.white(' ERROR '),
warn: chalk.bgYellow.black(' WARN '),
info: chalk.bgBlue.black(' INFO '),
start: chalk.bgBlue.black(' START '),
success: chalk.bgGreen.black(' SUCCESS '),
debug: chalk.bgCyan.black(' DEBUG '),
trace: chalk.bgWhite.black(' TRACE ')
}
const levelArrows = {
fatal: chalk.white('›'),
function getStorageDirectory(distDir: string): string | undefined {
const isLikelyEphemeral = ciEnvironment.isCI || isDockerFunction()
if (isLikelyEphemeral) {
return path.join(distDir, 'cache')
}
return undefined
}