refactor: Use declarations style for functions.

This commit is contained in:
Ruben Verborgh
2021-01-06 11:24:43 +01:00
parent e70e060225
commit f9a20799eb
23 changed files with 208 additions and 162 deletions

View File

@@ -29,13 +29,13 @@ class DummyFactory implements FileIdentifierMapperFactory {
}
}
const genToArray = async<T>(iterable: AsyncIterable<T>): Promise<T[]> => {
async function genToArray<T>(iterable: AsyncIterable<T>): Promise<T[]> {
const arr: T[] = [];
for await (const result of iterable) {
arr.push(result);
}
return arr;
};
}
describe('A TemplatedResourcesGenerator', (): void => {
const rootFilePath = 'templates';

View File

@@ -21,13 +21,13 @@ describe('A LockingResourceStore', (): void => {
jest.clearAllMocks();
order = [];
const delayedResolve = (resolve: (resolveParams: any) => void, name: string, resolveParams?: any): void => {
function delayedResolve(resolve: (value: any) => void, name: string, resolveValue?: any): void {
// `setImmediate` is introduced to make sure the promise doesn't execute immediately
setImmediate((): void => {
order.push(name);
resolve(resolveParams);
resolve(resolveValue);
});
};
}
const readable = streamifyArray([ 1, 2, 3 ]);
source = {
@@ -70,14 +70,14 @@ describe('A LockingResourceStore', (): void => {
store = new LockingResourceStore(source, locker);
});
const registerEventOrder = async(eventSource: EventEmitter, event: string): Promise<void> => {
async function registerEventOrder(eventSource: EventEmitter, event: string): Promise<void> {
await new Promise((resolve): any => {
eventSource.prependListener(event, (): any => {
order.push(event);
resolve();
});
});
};
}
it('acquires a lock on the container when adding a representation.', async(): Promise<void> => {
await store.addResource({ path: 'path' }, {} as Representation);

View File

@@ -20,12 +20,12 @@ const { literal, namedNode, quad } = DataFactory;
jest.mock('fetch-sparql-endpoint');
const simplifyQuery = (query: string | string[]): string => {
function simplifyQuery(query: string | string[]): string {
if (Array.isArray(query)) {
query = query.join(' ');
}
return query.replace(/\n/gu, ' ').trim();
};
}
describe('A SparqlDataAccessor', (): void => {
const endpoint = 'http://test.com/sparql';

View File

@@ -65,7 +65,7 @@ describe('A SparqlUpdatePatchHandler', (): void => {
handler = new SparqlUpdatePatchHandler(source, locker);
});
const basicChecks = async(quads: Quad[]): Promise<boolean> => {
async function basicChecks(quads: Quad[]): Promise<boolean> {
expect(source.getRepresentation).toHaveBeenCalledTimes(1);
expect(source.getRepresentation).toHaveBeenLastCalledWith(
{ path: 'path' }, { type: { [INTERNAL_QUADS]: 1 }},
@@ -81,7 +81,7 @@ describe('A SparqlUpdatePatchHandler', (): void => {
expect(setParams[1].metadata.contentType).toEqual(INTERNAL_QUADS);
await expect(arrayifyStream(setParams[1].data)).resolves.toBeRdfIsomorphic(quads);
return true;
};
}
it('only accepts SPARQL updates.', async(): Promise<void> => {
const input = { identifier: { path: 'path' },

View File

@@ -9,14 +9,14 @@ describe('A WrappedExpiringResourceLocker', (): void => {
order = [];
});
const registerEventOrder = async(eventSource: EventEmitter, event: string): Promise<void> => {
async function registerEventOrder(eventSource: EventEmitter, event: string): Promise<void> {
await new Promise((resolve): any => {
eventSource.prependListener(event, (): any => {
order.push(event);
resolve();
});
});
};
}
it('emits an error event when releasing the lock errors.', async(): Promise<void> => {
jest.useFakeTimers();