UNPKG

rdf-test-suite

Version:
73 lines 3.95 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ManifestLoader = void 0; const rdf_object_1 = require("rdf-object"); const rdf_string_1 = require("rdf-string"); const IManifest_1 = require("./IManifest"); const Util_1 = require("./Util"); /** * A ManifestLoader loads test suites from URLs. */ class ManifestLoader { constructor(args) { if (!args) { args = {}; } this.testCaseHandlers = args.testCaseHandlers || ManifestLoader.DEFAULT_TEST_CASE_HANDLERS; } /** * Load the manifest from the given URL. * @param {string} url The URL of a manifest. * @param {IFetchOptions} options The fetch options. * @return {Promise<IManifest>} A promise that resolves to a manifest object. */ from(url, options) { return __awaiter(this, void 0, void 0, function* () { const objectLoader = new rdf_object_1.RdfObjectLoader({ context: ManifestLoader.LOADER_CONTEXT }); const manifest = yield this.import(objectLoader, url, options); return (0, IManifest_1.manifestFromResource)(this.testCaseHandlers, options, manifest, objectLoader); }); } import(objectLoader, urlInitial, options) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d; const [url, parsed] = yield Util_1.Util.fetchRdf(urlInitial, options); // Dereference the URL and load it yield objectLoader.import(parsed); // Import all sub-manifests let manifest = // First try the same URL as the document URL (_b = (_a = objectLoader.resources[url]) !== null && _a !== void 0 ? _a : objectLoader.resources[url.slice(0, url.lastIndexOf('.'))]) !== null && _b !== void 0 ? _b : objectLoader.resources[url.slice(0, url.lastIndexOf('.')).replace(/\/manifest$/, '#manifest')]; if (!manifest) { throw new Error(`Could not find a resource ${url} in the document at ${url}`); } const includeJobs = []; for (const includeList of manifest.properties.include) { for (const include of includeList.list) { if (include.term.termType !== 'NamedNode') { throw new Error(`Found invalid manifest term ${(0, rdf_string_1.termToString)(include.term)} when parsing ${url}`); } includeJobs.push(this.import(objectLoader, include.value, options)); } } const jobs = yield Promise.all(includeJobs); manifest = // First try the same URL as the document URL (_d = (_c = objectLoader.resources[url]) !== null && _c !== void 0 ? _c : objectLoader.resources[url.slice(0, url.lastIndexOf('.'))]) !== null && _d !== void 0 ? _d : objectLoader.resources[url.slice(0, url.lastIndexOf('.')).replace(/\/manifest$/, '#manifest')]; return manifest; }); } } exports.ManifestLoader = ManifestLoader; ManifestLoader.DEFAULT_TEST_CASE_HANDLERS = require('./testcase/TestCaseHandlers'); ManifestLoader.LOADER_CONTEXT = require('./context-manifest.json'); //# sourceMappingURL=ManifestLoader.js.map