import * as path from 'path'; import { SettingsFileLoader } from '../../src/builder/SettingsFileLoader'; import { settingsFileLoaderDir } from '../helpers'; describe('SettingsFileLoader', () => { const allBaseRootPath = path.resolve(settingsFileLoaderDir, 'all-base'); const baseJsYamlRootPath = path.resolve(settingsFileLoaderDir, 'base-js-yaml'); const settingsLoader = new SettingsFileLoader(); it('Should load a yaml settings file', async () => { const baseYaml = path.join(allBaseRootPath, 'base.yaml'); const loaded = await settingsLoader.load(baseYaml); expect(loaded).toHaveProperty('setting1', 'baseValue1') }); it('Should load a json settings file', async () => { const baseJson = path.join(allBaseRootPath, 'base.json'); const loaded = await settingsLoader.load(baseJson); expect(loaded).toHaveProperty('setting1', 'baseValue1') }); it('Should load a ts file with default export', async () => { const baseTs = path.join(allBaseRootPath, 'base.ts'); const loaded = await settingsLoader.load(baseTs); expect(loaded).toHaveProperty('setting1', 'baseValue1') }); it('Should load a js file with default export', async () => { const baseJs = path.join(allBaseRootPath, 'base.js'); const loaded = await settingsLoader.load(baseJs); expect(loaded).toHaveProperty('setting1', 'baseValue1') }); it('Should return path to base.ts from call to getSupportedExistingFile with baseName base', () => { const supportedFilePath = settingsLoader.getSupportedExistingFile(allBaseRootPath, 'base'); const supportedFileBaseName = path.basename(supportedFilePath); expect(supportedFileBaseName).toEqual('base.ts'); }); it('Should return null from call to getSupportedExistingFile with baseName that doesn\'t exist', () => { const supportedFilePath = settingsLoader.getSupportedExistingFile(allBaseRootPath, 'doesnotexist'); expect(supportedFilePath).toBeNull(); }); it('Should prioritize js file over yaml on call to getSupportedExistingFile', () => { const supportedFilePath = settingsLoader.getSupportedExistingFile(baseJsYamlRootPath, 'base'); const supportedFileBaseName = path.basename(supportedFilePath); expect(supportedFileBaseName).toEqual('base.js'); }); });