1 | 'use strict'
|
2 |
|
3 | const path = require('path')
|
4 |
|
5 |
|
6 | module.exports = function loadFixtures (filePath, module) {
|
7 | if (module) {
|
8 | filePath = path.join(module, filePath)
|
9 | }
|
10 |
|
11 | const fs = require('fs')
|
12 | const paths = [
|
13 | path.join(process.cwd(), filePath),
|
14 | path.join(process.cwd(), 'node_modules', filePath),
|
15 | resolve(filePath)
|
16 | ]
|
17 |
|
18 | const resourcePath = paths.find(path => fs.existsSync(path))
|
19 |
|
20 | if (!resourcePath) {
|
21 | throw new Error(`Could not load ${filePath}`)
|
22 | }
|
23 |
|
24 | return fs.readFileSync(resourcePath)
|
25 | }
|
26 |
|
27 | function resolve (filePath) {
|
28 | try {
|
29 | return require.resolve(filePath)
|
30 | } catch (error) {
|
31 |
|
32 | }
|
33 | }
|