├── .editorconfig ├── .gitignore ├── .jshintrc ├── .npmignore ├── .travis.yml ├── Gruntfile.js ├── LICENSE ├── README.md ├── bin └── grunt-preprocess ├── package.json ├── tasks └── preprocess.js └── test ├── expected ├── test.context-precedence.expected-1.js ├── test.context-precedence.expected-2.js ├── test.processed.custom.eol.expected.coffee ├── test.processed.expected.coffee ├── test.processed.expected.html ├── test.processed.expected.js └── test.processed.legacy.notfound.expected.coffee ├── fixtures ├── context-precedence.js ├── include.txt ├── inline │ ├── include.txt │ ├── test.js │ └── test2.js ├── test.coffee ├── test.html └── test.js └── preprocess_test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines, UTF-8 for all files 7 | [*] 8 | end_of_line = lf 9 | charset = utf-8 10 | 11 | # A newline ending every file (not sure if needed) 12 | #insert_final_newline = true 13 | 14 | # Tab indentation 15 | indent_style = space 16 | indent_size = 2 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.iml 3 | node_modules 4 | 5 | tmp 6 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "curly": false, 3 | "eqeqeq": true, 4 | "immed": true, 5 | "latedef": false, 6 | "newcap": true, 7 | "noarg": true, 8 | "sub": true, 9 | "undef": true, 10 | "boss": true, 11 | "eqnull": true, 12 | "node": true 13 | } 14 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | /tmp 3 | .idea 4 | *.iml -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "5" 4 | - "4" 5 | - "0.12" 6 | - "0.11" 7 | - "0.10" 8 | - "iojs" 9 | before_script: 10 | - npm install -g grunt-cli 11 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function(grunt) { 4 | 5 | // Project configuration. 6 | grunt.initConfig({ 7 | preprocess : { 8 | options : { 9 | context : { 10 | globalOption : "bar" 11 | } 12 | }, 13 | html : { 14 | src : 'test/fixtures/test.html', 15 | dest : 'tmp/test.processed.html', 16 | options : { 17 | context : { 18 | customOption : 'foo', 19 | foo: function (param) { 20 | return param + '-baz'; 21 | } 22 | } 23 | } 24 | }, 25 | js : { 26 | src : 'test/fixtures/test.js', 27 | dest : 'tmp/test.processed.js' 28 | }, 29 | coffee : { 30 | src : 'test/fixtures/test.coffee', 31 | dest : 'tmp/test.processed.coffee' 32 | }, 33 | 'customext with srcDir': { 34 | options: { 35 | type: 'coffee', 36 | srcDir: 'test/fixtures' 37 | }, 38 | src : 'tmp/test.coffee.customext', 39 | dest : 'tmp/test.processed.coffee.customext' 40 | }, 41 | fileNotFoundSilentFail: { 42 | options: { 43 | type: 'coffee', 44 | fileNotFoundSilentFail: true 45 | }, 46 | src : 'tmp/test.coffee.customext', 47 | dest : 'tmp/test.processed.legacy.notfound.coffee' 48 | }, 49 | customEol: { 50 | options: { 51 | srcEol: '\r\n' 52 | }, 53 | src : 'test/fixtures/test.coffee', 54 | dest : 'tmp/test.processed.custom.eol.coffee' 55 | }, 56 | deep : { 57 | src : 'test/fixtures/test.js', 58 | dest : 'tmp/deep/directory/structure/test.processed.js' 59 | }, 60 | multifile : { 61 | files : { 62 | 'tmp/multifile.test.processed.js': 'test/fixtures/test.js', 63 | 'tmp/multifile.test.processed.coffee': 'test/fixtures/test.coffee' 64 | } 65 | }, 66 | expanded : { 67 | files : { 68 | 'tmp/test-inline-expected.js' : 'test/fixtures/inline/test.js', 69 | 'tmp/test2-inline-expected.js' : 'test/fixtures/inline/test2.js' 70 | } 71 | }, 72 | inline : { 73 | src : 'tmp/inline-temp/*.js', 74 | options : { 75 | inline : true 76 | } 77 | }, 78 | 'context-precedence-1' : { 79 | src : 'test/fixtures/context-precedence.js', 80 | dest : 'tmp/context-precedence-result-1.js' 81 | }, 82 | 'context-precedence-2' : { 83 | options : { 84 | context : { 85 | globalOption : "foo" 86 | } 87 | }, 88 | src : 'test/fixtures/context-precedence.js', 89 | dest : 'tmp/context-precedence-result-2.js' 90 | } 91 | }, 92 | jshint: { 93 | options: { 94 | jshintrc : '.jshintrc' 95 | }, 96 | all : ['Gruntfile.js', 'tasks/**/*.js'] 97 | }, 98 | copy : { 99 | test : { 100 | files : [ 101 | {src : '*', dest : 'tmp/inline-temp', expand : true, cwd : 'test/fixtures/inline/'}, 102 | {src : "test/fixtures/test.coffee", dest: "tmp/test.coffee.customext"} 103 | ] 104 | } 105 | }, 106 | clean : { 107 | test : ['tmp'] 108 | }, 109 | nodeunit: { 110 | tests: ['test/*_test.js'] 111 | } 112 | }); 113 | 114 | grunt.loadNpmTasks('grunt-contrib-nodeunit'); 115 | grunt.loadNpmTasks('grunt-contrib-clean'); 116 | grunt.loadNpmTasks('grunt-contrib-copy'); 117 | grunt.loadNpmTasks('grunt-contrib-jshint'); 118 | 119 | // Load local tasks. 120 | grunt.loadTasks('tasks'); 121 | 122 | // Default task. 123 | grunt.registerTask('test', ['jshint','clean', 'fake-env', 'copy', 'preprocess', 'nodeunit']); 124 | 125 | grunt.registerTask('default', ['test']); 126 | 127 | grunt.registerTask('fake-env', function() { 128 | // create a fake env var for tests 129 | process.env['FAKEHOME'] = '/Users/joverson'; 130 | }); 131 | 132 | }; 133 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2012 OneHealth Solutions, Inc 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # grunt-preprocess 2 | [![NPM][npm-image]][npm-url] 3 | 4 | [![Linux Build Status][linux-ci-image]][linux-ci-url] [![dependencies][deps-image]][deps-url] [![dev-dependencies][dev-deps-image]][dev-deps-url] 5 | 6 | 7 | Grunt task around [preprocess](https://github.com/jsoverson/preprocess) npm module 8 | 9 | ## What does it look like? 10 | 11 | ```html 12 | 13 | Your App 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |

