[484] | 1 | var grunt = require('grunt'); |
---|
| 2 | var fs = require('fs'); |
---|
| 3 | |
---|
| 4 | function readFile(file) { |
---|
| 5 | 'use strict'; |
---|
| 6 | |
---|
| 7 | var contents = grunt.file.read(file); |
---|
| 8 | |
---|
| 9 | if (process.platform === 'win32') { |
---|
| 10 | contents = contents.replace(/\r\n/g, '\n'); |
---|
| 11 | } |
---|
| 12 | |
---|
| 13 | return contents; |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | function assertFileEquality(test, pathToActual, pathToExpected, message) { |
---|
| 17 | var actual = readFile(pathToActual); |
---|
| 18 | var expected = readFile(pathToExpected); |
---|
| 19 | test.equal(expected, actual, message); |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | exports.coffee = { |
---|
| 23 | compileBare: function(test) { |
---|
| 24 | 'use strict'; |
---|
| 25 | |
---|
| 26 | test.expect(4); |
---|
| 27 | |
---|
| 28 | assertFileEquality(test, |
---|
| 29 | 'tmp/bare/coffee.js', |
---|
| 30 | 'test/expected/bare/coffee.js', |
---|
| 31 | 'Should compile coffeescript to unwrapped javascript'); |
---|
| 32 | |
---|
| 33 | assertFileEquality(test, |
---|
| 34 | 'tmp/bare/litcoffee.js', |
---|
| 35 | 'test/expected/bare/litcoffee.js', |
---|
| 36 | 'Should compile literate coffeescript to unwrapped javascript'); |
---|
| 37 | |
---|
| 38 | assertFileEquality(test, |
---|
| 39 | 'tmp/bare/litcoffeemd.js', |
---|
| 40 | 'test/expected/bare/litcoffee.js', |
---|
| 41 | 'Should compile literate coffeescript to unwrapped javascript'); |
---|
| 42 | |
---|
| 43 | assertFileEquality(test, |
---|
| 44 | 'tmp/bare/concat.js', |
---|
| 45 | 'test/expected/bare/concat.js', |
---|
| 46 | 'Should compile coffeescript files without wrappers and concatenate them into a single javascript file'); |
---|
| 47 | |
---|
| 48 | test.done(); |
---|
| 49 | }, |
---|
| 50 | compileDefault: function(test) { |
---|
| 51 | 'use strict'; |
---|
| 52 | |
---|
| 53 | test.expect(4); |
---|
| 54 | |
---|
| 55 | assertFileEquality(test, |
---|
| 56 | 'tmp/default/coffee.js', |
---|
| 57 | 'test/expected/default/coffee.js', |
---|
| 58 | 'Should compile coffeescript to javascript'); |
---|
| 59 | |
---|
| 60 | assertFileEquality(test, |
---|
| 61 | 'tmp/default/litcoffee.js', |
---|
| 62 | 'test/expected/default/litcoffee.js', |
---|
| 63 | 'Should compile literate coffeescript to wrapped javascript'); |
---|
| 64 | |
---|
| 65 | assertFileEquality(test, |
---|
| 66 | 'tmp/default/litcoffeemd.js', |
---|
| 67 | 'test/expected/default/litcoffee.js', |
---|
| 68 | 'Should compile literate coffeescript to wrapped javascript'); |
---|
| 69 | |
---|
| 70 | assertFileEquality(test, |
---|
| 71 | 'tmp/default/concat.js', |
---|
| 72 | 'test/expected/default/concat.js', |
---|
| 73 | 'Should compile coffeescript files with wrappers and concatenate them into a single javascript file'); |
---|
| 74 | |
---|
| 75 | test.done(); |
---|
| 76 | }, |
---|
| 77 | compileJoined: function(test) { |
---|
| 78 | 'use strict'; |
---|
| 79 | |
---|
| 80 | test.expect(4); |
---|
| 81 | |
---|
| 82 | assertFileEquality(test, |
---|
| 83 | 'tmp/join/coffee.js', |
---|
| 84 | 'test/expected/default/coffee.js', |
---|
| 85 | 'Compilation of one file with join enabled should match normal compilation'); |
---|
| 86 | |
---|
| 87 | assertFileEquality(test, |
---|
| 88 | 'tmp/join/join.js', |
---|
| 89 | 'test/expected/join/join.js', |
---|
| 90 | 'Should concatenate coffeescript files prior to compilation into a single javascript file'); |
---|
| 91 | |
---|
| 92 | assertFileEquality(test, |
---|
| 93 | 'tmp/join/bareCoffee.js', |
---|
| 94 | 'test/expected/bare/coffee.js', |
---|
| 95 | 'Bare compilation of one file with join enabled should match bare compilation'); |
---|
| 96 | |
---|
| 97 | assertFileEquality(test, |
---|
| 98 | 'tmp/join/bareJoin.js', |
---|
| 99 | 'test/expected/join/bareJoin.js', |
---|
| 100 | 'Bare compilation of multiple join files should be equivalent to concatenated compilation'); |
---|
| 101 | |
---|
| 102 | test.done(); |
---|
| 103 | }, |
---|
| 104 | compileMaps: function(test) { |
---|
| 105 | 'use strict'; |
---|
| 106 | |
---|
| 107 | test.expect(10); |
---|
| 108 | |
---|
| 109 | assertFileEquality(test, |
---|
| 110 | 'tmp/maps/coffee.js', |
---|
| 111 | 'test/expected/maps/coffee.js', |
---|
| 112 | 'Compilation of single file with source maps should generate javascript'); |
---|
| 113 | |
---|
| 114 | assertFileEquality(test, |
---|
| 115 | 'tmp/maps/coffee.js.map', |
---|
| 116 | 'test/expected/maps/coffee.js.map', |
---|
| 117 | 'Compilation of single file with source maps should generate map'); |
---|
| 118 | |
---|
| 119 | assertFileEquality(test, |
---|
| 120 | 'tmp/maps/coffeeJoin.js', |
---|
| 121 | 'test/expected/maps/coffeeJoin.js', |
---|
| 122 | 'Compilation of multiple files with source maps should generate javascript'); |
---|
| 123 | |
---|
| 124 | assertFileEquality(test, |
---|
| 125 | 'tmp/maps/coffeeJoin.js.map', |
---|
| 126 | 'test/expected/maps/coffeeJoin.js.map', |
---|
| 127 | 'Compilation of multiple files with source maps should generate map'); |
---|
| 128 | |
---|
| 129 | assertFileEquality(test, |
---|
| 130 | 'tmp/maps/coffeeJoin.src.coffee', |
---|
| 131 | 'test/expected/maps/coffeeJoin.src.coffee', |
---|
| 132 | 'Compilation of multiple files with source maps should output concatenated source'); |
---|
| 133 | |
---|
| 134 | assertFileEquality(test, |
---|
| 135 | 'tmp/maps/coffeeBare.js', |
---|
| 136 | 'test/expected/maps/coffeeBare.js', |
---|
| 137 | 'Bare compilation of single file with source maps should generate javascript'); |
---|
| 138 | |
---|
| 139 | assertFileEquality(test, |
---|
| 140 | 'tmp/maps/coffeeBare.js.map', |
---|
| 141 | 'test/expected/maps/coffeeBare.js.map', |
---|
| 142 | 'Bare compilation of single file with source maps should generate map'); |
---|
| 143 | |
---|
| 144 | assertFileEquality(test, |
---|
| 145 | 'tmp/maps/coffeeBareJoin.js', |
---|
| 146 | 'test/expected/maps/coffeeBareJoin.js', |
---|
| 147 | 'Bare compilation of multiple files with source maps should generate javascript'); |
---|
| 148 | |
---|
| 149 | assertFileEquality(test, |
---|
| 150 | 'tmp/maps/coffeeBareJoin.js.map', |
---|
| 151 | 'test/expected/maps/coffeeBareJoin.js.map', |
---|
| 152 | 'Bare compilation of multiple files with source maps should generate map'); |
---|
| 153 | |
---|
| 154 | assertFileEquality(test, |
---|
| 155 | 'tmp/maps/coffeeBareJoin.src.coffee', |
---|
| 156 | 'test/expected/maps/coffeeBareJoin.src.coffee', |
---|
| 157 | 'Bare compilation of multiple files with source maps should output concatenated source'); |
---|
| 158 | |
---|
| 159 | test.done(); |
---|
| 160 | }, |
---|
| 161 | compileEachMap: function(test) { |
---|
| 162 | 'use strict'; |
---|
| 163 | |
---|
| 164 | test.expect(4); |
---|
| 165 | |
---|
| 166 | assertFileEquality(test, |
---|
| 167 | 'tmp/eachMap/coffee1.js', |
---|
| 168 | 'test/expected/eachMap/coffee1.js', |
---|
| 169 | 'Separate compilation of coffee and litcoffee files with source maps should generate javascript'); |
---|
| 170 | |
---|
| 171 | assertFileEquality(test, |
---|
| 172 | 'tmp/eachMap/litcoffee.js', |
---|
| 173 | 'test/expected/eachMap/litcoffee.js', |
---|
| 174 | 'Separate compilation of coffee and litcoffee files with source maps should generate javascript'); |
---|
| 175 | |
---|
| 176 | assertFileEquality(test, |
---|
| 177 | 'tmp/eachMap/coffee1.js.map', |
---|
| 178 | 'test/expected/eachMap/coffee1.js.map', |
---|
| 179 | 'Separate compilation of coffee and litcoffee files with source maps should generate map'); |
---|
| 180 | |
---|
| 181 | assertFileEquality(test, |
---|
| 182 | 'tmp/eachMap/litcoffee.js.map', |
---|
| 183 | 'test/expected/eachMap/litcoffee.js.map', |
---|
| 184 | 'Separate compilation of coffee and litcoffee files with source maps should generate map'); |
---|
| 185 | |
---|
| 186 | test.done(); |
---|
| 187 | } |
---|
| 188 | }; |
---|