-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathpath_test.js
More file actions
184 lines (156 loc) · 5.82 KB
/
path_test.js
File metadata and controls
184 lines (156 loc) · 5.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/* eslint-env mocha */
'use strict';
var path = require('path');
var Vinyl = require('vinyl');
require('should');
var getFilepath = require('./');
describe('getFilepath', function () {
describe('(relative=false)', function () {
it('returns the path relative to the source file\'s cwd', function () {
var source = new Vinyl({
cwd: __dirname,
path: path.join(__dirname, 'dir', 'file.js'),
base: path.join(__dirname, 'dir')
});
var filepath = getFilepath(source);
filepath.should.equal('dir/file.js');
});
it('returns the unixified path relative to the source file\'s cwd', function () {
var source = new Vinyl({
cwd: 'C:\\a\\folder',
path: 'C:\\a\\folder\\dir\\file.js',
base: 'C:\\a\\folder\\dir'
});
var filepath = getFilepath(source);
filepath.should.equal('dir/file.js');
});
});
describe('(relative=true)', function () {
it('returns the path relative to the target file\'s directory', function () {
var target = new Vinyl({
cwd: __dirname,
path: path.join(__dirname, 'dir1', 'index.html'),
base: path.join(__dirname, 'dir1')
});
var source = new Vinyl({
cwd: __dirname,
path: path.join(__dirname, 'dir2', 'file.js'),
base: path.join(__dirname, 'dir2')
});
var filepath = getFilepath(source, target, {relative: true});
filepath.should.equal('../dir2/file.js');
});
it('returns the unixified path relative to the source file\'s cwd', function () {
var target = new Vinyl({
cwd: 'C:\\a\\folder',
path: 'C:\\a\\folder\\dir1\\index.html',
base: 'C:\\a\\folder\\dir1'
});
var source = new Vinyl({
cwd: 'C:\\a\\folder',
path: 'C:\\a\\folder\\dir2\\file.js',
base: 'C:\\a\\folder\\dir2'
});
var filepath = getFilepath(source, target, {relative: true});
filepath.should.equal('../dir2/file.js');
});
});
describe('(ignorePath)', function () {
it('removes the provided `ignorePath` from the beginning of the path', function () {
var source = new Vinyl({
cwd: __dirname,
path: path.join(__dirname, 'dir', 'file.js'),
base: path.join(__dirname, 'dir')
});
var filepath = getFilepath(source, null, {ignorePath: 'dir'});
filepath.should.equal('file.js');
});
it('removes the provided `ignorePath` even if it both begins and ends in a `/` from the beginning of the path', function () {
var source = new Vinyl({
cwd: __dirname,
path: path.join(__dirname, 'dir', 'file.js'),
base: path.join(__dirname, 'dir')
});
var filepath = getFilepath(source, null, {ignorePath: '/dir/'});
filepath.should.equal('file.js');
});
it('removes the provided `ignorePath`s from the beginning of the path', function () {
var source = new Vinyl({
cwd: __dirname,
path: path.join(__dirname, 'dir', 'file.js'),
base: path.join(__dirname, 'dir')
});
var filepath = getFilepath(source, null, {ignorePath: ['dir', 'dir2']});
filepath.should.equal('file.js');
});
it('removes the provided `ignorePath` unixified from the beginning of the path', function () {
var source = new Vinyl({
cwd: __dirname,
path: path.join(__dirname, 'dir', 'deep', 'file.js'),
base: path.join(__dirname, 'dir', 'deep')
});
var filepath = getFilepath(source, null, {ignorePath: ['\\dir\\deep']});
filepath.should.equal('file.js');
});
it('removes the provided `ignorePath` unixified from the beginning of a unixified path', function () {
var source = new Vinyl({
cwd: 'C:\\a\\folder',
path: 'C:\\a\\folder\\dir\\deep\\file.js',
base: 'C:\\a\\folder\\dir\\deep'
});
var filepath = getFilepath(source, null, {ignorePath: ['\\dir\\deep']});
filepath.should.equal('file.js');
});
it('removes the provided `ignorePath` from the beginning of a unixified path', function () {
var source = new Vinyl({
cwd: 'C:\\a\\folder',
path: 'C:\\a\\folder\\dir\\deep\\file.js',
base: 'C:\\a\\folder\\dir\\deep'
});
var filepath = getFilepath(source, null, {ignorePath: ['dir/deep']});
filepath.should.equal('file.js');
});
});
describe('(addRootSlash=true)', function () {
it('prepends the path with a `/`', function () {
var source = new Vinyl({
cwd: __dirname,
path: path.join(__dirname, 'dir', 'file.js'),
base: path.join(__dirname, 'dir')
});
var filepath = getFilepath(source, null, {addRootSlash: true});
filepath.should.equal('/dir/file.js');
});
});
describe('(addPrefix)', function () {
it('prepends the prefix and a `/` to the path', function () {
var source = new Vinyl({
cwd: __dirname,
path: path.join(__dirname, 'dir', 'file.js'),
base: path.join(__dirname, 'dir')
});
var filepath = getFilepath(source, null, {addPrefix: 'hello'});
filepath.should.equal('hello/dir/file.js');
});
it('keeps any leading `/` from the prefix', function () {
var source = new Vinyl({
cwd: __dirname,
path: path.join(__dirname, 'dir', 'file.js'),
base: path.join(__dirname, 'dir')
});
var filepath = getFilepath(source, null, {addPrefix: '/hello'});
filepath.should.equal('/hello/dir/file.js');
});
});
describe('(addSuffix)', function () {
it('appends the suffix to the path', function () {
var source = new Vinyl({
cwd: __dirname,
path: path.join(__dirname, 'dir', 'file.js'),
base: path.join(__dirname, 'dir')
});
var filepath = getFilepath(source, null, {addSuffix: '?hello'});
filepath.should.equal('dir/file.js?hello');
});
});
});