diff --git a/lib/create-job.js b/lib/create-job.js index 9d0fdf1..97eac99 100644 --- a/lib/create-job.js +++ b/lib/create-job.js @@ -17,9 +17,11 @@ function createJob (src, node, loaders) { } function notify (err, resource, job) { - listeners.forEach(function (cb) { - cb(err, resource, job) - }) + setTimeout(function () { + listeners.forEach(function (cb) { + cb(err, resource, job) + }) + }, 0) return job } diff --git a/package.json b/package.json index 4a7a2c7..02172a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "getres", - "version": "1.2.3", + "version": "1.3.0", "description": "Universal Resource Loader for the Browser and Node.js", "main": "lib", "browser": { diff --git a/test/index.js b/test/index.js index 560f93c..9bfb3df 100644 --- a/test/index.js +++ b/test/index.js @@ -662,26 +662,32 @@ test.cb('send http credentials', (t) => { }) test('register custom loaders', (t) => { - const { getres } = createGetres() + const { getres } = createGetres({ + '/foo.txt': { body: 'Foo' } + }) getres - .register('twinsen', (node, cb) => { + .register('twinsen', function twinsen (node, cb) { cb(null, 'Twinsen ' + node.src) }) - .register('joe', (node, cb) => 'the-elf') + .register('zoe', function zoe (node, cb) { + cb(null, 'Zoe ' + node.src) + }) - return getres({ - zoe: { - src: 'some-file', - type: 'twinsen' - }, - elf: { - src: 'another-file', - type: 'joe' + return getres( + { + twinsen: { + src: 'CITADEL.txt', + type: 'twinsen' + }, + zoe: { + src: 'TWINSEN.txt', + type: 'zoe' + } } - }).then(({ zoe, elf }) => { - t.is(zoe, 'Twinsen some-file') - t.is(elf, 'the-elf') + ).then(({ twinsen, zoe }) => { + t.is(twinsen, 'Twinsen CITADEL.txt') + t.is(zoe, 'Zoe TWINSEN.txt') }) })