1 | 'use strict'
|
2 |
|
3 | var join = require('path').join
|
4 | var fs = require('fs')
|
5 |
|
6 | function Fixture (path) {
|
7 | if (!(this instanceof Fixture)) return new Fixture(path)
|
8 | this.root = path
|
9 | }
|
10 |
|
11 | Fixture.root = join(__dirname, '../../fixture')
|
12 |
|
13 | Fixture.prototype.path = function (file) {
|
14 | return join(Fixture.root, this.root, file || '')
|
15 | }
|
16 |
|
17 | Fixture.prototype.exists = function (file) {
|
18 | try {
|
19 | fs.statSync(this.path(file))
|
20 | return true
|
21 | } catch (e) { return false }
|
22 | }
|
23 |
|
24 | Fixture.prototype.read = function (file) {
|
25 | return fs.readFileSync(this.path(file), 'utf-8')
|
26 | }
|
27 |
|
28 | module.exports = Fixture
|