Debugging mode -

23 | 24 |

25 | 26 |

27 | 28 | ``` 29 | 30 | ```js 31 | var configValue = '/* @echo FOO */' || 'default value'; 32 | 33 | // @ifdef DEBUG 34 | someDebuggingCall() 35 | // @endif 36 | 37 | ``` 38 | 39 | See preprocess documentation for more information 40 | 41 | 42 | ## Getting Started 43 | Install this grunt plugin next to your project's Gruntfile with: `npm install --save-dev grunt-preprocess` 44 | 45 | Then add this line to your project's Gruntfile: 46 | 47 | ```javascript 48 | grunt.loadNpmTasks('grunt-preprocess'); 49 | ``` 50 | 51 | ## Options 52 | 53 | #### context 54 | Type: `Object` 55 | Default: `{NODE_ENV: 'development'}` 56 | 57 | The additional context on top of ENV that should be passed to templates. If NODE_ENV is not set, the task sets it to `development` by default. 58 | 59 | #### inline 60 | Type: `Boolean` 61 | Default: `undefined` 62 | 63 | Required to enable overwriting of source files 64 | 65 | #### srcDir 66 | Type: `String` 67 | Default: `` 68 | 69 | The directory where to look for files included via `@include` variants and `@extend`. 70 | 71 | #### srcEol 72 | Type: `String` 73 | Default: EOL of source file or `os.EOL` if source file contains multiple different or no EOLs. 74 | 75 | The end of line (EOL) character to use for the preprocessed result. May be one of: 76 | - `\r\n` - Windows 77 | - `\n` - Linux/OSX/Unix 78 | - `\r` - legacy Mac 79 | 80 | #### type 81 | Type: `String` 82 | Default: file extension of the file to be processed 83 | 84 | The syntax type of source file to preprocess. See [preprocess() description](https://github.com/jsoverson/preprocess#optionstype) for a list of all supported file types. 85 | 86 | ## Example Usage 87 | 88 | ```js 89 | preprocess : { 90 | options: { 91 | context : { 92 | DEBUG: true 93 | } 94 | }, 95 | html : { 96 | src : 'test/test.html', 97 | dest : 'test/test.processed.html' 98 | }, 99 | js : { 100 | src : 'test/test.js', 101 | dest : 'test/test.processed.js' 102 | }, 103 | multifile : { 104 | files : { 105 | 'test/test.processed.html' : 'test/test.html', 106 | 'test/test.processed.js' : 'test/test.js' 107 | } 108 | }, 109 | inline : { 110 | src : [ 'processed/**/*.js' ], 111 | options: { 112 | inline : true, 113 | context : { 114 | DEBUG: false 115 | } 116 | } 117 | }, 118 | all_from_dir: { 119 | src: '**/*.tmpl', 120 | ext: '.html', 121 | cwd: 'src', 122 | dest: 'build', 123 | expand: true 124 | } 125 | } 126 | ``` 127 | 128 | 129 | [grunt]: https://github.com/gruntjs/grunt 130 | 131 | ## Contributing 132 | In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt][grunt]. 133 | 134 | ## Release History 135 | 136 | - 5.1.0 137 | - Grunt peer dependency tagged >= 0.4.0, dependency updates 138 | - added explicit dependency on lodash 139 | - added logging for preprocess errors (@marcominetti, #53) 140 | - 5.0.1 fixed processing of mutifile-style tasks for multiple different file extensions or different containing directories (#50) 141 | - 5.0.0 bumped preprocess dep to 3.0.2, implemented backward-compatible mapping of old to new options and pass-through for new options (#34, #39, #48) 142 | - 4.2.0 bumped preprocess dep to 2.3.1, bumped dev dependencies 143 | - 4.1.0 bumped preprocess dep to 2.1.0 144 | - 4.0.0 Switched order of context assignment, small change but necessitated major version 145 | - 3.0.1 Fixed issue arising from undefined options (#19) 146 | - 3.0.0 Updated dependencies, added merge from global options context to subtask context (#13) 147 | - 2.3.0 Updated preprocess, changes default handling to html 148 | - 2.2.0 Delegating to grunt's file.read/write for consistent usage within grunt (e.g. deep writes) 149 | - 2.1.0 updated preprocess dependency 150 | - 2.0.0 updated for grunt 0.4.0, moved context override to `context` option 151 | - 1.3.0 Moved logic to 'preprocess' npm module 152 | - 1.2.1 Added @include to include external files 153 | - 1.2.0 Added @include to include external files 154 | - 1.1.0 Added ability to process multiple destinations in a files block 155 | - 1.0.0 Changed syntax, added directives 156 | - 0.4.0 Added support for inline JS directives 157 | - 0.3.0 Added insert, extended context to all environment 158 | - 0.2.0 Added simple directive syntax 159 | - 0.1.0 Initial release 160 | 161 | ## License 162 | 163 | Written by Jarrod Overson 164 | 165 | Licensed under the Apache 2.0 license. 166 | 167 | [npm-image]: https://nodei.co/npm/grunt-preprocess.png?downloads=true 168 | [npm-url]: https://www.npmjs.com/package/grunt-preprocess 169 | [linux-ci-image]: https://img.shields.io/travis/jsoverson/grunt-preprocess/master.svg?style=flat-square 170 | [linux-ci-url]: https://travis-ci.org/jsoverson/grunt-preprocess 171 | [deps-image]: https://img.shields.io/david/jsoverson/grunt-preprocess.svg?style=flat-square 172 | [deps-url]: https://david-dm.org/jsoverson/grunt-preprocess 173 | [dev-deps-image]: https://img.shields.io/david/dev/jsoverson/grunt-preprocess.svg?style=flat-square 174 | [dev-deps-url]: https://david-dm.org/jsoverson/grunt-preprocess#info=devDependencies 175 | -------------------------------------------------------------------------------- /bin/grunt-preprocess: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('grunt').npmTasks('grunt-preprocess').cli(); 3 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "grunt-preprocess", 3 | "description": "Preprocess HTML and JavaScript directives based off environment configuration", 4 | "version": "5.1.0", 5 | "homepage": "https://github.com/jsoverson/grunt-preprocess", 6 | "author": { 7 | "name": "Jarrod Overson", 8 | "email": "jsoverson@gmail.com", 9 | "url": "http://jarrodoverson.com/" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git://github.com/jsoverson/grunt-preprocess.git" 14 | }, 15 | "bugs": { 16 | "url": "https://github.com/jsoverson/grunt-preprocess/issues" 17 | }, 18 | "licenses": [ 19 | { 20 | "type": "Apache", 21 | "url": "https://github.com/jsoverson/grunt-preprocess/blob/master/LICENSE" 22 | } 23 | ], 24 | "main": "Gruntfile.js", 25 | "bin": "bin/grunt-preprocess", 26 | "engines": { 27 | "node": ">=0.10.0" 28 | }, 29 | "scripts": { 30 | "test": "grunt test" 31 | }, 32 | "peerDependencies": { 33 | "grunt": ">=0.4.0" 34 | }, 35 | "dependencies": { 36 | "lodash": "^4.5.0", 37 | "preprocess": "^3.0.2" 38 | }, 39 | "devDependencies": { 40 | "grunt": "^0.4.5", 41 | "grunt-contrib-clean": "^1.0.0", 42 | "grunt-contrib-copy": "^0.8.0", 43 | "grunt-contrib-jshint": "^1.0.0", 44 | "grunt-contrib-nodeunit": "^0.4.0" 45 | }, 46 | "keywords": [ 47 | "gruntplugin", 48 | "directive", 49 | "var", 50 | "ENV", 51 | "environment", 52 | "ifdef", 53 | "echo", 54 | "include", 55 | "exclude", 56 | "process", 57 | "preprocess", 58 | "pragma" 59 | ] 60 | } 61 | -------------------------------------------------------------------------------- /tasks/preprocess.js: -------------------------------------------------------------------------------- 1 | /* 2 | * preprocess 3 | * https://github.com/onehealth/grunt-preprocess 4 | * 5 | * Copyright (c) 2012 OneHealth Solutions, Inc. 6 | * Written by Jarrod Overson - http://jarrodoverson.com/ 7 | * Licensed under the Apache 2.0 license. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | var _ = require('lodash'); 13 | var path = require('path'); 14 | 15 | module.exports = init; 16 | 17 | var preprocess = require('preprocess'); 18 | 19 | function init(grunt) { 20 | grunt.registerMultiTask('preprocess', 'Preprocess files based off environment configuration', function() { 21 | 22 | grunt.config.requires(this.name); 23 | 24 | var taskOptions = _.clone(this.options() || {}); 25 | var globalOptions = _.clone(grunt.config(this.name).options || {}); 26 | 27 | if (taskOptions.srcEol != null) { 28 | taskOptions.srcEol = grunt.config.getRaw([this.name, this.target, 'options.srcEol'].join('.')); 29 | } 30 | if (globalOptions.srcEol != null) { 31 | globalOptions.srcEol = grunt.config.getRaw(this.name + '.options.srcEol'); 32 | } 33 | 34 | var context = _.merge({}, process.env, globalOptions.context, taskOptions.context); 35 | context.NODE_ENV = context.NODE_ENV || 'development'; 36 | 37 | delete taskOptions.context; 38 | delete globalOptions.context; 39 | 40 | var options = _.merge(globalOptions, taskOptions); 41 | 42 | this.files.forEach(function(fileObj){ 43 | if (!fileObj.dest) { 44 | if (!taskOptions.inline) { 45 | grunt.log.error('WARNING : POTENTIAL CODE LOSS.'.yellow); 46 | grunt.log.error('You must specify "inline : true" when using the "files" configuration.'); 47 | grunt.log.errorlns( 48 | 'This WILL REWRITE FILES WITHOUT MAKING BACKUPS. Make sure your ' + 49 | 'code is checked in or you are configured to operate on a copied directory.' 50 | ); 51 | return; 52 | } 53 | fileObj.src.forEach(function(src) { 54 | preprocessFile(grunt, src, src, context, options); 55 | }); 56 | } else { 57 | var src = fileObj.src[0]; 58 | var dest = grunt.template.process(fileObj.dest); 59 | 60 | preprocessFile(grunt, src, dest, context, options); 61 | } 62 | }); 63 | }); 64 | } 65 | 66 | function preprocessFile(grunt, src, dest, context, options) { 67 | try { 68 | var srcText = grunt.file.read(src); 69 | context.src = src; 70 | 71 | // need to copy options so that any further file-specific modifications on the object 72 | // are not persisted for different files 73 | options = _.clone(options); 74 | 75 | // context.srcDir is for backwards-compatibility only 76 | options.srcDir = context.srcDir || options.srcDir || path.dirname(src); 77 | options.type = options.type || getExtension(src); 78 | var processed = preprocess.preprocess(srcText, context, options); 79 | grunt.file.write(dest, processed); 80 | } catch(e) { 81 | grunt.log.error('Error while preprocessing %s', src); 82 | throw e; 83 | } 84 | } 85 | 86 | function getExtension(filename) { 87 | var ext = path.extname(filename||'').split('.'); 88 | return ext[ext.length - 1]; 89 | } 90 | -------------------------------------------------------------------------------- /test/expected/test.context-precedence.expected-1.js: -------------------------------------------------------------------------------- 1 | /*global define*/ 2 | 3 | define([], function () { 4 | "use strict"; 5 | 6 | bar(); 7 | 8 | 9 | }); 10 | -------------------------------------------------------------------------------- /test/expected/test.context-precedence.expected-2.js: -------------------------------------------------------------------------------- 1 | /*global define*/ 2 | 3 | define([], function () { 4 | "use strict"; 5 | 6 | 7 | foo(); 8 | 9 | }); 10 | -------------------------------------------------------------------------------- /test/expected/test.processed.custom.eol.expected.coffee: -------------------------------------------------------------------------------- 1 | #global define 2 | 3 | define [], -> 4 | "use strict" 5 | 6 | superExpensiveFunction() 7 | 8 | 9 | !foobar! 10 | -------------------------------------------------------------------------------- /test/expected/test.processed.expected.coffee: -------------------------------------------------------------------------------- 1 | #global define 2 | 3 | define [], -> 4 | "use strict" 5 | 6 | superExpensiveFunction() 7 | 8 | 9 | !foobar! 10 | -------------------------------------------------------------------------------- /test/expected/test.processed.expected.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | dev title 5 | 6 | 7 | 8 | 9 |

