diff --git a/bunfig.toml b/bunfig.toml new file mode 100644 index 0000000..f9e1944 --- /dev/null +++ b/bunfig.toml @@ -0,0 +1,3 @@ +[test] +# Load these modules before running tests. +preload = ["./test/preload.ts"] \ No newline at end of file diff --git a/src/utils/compose.ts b/src/utils/compose.ts index 1c7828c..51309cf 100644 --- a/src/utils/compose.ts +++ b/src/utils/compose.ts @@ -1,4 +1,4 @@ -import * as fs from 'node:fs'; +import fs from 'node:fs'; import * as path from 'node:path'; import { projectConfig } from '../config/project'; import { cmd as $ } from './cmd'; diff --git a/test/preload.ts b/test/preload.ts new file mode 100644 index 0000000..96b946c --- /dev/null +++ b/test/preload.ts @@ -0,0 +1,19 @@ +import { mock } from 'bun:test'; + +mock.module('node:fs', () => ({ + default: { + readdirSync: (dir: string) => { + switch (true) { + case dir.includes('frontend'): + return ['compose-frontend.yml']; + case dir.includes('backend'): + return ['compose-backend.yml']; + default: + return ['compose.yml']; + } + }, + existsSync: (path: string) => true, + lstatSync: (path: string) => ({ isFile: () => true }), + readFileSync: (path: string) => '', + }, +})); diff --git a/test/utils/compose.test.ts b/test/utils/compose.test.ts new file mode 100644 index 0000000..f4515ad --- /dev/null +++ b/test/utils/compose.test.ts @@ -0,0 +1,21 @@ +import { describe, expect, mock, test } from 'bun:test'; +import { composeFiles } from '../../src/utils/compose.ts'; + +mock.module('../../src/utils/git.ts', () => ({ + validateLocalGitRepo: () => null, +})); + +describe('Utils: compose', () => { + test('composeFiles returns the correct output', () => { + const output = composeFiles({ + filesDir: '.dems', + prefix: 'compose.+.', + repos: ['frontend', 'backend'], + reposRoot: '/projects', + }); + expect(output).toEqual([ + '--file /projects/frontend/.dems/compose-frontend.yml', + '--file /projects/backend/.dems/compose-backend.yml', + ]); + }); +});