Skip to content

Commit

Permalink
Merge 1369714 into 0476ba8
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenVerborgh committed Nov 2, 2020
2 parents 0476ba8 + 1369714 commit 88aa386
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 44 deletions.
14 changes: 7 additions & 7 deletions .eslintrc.js
Expand Up @@ -6,15 +6,15 @@ module.exports = {
project: ['./tsconfig.json'],
},
plugins: [
'eslint-plugin-tsdoc',
'eslint-plugin-import',
'eslint-plugin-unused-imports'
'tsdoc',
'import',
'unused-imports',
],
extends: [
'es/node',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript'
'plugin:import/typescript',
],
settings: {
'import/resolver': {
Expand Down Expand Up @@ -72,7 +72,7 @@ module.exports = {
{
selector: [ 'typeParameter' ],
format: [ 'PascalCase' ],
prefix: [ 'T' ]
prefix: [ 'T' ],
}
],

Expand All @@ -81,12 +81,12 @@ module.exports = {
'import/order': ['error', {
alphabetize: {
order: 'asc',
caseInsensitive: true
caseInsensitive: true,
}
}],
'import/no-duplicates': 'error',
'import/no-extraneous-dependencies': 'error',
'no-duplicate-imports': 'off', // doesn't work with type imports
'unused-imports/no-unused-imports-ts': 'error'
'unused-imports/no-unused-imports-ts': 'error',
},
};
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -106,6 +106,7 @@
"eslint-config-es": "^3.20.3",
"eslint-import-resolver-typescript": "^2.3.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jest": "^24.1.0",
"eslint-plugin-tsdoc": "^0.2.7",
"eslint-plugin-unused-imports": "^1.0.0",
"husky": "^4.2.5",
Expand Down
12 changes: 8 additions & 4 deletions test/.eslintrc.js
@@ -1,13 +1,17 @@
module.exports = {
env: {
jest: true
},
plugins: [
'jest',
],
extends: [
'plugin:jest/recommended',
'plugin:jest/style',
],
rules: {
'@typescript-eslint/no-unsafe-assignment': 'off',
'unicorn/no-useless-undefined': 'off',

// Need these 2 to run tests for throwing non-Error objects
'@typescript-eslint/no-throw-literal': 'off',
'no-throw-literal': 'off',
}
},
};
2 changes: 1 addition & 1 deletion test/unit/init/CliRunner.test.ts
Expand Up @@ -78,7 +78,7 @@ describe('CliRunner', (): void => {

expect(calledInstantiateFromUrl).toBeTruthy();
expect(calledRegisterAvailableModuleResources).toBeTruthy();
expect(mockSetup.setup).toBeCalledTimes(1);
expect(mockSetup.setup).toHaveBeenCalledTimes(1);
});

