-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
152 lines (135 loc) · 3.94 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
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
'use strict';
const async = require('async');
const expect = require('chai').expect;
const filesystem = require('fs');
describe('ReplacePlugin', function() {
const Plugin = require('./index.js');
afterEach(
(done) => {
async.parallel(
[
async.apply(filesystem.writeFile, 'test_files/date.txt', '{!date!}', 'utf8'),
async.apply(filesystem.writeFile, 'test_files/manifest.json', '{"version": "{?version?}"}', 'utf8'),
async.apply(filesystem.writeFile, 'test_files/timestamp.txt', '{!timestamp!}', 'utf8'),
async.apply(filesystem.writeFile, 'test_files/version.txt', '{?version?}', 'utf8')
],
done
);
}
);
it('should compile user specified paths',
() => {
const options = {
plugins: {
replace: {
paths: ['test_files/version.txt']
}
}
};
const plugin = new Plugin(options);
const pluginConfig = plugin.config;
const paths = plugin.getPaths(
[
{path: 'test_files/date.txt'},
{path: 'test_files/manifest.json'},
{path: 'test_files/timestamp.txt'},
{path: 'test_files/version.txt'}
],
pluginConfig
);
expect(paths[0]).to.equal('test_files/version.txt');
}
);
it('should set default configs and paths',
() => {
const plugin = new Plugin();
const pluginConfig = plugin.config;
const paths = plugin.getPaths(
[
{path: 'test_files/date.txt'},
{path: 'test_files/manifest.json'},
{path: 'test_files/timestamp.txt'},
{path: 'test_files/version.txt'}
],
pluginConfig
);
expect(pluginConfig.encoding).to.equal('utf8');
expect(pluginConfig.mappings.date).to.be.a('string');
expect(pluginConfig.mappings.timestamp).to.be.a('number');
expect(pluginConfig.replacePrefix).to.equal('{!');
expect(pluginConfig.replaceSuffix).to.equal('!}');
expect(paths).to.have.length(4);
}
);
it('should replace default string mappings',
(done) => {
const plugin = new Plugin();
const pluginConfig = plugin.config;
async.parallel(
[
(callback) => {
plugin.replaceFile('test_files/date.txt', pluginConfig)
.catch(callback)
.then(
(data) => {
expect(data.toString()).to.have.equal(pluginConfig.mappings.date);
callback();
}
);
},
(callback) => {
plugin.replaceFile('test_files/timestamp.txt', pluginConfig)
.catch(callback)
.then(
(data) => {
expect(parseInt(data, 10)).to.equal(pluginConfig.mappings.timestamp);
callback();
}
);
}
],
done
);
}
);
it('should replace user string mappings',
(done) => {
const options = {
plugins: {
replace: {
mappings: {'version': '0.0.1'},
replacePrefix: '{?',
replaceSuffix: '?}'
}
}
};
const plugin = new Plugin(options);
const pluginConfig = plugin.config;
async.parallel(
[
(callback) => {
plugin.replaceFile('test_files/manifest.json', pluginConfig)
.catch(callback)
.then(
(data) => {
expect(data.toString()).to.equal('{"version": "0.0.1"}');
callback();
}
);
},
(callback) => {
plugin.replaceFile('test_files/version.txt', pluginConfig)
.catch(callback)
.then(
(data) => {
expect(data.toString()).to.equal('0.0.1');
callback();
}
);
}
],
done
);
}
);
});