Skip to content
This repository has been archived by the owner on Aug 14, 2024. It is now read-only.

Commit

Permalink
Expect content to be a buffer and not a string
Browse files Browse the repository at this point in the history
  • Loading branch information
fbaiodias committed Jul 31, 2018
1 parent 6f91ddb commit 090d499
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = function (content) {
this.cacheable && this.cacheable()
this.value = content

return `module.exports = Buffer.from("${content}")`
return `module.exports = Buffer.from("${content.toString('base64')}", "base64")`
}

module.exports.raw = true
6 changes: 4 additions & 2 deletions index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ const loader = require('.')

describe('buffer-loader', () => {
it('returns a buffer with the content', () => {
const content = 'some random content'
const contentString = 'some random content'
const content = Buffer.from(contentString, 'utf-8')
const output = loader(content)
const buffer = nodeEval(output)

expect(buffer.toString()).toEqual(content)
expect(buffer).toEqual(content)
expect(buffer.toString()).toEqual(contentString)
})
})

1 comment on commit 090d499

@jonathanperret
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most common use case for buffer-loader is probably binary files, not text. So I would rather test here with a buffer containing non-text data, e.g. const content = Buffer.from([0, 1, 2, 3]). And drop the assertion on buffer.toString() which does not add anything IMHO.

Please sign in to comment.