-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
73 lines (65 loc) · 1.99 KB
/
test.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
var expect = require('chai').use(require('dirty-chai')).expect;
var concat = require('concat-stream');
var from = require('from2-array');
var anyify = require('./');
describe('anyify', function() {
it('should load a transform for an extension and execute it', function(done) {
from(['hello'])
.pipe(anyify('test.foo', {foo: './fixtures/basic.js'}))
.pipe(concat(function(data) {
expect(data.toString()).to.equal('HELLO');
done();
}));
});
it('should handle an error in a transform', function(done) {
from(['hello'])
.pipe(anyify('test.foo', {foo: './fixtures/error.js'}))
.on('error', function(e) {
expect(e).to.be.an.instanceof(Error);
expect(e.message).to.equal('error');
done();
});
});
it('should do nothing if no transform matches', function(done) {
from(['hello'])
.pipe(anyify('test.foo', {}))
.pipe(concat(function(data) {
expect(data.toString()).to.equal('hello');
done();
}));
});
it('could also use first thing of _', function(done) {
from(['hello'])
.pipe(anyify('test.foo', {foo: {_: ['./fixtures/basic.js']}}))
.pipe(concat(function(data) {
expect(data.toString()).to.equal('HELLO');
done();
}));
});
it('passes the things as options', function(done) {
from(['hello'])
.pipe(anyify('test.foo', {foo: {_: ['./fixtures/opts.js'], baz: 'quux'}}))
.pipe(concat(function(data) {
expect(data.toString()).to.equal('HELLO');
done();
}));
});
describe('module methods', function() {
it('should access a transform by a key', function(done) {
from(['hello'])
.pipe(anyify('test.foo', {'foo': './fixtures/key.js?bar'}))
.pipe(concat(function(data) {
expect(data.toString()).to.equal('HELLO');
done();
}));
});
it('should access a transform by a deep key', function(done) {
from(['hello'])
.pipe(anyify('test.foo', {'foo': './fixtures/deep.js?bar.baz.quux'}))
.pipe(concat(function(data) {
expect(data.toString()).to.equal('HELLO');
done();
}));
});
});
});