mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Allow for custom CLI and variable options
* feat: (AppRunner) Mechanism to configure cli args and derive componentsjs vars from them implemented * fix: (AppRunner) tidying * fix: (AppRunner) tidying up * fix: (AppRunner) runCli method made sync * fix; (VarResolver) refactored to multiple files, and other stylistic fixes. * chore: (AppRunner) Uses builder pattern for yargs base arguments setup to enable better typescript inference * fix(AppRunner): refactoring AppRunner and VarResolver * fix(AppRunner): refactoring AppRunner promise handling * fix(AppRunner): verror dependency removal * fix: Simplify CLI error handling * feat: Use same config for both CLI and app instantiation * fix: Update typings and imports * feat: Split VariableResolver behaviour to 2 classes * feat: Move default value behaviour from CLI to ValueComputers * test: Add unit tests for new CLI classes * feat: Integrate new CLI configuration with all default configurations * feat: Add createApp function to AppRunner * docs: Update comments in CLI-related classes * fix: Various fixes and refactors Co-authored-by: damooo <damodara@protonmail.com>
This commit is contained in:
committed by
GitHub
parent
d067165b68
commit
c216efd62f
38
test/unit/init/variables/CombinedSettingsResolver.test.ts
Normal file
38
test/unit/init/variables/CombinedSettingsResolver.test.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { CombinedSettingsResolver } from '../../../../src/init/variables/CombinedSettingsResolver';
|
||||
import type { SettingsExtractor } from '../../../../src/init/variables/extractors/SettingsExtractor';
|
||||
|
||||
describe('A CombinedSettingsResolver', (): void => {
|
||||
const values = { test: 'data' };
|
||||
const varPort = 'urn:solid-server:default:variable:port';
|
||||
const varLog = 'urn:solid-server:default:variable:loggingLevel';
|
||||
let computerPort: jest.Mocked<SettingsExtractor>;
|
||||
let computerLog: jest.Mocked<SettingsExtractor>;
|
||||
let resolver: CombinedSettingsResolver;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
computerPort = {
|
||||
handleSafe: jest.fn().mockResolvedValue(3000),
|
||||
} as any;
|
||||
|
||||
computerLog = {
|
||||
handleSafe: jest.fn().mockResolvedValue('info'),
|
||||
} as any;
|
||||
|
||||
resolver = new CombinedSettingsResolver({
|
||||
[varPort]: computerPort,
|
||||
[varLog]: computerLog,
|
||||
});
|
||||
});
|
||||
|
||||
it('assigns variable values based on the Computers output.', async(): Promise<void> => {
|
||||
await expect(resolver.handle(values)).resolves.toEqual({
|
||||
[varPort]: 3000,
|
||||
[varLog]: 'info',
|
||||
});
|
||||
});
|
||||
|
||||
it('rethrows the error if something goes wrong.', async(): Promise<void> => {
|
||||
computerPort.handleSafe.mockRejectedValueOnce(new Error('bad data'));
|
||||
await expect(resolver.handle(values)).rejects.toThrow(`Error in computing value for variable ${varPort}: bad data`);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
import { AssetPathExtractor } from '../../../../../src/init/variables/extractors/AssetPathExtractor';
|
||||
import { joinFilePath } from '../../../../../src/util/PathUtil';
|
||||
|
||||
describe('An AssetPathExtractor', (): void => {
|
||||
let resolver: AssetPathExtractor;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
resolver = new AssetPathExtractor('path');
|
||||
});
|
||||
|
||||
it('resolves the asset path.', async(): Promise<void> => {
|
||||
await expect(resolver.handle({ path: '/var/data' })).resolves.toBe('/var/data');
|
||||
});
|
||||
|
||||
it('errors if the path is not a string.', async(): Promise<void> => {
|
||||
await expect(resolver.handle({ path: 1234 })).rejects.toThrow('Invalid path argument');
|
||||
});
|
||||
|
||||
it('converts paths containing the module path placeholder.', async(): Promise<void> => {
|
||||
await expect(resolver.handle({ path: '@css:config/file.json' }))
|
||||
.resolves.toEqual(joinFilePath(__dirname, '../../../../../config/file.json'));
|
||||
});
|
||||
|
||||
it('defaults to the given path if none is provided.', async(): Promise<void> => {
|
||||
resolver = new AssetPathExtractor('path', '/root');
|
||||
await expect(resolver.handle({ otherPath: '/var/data' })).resolves.toBe('/root');
|
||||
});
|
||||
});
|
||||
22
test/unit/init/variables/extractors/BaseUrlExtractor.test.ts
Normal file
22
test/unit/init/variables/extractors/BaseUrlExtractor.test.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { BaseUrlExtractor } from '../../../../../src/init/variables/extractors/BaseUrlExtractor';
|
||||
|
||||
describe('A BaseUrlExtractor', (): void => {
|
||||
let computer: BaseUrlExtractor;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
computer = new BaseUrlExtractor();
|
||||
});
|
||||
|
||||
it('extracts the baseUrl parameter.', async(): Promise<void> => {
|
||||
await expect(computer.handle({ baseUrl: 'http://example.com/', port: 3333 }))
|
||||
.resolves.toBe('http://example.com/');
|
||||
});
|
||||
|
||||
it('uses the port parameter if baseUrl is not defined.', async(): Promise<void> => {
|
||||
await expect(computer.handle({ port: 3333 })).resolves.toBe('http://localhost:3333/');
|
||||
});
|
||||
|
||||
it('defaults to port 3000.', async(): Promise<void> => {
|
||||
await expect(computer.handle({})).resolves.toBe('http://localhost:3000/');
|
||||
});
|
||||
});
|
||||
19
test/unit/init/variables/extractors/KeyExtractor.test.ts
Normal file
19
test/unit/init/variables/extractors/KeyExtractor.test.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { KeyExtractor } from '../../../../../src/init/variables/extractors/KeyExtractor';
|
||||
|
||||
describe('An KeyExtractor', (): void => {
|
||||
const key = 'test';
|
||||
let extractor: KeyExtractor;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
extractor = new KeyExtractor(key);
|
||||
});
|
||||
|
||||
it('extracts the value.', async(): Promise<void> => {
|
||||
await expect(extractor.handle({ test: 'data', notTest: 'notData' })).resolves.toBe('data');
|
||||
});
|
||||
|
||||
it('defaults to a given value if none is defined.', async(): Promise<void> => {
|
||||
extractor = new KeyExtractor(key, 'defaultData');
|
||||
await expect(extractor.handle({ notTest: 'notData' })).resolves.toBe('defaultData');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user