mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
test: Add CLI integration tests
This commit is contained in:
parent
4e999eba98
commit
df2cb189be
49
test/integration/Cli.test.ts
Normal file
49
test/integration/Cli.test.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import type { CliResolver } from '../../src/init/CliResolver';
|
||||
import { resolveModulePath } from '../../src/util/PathUtil';
|
||||
import { instantiateFromConfig } from './Config';
|
||||
|
||||
// Needed to prevent yargs from stopping the process on error
|
||||
const error = jest.spyOn(console, 'error').mockImplementation(jest.fn());
|
||||
const exit = jest.spyOn(process, 'exit').mockImplementation(jest.fn() as any);
|
||||
|
||||
describe('An instantiated CliResolver', (): void => {
|
||||
let cliResolver: CliResolver;
|
||||
|
||||
beforeAll(async(): Promise<void> => {
|
||||
// Create the CliExtractor
|
||||
cliResolver = await instantiateFromConfig(
|
||||
'urn:solid-server-app-setup:default:CliResolver',
|
||||
resolveModulePath('config/default.json'),
|
||||
);
|
||||
});
|
||||
|
||||
it('converts known abbreviations to the full parameter.', async(): Promise<void> => {
|
||||
const shorthand = await cliResolver.cliExtractor.handleSafe([ 'node', 'server.js',
|
||||
'-c', 'c',
|
||||
'-m', 'm',
|
||||
'-l', 'l',
|
||||
'-b', 'b',
|
||||
'-p', '3000',
|
||||
'-f', 'f',
|
||||
'-t',
|
||||
'-s', 's',
|
||||
'-w', '2',
|
||||
]);
|
||||
expect(shorthand.config).toBe('c');
|
||||
expect(shorthand.mainModulePath).toBe('m');
|
||||
expect(shorthand.loggingLevel).toBe('l');
|
||||
expect(shorthand.baseUrl).toBe('b');
|
||||
expect(shorthand.port).toBe(3000);
|
||||
expect(shorthand.rootFilePath).toBe('f');
|
||||
expect(shorthand.showStackTrace).toBe(true);
|
||||
expect(shorthand.sparqlEndpoint).toBe('s');
|
||||
expect(shorthand.workers).toBe(2);
|
||||
});
|
||||
|
||||
it('errors on unknown parameters.', async(): Promise<void> => {
|
||||
await cliResolver.cliExtractor.handleSafe([ 'node', 'server.js', '-a', 'abc' ]);
|
||||
|
||||
expect(exit).toHaveBeenCalledTimes(1);
|
||||
expect(error).toHaveBeenCalledWith('Unknown argument: a');
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user