Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Config> => {
export const configFilePath = (path = getDefaultPath()) =>
join(path, 'config.ini');

export const load = async (path = getDefaultPath()): Promise<Config> => {
const data = parse(
await loadFile(configFilePath(await ensureFolderExists(path)))
);
Expand All @@ -45,7 +50,7 @@ export const load = async (path = defaultPath): Promise<Config> => {

export const save = async (
data: Partial<Config>,
path = defaultPath
path = getDefaultPath()
): Promise<void> =>
fs.writeFile(
configFilePath(await ensureFolderExists(path)),
Expand Down
4 changes: 2 additions & 2 deletions src/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Config> => {
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 });
Expand Down
9 changes: 8 additions & 1 deletion src/test/cli.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {

describe('Integration CLI (Deploy)', function () {
this.timeout(2000000);
before(async function () {
process.env.HOME = await createTmpDirectory();
});

Comment on lines 16 to 20
const url = 'https://github.com/metacall/examples';
const addRepoSuffix = 'metacall-examples';
Expand All @@ -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;
Comment on lines 35 to +41
const workdir = await createTmpDirectory();

try {
Expand Down
10 changes: 3 additions & 7 deletions src/test/cli.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;

Expand All @@ -41,7 +39,7 @@ export const run = (
{
NODE_ENV: 'test',
PATH,
HOME
HOME: process.env.HOME || os.homedir()
},
env
),
Expand Down Expand Up @@ -209,14 +207,12 @@ export const clearCache = async (): Promise<void> => {
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 };
Expand Down
5 changes: 4 additions & 1 deletion src/test/login.cli.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Comment on lines 19 to +23
}
Comment on lines 20 to +24
});

// Invalid token login
Expand Down
Loading