1 | module.exports = function(grunt) {
|
2 | grunt.initConfig({
|
3 | exec: {
|
4 | create_dir: { cmd: 'mkdir "tmp dir"' },
|
5 | remove_logs: {
|
6 | command: process.platform === 'win32' ? 'del *.log' : 'rm -f *.log'
|
7 | , stdout: false
|
8 | , stderr: false
|
9 | }
|
10 | , list_files: {
|
11 | cmd: process.platform === 'win32' ? 'dir' : 'ls -l **'
|
12 | }
|
13 | , list_all_files: process.platform === 'win32' ? 'dir' : 'ls -la'
|
14 | , echo_grunt_version: {
|
15 | cmd: function() { return 'echo ' + this.version; }
|
16 | }
|
17 | , print_name: {
|
18 | cmd: function(firstName, lastName) {
|
19 | var formattedName = [
|
20 | (lastName || 'grunt').toUpperCase()
|
21 | , (firstName || 'exec').toUpperCase()
|
22 | ].join(', ');
|
23 |
|
24 | return 'echo ' + formattedName;
|
25 | }
|
26 | }
|
27 | , test_mysql_ticket: {
|
28 |
|
29 | cmd: function () {
|
30 | var DB_USER = "abc";
|
31 | var DB_PASSWORD = "password";
|
32 | var DATABASE = "database-with-dashes";
|
33 | return `echo mysql -u "${DB_USER}" -p"${DB_PASSWORD}" -e "CREATE DATABASE IF NOT EXISTS \'${DATABASE}\';"`;
|
34 | },
|
35 | callback: function(err, stdout, stderr) {
|
36 | console.log('stdout: ' + stdout);
|
37 | if (process.platform === 'win32') {
|
38 | if ((stdout + "").trim() !== `mysql -u "abc" -p"password" -e "CREATE DATABASE IF NOT EXISTS 'database-with-dashes';"`) {
|
39 | grunt.log.error("Unexpected result: " + stdout);
|
40 | return false;
|
41 | }
|
42 | } else {
|
43 | if ((stdout + "").trim() !== `mysql -u abc -ppassword -e CREATE DATABASE IF NOT EXISTS 'database-with-dashes';`) {
|
44 | grunt.log.error("Unexpected result: " + stdout);
|
45 | return false;
|
46 | }
|
47 | }
|
48 | }
|
49 | }
|
50 | , test_large_stdout_buffer: {
|
51 |
|
52 | options: { maxBuffer: 10000001, encoding: 'buffer' },
|
53 |
|
54 | stdout: false,
|
55 |
|
56 | cmd: function () {
|
57 | var count = 1000000;
|
58 |
|
59 | return `node -e "var garbage = ''; var count = ${count}; for (var i = 0; i < count; i++) { var c = String.fromCharCode(Math.floor(32 + (Math.random() * 94))); garbage += c; } process.stdout.write(garbage);"`;
|
60 | },
|
61 | callback: function(err, stdout, stderr) {
|
62 | var count = 1000000;
|
63 |
|
64 | if (err && err.toString() === "Error: stdout maxBuffer exceeded") {
|
65 | grunt.log.error("Unexpected maxBuffer exceeded");
|
66 | return false;
|
67 | }
|
68 |
|
69 | if (typeof stdout === "string") {
|
70 | grunt.log.error("Unexpected stdout type (string), expected buffer. String length was " + stdout.length);
|
71 | return false;
|
72 | }
|
73 |
|
74 | var str = stdout.toString();
|
75 |
|
76 | if (str.length !== count) {
|
77 | grunt.log.error("Unexpected result: " + str.length + " != " + count.toString());
|
78 | return false;
|
79 | }
|
80 | }
|
81 | }
|
82 |
|
83 | , test_large_stdout_nocallback: {
|
84 | stdout: false,
|
85 |
|
86 | cmd: function () {
|
87 | var count = 1000000;
|
88 |
|
89 | return `node -e "var garbage = ''; var count = ${count}; for (var i = 0; i < count; i++) { var c = String.fromCharCode(Math.floor(32 + (Math.random() * 94))); garbage += c; } process.stdout.write(garbage);"`;
|
90 | },
|
91 | }
|
92 | , test_large_stdout_string: {
|
93 |
|
94 | options: { maxBuffer: 10000001 },
|
95 |
|
96 | stdout: false,
|
97 |
|
98 | cmd: function () {
|
99 | var count = 1000000;
|
100 |
|
101 | return `node -e "var garbage = ''; var count = ${count}; for (var i = 0; i < count; i++) { var c = String.fromCharCode(Math.floor(32 + (Math.random() * 94))); garbage += c; } process.stdout.write(garbage);"`;
|
102 | },
|
103 | callback: function(err, stdout, stderr) {
|
104 | var count = 1000000;
|
105 |
|
106 | if (err && err.toString() === "Error: stdout maxBuffer exceeded") {
|
107 | grunt.log.error("Unexpected maxBuffer exceeded");
|
108 | return false;
|
109 | }
|
110 |
|
111 | if (typeof stdout !== "string") {
|
112 | grunt.log.error("Unexpected stdout type (" + (typeof stdout) + "), expected string.");
|
113 | return false;
|
114 | }
|
115 |
|
116 | if (stdout.length !== count) {
|
117 | grunt.log.error("Unexpected result: " + stdout.length + " != " + count.toString());
|
118 | return false;
|
119 | }
|
120 | }
|
121 | }
|
122 | , test_callback: {
|
123 | cmd : process.platform === 'win32' ? 'dir' : 'ls -h',
|
124 | callback : function(error, stdout, stderr){
|
125 | var util = require('util');
|
126 | console.log(util.inspect(error));
|
127 | console.log('stdout: ' + stdout);
|
128 | console.log('stderr: ' + stderr);
|
129 | },
|
130 | stdout: 'pipe'
|
131 | },
|
132 | test_callback_no_data: {
|
133 | cmd : process.platform === 'win32' ? 'dir' : 'ls -h',
|
134 | callback : function(error, stdout, stderr){
|
135 | var util = require('util');
|
136 | console.log(util.inspect(error));
|
137 | console.log('stdout: ' + stdout);
|
138 | console.log('stderr: ' + stderr);
|
139 | }
|
140 | },
|
141 | npm_outdated_color_test: {
|
142 | command: 'npm outdated --long --ansi --color',
|
143 | stdout: 'inherit',
|
144 | stderr: 'inherit'
|
145 | },
|
146 | set_user_input: {
|
147 | cmd: 'set /p TestCurrentUserName= "Enter your name: "',
|
148 | stdout: 'inherit',
|
149 | stderr: 'inherit',
|
150 | stdin: 'inherit'
|
151 | },
|
152 | test_timeout: {
|
153 | cmd: 'set /p TestCurrentUserName= "Please do not enter your name: "',
|
154 | stdout: 'inherit',
|
155 | stderr: 'inherit',
|
156 | stdin: 'inherit',
|
157 | timeout: 500
|
158 | },
|
159 | test_stdio_inherit: {
|
160 | cmd: 'npm list',
|
161 | stdio: 'inherit'
|
162 | },
|
163 | test_stdio_ignore: {
|
164 | cmd: 'npm list',
|
165 | stdio: 'ignore'
|
166 | }
|
167 | }
|
168 |
|
169 | , jshint: {
|
170 | options: {
|
171 |
|
172 | curly: true
|
173 | , forin: true
|
174 | , newcap: true
|
175 | , noarg: true
|
176 | , noempty: true
|
177 | , nonew: true
|
178 | , quotmark: true
|
179 | , undef: true
|
180 | , unused: true
|
181 | , trailing: true
|
182 | , maxlen: 80
|
183 |
|
184 |
|
185 | , boss: true
|
186 | , es5: true
|
187 | , expr: true
|
188 | , laxcomma: true
|
189 |
|
190 |
|
191 | , node: true
|
192 | }
|
193 | , tasks: ['tasks/*.js']
|
194 | , tests: ['test/*.js']
|
195 | , gruntfile: ['Gruntfile.js']
|
196 | }
|
197 | });
|
198 |
|
199 | grunt.loadTasks('tasks');
|
200 | grunt.loadNpmTasks('grunt-contrib-jshint');
|
201 |
|
202 | grunt.registerTask('lint', 'jshint');
|
203 | };
|