Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80748 views
1
var join = require('path').join;
2
var read = require('fs').readFileSync;
3
var inspect = require('util').inspect;
4
var assert = require('assert');
5
var rfile = require('../');
6
7
var testCases = [];
8
function equal(reqPath, fullPath, options) {
9
testCases.push([reqPath, fullPath, options]);
10
}
11
12
equal('./index.js', __filename);
13
equal('../package.json', join(__dirname, '..', 'package.json'));
14
equal('./index', __filename);
15
equal('../package', join(__dirname, '..', 'package.json'));
16
equal('../README', join(__dirname, '..', 'README.md'), {extensions: ['.md']});
17
18
19
describe('rfile.resolve', function () {
20
testCases.forEach(function (testCase) {
21
describe('(' + inspect(testCase[0]) + (testCase[2] ? ', ' + inspect(testCase[2]) : '') + ')', function () {
22
it('resolves to ' + inspect(testCase[1]), function () {
23
assert.equal(rfile.resolve(testCase[0], testCase[2]), testCase[1]);
24
});
25
});
26
});
27
});
28
29
describe('rfile', function () {
30
testCases.forEach(function (testCase) {
31
describe('(' + inspect(testCase[0]) + (testCase[2] ? ', ' + inspect(testCase[2]) : '') + ')', function () {
32
it('reads ' + inspect(testCase[1]), function () {
33
assert.equal(rfile(testCase[0], testCase[2]), stripBOM(read(testCase[1]).toString()).replace(/\r/g, ''));
34
});
35
});
36
});
37
});
38
39
function stripBOM(str){
40
return 0xFEFF == str.charCodeAt(0)
41
? str.substring(1)
42
: str;
43
}
44