exports['bump_version'] = function(test) { test.expect(3); test.equal(grunt.helper('bump_version', '0.0.1', 'patch'), '0.0.2'); test.equal(grunt.helper('bump_version', '1.0.1', 'minor'), '1.1.0'); test.equal(grunt.helper('bump_version', '1.5.1', 'major'), '2.0.0'); test.done(); };
'helper': function(test) { test.expect(2); grunt.helper('coffee', [src], outputFolder); test.equal(grunt.file.read(outputFolder + '/hello_world.js'), '\nconsole.log("Hello CoffeeScript!");\n', 'it should compile the coffee'); grunt.helper('coffee', [src], outputFolder, { bare:false }); test.equal(grunt.file.read(outputFolder + '/hello_world.js'), '(function() {\n\n console.log("Hello CoffeeScript!");\n\n}).call(this);\n', 'it should compile the coffee'); test.done(); },
it('should also replace local reference in anchors', function() { grunt.file.write('images/23012.foo.png', "foo"); var content = '<a href="http://foo/bar"></a><a href="ftp://bar"></a><a href="images/foo.png"></a><a href="/images/foo.png"></a><a href="#local"></a>'; var awaited = '<a href="http://foo/bar"></a><a href="ftp://bar"></a><a href="images/23012.foo.png"></a><a href="/images/23012.foo.png"></a><a href="#local"></a>'; var changed = grunt.helper('usemin:post:html', content); assert.ok( changed == awaited ); });
it('should treat files referenced from site root', function() { grunt.file.write('images/23012.foo.png', "foo"); var content = '<img src="/images/foo.png">'; var awaited = '<img src="/images/23012.foo.png">'; var changed = grunt.helper('usemin:post:html', content); assert.ok( changed == awaited ); });
it('do not depend on tag position', function() { grunt.file.write('css/23012.main.css', "foo"); var content = '<link href="css/main.css" rel="stylesheet"/><link rel="stylesheet" href="css/main.css"/>'; var awaited = '<link href="css/23012.main.css" rel="stylesheet"/><link rel="stylesheet" href="css/23012.main.css"/>'; var changed = grunt.helper('usemin:post:html', content); assert.ok( changed == awaited ); });
it('should skip external filei', function() { grunt.file.write('images/23012.foo.png', "foo"); var content = '<img src="//css/main.css">'; var awaited = '<img src="//css/main.css">'; var changed = grunt.helper('usemin:post:html', content); assert.ok( changed == awaited ); });
it("should replace a block with link on furnished target", function() { grunt.log.muted = true; var block = " foo\nbar\nbaz"; var content = "before block\n" + block + "\nafter block"; var awaited = "before block\n <link rel=\"stylesheet\" href=\"foo\"/>\nafter block"; var changed = grunt.helper('usemin:css', content, block, 'foo'); assert.ok( changed == awaited ); });
'helper-dirs': function(test) { test.expect(1); grunt.helper('coffee', [src], outputFolder, { preserve_dirs:true }); test.equal(grunt.file.read(path.join(outputFolder, expectedJSFile)), '\nconsole.log("Hello CoffeeScript!");\n', 'it should compile the coffee'); test.done(); },
'helper-nodest': function(test) { test.expect(1); grunt.helper('coffee', [src]); test.equal(grunt.file.read(expectedJSFile), '\nconsole.log("Hello CoffeeScript!");\n', 'it should compile the coffee'); test.done(); },
'testRequireSizeInfoHelper': function(test) { var helperValuesSeriesA = grunt.helper('require_size_info', 'a', true, 'foo'), helperValuesSeriesB = grunt.helper('require_size_info', 'b', false, 'foobar'); test.expect(8); // tests here test.equal(helperValuesSeriesA.module, 'a', 'Should determine the module'); test.equal(helperValuesSeriesA.gzipSize, 23, 'Should determine the correct gzip size'); test.equal(helperValuesSeriesA.fileSize, 3, 'Should determine the correct "file" size'); test.equal(helperValuesSeriesA.message, 'Compressed size for module "a": \u001b[32m23\u001b[39m bytes gzipped (\u001b[32m3\u001b[39m bytes minified).', 'Should output the correct message'); test.equal(helperValuesSeriesB.module, 'b', 'Should determine the module'); test.equal(helperValuesSeriesB.gzipSize, 26, 'Should determine the correct gzip size'); test.equal(helperValuesSeriesB.fileSize, 6, 'Should determine the correct "file" size'); test.equal(helperValuesSeriesB.message, 'Compressed size for module "b": \u001b[32m26\u001b[39m bytes gzipped (\u001b[32m6\u001b[39m bytes uncompressed).'); test.done(); },
it('should write a file with valid JSON', function () { grunt.helper('build-jquery-json-file', pkg, config); (function () { var manifest = JSON.parse(grunt.file.read('testplugin.jquery.json')); manifest.should.be.a('object').and.have.property('name', 'testplugin'); }).should.not.throwError(); });
'helper xmltojson': function(test) { test.expect(2); // tests here var file = grunt.file.read(grunt.file.expandFiles("test/fixtures/demofile.resx")); var result = grunt.helper('resx2json',file); test.equal(typeof result,"object"); test.ok(true,"done."); test.done(); }
it('should overwrite "pkg" values with "config" values', function () { var config = { title: 'Different Plugin Name', description: 'A different description.' }, manifest = grunt.helper('build-jquery-json', pkg, config); manifest.should.have.property('title', 'Different Plugin Name'); manifest.should.have.property('description', 'A different description.'); });
it('should include required fields', function () { var manifest = grunt.helper('build-jquery-json', pkg, config); manifest.should.have.property('name', 'testplugin'); manifest.should.have.property('version', '1.2.3'); manifest.should.have.property('title', 'jQuery Test Plugin'); manifest.should.have.property('author').and.eql({ name: 'Test Author' }); manifest.should.have.property('licenses').and.eql([{ type: 'MIT', url: 'http://opensource.org/licenses/MIT' }]); manifest.should.have.property('dependencies').and.eql({ jquery: '1.4.3' }); });
'can register and use helpers': function (test) { test.expect(1); // Register and use our helper grunt.registerHelper('hello', function () { return 'world'; }); test.strictEqual(grunt.helper('hello'), 'world'); // Callback test.done(); },
it('should include optional fields', function () { var manifest = grunt.helper('build-jquery-json', pkg, config); manifest.should.have.property('description', 'A jQuery plugin for testing.'); manifest.should.have.property('keywords').and.eql(['jquery', 'test', 'plugin']); manifest.should.have.property('homepage', 'https://github.com/tauthor/jquery-testplugin'); manifest.should.have.property('docs', 'https://github.com/tauthor/jquery-testplugin/blob/master/README.md'); manifest.should.have.property('demo', 'http://tauthor.github.com/jquery-testplugin'); manifest.should.have.property('download', 'http://tauthor.github.com/jquery-testplugin/latest.zip'); manifest.should.have.property('bugs', 'https://github.com/tauthor/jquery-testplugin/issues'); manifest.should.have.property('maintainers').and.eql([{ name: 'Test Maintainer', email: '*****@*****.**', url: 'http://jquerymaintainer.net' }]); });
'helper': function(test) { test.expect(1); // tests here grunt.helper('htmllint', ['test/valid.html', 'test/invalid.html'], function(error, result) { if (error) { throw error; } test.deepEqual(result, [ '"test/invalid.html":10.1-10.81: error: An "img" element must have an "alt" attribute, except under certain conditions. For details, consult guidance on providing text alternatives for images.', '"test/invalid.html":12.1-12.19: error: The "clear" attribute on the "br" element is obsolete. Use CSS instead.', '"test/invalid.html": info warning: The character encoding of the document was not declared.' ], 'three errors from test/invalid.html'); test.done(); }); }
'go': function(test) { "use strict"; var data = { language: "go" }; var expected = "language: go"; test.equal(grunt.helper('travisBuildFile',data), expected, 'Test to make sure go files are being built correctly'); test.done(); },
'almond helper runs callback even if almond: false': function(test) { var wasCalled = false, options = { config: { modules: [] }, almond: false, cb: function() { wasCalled = true; } }; grunt.helper('almond', options); test.equal(true, wasCalled); test.done(); }
'helper': function(test) { test.expect(1); // tests here var fs = require('fs'), testDir = process.cwd() + "/test/foo"; fs.mkdirSync(testDir); // not exactly sure how to test... test.equal( grunt.helper('clean', testDir), undefined, 'clean failed' ); test.done(); }
'node': function(test) { "use strict"; var data = { language: "node_js", node_js: ["0.8","0.6"] }; var expected = "language: node_js\n"; expected += "node_js:\n"; expected += " - 0.8\n"; expected += " - 0.6"; test.equal(grunt.helper('travisBuildFile',data), expected, 'Test to make sure node files are being built correctly'); test.done(); },
'helper-dirs-base': function(test) { var base = 'test'; test.expect(1); grunt.helper('coffee', [src], outputFolder, { preserve_dirs:true, base_path:base }); test.equal( grunt.file.read( path.join(outputFolder, expectedJSFile.replace(new RegExp('^'+base), '')) ), '\nconsole.log("Hello CoffeeScript!");\n', 'it should compile the coffee'); test.done(); },
'java': function(test) { "use strict"; var data = { language: "java", jdk: ["oraclejdk7","openjdk7","openjdk6"] }; var expected = "language: java\n"; expected += "jdk:\n"; expected += " - oraclejdk7\n"; expected += " - openjdk7\n"; expected += " - openjdk6"; test.equal(grunt.helper('travisBuildFile',data), expected, 'Test to make sure java files are being built correctly'); test.done(); },
'erlang': function(test) { "use strict"; var data = { language: "erlang", otp_release: ["R15B02","R15B01","R14B04"] }; var expected = "language: erlang\n"; expected += "otp_release:\n"; expected += " - R15B02\n"; expected += " - R15B01\n"; expected += " - R14B04"; test.equal(grunt.helper('travisBuildFile',data), expected, 'Test to make sure erlang files are being built correctly'); test.done(); },
'cplusplus': function(test) { "use strict"; var data = { language: "cpp", compiler: ["gcc","clang"], script: "./configure && make" }; var expected = "language: cpp\n"; expected += "compiler:\n"; expected += " - gcc\n"; expected += " - clang\n"; expected += "script: ./configure && make"; test.equal(grunt.helper('travisBuildFile',data), expected, 'Test to make sure c++ files are being built correctly'); test.done(); },
'clojure': function(test) { "use strict"; var data = { language: "clojure", jdk: ["oraclejdk7","openjdk7","openjdk6"], lein: "lein2" }; var expected = "language: clojure\n"; expected += "lein: lein2\n"; expected += "jdk:\n"; expected += " - oraclejdk7\n"; expected += " - openjdk7\n"; expected += " - openjdk6"; test.equal(grunt.helper('travisBuildFile',data), expected, 'Test to make sure clojure files are being built correctly'); test.done(); },
it("should take into account path", function() { usemin.call(grunt,grunt); // Let's prepare our context: in index.html we do have references // to images/test.png and images/misc/test.png. // Usemin's replace is supposed to change this by files // found on the filesystem matching the same path, but // potentially prefixed // e.g images/test.pmg -> images/misc/23012.test.png grunt.file.mkdir('images'); grunt.file.mkdir('images/misc'); grunt.file.write('images/23012.test.png', "foo"); grunt.file.write('images/misc/2a436.test.png', "foo"); // Let's avoid cluttering the output grunt.log.muted = true; var content = grunt.file.read(path.join(__dirname,"fixtures/usemin.html")); var changed = grunt.helper('replace',content, /<img[^\>]+src=['"]([^"']+)["']/gm); // Check replace has performed its duty assert.ok( changed.match(/img[^\>]+src=['"]images\/23012\.test\.png["']/) ); assert.ok( changed.match(/img[^\>]+src=['"]images\/misc\/2a436\.test\.png["']/) ); });
'scala': function(test) { "use strict"; var data = { language: "scala", scala: ["2.9.2","2.8.2"], jdk: ["oraclejdk7","openjdk7","openjdk6"] }; var expected = "language: scala\n"; expected += "scala:\n"; expected += " - 2.9.2\n"; expected += " - 2.8.2\n"; expected += "jdk:\n"; expected += " - oraclejdk7\n"; expected += " - openjdk7\n"; expected += " - openjdk6"; test.equal(grunt.helper('travisBuildFile',data), expected, 'Test to make sure scala files are being built correctly'); test.done(); }
setUp: function(done) { grunt.helper("testContribTask", "less:compile", done); },
it('should remove "jquery" from the "name" field', function () { var manifest = grunt.helper('build-jquery-json', pkg, config); manifest.should.have.property('name', 'testplugin'); });