Skip to content

Commit

Permalink
Fix notify not firing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
willbamford committed Nov 16, 2016
1 parent 94a5a19 commit e32488f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
8 changes: 5 additions & 3 deletions lib/create-job.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
34 changes: 20 additions & 14 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

Expand Down

0 comments on commit e32488f

Please sign in to comment.