-
Notifications
You must be signed in to change notification settings - Fork 168
Expand file tree
/
Copy pathconcat_test.js
More file actions
132 lines (104 loc) · 5.64 KB
/
concat_test.js
File metadata and controls
132 lines (104 loc) · 5.64 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
'use strict';
var grunt = require('grunt');
var comment = require('../tasks/lib/comment').init(grunt);
var exec = require('child_process').exec;
var path = require('path');
var fs = require('fs');
var execOptions = {cwd: path.join(__dirname, '..')};
function getNormalizedFile(filepath) {
return grunt.util.normalizelf(grunt.file.read(filepath));
}
exports.concat = {
default_options: function(test) {
test.expect(1);
var actual = getNormalizedFile('tmp/default_options');
var expected = getNormalizedFile('test/expected/default_options');
test.equal(actual, expected, 'should describe what the default behavior is.');
test.done();
},
custom_options: function(test) {
test.expect(1);
var actual = getNormalizedFile('tmp/custom_options');
var expected = getNormalizedFile('test/expected/custom_options');
test.equal(actual, expected, 'should utilize custom banner, footer and separator.');
test.done();
},
handling_invalid_files: function(test) {
test.expect(3);
exec('grunt concat-warn', execOptions, function(error, stdout) {
test.ok(stdout.indexOf('Warning:') > -1, 'should print a warning.');
test.ok(stdout.indexOf('Aborted due to warnings.') > -1, 'should abort.');
fs.exists('tmp/handling_invalid_files', function(exists) {
test.ok(!exists, 'should not have created a file.');
test.done();
});
});
},
handling_invalid_files_force: function(test) {
test.expect(2);
exec('grunt concat-force --force', execOptions, function(error, stdout) {
test.ok(stdout.indexOf('Warning:') > -1, 'should print a warning.');
var actual = getNormalizedFile('tmp/handling_invalid_files_force');
var expected = getNormalizedFile('test/expected/handling_invalid_files_force');
test.equal(actual, expected, 'should not fail.');
test.done();
});
},
strip_banner: function(test) {
test.expect(10);
var src = getNormalizedFile('test/fixtures/banner.js');
test.equal(comment.stripBanner(src), grunt.util.normalizelf('// Comment\n\n/* Comment */\n'), 'It should strip the top banner.');
test.equal(comment.stripBanner(src, {block: true}), grunt.util.normalizelf('// Comment\n\n/* Comment */\n'), 'It should strip the top banner.');
test.equal(comment.stripBanner(src, {block: true, line: true}), grunt.util.normalizelf('// Comment\n\n/* Comment */\n'), 'It should strip the top banner.');
src = getNormalizedFile('test/fixtures/banner2.js');
test.equal(comment.stripBanner(src), grunt.util.normalizelf('\n/*! SAMPLE\n * BANNER */\n\n// Comment\n\n/* Comment */\n'), 'It should not strip the top banner.');
test.equal(comment.stripBanner(src, {block: true}), grunt.util.normalizelf('// Comment\n\n/* Comment */\n'), 'It should strip the top banner.');
test.equal(comment.stripBanner(src, {block: true, line: true}), grunt.util.normalizelf('// Comment\n\n/* Comment */\n'), 'It should strip the top banner.');
src = getNormalizedFile('test/fixtures/banner3.js');
test.equal(comment.stripBanner(src), grunt.util.normalizelf('\n// This is\n// A sample\n// Banner\n\n// But this is not\n\n/* And neither\n * is this\n */\n'), 'It should not strip the top banner.');
test.equal(comment.stripBanner(src, {block: true}), grunt.util.normalizelf('\n// This is\n// A sample\n// Banner\n\n// But this is not\n\n/* And neither\n * is this\n */\n'), 'It should not strip the top banner.');
test.equal(comment.stripBanner(src, {line: true}), grunt.util.normalizelf('// But this is not\n\n/* And neither\n * is this\n */\n'), 'It should strip the top banner.');
test.equal(comment.stripBanner(src, {block: true, line: true}), grunt.util.normalizelf('// But this is not\n\n/* And neither\n * is this\n */\n'), 'It should strip the top banner.');
test.done();
},
process_function: function(test) {
test.expect(1);
var actual = getNormalizedFile('tmp/process_function');
var expected = getNormalizedFile('test/expected/process_function');
test.equal(actual, expected, 'should have processed file content.');
test.done();
},
process_dir_path: function(test) {
test.expect(1);
var actual = getNormalizedFile('tmp/process_dir_path');
var expected = getNormalizedFile('test/expected/process_dir_path');
test.equal(actual, expected, 'should have nothing.');
test.done();
},
overwrite: function(test) {
test.expect(1);
var actual = getNormalizedFile('tmp/overwrite');
var expected = getNormalizedFile('test/expected/overwrite');
test.equal(actual, expected, 'should overwrite contents.');
test.done();
},
sourcemap_options: function(test) {
test.expect(5);
var actual = getNormalizedFile('tmp/sourcemap_inline');
var expected = getNormalizedFile('test/expected/sourcemap_inline');
test.equal(actual, expected, 'should output the source with inlined map.');
actual = getNormalizedFile('tmp/maps/sourcemap2_link.map');
expected = getNormalizedFile('test/expected/sourcemap2_link.map');
test.equal(actual, expected, 'should output the constructed map.');
actual = getNormalizedFile('tmp/sourcemap3_embed_map.map');
expected = getNormalizedFile('test/expected/sourcemap3_embed.map');
test.equal(actual, expected, 'should output the constructed map.');
actual = getNormalizedFile('tmp/sourcemap_js.js.map');
expected = getNormalizedFile('test/expected/sourcemap_js.js.map');
test.equal(actual, expected, 'should output the js map.');
actual = getNormalizedFile('tmp/sourcemap_css.css.map');
expected = getNormalizedFile('test/expected/sourcemap_css.css.map');
test.equal(actual, expected, 'should output the css map.');
test.done();
}
};