@@ -19,34 +19,67 @@ exports.javascript_obfuscator = {
1919 } ) ;
2020 } ,
2121
22+ no_file : function ( test ) {
23+ test . expect ( 2 ) ;
24+
25+ helper . callGruntfile ( 'fixtures/gruntfile_no_file.js' , function ( error , stdout , stderr ) {
26+ test . ok ( error , "Command should fail." ) ;
27+ test . ok ( stdout . indexOf ( "Target files not found." ) > - 1 , "Standard error stream should be contain error message." ) ;
28+
29+ test . done ( ) ;
30+ } ) ;
31+ } ,
32+
2233 single_file : function ( test ) {
2334 test . expect ( 5 ) ;
2435
2536 helper . callGruntfile ( 'fixtures/gruntfile_single_file.js' , function ( error , stdout , stderr ) {
2637 test . equal ( error , null , "Command should not fail." ) ;
2738 test . equal ( stderr , '' , "Standard error stream should be empty." ) ;
2839
29- var obfuscated = grunt . file . read ( 'tmp/single_file' ) ;
40+ var obfuscated = grunt . file . read ( 'tmp/single_file.js' ) ;
41+
42+ // should NOT be obfuscated
43+ test . ok ( obfuscated . indexOf ( 'console' ) > - 1 , '`console` shouldn\'t be obfuscated' ) ;
44+ test . ok ( obfuscated . indexOf ( 'FIRST_LOCAL_VARIABLE' ) > - 1 , '`FIRST_LOCAL_VARIABLE` shouldn\'t be obfuscated' ) ;
45+
46+ // should be obfuscated
47+ test . ok ( obfuscated . indexOf ( 'FIRST_STRING_LITERAL' ) === - 1 , '`FIRST_STRING_LITERAL` should be obfuscated' ) ;
48+
49+ test . done ( ) ;
50+ } ) ;
51+ } ,
52+
53+ multiple_files1 : function ( test ) {
54+ test . expect ( 7 ) ;
55+
56+ helper . callGruntfile ( 'fixtures/gruntfile_multiple_files1.js' , function ( error , stdout , stderr ) {
57+ test . equal ( error , null , "Command should not fail." ) ;
58+ test . equal ( stderr , '' , "Standard error stream should be empty." ) ;
59+
60+ var obfuscated = grunt . file . read ( 'tmp/multiple_files1.js' ) ;
3061
3162 // should NOT be obfuscated
3263 test . ok ( obfuscated . indexOf ( 'console' ) > - 1 , '`console` shouldn\'t be obfuscated' ) ;
3364 test . ok ( obfuscated . indexOf ( 'FIRST_LOCAL_VARIABLE' ) > - 1 , '`FIRST_LOCAL_VARIABLE` shouldn\'t be obfuscated' ) ;
65+ test . ok ( obfuscated . indexOf ( 'SECOND_LOCAL_VARIABLE' ) > - 1 , '`SECOND_LOCAL_VARIABLE` shouldn\'t be obfuscated' ) ;
3466
3567 // should be obfuscated
3668 test . ok ( obfuscated . indexOf ( 'FIRST_STRING_LITERAL' ) === - 1 , '`FIRST_STRING_LITERAL` should be obfuscated' ) ;
69+ test . ok ( obfuscated . indexOf ( 'SECOND_STRING_LITERAL' ) === - 1 , '`SECOND_STRING_LITERAL` should be obfuscated' ) ;
3770
3871 test . done ( ) ;
3972 } ) ;
4073 } ,
4174
42- multiple_files : function ( test ) {
75+ multiple_files2 : function ( test ) {
4376 test . expect ( 7 ) ;
4477
45- helper . callGruntfile ( 'fixtures/gruntfile_multiple_files .js' , function ( error , stdout , stderr ) {
78+ helper . callGruntfile ( 'fixtures/gruntfile_multiple_files2 .js' , function ( error , stdout , stderr ) {
4679 test . equal ( error , null , "Command should not fail." ) ;
4780 test . equal ( stderr , '' , "Standard error stream should be empty." ) ;
4881
49- var obfuscated = grunt . file . read ( 'tmp/multiple_files ' ) ;
82+ var obfuscated = grunt . file . read ( 'tmp/multiple_files2.js ' ) ;
5083
5184 // should NOT be obfuscated
5285 test . ok ( obfuscated . indexOf ( 'console' ) > - 1 , '`console` shouldn\'t be obfuscated' ) ;
@@ -61,16 +94,39 @@ exports.javascript_obfuscator = {
6194 } ) ;
6295 } ,
6396
64- overwrite : function ( test ) {
97+
98+ overwrite1 : function ( test ) {
99+ test . expect ( 5 ) ;
100+
101+ grunt . file . copy ( 'test/fixtures/first_sample.js' , 'tmp/overwrite1.js' ) ;
102+
103+ helper . callGruntfile ( 'fixtures/gruntfile_overwrite1.js' , function ( error , stdout , stderr ) {
104+ test . equal ( error , null , "Command should not fail." ) ;
105+ test . equal ( stderr , '' , "Standard error stream should be empty." ) ;
106+
107+ var obfuscated = grunt . file . read ( 'tmp/overwrite1.js' ) ;
108+
109+ // should NOT be obfuscated
110+ test . ok ( obfuscated . indexOf ( 'console' ) > - 1 , '`console` shouldn\'t be obfuscated' ) ;
111+ test . ok ( obfuscated . indexOf ( 'FIRST_LOCAL_VARIABLE' ) > - 1 , '`FIRST_LOCAL_VARIABLE` shouldn\'t be obfuscated' ) ;
112+
113+ // should be obfuscated
114+ test . ok ( obfuscated . indexOf ( 'FIRST_STRING_LITERAL' ) === - 1 , '`FIRST_STRING_LITERAL` should be obfuscated' ) ;
115+
116+ test . done ( ) ;
117+ } ) ;
118+ } ,
119+
120+ overwrite2 : function ( test ) {
65121 test . expect ( 5 ) ;
66122
67- grunt . file . copy ( 'test/fixtures/first_sample.js' , 'tmp/overwrite .js' ) ;
123+ grunt . file . copy ( 'test/fixtures/first_sample.js' , 'tmp/overwrite2 .js' ) ;
68124
69- helper . callGruntfile ( 'fixtures/gruntfile_overwrite .js' , function ( error , stdout , stderr ) {
125+ helper . callGruntfile ( 'fixtures/gruntfile_overwrite2 .js' , function ( error , stdout , stderr ) {
70126 test . equal ( error , null , "Command should not fail." ) ;
71127 test . equal ( stderr , '' , "Standard error stream should be empty." ) ;
72128
73- var obfuscated = grunt . file . read ( 'tmp/overwrite .js' ) ;
129+ var obfuscated = grunt . file . read ( 'tmp/overwrite2 .js' ) ;
74130
75131 // should NOT be obfuscated
76132 test . ok ( obfuscated . indexOf ( 'console' ) > - 1 , '`console` shouldn\'t be obfuscated' ) ;
0 commit comments