-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathversion-test.js
164 lines (125 loc) · 4.46 KB
/
version-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
153
154
155
156
157
158
159
160
161
162
163
164
'use strict';
var semver = require('semver');
var grunt = require('grunt');
/*
======== A Handy Little Nodeunit Reference ========
https://github.com/caolan/nodeunit
Test methods:
test.expect(numAssertions)
test.done()
Test assertions:
test.ok(value, [message])
test.equal(actual, expected, [message])
test.notEqual(actual, expected, [message])
test.deepEqual(actual, expected, [message])
test.notDeepEqual(actual, expected, [message])
test.strictEqual(actual, expected, [message])
test.notStrictEqual(actual, expected, [message])
test.throws(block, [error], [message])
test.doesNotThrow(block, [error], [message])
test.ifError(value)
*/
exports.version = {
setUp: function(done) {
done();
},
prefixOption: function(test) {
var files = grunt.config('version.prefixOption.src');
test.expect(files.length);
files.forEach(function(file) {
var content = grunt.file.read(file);
var actual = /version['"]?\s*[:=] ['"](\d\.\d\.\d)/.exec(content);
actual = actual && actual[1];
test.equal(actual, '0.1.0', 'Updates the file with version.');
});
test.done();
},
patch: function(test) {
var files = grunt.config('version.patch.src');
test.expect(files.length);
files.forEach(function(file) {
var content = grunt.file.read(file);
var actual = /version['"]?\s*[:=] ['"](\d\.\d\.\d)/.exec(content);
actual = actual && actual[1];
test.equal(actual, '0.1.1', 'Increments the version and updates the file.');
});
test.done();
},
prerelease: function(test) {
var file = grunt.config('version.prerelease.src');
var content = grunt.file.read(file);
var actual = /version['"]?\s*[:=] ['"](\d\.\d\.\d[-+a-zA-Z0-9.]*)/.exec(content);
actual = actual && actual[1];
test.expect(1);
test.equal(actual, '1.2.3-alpha.0', 'Increments the version and updates the file.');
test.done();
},
minor: function(test) {
var files = grunt.config('version.minor.src');
test.expect(files.length);
files.forEach(function(file) {
var content = grunt.file.read(file);
var actual = /version['"]?\s*[:=] ['"](\d\.\d\.\d)/.exec(content);
actual = actual && actual[1];
test.equal(actual, '1.3.0', 'Increments the minor version and updates the file.');
});
test.done();
},
minorwitharg: function(test) {
test.expect(1);
var pkg = grunt.file.readJSON('tmp/test-pkg-arg.json');
test.equal(pkg.version, '1.3.0', 'Increments the minor version and updates the file.');
test.done();
},
excludeFiles: function(test) {
test.expect(4);
var patchedFiles = [
'tmp/exclude-some/123.js',
'tmp/exclude-some/testing.js',
];
var excludedFiles = [
'tmp/exclude-some/no-123.js',
'tmp/exclude-some/no-testing.js',
];
patchedFiles.forEach(function(file) {
var content = grunt.file.read(file);
var actual = /version['"]?\s*[:=] ['"]([^'"]+)/.exec(content);
actual = actual && actual[1];
test.equal(actual, '1.2.4', 'Increments the version and updates the file.');
});
excludedFiles.forEach(function(file) {
var content = grunt.file.read(file);
var actual = /version['"]?\s*[:=] ['"]([^'"]+)/.exec(content);
actual = actual && actual[1];
test.equal(actual, '1.2.3', 'Ignores the file; version remains the same.');
});
test.done();
},
literal: function(test) {
test.expect(2);
var pkg = grunt.file.readJSON('tmp/test-package-v.json');
test.equal(pkg.version, '3.2.1', 'Sets package version to literal value');
test.equal(pkg.devDependencies['grunt-version'], '>=0.1.0', 'Does NOT increment grunt-version');
test.done();
},
prereleaseBuild: function(test) {
var files = grunt.config('version.prereleaseBuild.src');
test.expect(files.length);
files.forEach(function(file) {
var content = grunt.file.read(file);
var actual = /version['"]?\s*[:=] ['"]([^'"]+)/.exec(content);
actual = actual && actual[1];
test.equal(actual, '1.0.0-beta.2', 'Increments the version and updates the file.');
});
test.done();
},
flags: function(test) {
var file = grunt.config('version.flags.src');
var content = grunt.file.read(file);
var actual = /vErSIoN = '(\d\.\d\.\d)/.exec(content);
actual = actual && actual[1];
test.expect(1);
test.equal(actual, '1.2.4', 'Case insensitive version update and updates the file');
test.done();
},
};