mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Change YargsCliExtractor structure to avoid Components.js issues
This commit is contained in:
@@ -1,19 +1,18 @@
|
||||
import type { YargsArgOptions } from '../../../../src/init/cli/YargsCliExtractor';
|
||||
import { YargsCliExtractor } from '../../../../src/init/cli/YargsCliExtractor';
|
||||
import { YargsParameter, YargsCliExtractor } from '../../../../src/init/cli/YargsCliExtractor';
|
||||
|
||||
const error = jest.spyOn(console, 'error').mockImplementation(jest.fn());
|
||||
const log = jest.spyOn(console, 'log').mockImplementation(jest.fn());
|
||||
const exit = jest.spyOn(process, 'exit').mockImplementation(jest.fn() as any);
|
||||
|
||||
describe('A YargsCliExtractor', (): void => {
|
||||
const parameters: YargsArgOptions = {
|
||||
baseUrl: { alias: 'b', requiresArg: true, type: 'string' },
|
||||
port: { alias: 'p', requiresArg: true, type: 'number' },
|
||||
};
|
||||
const parameters: YargsParameter[] = [
|
||||
new YargsParameter('baseUrl', { alias: 'b', requiresArg: true, type: 'string' }),
|
||||
new YargsParameter('port', { alias: 'p', requiresArg: true, type: 'number' }),
|
||||
];
|
||||
let extractor: YargsCliExtractor;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
extractor = new YargsCliExtractor(parameters);
|
||||
extractor = new YargsCliExtractor(parameters, {});
|
||||
});
|
||||
|
||||
afterEach(async(): Promise<void> => {
|
||||
@@ -36,22 +35,6 @@ describe('A YargsCliExtractor', (): void => {
|
||||
}));
|
||||
});
|
||||
|
||||
it('defaults to no parameters if none are provided.', async(): Promise<void> => {
|
||||
extractor = new YargsCliExtractor();
|
||||
const argv = [ 'node', 'script', '-b', 'http://localhost:3000/', '-p', '3000' ];
|
||||
await expect(extractor.handle(argv)).resolves.toEqual(expect.objectContaining({}));
|
||||
});
|
||||
|
||||
it('combines parameters and extra parameters.', async(): Promise<void> => {
|
||||
extractor = new YargsCliExtractor(parameters, {}, { test: { alias: 't', requiresArg: true, type: 'string' }});
|
||||
const argv = [ 'node', 'script', '-b', 'http://localhost:3000/', '-p', '3000', '-t', 'test' ];
|
||||
await expect(extractor.handle(argv)).resolves.toEqual(expect.objectContaining({
|
||||
baseUrl: 'http://localhost:3000/',
|
||||
port: 3000,
|
||||
test: 'test',
|
||||
}));
|
||||
});
|
||||
|
||||
it('prints usage if defined.', async(): Promise<void> => {
|
||||
extractor = new YargsCliExtractor(parameters, { usage: 'node ./bin/server.js [args]' });
|
||||
const argv = [ 'node', 'script', '--help' ];
|
||||
|
||||
Reference in New Issue
Block a user