Skip to content

Commit

Permalink
test: fix FS race condition in #build should return a promise only wh…
Browse files Browse the repository at this point in the history
…en callback omitted
  • Loading branch information
webketje committed May 7, 2023
1 parent dbfe32a commit 3a93270
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions test/index.js
Expand Up @@ -1242,14 +1242,21 @@ describe('Metalsmith', function () {
it('should return a promise only when callback is omitted', function (done) {
const m = Metalsmith(fixture('basic'))

assert.strictEqual(
m.build(() => {}),
undefined
)

m.build()
.then((files) => {
assert.strictEqual(typeof files, 'object')
//2 builds on the same metalsmith instance have to be executed sequentially in order not to create race conditions
const promiseReturnValue = m
.build()
.then(
() =>
new Promise((resolve, reject) => {
const returnValue = m.build((err) => {
if (err) reject(err)
resolve(returnValue)
})
})
)
.then((callbackReturnValue) => {
assert.strictEqual(typeof callbackReturnValue, 'undefined')
assert(promiseReturnValue instanceof Promise)
done()
})
.catch(done)
Expand Down

0 comments on commit 3a93270

Please sign in to comment.