forked from assemble/assemble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
item.js
1070 lines (940 loc) · 29 KB
/
item.js
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'use strict';
require('mocha');
var should = require('should');
var fs = require('fs');
var path = require('path');
var util = require('util');
var assert = require('assert');
var es = require('event-stream');
var Stream = require('stream');
var support = require('./support');
var App = support.resolve();
var Item = App.Item;
var item;
describe('Item', function() {
describe('instance', function() {
it('should create an instance of Item:', function() {
item = new Item();
assert(item instanceof Item);
});
it('should instantiate without new:', function() {
item = Item();
assert(item instanceof Item);
});
it('inspect should not double name `Stream` when ctor is `Stream`', function(cb) {
var val = new Stream();
var item = new Item({contents: val});
cb();
});
});
describe('static methods', function() {
it('should expose `extend`:', function() {
assert(typeof Item.extend === 'function');
});
});
describe('prototype methods', function() {
beforeEach(function() {
item = new Item();
});
it('should expose `set`:', function() {
assert(typeof item.set === 'function');
});
it('should expose `get`:', function() {
assert(typeof item.get === 'function');
});
it('should expose `del`:', function() {
assert(typeof item.del === 'function');
});
it('should expose `define`:', function() {
assert(typeof item.define === 'function');
});
it('should expose `visit`:', function() {
assert(typeof item.visit === 'function');
});
});
describe('properties', function() {
it('should expose an `options` property', function() {
item = new Item({});
assert.deepEqual(item.options, {});
assert(item.hasOwnProperty('options'));
});
it('should add `options` when passed on the constructor', function() {
item = new Item({options: {foo: 'bar'}});
assert(item.options.foo === 'bar');
});
it('should expose a `data` property', function() {
item = new Item({app: {}});
assert.deepEqual(item.data, {});
assert(item.hasOwnProperty('data'));
});
it('should add `data` when passed on the constructor', function() {
item = new Item({data: {foo: 'bar'}});
assert(item.data.foo === 'bar');
});
it('should add `locals` when passed on the constructor', function() {
item = new Item({locals: {foo: 'bar'}});
assert(item.locals.foo === 'bar');
});
});
describe('set', function() {
it('should set properties on the object', function() {
item = new Item();
item.set('foo', 'bar');
assert.equal(item.foo, 'bar');
});
});
describe('get', function() {
it('should get properties from the object', function() {
item = new Item();
item.set('foo', 'bar');
assert.equal(item.get('foo'), 'bar');
});
});
describe('cwd', function() {
it('should get properties from the object', function() {
item = new Item({cwd: 'test/fixtures'});
assert(item.cwd === 'test/fixtures');
});
});
describe('clone', function() {
it('should clone the item:', function() {
item = new Item({content: 'foo'});
item.set({path: 'foo/bar'});
item.set('options.one', 'two');
var clone = item.clone();
assert(clone.contents);
clone.set('baz', 'quux');
clone.set('options.three', 'four');
assert.equal(clone.get('foo'), item.get('foo'));
assert(clone.get('baz') === 'quux');
assert(!item.get('baz'));
// not deep cloned
assert(clone.get('options.three') === 'four');
assert(item.get('options.three') === 'four');
});
it('should deep clone the entire object', function() {
item = new Item({content: 'foo'});
item.set({path: 'foo/bar'});
item.set('options.one', 'two');
var clone = item.clone({deep: true});
clone.set('options.three', 'four');
assert(item.get('options.one') === 'two');
assert(clone.get('options.one') === 'two');
assert(clone.get('options.three') === 'four');
assert(!item.get('options.three'));
});
});
describe('visit', function() {
it('should visit all properties on an object and call the specified method', function() {
item = new Item();
var obj = {
foo: 'bar',
bar: 'baz',
baz: 'bang'
};
item.visit('set', obj);
assert.equal(item.get('foo'), 'bar');
assert.equal(item.get('bar'), 'baz');
assert.equal(item.get('baz'), 'bang');
});
it('should visit all properties on all objects in an array and call the specified method', function() {
item = new Item();
var arr = [{foo: 'bar', bar: 'baz', baz: 'bang'}];
item.visit('set', arr);
assert.equal(item.get('foo'), 'bar');
assert.equal(item.get('bar'), 'baz');
assert.equal(item.get('baz'), 'bang');
});
});
});
/**
* The following unit tests are from Vinyl
* Since we inherit vinyl in Item, we need
* to ensure that these still pass.
*/
describe('Item', function() {
describe('isVinyl()', function() {
it('should return true on a vinyl object', function(cb) {
var item = new Item();
assert(Item.isVinyl(item) === true);
cb();
});
it('should return false on a normal object', function(cb) {
assert(Item.isVinyl({}) === false);
cb();
});
it('should return false on a null object', function(cb) {
assert(Item.isVinyl({}) === false);
cb();
});
});
describe('constructor()', function() {
it('should default cwd to process.cwd', function(cb) {
var item = new Item();
item.cwd.should.equal(process.cwd());
cb();
});
it('should default base to cwd', function(cb) {
var cwd = '/';
var item = new Item({cwd: cwd});
item.base.should.equal(cwd);
cb();
});
it('should default base to cwd even when none is given', function(cb) {
var item = new Item();
item.base.should.equal(process.cwd());
cb();
});
it('should default path to null', function(cb) {
var item = new Item();
should.not.exist(item.path);
cb();
});
it('should default history to []', function(cb) {
var item = new Item();
item.history.should.eql([]);
cb();
});
it('should default stat to null', function(cb) {
var item = new Item();
should.not.exist(item.stat);
cb();
});
it('should default contents to null', function(cb) {
var item = new Item();
should.not.exist(item.contents);
cb();
});
it('should set base to given value', function(cb) {
var val = '/';
var item = new Item({base: val});
item.base.should.equal(val);
cb();
});
it('should set cwd to given value', function(cb) {
var val = '/';
var item = new Item({cwd: val});
item.cwd.should.equal(val);
cb();
});
it('should set path to given value', function(cb) {
var val = '/test.coffee';
var item = new Item({path: val});
item.path.should.equal(val);
item.history.should.eql([val]);
cb();
});
it('should set history to given value', function(cb) {
var val = '/test.coffee';
var item = new Item({history: [val]});
item.path.should.equal(val);
item.history.should.eql([val]);
cb();
});
it('should set stat to given value', function(cb) {
var val = {};
var item = new Item({stat: val});
item.stat.should.equal(val);
cb();
});
it('should set contents to given value', function(cb) {
var val = new Buffer('test');
var item = new Item({contents: val});
item.contents.should.equal(val);
cb();
});
});
describe('isBuffer()', function() {
it('should return true when the contents are a Buffer', function(cb) {
var val = new Buffer('test');
var item = new Item({contents: val});
item.isBuffer().should.equal(true);
cb();
});
it('should return false when the contents are a Stream', function(cb) {
var val = new Stream();
var item = new Item({contents: val});
item.isBuffer().should.equal(false);
cb();
});
it('should return false when the contents are a null', function(cb) {
var item = new Item({contents: null});
item.isBuffer().should.equal(false);
cb();
});
});
describe('isStream()', function() {
it('should return false when the contents are a Buffer', function(cb) {
var val = new Buffer('test');
var item = new Item({contents: val});
item.isStream().should.equal(false);
cb();
});
it('should return true when the contents are a Stream', function(cb) {
var val = new Stream();
var item = new Item({contents: val});
item.isStream().should.equal(true);
cb();
});
it('should return false when the contents are a null', function(cb) {
var item = new Item({contents: null});
item.isStream().should.equal(false);
cb();
});
});
describe('isNull()', function() {
it('should return false when the contents are a Buffer', function(cb) {
var val = new Buffer('test');
var item = new Item({contents: val});
item.isNull().should.equal(false);
cb();
});
it('should return false when the contents are a Stream', function(cb) {
var val = new Stream();
var item = new Item({contents: val});
item.isNull().should.equal(false);
cb();
});
it('should return true when the contents are a null', function(cb) {
var item = new Item({contents: null});
item.isNull().should.equal(true);
cb();
});
});
describe('isDirectory()', function() {
var fakeStat = {
isDirectory: function() {
return true;
}
};
it('should return false when the contents are a Buffer', function(cb) {
var val = new Buffer('test');
var item = new Item({contents: val, stat: fakeStat});
item.isDirectory().should.equal(false);
cb();
});
it('should return false when the contents are a Stream', function(cb) {
var val = new Stream();
var item = new Item({contents: val, stat: fakeStat});
item.isDirectory().should.equal(false);
cb();
});
it('should return true when the contents are a null', function(cb) {
var item = new Item({contents: null, stat: fakeStat});
item.isDirectory().should.equal(true);
cb();
});
});
describe('clone()', function() {
it('should copy all attributes over with Buffer', function(cb) {
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: new Buffer('test')
};
var item = new Item(options);
var item2 = item.clone();
item2.should.not.equal(item, 'refs should be different');
item2.cwd.should.equal(item.cwd);
item2.base.should.equal(item.base);
item2.path.should.equal(item.path);
item2.contents.should.not.equal(item.contents, 'buffer ref should be different');
item2.contents.toString('utf8').should.equal(item.contents.toString('utf8'));
cb();
});
it('should copy buffer\'s reference with option contents: false', function(cb) {
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.js',
contents: new Buffer('test')
};
var item = new Item(options);
var copy1 = item.clone({ contents: false });
copy1.contents.should.equal(item.contents);
var copy2 = item.clone({});
copy2.contents.should.not.equal(item.contents);
var copy3 = item.clone({ contents: 'any string' });
copy3.contents.should.not.equal(item.contents);
cb();
});
it('should copy all attributes over with Stream', function(cb) {
var contents = new Stream.PassThrough();
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: contents
};
var item = new Item(options);
var item2 = item.clone();
contents.write(new Buffer('wa'));
process.nextTick(function() {
contents.write(new Buffer('dup'));
contents.end();
});
item2.should.not.equal(item, 'refs should be different');
item2.cwd.should.equal(item.cwd);
item2.base.should.equal(item.base);
item2.path.should.equal(item.path);
item2.contents.should.not.equal(item.contents, 'stream ref should not be the same');
item.contents.pipe(es.wait(function(err, data) {
item2.contents.pipe(es.wait(function(err, data2) {
data2.should.not.equal(data, 'stream contents ref should not be the same');
data2.should.eql(data, 'stream contents should be the same');
}));
}));
cb();
});
it('should copy all attributes over with null', function(cb) {
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: null
};
var item = new Item(options);
var item2 = item.clone();
item2.should.not.equal(item, 'refs should be different');
item2.cwd.should.equal(item.cwd);
item2.base.should.equal(item.base);
item2.path.should.equal(item.path);
should.not.exist(item2.contents);
cb();
});
it('should properly clone the `stat` property', function(cb) {
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.js',
contents: new Buffer('test'),
stat: fs.statSync(__filename)
};
var item = new Item(options);
var copy = item.clone();
assert(copy.stat.isFile());
assert(!copy.stat.isDirectory());
assert(item.stat.hasOwnProperty('birthtime'));
assert(copy.stat.hasOwnProperty('birthtime'));
assert.deepEqual(item.stat, copy.stat);
cb();
});
it('should properly clone the `history` property', function(cb) {
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.js',
contents: new Buffer('test'),
stat: fs.statSync(__filename)
};
var item = new Item(options);
var copy = item.clone();
copy.history[0].should.equal(options.path);
copy.path = 'lol';
item.path.should.not.equal(copy.path);
cb();
});
it('should copy custom properties', function(cb) {
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: null
};
var item = new Item(options);
item.custom = { a: 'custom property' };
var item2 = item.clone();
item2.should.not.equal(item, 'refs should be different');
item2.cwd.should.equal(item.cwd);
item2.base.should.equal(item.base);
item2.path.should.equal(item.path);
item2.custom.should.equal(item.custom);
item2.custom.a.should.equal(item.custom.a);
cb();
});
it('should copy history', function(cb) {
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: null
};
var item = new Item(options);
item.path = '/test/test.js';
item.path = '/test/test-938di2s.js';
var item2 = item.clone();
item2.history.should.eql([
'/test/test.coffee',
'/test/test.js',
'/test/test-938di2s.js'
]);
item2.history.should.not.equal([
'/test/test.coffee',
'/test/test.js',
'/test/test-938di2s.js'
]);
item2.path.should.eql('/test/test-938di2s.js');
cb();
});
it('should copy all attributes deeply', function(cb) {
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: null
};
var item = new Item(options);
item.custom = { a: 'custom property' };
var item2 = item.clone(true);
item2.custom.should.eql(item.custom);
item2.custom.should.not.equal(item.custom);
item2.custom.a.should.equal(item.custom.a);
var item3 = item.clone({ deep: true });
item3.custom.should.eql(item.custom);
item3.custom.should.not.equal(item.custom);
item3.custom.a.should.equal(item.custom.a);
var item4 = item.clone(false);
item4.custom.should.eql(item.custom);
item4.custom.should.equal(item.custom);
item4.custom.a.should.equal(item.custom.a);
var item5 = item.clone({ deep: false });
item5.custom.should.eql(item.custom);
item5.custom.should.equal(item.custom);
item5.custom.a.should.equal(item.custom.a);
cb();
});
});
describe('pipe()', function() {
it('should write to stream with Buffer', function(cb) {
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: new Buffer('test')
};
var item = new Item(options);
var stream = new Stream.PassThrough();
stream.on('data', function(chunk) {
should.exist(chunk);
(chunk instanceof Buffer).should.equal(true, 'should write as a buffer');
chunk.toString('utf8').should.equal(options.contents.toString('utf8'));
});
stream.on('end', function() {
cb();
});
var ret = item.pipe(stream);
ret.should.equal(stream, 'should return the stream');
});
it('should pipe to stream with Stream', function(cb) {
var testChunk = new Buffer('test');
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: new Stream.PassThrough()
};
var item = new Item(options);
var stream = new Stream.PassThrough();
stream.on('data', function(chunk) {
should.exist(chunk);
(chunk instanceof Buffer).should.equal(true, 'should write as a buffer');
chunk.toString('utf8').should.equal(testChunk.toString('utf8'));
cb();
});
var ret = item.pipe(stream);
ret.should.equal(stream, 'should return the stream');
item.contents.write(testChunk);
});
it('should do nothing with null', function(cb) {
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: null
};
var item = new Item(options);
var stream = new Stream.PassThrough();
stream.on('data', function() {
throw new Error('should not write');
});
stream.on('end', function() {
cb();
});
var ret = item.pipe(stream);
ret.should.equal(stream, 'should return the stream');
});
it('should write to stream with Buffer', function(cb) {
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: new Buffer('test')
};
var item = new Item(options);
var stream = new Stream.PassThrough();
stream.on('data', function(chunk) {
should.exist(chunk);
(chunk instanceof Buffer).should.equal(true, 'should write as a buffer');
chunk.toString('utf8').should.equal(options.contents.toString('utf8'));
cb();
});
stream.on('end', function() {
throw new Error('should not end');
});
var ret = item.pipe(stream, {end: false});
ret.should.equal(stream, 'should return the stream');
});
it('should pipe to stream with Stream', function(cb) {
var testChunk = new Buffer('test');
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: new Stream.PassThrough()
};
var item = new Item(options);
var stream = new Stream.PassThrough();
stream.on('data', function(chunk) {
should.exist(chunk);
(chunk instanceof Buffer).should.equal(true, 'should write as a buffer');
chunk.toString('utf8').should.equal(testChunk.toString('utf8'));
cb();
});
stream.on('end', function() {
throw new Error('should not end');
});
var ret = item.pipe(stream, {end: false});
ret.should.equal(stream, 'should return the stream');
item.contents.write(testChunk);
});
it('should do nothing with null', function(cb) {
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: null
};
var item = new Item(options);
var stream = new Stream.PassThrough();
stream.on('data', function() {
throw new Error('should not write');
});
stream.on('end', function() {
throw new Error('should not end');
});
var ret = item.pipe(stream, {end: false});
ret.should.equal(stream, 'should return the stream');
process.nextTick(cb);
});
});
describe('inspect()', function() {
it('should return correct format when no contents and no path', function(cb) {
var item = new Item();
item.inspect().should.equal('<Item >');
cb();
});
it('should return correct format when Buffer and no path', function(cb) {
var val = new Buffer('test');
var item = new Item({
contents: val
});
item.inspect().should.equal('<Item <Buffer 74 65 73 74>>');
cb();
});
it('should return correct format when Buffer and relative path', function(cb) {
var val = new Buffer('test');
var item = new Item({
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: val
});
item.inspect().should.equal('<Item "test.coffee" <Buffer 74 65 73 74>>');
cb();
});
it('should return correct format when Buffer and only path and no base', function(cb) {
var val = new Buffer('test');
var item = new Item({
cwd: '/',
path: '/test/test.coffee',
contents: val
});
delete item.base;
item.inspect().should.equal('<Item "/test/test.coffee" <Buffer 74 65 73 74>>');
cb();
});
it('should return correct format when Stream and relative path', function(cb) {
var item = new Item({
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: new Stream.PassThrough()
});
item.inspect().should.equal('<Item "test.coffee" <PassThroughStream>>');
cb();
});
it('should return correct format when null and relative path', function(cb) {
var item = new Item({
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: null
});
item.inspect().should.equal('<Item "test.coffee">');
cb();
});
});
describe('contents get/set', function() {
it('should work with Buffer', function(cb) {
var val = new Buffer('test');
var item = new Item();
item.contents = val;
item.contents.should.equal(val);
cb();
});
it('should work with Stream', function(cb) {
var val = new Stream.PassThrough();
var item = new Item();
item.contents = val;
item.contents.should.equal(val);
cb();
});
it('should work with null', function(cb) {
var val = null;
var item = new Item();
item.contents = val;
(item.contents === null).should.equal(true);
cb();
});
it('should work with string', function(cb) {
var val = 'test';
var item = new Item();
item.contents = val;
item.contents.should.deepEqual(new Buffer(val));
cb();
});
});
describe('relative get/set', function() {
it('should error on set', function(cb) {
var item = new Item();
try {
item.relative = 'test';
} catch (err) {
should.exist(err);
cb();
}
});
it('should error on get when no base', function(cb) {
var a;
var item = new Item();
delete item.base;
try {
a = item.relative;
} catch (err) {
should.exist(err);
cb();
}
});
it('should error on get when no path', function(cb) {
var a;
var item = new Item();
try {
a = item.relative;
} catch (err) {
should.exist(err);
cb();
}
});
it('should return a relative path from base', function(cb) {
var item = new Item({
cwd: '/',
base: '/test/',
path: '/test/test.coffee'
});
item.relative.should.equal('test.coffee');
cb();
});
it('should return a relative path from cwd', function(cb) {
var item = new Item({
cwd: '/',
path: '/test/test.coffee'
});
item.relative.should.equal(path.join('test', 'test.coffee'));
cb();
});
});
describe('dirname get/set', function() {
it('should error on get when no path', function(cb) {
var a;
var item = new Item();
try {
a = item.dirname;
} catch (err) {
should.exist(err);
cb();
}
});
it('should return the dirname of the path', function(cb) {
var item = new Item({
cwd: '/',
base: '/test/',
path: '/test/test.coffee'
});
item.dirname.should.equal('/test');
cb();
});
it('should error on set when no path', function(cb) {
var item = new Item();
try {
item.dirname = '/test';
} catch (err) {
should.exist(err);
cb();
}
});
it('should set the dirname of the path', function(cb) {
var item = new Item({
cwd: '/',
base: '/test/',
path: '/test/test.coffee'
});
item.dirname = '/test/foo';
item.path.should.equal('/test/foo/test.coffee');
cb();
});
});
describe('basename get/set', function() {
it('should error on get when no path', function(cb) {
var a;
var item = new Item();
try {
a = item.basename;
} catch (err) {
should.exist(err);
cb();
}
});
it('should return the basename of the path', function(cb) {
var item = new Item({
cwd: '/',
base: '/test/',
path: '/test/test.coffee'
});
item.basename.should.equal('test.coffee');
cb();
});
it('should error on set when no path', function(cb) {
var item = new Item();
try {
item.basename = 'test.coffee';
} catch (err) {
should.exist(err);
cb();
}
});
it('should set the basename of the path', function(cb) {
var item = new Item({
cwd: '/',
base: '/test/',
path: '/test/test.coffee'
});
item.basename = 'foo.png';
item.path.should.equal('/test/foo.png');
cb();
});
});
describe('extname get/set', function() {
it('should error on get when no path', function(cb) {
var a;
var item = new Item();
try {
a = item.extname;
} catch (err) {
should.exist(err);
cb();
}
});
it('should return the extname of the path', function(cb) {
var item = new Item({
cwd: '/',
base: '/test/',
path: '/test/test.coffee'
});
item.extname.should.equal('.coffee');
cb();
});
it('should error on set when no path', function(cb) {
var item = new Item();
try {
item.extname = '.coffee';
} catch (err) {
should.exist(err);
cb();
}
});
it('should set the extname of the path', function(cb) {
var item = new Item({
cwd: '/',
base: '/test/',
path: '/test/test.coffee'
});
item.extname = '.png';