Skip to content
This repository has been archived by the owner on Mar 5, 2022. It is now read-only.

Commit

Permalink
fix: encode image
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Apr 16, 2020
1 parent a62fc22 commit 4dbee03
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions plugins/utils/redirect-resource.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const debug = require('debug')('cypress-react-unit-test')
const path = require('path')
const mime = require('mime-types')
const fs = require('fs')

/**
* User code:
Expand All @@ -10,7 +11,7 @@ const mime = require('mime-types')
* image is "/__root/path/to/image.png"
* <img src={image} />
*/
function staticResourceLoader(content) {
function staticResourceLoader() {
debug('loading static resource %s', this.resourcePath)
debug('cwd', process.cwd())
const relativeResourcePath = path.relative(process.cwd(), this.resourcePath)
Expand All @@ -20,7 +21,8 @@ function staticResourceLoader(content) {
debug('resource is outside of the current working directory')
debug('inlining it instead (performance hit!)')
const mimetype = mime.lookup(this.resourcePath)
const encoded = content.toString('base64')
const content = fs.readFileSync(this.resourcePath)
const encoded = new Buffer(content).toString('base64')
return `module.exports = "data:${mimetype};base64,${encoded}"`
}

Expand Down

0 comments on commit 4dbee03

Please sign in to comment.