UNPKG

3.53 kBJavaScriptView Raw
1var assert = require("assert");
2var util = require("util");
3var minitest = require("../vendor/minitest.js/minitest");
4var file = require("../lib/main");
5var fs = require("fs");
6var path = require("path");
7
8minitest.setupListeners();
9
10var madeDirs = [];
11fs.mkdir = function (dir, mode, callback) {
12 madeDirs.push(dir);
13 callback();
14};
15
16fs.mkdirSync = function (dir, mode) {
17 madeDirs.push(dir);
18};
19
20GLOBAL.fs = fs;
21
22minitest.context("file#mkdirs", function () {
23 this.setup(function () {
24 madeDirs = [];
25 });
26
27 this.assertion("it should make all the directories in the tree", function (test) {
28 file.mkdirs("/test/test/test/test", 0755, function(err) {
29 assert.equal(madeDirs[0], "/test");
30 assert.equal(madeDirs[1], "/test/test");
31 assert.equal(madeDirs[2], "/test/test/test");
32 assert.equal(madeDirs[3], "/test/test/test/test");
33 test.finished();
34 });
35 });
36});
37
38minitest.context("file#mkdirsSync", function () {
39 this.setup(function () {
40 madeDirs = [];
41 });
42
43 this.assertion("it should make all the directories in the tree", function (test) {
44 file.mkdirsSync("/test/test/test/test", 0755, function(err) {});
45 assert.equal(madeDirs[0], "/test");
46 assert.equal(madeDirs[1], "/test/test");
47 assert.equal(madeDirs[2], "/test/test/test");
48 assert.equal(madeDirs[3], "/test/test/test/test");
49 test.finished();
50 });
51});
52
53minitest.context("file#walk", function () {
54 this.assertion("it should call \"callback\" for ever file in the tree", function (test) {
55 file.walk("/test", function(start, dirs, names) {});
56 test.finished();
57 });
58});
59
60minitest.context("file#walkSync", function () {
61 this.assertion("it should call \"callback\" for ever file in the tree", function (test) {
62 file.walkSync("/test", function(start, dirs, names) {});
63 test.finished();
64 });
65});
66
67minitest.context("file.path#abspath", function () {
68 this.setup(function () {});
69
70 this.assertion("it should convert . to the current directory", function (test) {
71 assert.equal(file.path.abspath("."), process.cwd());
72 assert.equal(file.path.abspath("./test/dir"), file.path.join(process.cwd(), "test/dir"));
73 test.finished();
74 });
75
76 this.assertion("it should convert .. to the parrent directory", function (test) {
77 assert.equal(file.path.abspath(".."), path.dirname(process.cwd()));
78 assert.equal(file.path.abspath("../test/dir"), file.path.join(path.dirname(process.cwd()), "test/dir"));
79 test.finished();
80 });
81
82 this.assertion("it should convert ~ to the home directory", function (test) {
83 assert.equal(file.path.abspath("~"), file.path.join(process.env.HOME, ""));
84 assert.equal(file.path.abspath("~/test/dir"), file.path.join(process.env.HOME, "test/dir"));
85 test.finished();
86 });
87
88 this.assertion("it should not convert paths begining with /", function (test) {
89 assert.equal(file.path.abspath("/x/y/z"), "/x/y/z");
90 test.finished();
91 });
92});
93
94
95minitest.context("file.path#relativePath", function () {
96 this.setup(function () {});
97
98 this.assertion("it should return the relative path", function (test) {
99 var rel = file.path.relativePath("/", "/test.js");
100 assert.equal(rel, "test.js");
101
102 var rel = file.path.relativePath("/test/loc", "/test/loc/test.js");
103 assert.equal(rel, "test.js");
104
105 test.finished();
106 });
107
108 this.assertion("it should take two equal paths and return \"\"", function (test) {
109 var rel = file.path.relativePath("/test.js", "/test.js");
110 assert.equal(rel, "");
111 test.finished();
112 });
113});