diff --git a/example-esm/lib/foo.json b/example-esm/lib/foo.json new file mode 100644 index 0000000..99de2d7 --- /dev/null +++ b/example-esm/lib/foo.json @@ -0,0 +1,3 @@ +{ + "quibble": "rocks" +} diff --git a/example-esm/test/helper.js b/example-esm/test/helper.js index fc0fc3f..f24aa8f 100644 --- a/example-esm/test/helper.js +++ b/example-esm/test/helper.js @@ -4,6 +4,7 @@ const quibble = require('quibble') beforeEach(function () { quibble.esm('../lib/animals/bear.mjs', undefined, function () { return 'a fake bear' }) quibble.esm('../lib/animals/lion.mjs', undefined, function () { return 'a fake lion' }) + quibble.esm('../lib/foo.json', undefined, { 'hello': 'quibble' }) }) afterEach(function () { diff --git a/example-esm/test/lib/zoo-spec.mjs b/example-esm/test/lib/zoo-spec.mjs index 0a7aba7..aa75a2b 100644 --- a/example-esm/test/lib/zoo-spec.mjs +++ b/example-esm/test/lib/zoo-spec.mjs @@ -5,9 +5,11 @@ const { expect } = chai describe('zoo', function () { var subject + var json beforeEach(async function () { subject = await import('../../lib/zoo.mjs') + json = await import('../../lib/foo.json') }) it('contains a fake bear', function () { @@ -17,4 +19,8 @@ describe('zoo', function () { it('contains a fake lion', function () { expect(subject.default().animals).to.contain('a fake lion') }) + + it('manipulates json', function () { + expect(json.default).to.deep.equal({ hello: 'quibble' }) + }) }) diff --git a/lib/quibble.mjs b/lib/quibble.mjs index a97707a..924be13 100644 --- a/lib/quibble.mjs +++ b/lib/quibble.mjs @@ -114,8 +114,9 @@ ${ */ export async function load (url, context, defaultLoad) { const stubsInfo = getStubsInfo(new URL(url)) + const isJson = url.endsWith('.json') return stubsInfo - ? { source: transformModuleSource(stubsInfo), format: 'module' } + ? { source: transformModuleSource(stubsInfo), format: isJson ? 'json' : 'module' } : defaultLoad(url, context, defaultLoad) }