bar

10 |

foo

11 |

/Users/joverson

12 |

!foobar! 13 |

14 |

bar-baz

15 | 16 | 17 | -------------------------------------------------------------------------------- /test/expected/test.processed.expected.js: -------------------------------------------------------------------------------- 1 | /*global define*/ 2 | 3 | define([], function () { 4 | "use strict"; 5 | 6 | bar 7 | 8 | superExpensiveFunction() 9 | 10 | 11 | !foobar! 12 | 13 | 14 | }); 15 | -------------------------------------------------------------------------------- /test/expected/test.processed.legacy.notfound.expected.coffee: -------------------------------------------------------------------------------- 1 | #global define 2 | 3 | define [], -> 4 | "use strict" 5 | 6 | superExpensiveFunction() 7 | 8 | 9 | tmp/include.txt not found! -------------------------------------------------------------------------------- /test/fixtures/context-precedence.js: -------------------------------------------------------------------------------- 1 | /*global define*/ 2 | 3 | define([], function () { 4 | "use strict"; 5 | 6 | //@if globalOption='bar' 7 | bar(); 8 | //@endif 9 | 10 | //@if globalOption='foo' 11 | foo(); 12 | //@endif 13 | 14 | }); 15 | -------------------------------------------------------------------------------- /test/fixtures/include.txt: -------------------------------------------------------------------------------- 1 | !foobar! 2 | -------------------------------------------------------------------------------- /test/fixtures/inline/include.txt: -------------------------------------------------------------------------------- 1 | !foobar! 2 | -------------------------------------------------------------------------------- /test/fixtures/inline/test.js: -------------------------------------------------------------------------------- 1 | /*global define*/ 2 | 3 | define([], function () { 4 | "use strict"; 5 | 6 | //@exclude NODE_ENV='production' 7 | superExpensiveFunction() 8 | //@endexclude 9 | 10 | //@if NODE_ENV='production' 11 | superExpensiveFunction() 12 | //@endif 13 | 14 | /*@include include.txt */ 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /test/fixtures/inline/test2.js: -------------------------------------------------------------------------------- 1 | /*global define*/ 2 | 3 | define([], function () { 4 | "use strict"; 5 | 6 | //@exclude NODE_ENV='production' 7 | foo2() 8 | //@endexclude 9 | 10 | //@if NODE_ENV='production' 11 | foo2() 12 | //@endif 13 | 14 | /*@include include.txt */ 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /test/fixtures/test.coffee: -------------------------------------------------------------------------------- 1 | #global define 2 | 3 | define [], -> 4 | "use strict" 5 | 6 | # @exclude NODE_ENV='production' 7 | superExpensiveFunction() 8 | # @endexclude 9 | 10 | # @if NODE_ENV='production' 11 | superExpensiveFunction() 12 | # @endif 13 | 14 | # @include include.txt -------------------------------------------------------------------------------- /test/fixtures/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | dev title 6 | 7 | 8 | 9 | prod title 10 | 11 | 12 | 13 | 14 |

