diff --git a/lib/module.js b/lib/module.js index ef0fad209ff9c8..3dc966b770f38e 100644 --- a/lib/module.js +++ b/lib/module.js @@ -444,6 +444,8 @@ Module._extensions['.json'] = function(module, filename) { } }; +// Native extension for .jsonld, same as JSON (but different MIME type) +Module._extensions['.jsonld'] = Module._extensions['.json']; //Native extension for .node Module._extensions['.node'] = function(module, filename) { diff --git a/test/fixtures/elementary.jsonld b/test/fixtures/elementary.jsonld new file mode 100644 index 00000000000000..1c6a141ed28c12 --- /dev/null +++ b/test/fixtures/elementary.jsonld @@ -0,0 +1,3 @@ +{ + "@id": "moo" +} diff --git a/test/fixtures/invalid.jsonld b/test/fixtures/invalid.jsonld new file mode 100644 index 00000000000000..f5ba6ca634c28e --- /dev/null +++ b/test/fixtures/invalid.jsonld @@ -0,0 +1,4 @@ +{ + "@id": "moo" + "@type": "http://example.org" +} diff --git a/test/parallel/test-require-jsonld.js b/test/parallel/test-require-jsonld.js new file mode 100644 index 00000000000000..679b841a7bce6b --- /dev/null +++ b/test/parallel/test-require-jsonld.js @@ -0,0 +1,14 @@ +'use strict'; +require('../common'); +const assert = require('assert'); + +assert.throws( + function() { + require('../fixtures/invalid.jsonld'); + }, + /test[\/\\]fixtures[\/\\]invalid.jsonld: Unexpected string/, + 'require() jsonld error should include path' +); + +var ld = require('../fixtures/elementary.jsonld'); +assert.strictEqual(ld['@id'], 'moo', 'require() loads jsonld');