diff --git a/src/fs/json2env.test.ts b/src/fs/json2env.test.ts new file mode 100644 index 0000000..d906bae --- /dev/null +++ b/src/fs/json2env.test.ts @@ -0,0 +1,39 @@ +import { objectToGithubActionsEnv, objectToShellExport } from './json2env' + +test('objectToGithubActionsEnv', () => { + expect(objectToGithubActionsEnv({})).toBe('') + + expect( + objectToGithubActionsEnv({ + a: 'a', + minInstances: 0, + maxInstances: 8, + c: false, + d: true, + }), + ).toMatchInlineSnapshot(` +"a=a +minInstances=0 +maxInstances=8 +c=false +d=true +" +`) + + expect( + objectToShellExport({ + a: 'a', + minInstances: 0, + maxInstances: 8, + c: false, + d: true, + }), + ).toMatchInlineSnapshot(` +"export a="a" +export minInstances="0" +export maxInstances="8" +export c="false" +export d="true" +" +`) +}) diff --git a/src/fs/json2env.ts b/src/fs/json2env.ts index e1ceec5..1c34f7a 100644 --- a/src/fs/json2env.ts +++ b/src/fs/json2env.ts @@ -148,7 +148,7 @@ export function objectToShellExport(obj: AnyObject, prefix = ''): string { return ( Object.entries(obj) .map(([k, v]) => { - if (v) { + if (v !== undefined && v !== null) { return `export ${prefix}${k}="${v}"` } }) @@ -179,7 +179,7 @@ export function objectToGithubActionsEnv(obj: AnyObject, prefix = ''): string { return ( Object.entries(obj) .map(([k, v]) => { - if (v) { + if (v !== undefined && v !== null) { return `${prefix}${k}=${v}` } })