Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/rdf/PrefetchedDocumentLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ export class PrefetchedDocumentLoader extends FetchDocumentLoader {
public static readonly contextPattern: RegExp =
/https:\/\/linkedsoftwaredependencies.org\/bundles\/npm\/componentsjs\/\^([0-9]+).0.0\/components\/context.jsonld/u;

/**
* @deprecated Use {@link PrefetchedDocumentLoader.cjsMajorVersion} instead.
*/
// eslint-disable-next-line ts/naming-convention
public static readonly CJS_MAJOR_VERSION: number = PrefetchedDocumentLoader.cjsMajorVersion;

/**
* @deprecated Use {@link PrefetchedDocumentLoader.contextUrl} instead.
*/
// eslint-disable-next-line ts/naming-convention
public static readonly CONTEXT_URL: string = PrefetchedDocumentLoader.contextUrl;

/**
* @deprecated Use {@link PrefetchedDocumentLoader.contextPattern} instead.
*/
// eslint-disable-next-line ts/naming-convention
public static readonly CONTEXT_PATTERN: RegExp = PrefetchedDocumentLoader.contextPattern;

private static readonly defaultContext: any = contextJson;

private static readonly defaultContexts: Record<string, any> = {
Expand Down
8 changes: 8 additions & 0 deletions test/unit/rdf/PrefetchedDocumentLoader-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ describe('PrefetchedDocumentLoader', () => {
});
});

describe('deprecated static fields', () => {
it('equal their renamed fields', () => {
expect(PrefetchedDocumentLoader.CJS_MAJOR_VERSION).toBe(PrefetchedDocumentLoader.cjsMajorVersion);
expect(PrefetchedDocumentLoader.CONTEXT_URL).toBe(PrefetchedDocumentLoader.contextUrl);
expect(PrefetchedDocumentLoader.CONTEXT_PATTERN).toBe(PrefetchedDocumentLoader.contextPattern);
});
});

describe('load', () => {
it('for a prefetched context', async() => {
await expect(loader.load('http://example.org/context')).resolves
Expand Down
15 changes: 15 additions & 0 deletions test/unit/rdf/RdfParser-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,17 @@ describe('RdfParser', () => {
});

it('for a Turtle stream with a slow import followed by an import to unknown file', async() => {
const parse = RdfParser.prototype.parse;
let resolveSlowImport: () => void;
const slowImportEnded = new Promise<void>(resolve => resolveSlowImport = resolve);
const parseSpy = jest.spyOn(RdfParser.prototype, 'parse')
.mockImplementation(function(this: RdfParser, textStream, parseOptions) {
const stream = parse.call(this, textStream, parseOptions);
if (parseOptions.path === 'http://example.org/myfileslow.ttl') {
stream.on('end', () => resolveSlowImport());
}
return stream;
});
const options: RdfParserOptions = {
path: 'path/to/file.ttl',
};
Expand All @@ -431,6 +442,10 @@ describe('RdfParser', () => {
`;
await expect(arrayifyStream(parser.parse(streamifyString(doc), options))).rejects
.toThrow(new Error(`Error while parsing file "path/to/file.ttl": URL not found: http://example.org/myfileunknown.ttl`));

// The slow import is still being parsed, so it must end before this test does
await slowImportEnded;
parseSpy.mockRestore();
});

it('for a Turtle stream with imports and a blank node prefix should derive prefixes for imports', async() => {
Expand Down
Loading