UNPKG

@interaktiv/mibuilder-core

Version:

Core libraries to interact with MiBuilder projects.

82 lines (71 loc) 3.38 kB
"use strict"; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); var Path = _interopRequireWildcard(require("path")); var _testSetup2 = require("../test-setup"); var _configFile = require("./config-file"); // Setup the test environment. const _testSetup = (0, _testSetup2.testSetup)(); class TestConfig extends _configFile.ConfigFile { static getTestLocalPath() { return _testSetup.localPathRetriever(TestConfig.testId); } static async getOptions(filename, isGlobal, isState, filePath) { return { rootFolder: await _testSetup.rootPathRetriever(isGlobal, TestConfig.testId), filename, isGlobal, isState, filePath }; } static getFileName() { return 'testFileName'; } } TestConfig.testId = _testSetup.id; describe('instantiation', () => { it('should use project dir if not using global dir', async () => { const config = await TestConfig.create(await TestConfig.getOptions('test', false)); const expected = await TestConfig.getTestLocalPath(); expect(config.getPath()).toEqual(expect.stringContaining(expected)); }); it('should using global if does not have project dir', async () => { const config = await TestConfig.create(await TestConfig.getOptions('test', true)); const expected = await TestConfig.getTestLocalPath(); expect(config.getPath()).toEqual(expect.not.stringContaining(expected)); }); it('should using state folder for global even when state is set to false', async () => { const config = await TestConfig.create(await TestConfig.getOptions('test', true, false)); const expected = await TestConfig.getTestLocalPath(); expect(config.getPath()).toEqual(expect.not.stringContaining(expected)); expect(config.getPath()).toEqual(expect.stringContaining('.mibuilder')); }); it('should using local state folder', async () => { const config = await TestConfig.create(await TestConfig.getOptions('test', false, true)); const expected = await TestConfig.getTestLocalPath(); expect(config.getPath()).toEqual(expect.stringContaining(expected)); expect(config.getPath()).toEqual(expect.stringContaining('.mibuilder')); }); it('should using local file', async () => { const config = await TestConfig.create(await TestConfig.getOptions('test', false, false)); const expected = await TestConfig.getTestLocalPath(); expect(config.getPath()).toEqual(expect.stringContaining(expected)); expect(config.getPath()).toEqual(expect.not.stringContaining('.mibuilder')); }); it('should using local custom folder', async () => { const config = await TestConfig.create(await TestConfig.getOptions('test', false, false, Path.join('my', 'path'))); const expected = await TestConfig.getTestLocalPath(); expect(config.getPath()).toEqual(expect.stringContaining(expected)); expect(config.getPath()).toEqual(expect.not.stringContaining('.mibuilder')); expect(config.getPath()).toEqual(expect.stringContaining(Path.join('my', 'path', 'test'))); }); }); describe('default options', () => { it('should apply passed in options', async () => { // Pass in custom options const config = await TestConfig.create({ isState: true }); // Creation doesn't fail with missing file name expect(config.getPath()).toEqual(expect.stringContaining('testFileName')); }); });