pinafore/tests/loadMedia.cjs
Nolan Lawson 16e66346d7
fix!: remove esm package, use native Node ES modules (#2064)
BREAKING CHANGE: Node v12.20+, v14.14+, or v16.0+ is required

* fix!: remove esm package, use native Node ES modules

* fix: fix some CJS imports
2021-07-04 20:19:04 -07:00

14 lines
444 B
JavaScript

const fs = require('fs')
const path = require('path')
// Have to use CJS so this file can run in TestCafe. Otherwise it's impossible to get __dirname to work in both envs
const dirname = __dirname
exports.loadMedia = function loadMedia (filename) {
const filepath = path.join(dirname, 'images', filename)
if (!fs.existsSync(filepath)) {
throw new Error('File does not exist: ' + filepath)
}
return fs.createReadStream(filepath)
}