diff --git a/src/config.ts b/src/config.ts index c7d70ce..652c0a1 100644 --- a/src/config.ts +++ b/src/config.ts @@ -28,11 +28,16 @@ const defaultConfig: Config = { renewTime: 1000 * 60 * 60 * 24 * 15 }; -export const defaultPath = configDir(join('metacall', 'deploy')); +export const getDefaultPath = (): string => + configDir(join('metacall', 'deploy')); -export const configFilePath = (path = defaultPath) => join(path, 'config.ini'); +// Keep exported defaultPath for backward compatibility. +export const defaultPath = getDefaultPath(); -export const load = async (path = defaultPath): Promise => { +export const configFilePath = (path = getDefaultPath()) => + join(path, 'config.ini'); + +export const load = async (path = getDefaultPath()): Promise => { const data = parse( await loadFile(configFilePath(await ensureFolderExists(path))) ); @@ -45,7 +50,7 @@ export const load = async (path = defaultPath): Promise => { export const save = async ( data: Partial, - path = defaultPath + path = getDefaultPath() ): Promise => fs.writeFile( configFilePath(await ensureFolderExists(path)), diff --git a/src/startup.ts b/src/startup.ts index 593a5f8..fe4446c 100644 --- a/src/startup.ts +++ b/src/startup.ts @@ -9,12 +9,12 @@ import { auth } from './auth'; import args from './cli/args'; -import { Config, defaultPath, load } from './config'; +import { Config, getDefaultPath, load } from './config'; const devToken = 'local'; // Use some random token in order to proceed export const startup = async (confDir: string | undefined): Promise => { - const config = await load(confDir || defaultPath); + const config = await load(confDir || getDefaultPath()); const token = args['dev'] ? devToken : await auth(config); return Object.assign(config, { token }); diff --git a/src/test/cli.integration.spec.ts b/src/test/cli.integration.spec.ts index 80eb0ad..2e7b96c 100644 --- a/src/test/cli.integration.spec.ts +++ b/src/test/cli.integration.spec.ts @@ -14,6 +14,9 @@ import { describe('Integration CLI (Deploy)', function () { this.timeout(2000000); + before(async function () { + process.env.HOME = await createTmpDirectory(); + }); const url = 'https://github.com/metacall/examples'; const addRepoSuffix = 'metacall-examples'; @@ -31,7 +34,11 @@ describe('Integration CLI (Deploy)', function () { // --email & --password it('Should be able to login using --email & --password flag', async function () { await clearCache(); - const { email, password } = checkEnvVars(); + const creds = checkEnvVars(); + if (!creds) { + this.skip(); + } + const { email, password } = creds; const workdir = await createTmpDirectory(); try { diff --git a/src/test/cli.ts b/src/test/cli.ts index 7b11b37..fc65e58 100644 --- a/src/test/cli.ts +++ b/src/test/cli.ts @@ -1,5 +1,4 @@ import API from '@metacall/protocol/protocol'; -import { fail } from 'assert'; import concat from 'concat-stream'; import spawn from 'cross-spawn'; import * as dotenv from 'dotenv'; @@ -20,7 +19,6 @@ process.env.NODE_ENV = 'testing'; process.env.METACALL_DEPLOY_INTERACTIVE = 'true'; const PATH = process.env.PATH; -const HOME = process.env.HOME; export const isInDebugMode = () => inspector.url() !== undefined; @@ -41,7 +39,7 @@ export const run = ( { NODE_ENV: 'test', PATH, - HOME + HOME: process.env.HOME || os.homedir() }, env ), @@ -209,14 +207,12 @@ export const clearCache = async (): Promise => { await runCLI(['-l'], [keys.enter]).promise; }; -export const checkEnvVars = (): { email: string; password: string } | never => { +export const checkEnvVars = (): { email: string; password: string } | null => { const email = process.env.METACALL_AUTH_EMAIL; const password = process.env.METACALL_AUTH_PASSWORD; if (typeof email === 'undefined' || typeof password === 'undefined') { - fail( - 'No environment files present to test the below flags, please set up METACALL_AUTH_EMAIL and METACALL_AUTH_PASSWORD' - ); + return null; } return { email, password }; diff --git a/src/test/login.cli.integration.spec.ts b/src/test/login.cli.integration.spec.ts index da205af..1f4d349 100644 --- a/src/test/login.cli.integration.spec.ts +++ b/src/test/login.cli.integration.spec.ts @@ -18,7 +18,10 @@ describeTest('Integration CLI (Login)', function () { // Test for env variables before running tests before(async function () { await clearCache(); - checkEnvVars(); + process.env.HOME = await createTmpDirectory(); + if (!checkEnvVars()) { + this.skip(); + } }); // Invalid token login