UNPKG

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