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

Commit 4dbee03

Browse files
committed
fix: encode image
1 parent a62fc22 commit 4dbee03

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

plugins/utils/redirect-resource.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const debug = require('debug')('cypress-react-unit-test')
22
const path = require('path')
33
const mime = require('mime-types')
4+
const fs = require('fs')
45

56
/**
67
* User code:
@@ -10,7 +11,7 @@ const mime = require('mime-types')
1011
* image is "/__root/path/to/image.png"
1112
* <img src={image} />
1213
*/
13-
function staticResourceLoader(content) {
14+
function staticResourceLoader() {
1415
debug('loading static resource %s', this.resourcePath)
1516
debug('cwd', process.cwd())
1617
const relativeResourcePath = path.relative(process.cwd(), this.resourcePath)
@@ -20,7 +21,8 @@ function staticResourceLoader(content) {
2021
debug('resource is outside of the current working directory')
2122
debug('inlining it instead (performance hit!)')
2223
const mimetype = mime.lookup(this.resourcePath)
23-
const encoded = content.toString('base64')
24+
const content = fs.readFileSync(this.resourcePath)
25+
const encoded = new Buffer(content).toString('base64')
2426
return `module.exports = "data:${mimetype};base64,${encoded}"`
2527
}
2628

0 commit comments

Comments
 (0)