UNPKG

1.61 kBJavaScriptView Raw
1var chai = require('chai');
2
3
4/** @type {boolean} */
5chai.Assertion.includeStack = true;
6
7
8/**
9 * Chai's assert function configured to include stacks on failure.
10 * @type {function}
11 */
12exports.assert = chai.assert;
13
14
15var constants = process.binding('constants');
16
17
18/**
19 * Convert a string to flags for fs.open.
20 * @param {string} str String.
21 * @return {number} Flags.
22 */
23exports.flags = function(str) {
24 switch (str) {
25 case 'r' :
26 return constants.O_RDONLY;
27 case 'rs' :
28 return constants.O_RDONLY | constants.O_SYNC;
29 case 'r+' :
30 return constants.O_RDWR;
31 case 'rs+' :
32 return constants.O_RDWR | constants.O_SYNC;
33
34 case 'w' :
35 return constants.O_TRUNC | constants.O_CREAT | constants.O_WRONLY;
36 case 'wx' : // fall through
37 case 'xw' :
38 return constants.O_TRUNC | constants.O_CREAT | constants.O_WRONLY |
39 constants.O_EXCL;
40
41 case 'w+' :
42 return constants.O_TRUNC | constants.O_CREAT | constants.O_RDWR;
43 case 'wx+': // fall through
44 case 'xw+':
45 return constants.O_TRUNC | constants.O_CREAT | constants.O_RDWR |
46 constants.O_EXCL;
47
48 case 'a' :
49 return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY;
50 case 'ax' : // fall through
51 case 'xa' :
52 return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY |
53 constants.O_EXCL;
54
55 case 'a+' :
56 return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR;
57 case 'ax+': // fall through
58 case 'xa+':
59 return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR |
60 constants.O_EXCL;
61 }
62};