Skip to content

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiller1990 committed Jun 7, 2021
1 parent c4569eb commit 5af8b76
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions npm/webpack-preprocessor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ const preprocessor: WebpackPreprocessor = (options: PreprocessorOptions = {}): F
// Seems to be a race condition where changing file before next tick
// does not cause build to rerun
Promise.delay(0).then(() => {
if (!bundles[filePath]) {
return
}

bundles[filePath].deferreds.forEach((deferred) => {
deferred.resolve(outputPath)
})
Expand Down Expand Up @@ -386,6 +390,12 @@ preprocessor.__reset = () => {
bundles = {}
}

// for testing purposes, but do not add this to the typescript interface
// @ts-ignore
preprocessor.__bundles = () => {
return bundles
}

function cleanseError (err: string) {
return err.replace(/\n\s*at.*/g, '').replace(/From previous event:\n?/g, '')
}
Expand Down
3 changes: 3 additions & 0 deletions npm/webpack-preprocessor/test/unit/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ describe('webpack preprocessor', function () {
})

it('runs webpack', function () {
expect(preprocessor.__bundles()[this.file.filePath]).to.be.undefined

return this.run().then(() => {
expect(preprocessor.__bundles()[this.file.filePath].deferreds).to.be.empty
expect(webpack).to.be.called
})
})
Expand Down

0 comments on commit 5af8b76

Please sign in to comment.