it('Writes to stderr when an exception occurs.', async(): Promise<void> => {
Expand Down
34 changes: 20 additions & 14 deletions test/unit/ldp/http/BasicResponseWriter.test.ts
Expand Up @@ -30,41 +30,47 @@ describe('A BasicResponseWriter', (): void => {
expect(response._getHeaders()).toMatchObject({ location: 'path' });
});

it('responds with a body if the description has a body.', async(done): Promise<void> => {
it('responds with a body if the description has a body.', async(): Promise<void> => {
const body = {
binary: true,
data: streamifyArray([ '<http://test.com/s> <http://test.com/p> <http://test.com/o>.' ]),
metadata: new RepresentationMetadata(),
};

response.on('end', (): void => {
expect(response._isEndCalled()).toBeTruthy();
expect(response._getStatusCode()).toBe(200);
expect(response._getHeaders()).toMatchObject({ location: 'path' });
expect(response._getData()).toEqual('<http://test.com/s> <http://test.com/p> <http://test.com/o>.');
done();
const end = new Promise((resolve): void => {
response.on('end', (): void => {
expect(response._isEndCalled()).toBeTruthy();
expect(response._getStatusCode()).toBe(200);
expect(response._getHeaders()).toMatchObject({ location: 'path' });
expect(response._getData()).toEqual('<http://test.com/s> <http://test.com/p> <http://test.com/o>.');
resolve();
});
});

await writer.handle({ response, result: { identifier: { path: 'path' }, body }});
await end;
});

it('responds with a content-type if the metadata has it.', async(done): Promise<void> => {
it('responds with a content-type if the metadata has it.', async(): Promise<void> => {
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: 'text/turtle' });
const body = {
binary: true,
data: streamifyArray([ '<http://test.com/s> <http://test.com/p> <http://test.com/o>.' ]),
metadata,
};

response.on('end', (): void => {
expect(response._isEndCalled()).toBeTruthy();
expect(response._getStatusCode()).toBe(200);
expect(response._getHeaders()).toMatchObject({ location: 'path', 'content-type': 'text/turtle' });
expect(response._getData()).toEqual('<http://test.com/s> <http://test.com/p> <http://test.com/o>.');
done();
const end = new Promise((resolve): void => {
response.on('end', (): void => {
expect(response._isEndCalled()).toBeTruthy();
expect(response._getStatusCode()).toBe(200);
expect(response._getHeaders()).toMatchObject({ location: 'path', 'content-type': 'text/turtle' });
expect(response._getData()).toEqual('<http://test.com/s> <http://test.com/p> <http://test.com/o>.');
resolve();
});
});

await writer.handle({ response, result: { identifier: { path: 'path' }, body }});
await end;
});

it('responds with 500 if an error if there is an error.', async(): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ldp/http/metadata/BasicMetadataExtractor.test.ts
Expand Up @@ -21,7 +21,7 @@ class BasicParser implements MetadataParser {
}
}

describe(' A BasicMetadataExtractor', (): void => {
describe('A BasicMetadataExtractor', (): void => {
const handler = new BasicMetadataExtractor([
new BasicParser('aa'),
new BasicParser('bb'),
Expand Down
6 changes: 3 additions & 3 deletions test/unit/logging/LogUtil.test.ts
Expand Up @@ -20,13 +20,13 @@ describe('LogUtil', (): void => {
});

it('allows setting the global logger factory.', async(): Promise<void> => {
expect(setGlobalLoggerFactory(new VoidLoggerFactory()));
setGlobalLoggerFactory(new VoidLoggerFactory());
expect(LazyLoggerFactory.getInstance().loggerFactory).toBeInstanceOf(VoidLoggerFactory);
});

it('allows unsetting the global logger factory.', async(): Promise<void> => {
expect(setGlobalLoggerFactory(new VoidLoggerFactory()));
expect(resetGlobalLoggerFactory());
setGlobalLoggerFactory(new VoidLoggerFactory());
resetGlobalLoggerFactory();
expect((): any => LazyLoggerFactory.getInstance().loggerFactory)
.toThrow(new Error('No logger factory has been set. Can be caused by logger invocation during initialization.'));
});
Expand Down
2 changes: 1 addition & 1 deletion test/unit/server/ExpressHttpServer.test.ts
Expand Up @@ -72,7 +72,7 @@ describe('ExpressHttpServer', (): void => {
.map((method: string): string => method.trim());
const allowedMethods = [ 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE' ];
expect(corsMethods).toEqual(expect.arrayContaining(allowedMethods));
expect(corsMethods.length).toBe(allowedMethods.length);
expect(corsMethods).toHaveLength(allowedMethods.length);
});

it('specifies CORS origin header if an origin was supplied.', async(): Promise<void> => {
Expand Down
5 changes: 3 additions & 2 deletions test/unit/storage/LockingResourceStore.test.ts
Expand Up @@ -123,6 +123,7 @@ describe('A LockingResourceStore', (): void => {
it('destroys the resource and releases the lock when the readable errors.', async(): Promise<void> => {
// Make the representation error
const representation = await store.getRepresentation({ path: 'path' }, {});
// eslint-disable-next-line jest/valid-expect-in-promise
Promise.resolve().then((): any =>
representation.data.emit('error', new Error('Error on the readable')), null);
await registerEventOrder(representation.data, 'error');
Expand Down Expand Up @@ -176,7 +177,7 @@ describe('A LockingResourceStore', (): void => {

// Wait 1000ms and read
jest.advanceTimersByTime(1000);
expect(representation.data.read()).toBe(null);
expect(representation.data.read()).toBeNull();
await registerEventOrder(representation.data, 'close');

// Verify a timeout error was thrown
Expand Down Expand Up @@ -207,7 +208,7 @@ describe('A LockingResourceStore', (): void => {

// Wait 1000ms and watch the stream be destroyed
jest.advanceTimersByTime(1000);
expect(representation.data.read()).toBe(null);
expect(representation.data.read()).toBeNull();
await registerEventOrder(representation.data, 'close');

// Verify a timeout error was thrown
Expand Down
1 change: 1 addition & 0 deletions test/unit/storage/SingleThreadedResourceLocker.test.ts
Expand Up @@ -23,6 +23,7 @@ describe('A SingleThreadedResourceLocker', (): void => {
expect(lock).toEqual(expect.objectContaining({ release: expect.any(Function) }));
});

/* eslint-disable jest/valid-expect-in-promise */
it('blocks lock acquisition until they are released.', async(): Promise<void> => {
const results: number[] = [];
const lock1 = locker.acquire({ path: 'path' });
Expand Down
4 changes: 2 additions & 2 deletions test/unit/storage/accessors/FileDataAccessor.test.ts
Expand Up @@ -129,11 +129,11 @@ describe('A FileDataAccessor', (): void => {
it('adds stored metadata when requesting metadata.', async(): Promise<void> => {
cache.data = { resource: 'data', 'resource.meta': '<this> <is> <metadata>.' };
metadata = await accessor.getMetadata({ path: `${base}resource` });
expect(metadata.quads().some((quad): boolean => quad.subject.value === 'this'));
expect(metadata.quads().some((quad): boolean => quad.subject.value === 'this')).toBe(true);

cache.data = { container: { '.meta': '<this> <is> <metadata>.' }};
metadata = await accessor.getMetadata({ path: `${base}container/` });
expect(metadata.quads().some((quad): boolean => quad.subject.value === 'this'));
expect(metadata.quads().some((quad): boolean => quad.subject.value === 'this')).toBe(true);
});

it('throws an error if there is a problem with the internal metadata.', async(): Promise<void> => {
Expand Down
19 changes: 10 additions & 9 deletions test/unit/storage/patch/SparqlUpdatePatchHandler.test.ts
Expand Up @@ -63,7 +63,7 @@ describe('A SparqlUpdatePatchHandler', (): void => {
handler = new SparqlUpdatePatchHandler(source, locker);
});

const basicChecks = async(quads: Quad[]): Promise<void> => {
const basicChecks = async(quads: Quad[]): Promise<boolean> => {
expect(source.getRepresentation).toHaveBeenCalledTimes(1);
expect(source.getRepresentation).toHaveBeenLastCalledWith(
{ path: 'path' }, { type: [{ value: INTERNAL_QUADS, weight: 1 }]},
Expand All @@ -78,6 +78,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> => {
Expand All @@ -95,10 +96,10 @@ describe('A SparqlUpdatePatchHandler', (): void => {
'<http://test.com/s2> <http://test.com/p2> <http://test.com/o2> }',
{ quads: true },
) } as SparqlUpdatePatch });
await basicChecks(startQuads.concat(
expect(await basicChecks(startQuads.concat(
[ quad(namedNode('http://test.com/s1'), namedNode('http://test.com/p1'), namedNode('http://test.com/o1')),
quad(namedNode('http://test.com/s2'), namedNode('http://test.com/p2'), namedNode('http://test.com/o2')) ],
));
))).toBe(true);
});

it('handles DELETE DATA updates.', async(): Promise<void> => {
Expand All @@ -107,11 +108,11 @@ describe('A SparqlUpdatePatchHandler', (): void => {
'DELETE DATA { <http://test.com/startS1> <http://test.com/startP1> <http://test.com/startO1> }',
{ quads: true },
) } as SparqlUpdatePatch });
await basicChecks(
expect(await basicChecks(
[ quad(namedNode('http://test.com/startS2'),
namedNode('http://test.com/startP2'),
namedNode('http://test.com/startO2')) ],
);
)).toBe(true);
});

it('handles DELETE WHERE updates with no variables.', async(): Promise<void> => {
Expand All @@ -120,11 +121,11 @@ describe('A SparqlUpdatePatchHandler', (): void => {
'DELETE WHERE { <http://test.com/startS1> <http://test.com/startP1> <http://test.com/startO1> }',
{ quads: true },
) } as SparqlUpdatePatch });
await basicChecks(
expect(await basicChecks(
[ quad(namedNode('http://test.com/startS2'),
namedNode('http://test.com/startP2'),
namedNode('http://test.com/startO2')) ],
);
)).toBe(true);
});

it('handles DELETE/INSERT updates with empty WHERE.', async(): Promise<void> => {
Expand All @@ -135,14 +136,14 @@ describe('A SparqlUpdatePatchHandler', (): void => {
'WHERE {}',
{ quads: true },
) } as SparqlUpdatePatch });
await basicChecks([
expect(await basicChecks([
quad(namedNode('http://test.com/startS2'),
namedNode('http://test.com/startP2'),
namedNode('http://test.com/startO2')),
quad(namedNode('http://test.com/s1'),
namedNode('http://test.com/p1'),
namedNode('http://test.com/o1')),
]);
])).toBe(true);
});

it('rejects GRAPH inserts.', async(): Promise<void> => {
Expand Down
1 change: 1 addition & 0 deletions test/util/TestHelpers.ts
Expand Up @@ -14,6 +14,7 @@ import type { HttpRequest } from '../../src/server/HttpRequest';
import { CONTENT_TYPE } from '../../src/util/UriConstants';
import { call } from './Util';

/* eslint-disable jest/no-standalone-expect */
export class AclTestHelper {
public readonly store: ResourceStore;
public id: string;
Expand Down

0 comments on commit 88aa386

Please sign in to comment.