JSON-LD Conformance Test Suite
The `json-ld-test-suite` npm package provides a snapshot of the official JSON-LD Conformance Test Suite, designed to verify the compliance of JSON-LD processors against the JSON-LD 1.0 and 1.1 specifications. While this specific npm package (version 1.0.1) was last published over eight years ago and is effectively abandoned, the underlying JSON-LD Test Suite on GitHub (json-ld/json-ld.org) remains actively maintained and updated by the JSON-LD community. This suite is crucial for implementers, offering test cases for operations such as compaction, expansion, framing, normalization, and RDF conversion. It differentiates itself by being the authoritative W3C test suite, essential for ensuring interoperability and specification adherence across different JSON-LD processor implementations, though consumers of *this npm package* should be aware of its static nature.
Common errors
-
Error: Cannot find module 'json-ld-test-suite/manifest.jsonld'
cause Incorrect path or attempting to import a non-existent JavaScript module. The `manifest.jsonld` file is located within the `tests/` subdirectory of the package.fixUse the correct full path to the JSON file: `import manifest from 'json-ld-test-suite/tests/manifest.jsonld'` (ESM) or `const manifest = require('json-ld-test-suite/tests/manifest.jsonld')` (CJS). -
SyntaxError: Unexpected token '<' at JSON.parse (<anonymous>)
cause Attempting to parse an XML/HTML file (like vocab.html) or a non-JSON file (like .sparql) as JSON. This can happen if the wrong file is targeted or if a raw import of a `.sparql` file is not handled correctly.fixEnsure you are targeting actual JSON-LD (`.jsonld`) files for `JSON.parse`. For `.sparql` files, read them as plain text/strings. For example, using a raw import query parameter in ESM (`import query from './my.sparql?raw'`).
Warnings
- gotcha This npm package (json-ld-test-suite@1.0.1) has not been updated in over eight years. While the underlying JSON-LD Conformance Test Suite at json-ld/json-ld.org is actively maintained, updates to the test suite data are not reflected in this npm package. Users requiring the latest test data should consider fetching directly from the GitHub repository or using a different distribution method.
- gotcha Tests are often marked with specific `processingMode` requirements (e.g., `json-ld-1.0` or `json-ld-1.1`). Processors must only run tests compatible with their implemented JSON-LD version, otherwise, false positives or negatives will occur.
- gotcha Due to its community-driven nature, the JSON-LD Test Suite (the upstream data, not this npm package) 'may become unstable from time to time.' This means new test contributions or fixes could temporarily introduce regressions or inconsistencies, which are typically resolved quickly.
Install
-
npm install json-ld-test-suite -
yarn add json-ld-test-suite -
pnpm add json-ld-test-suite
Imports
- manifest
const manifest = require('json-ld-test-suite/manifest.jsonld')import manifest from 'json-ld-test-suite/tests/manifest.jsonld'
- testCase
const testCase = require('json-ld-test-suite/compact-0001-in.jsonld')import testCase from 'json-ld-test-suite/tests/compact-0001-in.jsonld'
- sparqlQuery
import sparqlQuery from 'json-ld-test-suite/tests/rdf-0001.sparql?raw'
Quickstart
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
// Assuming the package is installed at node_modules/json-ld-test-suite
const packageRoot = join(__dirname, '../node_modules/json-ld-test-suite');
// Load the main manifest for all tests
const manifestPath = join(packageRoot, 'tests/manifest.jsonld');
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
console.log(`Loaded JSON-LD Test Suite Manifest (v${manifest.version || 'unknown'})`);
console.log(`Number of manifests: ${manifest.sequence.length}`);
// Example: Accessing a specific test entry
const firstManifest = manifest.sequence[0];
console.log(`First test manifest type: ${firstManifest['@type']}`);
// To load an actual test input file, you'd typically iterate through the manifest
// and construct paths based on the 'input' property of each test entry.
// For example, if a test entry has 'input': 'compact-0001-in.jsonld'
const exampleInputPath = join(packageRoot, 'tests/compact-0001-in.jsonld');
const exampleInput = JSON.parse(readFileSync(exampleInputPath, 'utf8'));
console.log('Example test input data:', exampleInput);