UNPKG

mock-fs-require-fix

Version:

Fork of the tschaub/mock-fs project.

65 lines (53 loc) 1.73 kB
'use strict'; var chai = require('chai'); var constants = require('constants'); /** @type {boolean} */ chai.config.includeStack = true; /** * Chai's assert function configured to include stacks on failure. * @type {function} */ exports.assert = chai.assert; /** * Convert a string to flags for fs.open. * @param {string} str String. * @return {number} Flags. */ exports.flags = function(str) { switch (str) { case 'r': return constants.O_RDONLY; case 'rs': return constants.O_RDONLY | constants.O_SYNC; case 'r+': return constants.O_RDWR; case 'rs+': return constants.O_RDWR | constants.O_SYNC; case 'w': return constants.O_TRUNC | constants.O_CREAT | constants.O_WRONLY; case 'wx': // fall through case 'xw': return constants.O_TRUNC | constants.O_CREAT | constants.O_WRONLY | constants.O_EXCL; case 'w+': return constants.O_TRUNC | constants.O_CREAT | constants.O_RDWR; case 'wx+': // fall through case 'xw+': return constants.O_TRUNC | constants.O_CREAT | constants.O_RDWR | constants.O_EXCL; case 'a': return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY; case 'ax': // fall through case 'xa': return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY | constants.O_EXCL; case 'a+': return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR; case 'ax+': // fall through case 'xa+': return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR | constants.O_EXCL; default: throw new Error('Unsupported flag: ' + str); } };