rdf-test-suite
Version:
Executes the RDF and SPARQL test suites.
143 lines (141 loc) • 6.32 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const node_fs_1 = require("node:fs");
const Path = __importStar(require("node:path"));
// eslint-disable-next-line ts/no-require-imports
const minimist = require("minimist");
const n3_1 = require("n3");
const TestSuiteRunner_1 = require("../lib/TestSuiteRunner");
const args = minimist(process.argv.slice(2));
if (args._.length < 2) {
console.error(`sparql-test executes SPARQL test suites
Usage:
rdf-test-suite path/to/myengine.js http://w3c.github.io/rdf-tests/sparql11/data-sparql11/manifest-all.ttl
rdf-test-suite path/to/myengine.js http://w3c.github.io/rdf-tests/sparql11/data-sparql11/manifest-all.ttl \
-s http://www.w3.org/TR/sparql11-query/
rdf-test-suite path/to/myengine.js http://w3c.github.io/rdf-tests/sparql11/data-sparql11/manifest-all.ttl \
-o earl -p earl-meta.json > earl.ttl
Options:
-o output format (detailed, summary, eurl, ... defaults to detailed)
-p file with earl properties, autogenerated from package.json if not available (only needed for EARL reports)
-s a specification URI to filter by (e.g. http://www.w3.org/TR/sparql11-query/)
-c enable HTTP caching at the given directory (disabled by default)
-e always exit with status code 0 on test errors
-t regex for test IRIs to run
--skip regex for test IRIs to skip
-i JSON string with custom options that need to be passed to the engine
-d time out duration for test cases (in milliseconds, default 3000)
-m URL to local path mapping (e.g. 'https://w3c.github.io/json-ld-api/|/path/to/folder/')
-a Only run tests that have an explicit rdft:Accepted status [default: false]
-r Run tests that have an explicit rdft:Rejected status [default: false]
`);
process.exit(1);
}
// Enable caching if needed
let cachePath = null;
if (args.c) {
cachePath = Path.join(process.cwd(), (args.c === true ? '.rdf-test-suite-cache/' : args.c));
if (!(0, node_fs_1.existsSync)(cachePath)) {
(0, node_fs_1.mkdirSync)(cachePath);
}
}
// Import the engine
// eslint-disable-next-line ts/no-require-imports, ts/no-var-requires
const engine = require(`${process.cwd()}/${args._[0]}`);
const defaultConfig = {
exitWithStatusCode0: false,
outputFormat: 'detailed',
timeOutDuration: 3000,
};
const config = {
cachePath,
customEngingeOptions: args.i ? JSON.parse(args.i) : {},
exitWithStatusCode0: Boolean(args.e) || defaultConfig.exitWithStatusCode0,
outputFormat: args.o || defaultConfig.outputFormat,
specification: args.s,
testRegex: new RegExp(args.t, 'u'),
skipRegex: args.skip ? new RegExp(args.skip, 'u') : undefined,
timeOutDuration: args.d || defaultConfig.timeOutDuration,
urlToFileMapping: args.m,
runRejected: Boolean(args.r),
explicitApproval: Boolean(args.a),
};
// Fetch the manifest, run the tests, and print them
const testSuiteRunner = new TestSuiteRunner_1.TestSuiteRunner();
testSuiteRunner.runManifest(args._[1], engine, config)
.then((testResults) => {
switch (config.outputFormat) {
case 'earl':
if (!args.p) {
throw new Error(`EARL reporting requires the -p argument to point to an earl-meta.json file.`);
}
// Create properties file if it does not exist
if (!(0, node_fs_1.existsSync)(Path.join(process.cwd(), args.p))) {
// eslint-disable-next-line ts/no-require-imports, ts/no-var-requires
(0, node_fs_1.writeFileSync)(Path.join(process.cwd(), args.p), JSON.stringify(testSuiteRunner.packageJsonToEarlProperties(require(Path.join(process.cwd(), 'package.json'))), null, ' '));
}
// eslint-disable-next-line ts/no-require-imports, ts/no-var-requires
testSuiteRunner.resultsToEarl(testResults, require(Path.join(process.cwd(), args.p)), new Date())
// eslint-disable-next-line ts/no-require-imports
.pipe(new n3_1.StreamWriter({ format: 'text/turtle', prefixes: require('../lib/prefixes.json') }))
.pipe(process.stdout)
.on('end', () => onEnd(testResults));
break;
case 'summary':
testSuiteRunner.resultsToText(process.stdout, testResults, true);
onEnd(testResults);
break;
default:
testSuiteRunner.resultsToText(process.stdout, testResults, false);
onEnd(testResults);
break;
}
}).catch((e) => {
console.error(e);
process.exit(1);
});
function onEnd(testResults) {
// Exit with status code 1 if there was at least one failing test
if (!config.exitWithStatusCode0) {
for (const testResult of testResults) {
if (!testResult.skipped && !testResult.ok) {
process.exit(1);
}
}
}
}
//# sourceMappingURL=Runner.js.map