15 |

16 |

17 |

18 |

19 | 20 | 21 | -------------------------------------------------------------------------------- /test/fixtures/test.js: -------------------------------------------------------------------------------- 1 | /*global define*/ 2 | 3 | define([], function () { 4 | "use strict"; 5 | 6 | //@echo globalOption 7 | 8 | //@exclude NODE_ENV='production' 9 | superExpensiveFunction() 10 | //@endexclude 11 | 12 | //@if NODE_ENV='production' 13 | superExpensiveFunction() 14 | //@endif 15 | 16 | /*@include include.txt */ 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /test/preprocess_test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var grunt = require('grunt'); 4 | 5 | /* 6 | ======== A Handy Little Nodeunit Reference ======== 7 | https://github.com/caolan/nodeunit 8 | 9 | Test methods: 10 | test.expect(numAssertions) 11 | test.done() 12 | Test assertions: 13 | test.ok(value, [message]) 14 | test.equal(actual, expected, [message]) 15 | test.notEqual(actual, expected, [message]) 16 | test.deepEqual(actual, expected, [message]) 17 | test.notDeepEqual(actual, expected, [message]) 18 | test.strictEqual(actual, expected, [message]) 19 | test.notStrictEqual(actual, expected, [message]) 20 | test.throws(block, [error], [message]) 21 | test.doesNotThrow(block, [error], [message]) 22 | test.ifError(value) 23 | */ 24 | 25 | var task = require('../tasks/preprocess'); 26 | 27 | var read = grunt.file.read; 28 | 29 | exports['preprocess'] = { 30 | setUp: function(done) { 31 | // setup here 32 | done(); 33 | }, 34 | 'preprocess html': function(test) { 35 | test.expect(1); 36 | var expected, actual; 37 | 38 | expected = 'test/expected/test.processed.expected.html'; 39 | actual = 'tmp/test.processed.html'; 40 | test.equal(read(expected), read(actual), actual + ' differs'); 41 | 42 | test.done(); 43 | 44 | }, 45 | 'preprocess js': function(test) { 46 | test.expect(1); 47 | var expected, actual; 48 | 49 | expected = 'test/expected/test.processed.expected.js'; 50 | actual = 'tmp/test.processed.js'; 51 | test.equal(read(expected), read(actual), actual + ' differs'); 52 | 53 | test.done(); 54 | 55 | }, 56 | 'preprocess coffee': function(test) { 57 | test.expect(1); 58 | var expected, actual; 59 | 60 | expected = 'test/expected/test.processed.expected.coffee'; 61 | actual = 'tmp/test.processed.coffee'; 62 | test.equal(read(expected), read(actual), actual + ' differs'); 63 | 64 | test.done(); 65 | 66 | }, 67 | 'preprocess custom extensions and custom srcDir options': function(test) { 68 | test.expect(1); 69 | var expected, actual; 70 | 71 | expected = 'test/expected/test.processed.expected.coffee'; 72 | actual = 'tmp/test.processed.coffee.customext'; 73 | test.equal(read(expected), read(actual), actual + ' differs'); 74 | 75 | test.done(); 76 | 77 | }, 78 | 'preprocess files with fileNotFoundSilentFail option': function(test) { 79 | test.expect(1); 80 | var expected, actual; 81 | 82 | expected = 'test/expected/test.processed.legacy.notfound.expected.coffee'; 83 | actual = 'tmp/test.processed.legacy.notfound.coffee'; 84 | test.equal(read(expected), read(actual), actual + ' differs'); 85 | 86 | test.done(); 87 | 88 | }, 89 | 'preprocess files with srcEol option': function(test) { 90 | test.expect(1); 91 | var expected, actual; 92 | 93 | expected = 'test/expected/test.processed.custom.eol.expected.coffee'; 94 | actual = 'tmp/test.processed.custom.eol.coffee'; 95 | test.equal(read(expected), read(actual), actual + ' differs'); 96 | 97 | test.done(); 98 | 99 | }, 100 | 'preprocess multifile': function(test) { 101 | test.expect(2); 102 | var expected, actual; 103 | 104 | expected = 'test/expected/test.processed.expected.js'; 105 | actual = 'tmp/multifile.test.processed.js'; 106 | test.equal(read(expected), read(actual), actual + ' differs'); 107 | 108 | expected = 'test/expected/test.processed.expected.coffee'; 109 | actual = 'tmp/multifile.test.processed.coffee'; 110 | test.equal(read(expected), read(actual), actual + ' differs'); 111 | 112 | test.done(); 113 | 114 | }, 115 | 'inline': function(test) { 116 | test.expect(2); 117 | var expected, actual; 118 | 119 | expected = 'tmp/test-inline-expected.js'; 120 | actual = 'tmp/inline-temp/test.js'; 121 | test.equal(read(expected), read(actual), actual + ' differs'); 122 | 123 | expected = 'tmp/test2-inline-expected.js'; 124 | actual = 'tmp/inline-temp/test2.js'; 125 | test.equal(read(expected), read(actual), actual + ' differs'); 126 | 127 | test.done(); 128 | 129 | }, 130 | 'context precedence': function(test) { 131 | test.expect(2); 132 | var expected, actual; 133 | 134 | expected = 'test/expected/test.context-precedence.expected-1.js'; 135 | actual = 'tmp/context-precedence-result-1.js'; 136 | test.equal(read(expected), read(actual), actual + ' differs'); 137 | 138 | expected = 'test/expected/test.context-precedence.expected-2.js'; 139 | actual = 'tmp/context-precedence-result-2.js'; 140 | test.equal(read(expected), read(actual), actual + ' differs'); 141 | 142 | test.done(); 143 | 144 | } 145 | }; 146 | --------------------------------------------------------------------------------