diff --git a/CHANGELOG.md b/CHANGELOG.md index bd96c36..3fa7528 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,10 @@ previously installed nothing will change, this is just an informal update. * **Feed:** Updated the feed to be more up to par and completely valid * **Packages:** Updated the packages to be more up to date on NPM +#### Behind the scenes +* **Tests:** Continued working on tests to make errors even less likely. Yay + tests. + ## 0.7.1 - Bugfix diff --git a/app/index.js b/app/index.js index 98888a7..1465a35 100644 --- a/app/index.js +++ b/app/index.js @@ -231,6 +231,7 @@ module.exports = yeoman.generators.Base.extend({ this.amazonCloudfrontS3 = hasFeature("amazonCloudfrontS3"); this.rsync = hasFeature("rsync"); this.githubPages = hasFeature("githubPages"); + this.noUpload = hasFeature("noUpload"); this.amazonKey = props.amazonKey; this.amazonSecret = props.amazonSecret; diff --git a/app/templates/gulpfile.js b/app/templates/gulpfile.js index b8855f6..c7983a7 100755 --- a/app/templates/gulpfile.js +++ b/app/templates/gulpfile.js @@ -273,10 +273,10 @@ gulp.task("optimize", gulp.series( gulp.task("build", gulp.series( gulp.series(jekyllDev), gulp.parallel(styles, javascript, fonts, images) -)); +));<% if (!noUpload) { %> // Deploy your site for all to see -gulp.task("deploy", deploy); +gulp.task("deploy", deploy);<% } %> // Serves your site locally gulp.task("serve", serve); diff --git a/test-util.js b/test-util.js deleted file mode 100644 index 41b04b6..0000000 --- a/test-util.js +++ /dev/null @@ -1,37 +0,0 @@ -"use strict"; - -var fs = require("fs"); -var assert = require("assert"); - -exports.assertTaskExists = function (generator, taskName, features, done) { - var gulpFile = fs.readFileSync("./gulpfile.js", "utf8"); - var regExpGulp = new RegExp("gulp.task\\(\"" + taskName + "\""); - - assert.ok( - regExpGulp.test(gulpFile), - "gulpfile.js does not contain " + taskName + " task" - ); - done(); -}; - -exports.assertJekyllSettings = function (generator, settingName, settingValue, done) { - var configFile = fs.readFileSync("./_config.yml", "utf8"); - var settingRegExp = new RegExp(settingName + ": " + settingValue); - - assert.ok( - settingRegExp.test(configFile), - "_config.yml setting " + settingName + " does not contain the right value" - ); - done(); -}; - -exports.assertJekyllBuildSettings = function (generator, settingName, settingValue, done) { - var configBuildFile = fs.readFileSync("./_config.build.yml", "utf8"); - var settingRegExp = new RegExp(settingName + ": " + settingValue); - - assert.ok( - settingRegExp.test(configBuildFile), - "_config.build.yml setting " + settingName + " does not contain the right value" - ); - done(); -}; diff --git a/test/test-creation-aws.js b/test/test-creation-aws.js index 81577c9..3d9f48c 100755 --- a/test/test-creation-aws.js +++ b/test/test-creation-aws.js @@ -4,7 +4,6 @@ var path = require("path"); var helpers = require("yeoman-generator").test; var assert = require("yeoman-generator").assert; -var tasks = require("../test-util.js"); describe("Jekyllized generator test when using Amazon AWS", function () { before(function (done) { @@ -36,8 +35,28 @@ describe("Jekyllized generator test when using Amazon AWS", function () { assert.file(expected); }); - it("should contain deploy tasks", function (done) { - tasks.assertTaskExists(this.jekyllized, "deploy", [], done); + it("should contain the correct deploy function", function () { + assert.fileContent("gulpfile.js", /\/\/ Task to deploy your site to Amazon S3 and Cloudfront/); + }); + + it("should NOT contain either the GH Pages or Rsync function", function () { + assert.noFileContent("gulpfile.js", /\/\/ Task to upload your site via Rsync to your server/); + assert.noFileContent("gulpfile.js", /\/\/ Task to upload your site to your personal GH Pages repo/); + }); + + it("should contain deploy tasks", function () { + assert.fileContent("gulpfile.js", /gulp.task\(\"deploy\"/); + }); + + it("should contain the correct packages", function () { + var expected = [ + ["package.json", /\"concurrent-transform\"/], + ["package.json", /\"gulp-awspublish\"/], + ["package.json", /\"gulp-awspublish-router\"/], + ["package.json", /\"gulp-cloudfront\"/] + ]; + + assert.fileContent(expected); }); }); diff --git a/test/test-creation-ghpages.js b/test/test-creation-ghpages.js index 15d56bb..d4d5fb6 100644 --- a/test/test-creation-ghpages.js +++ b/test/test-creation-ghpages.js @@ -4,7 +4,6 @@ var path = require("path"); var helpers = require("yeoman-generator").test; var assert = require("yeoman-generator").assert; -var tasks = require("../test-util.js"); describe("Jekyllized generator test when using GitHub Pages", function () { before(function (done) { @@ -31,8 +30,21 @@ describe("Jekyllized generator test when using GitHub Pages", function () { assert.file(expected); }); - it("should contain deploy task", function (done) { - tasks.assertTaskExists(this.jekyllized, "deploy", [], done); + it("should contain the correct deploy function", function () { + assert.fileContent("gulpfile.js", /\/\/ Task to upload your site to your personal GH Pages repo/); + }); + + it("should NOT contain either the Amazon or Rsync function", function () { + assert.noFileContent("gulpfile.js", /\/\/ Task to upload your site via Rsync to your server/); + assert.noFileContent("gulpfile.js", /\/\/ Task to deploy your site to Amazon S3 and Cloudfront/); + }); + + it("should contain deploy tasks", function () { + assert.fileContent("gulpfile.js", /gulp.task\(\"deploy\"/); + }); + + it("should contain the correct packages", function () { + assert.fileContent("package.json", /\"gulp-gh-pages\"/); }); }); diff --git a/test/test-creation-rsync.js b/test/test-creation-rsync.js index 7a333c3..a801dfd 100755 --- a/test/test-creation-rsync.js +++ b/test/test-creation-rsync.js @@ -4,7 +4,6 @@ var path = require("path"); var helpers = require("yeoman-generator").test; var assert = require("yeoman-generator").assert; -var tasks = require("../test-util.js"); describe("Jekyllized generator test when using Rsync", function () { before(function (done) { @@ -35,8 +34,21 @@ describe("Jekyllized generator test when using Rsync", function () { assert.file(expected); }); - it("should contain deploy task", function (done) { - tasks.assertTaskExists(this.jekyllized, "deploy", [], done); + it("should contain the correct deploy function", function () { + assert.fileContent("gulpfile.js", /\/\/ Task to upload your site via Rsync to your server/); + }); + + it("should NOT contain either the GH Pages or Amazon function", function () { + assert.noFileContent("gulpfile.js", /\/\/ Task to deploy your site to Amazon S3 and Cloudfront/); + assert.noFileContent("gulpfile.js", /\/\/ Task to upload your site to your personal GH Pages repo/); + }); + + it("should contain deploy tasks", function () { + assert.fileContent("gulpfile.js", /gulp.task\(\"deploy\"/); + }); + + it("should contain the correct packages", function () { + assert.fileContent("package.json", /\"gulp-rsync\"/); }); }); diff --git a/test/test-gulp.js b/test/test-gulp.js index d4feb22..7fa53e2 100644 --- a/test/test-gulp.js +++ b/test/test-gulp.js @@ -4,7 +4,6 @@ var path = require("path"); var assert = require("assert"); var helpers = require("yeoman-generator").test; -var tasks = require("../test-util.js"); describe("Jekyllized generator test for Gulp tasks without any uploading", function () { before(function (done) { @@ -50,44 +49,24 @@ describe("Jekyllized generator test for Gulp tasks without any uploading", funct assert.noFile(unexpected); }); - it("should contain default task", function (done) { - tasks.assertTaskExists(this.jekyllized, "default", [], done); - }); - - it("should contain optimize task", function (done) { - tasks.assertTaskExists(this.jekyllized, "optimize", [], done); - }); - - it("should contain build task", function (done) { - tasks.assertTaskExists(this.jekyllized, "build", [], done); - }); - - it("should contain deploy task", function (done) { - tasks.assertTaskExists(this.jekyllized, "deploy", [], done); - }); - - it("should contain serve task", function (done) { - tasks.assertTaskExists(this.jekyllized, "serve", [], done); - }); - - it("should contain clean task", function (done) { - tasks.assertTaskExists(this.jekyllized, "clean", [], done); - }); - - it("should contain rebuild task", function (done) { - tasks.assertTaskExists(this.jekyllized, "rebuild", [], done); - }); - - it("should contain styles task", function (done) { - tasks.assertTaskExists(this.jekyllized, "styles", [], done); - }); + it ("should contain the standard tasks", function () { + var expected = [ + ["gulpfile.js", /gulp.task\(\"default\"/], + ["gulpfile.js", /gulp.task\(\"optimize\"/], + ["gulpfile.js", /gulp.task\(\"build\"/], + ["gulpfile.js", /gulp.task\(\"serve\"/], + ["gulpfile.js", /gulp.task\(\"clean\"/], + ["gulpfile.js", /gulp.task\(\"rebuild\"/], + ["gulpfile.js", /gulp.task\(\"styles\"/], + ["gulpfile.js", /gulp.task\(\"javascript\"/], + ["gulpfile.js", /gulp.task\(\"check\"/] + ]; - it("should contain javascript task", function (done) { - tasks.assertTaskExists(this.jekyllized, "javascript", [], done); + assert.fileContent(expected); }); - it("should contain check task", function (done) { - tasks.assertTaskExists(this.jekyllized, "check", [], done); + it("should NOT contain a deploy task", function () { + assert.noFileContent("gulpfile.js", /gulp.task\(\"deploy\"/); }); }); diff --git a/test/test-jekyll.js b/test/test-jekyll.js index 761c2a4..6041234 100644 --- a/test/test-jekyll.js +++ b/test/test-jekyll.js @@ -4,7 +4,6 @@ var path = require("path"); var helpers = require("yeoman-generator").test; var assert = require("yeoman-generator").assert; -var tasks = require("../test-util.js"); describe("Jekyllized generator", function () { describe("test for Jekyll settings", function () { @@ -44,64 +43,39 @@ describe("Jekyllized generator", function () { }); it("gulpfile.js does NOT contain a deploy task", function () { - assert.noFileContent("gulpfile.js", /gulp.task \("deploy"\)/); + assert.noFileContent("gulpfile.js", /gulp.task\(\"deploy\"/); }); - it("_config.yml contains the correct title", function (done) { - tasks.assertJekyllSettings(this.jekyllized, "title", "Mocha Test", done); - }); - - it("_config.yml contains the correct description", function (done) { - tasks.assertJekyllSettings(this.jekyllized, "description", "Mocha tests for Jekyllized", done); - }); - - it("_config.yml contains the correct tagline", function (done) { - tasks.assertJekyllSettings(this.jekyllized, "tagline", "Better hope this doesn\"t blow up", done); - }); - - it("_config.yml contains the correct author name", function (done) { - tasks.assertJekyllSettings(this.jekyllized, "name", "Ola Nordmann", done); - }); - - it("_config.yml contains the correct author email", function (done) { - tasks.assertJekyllSettings(this.jekyllized, "email", "ola.nordmann@email.com", done); - }); - - it("_config.yml contains the correct author bio", function (done) { - tasks.assertJekyllSettings(this.jekyllized, "bio", "Just your average Norwegian", done); - }); - - it("_config.yml contains the correct author Twitter", function (done) { - tasks.assertJekyllSettings(this.jekyllized, "twitter", "olanordmann123123", done); - }); - - it("_config.build.yml contains the corrent setting for future posts", function (done) { - tasks.assertJekyllBuildSettings(this.jekyllized, "future", "false", done); - }); - - it("_config.build.yml contains the corrent setting for drafts", function (done) { - tasks.assertJekyllBuildSettings(this.jekyllized, "show_drafts", "false", done); - }); - - it("_config.build.yml contains the corrent setting for LSI", function (done) { - tasks.assertJekyllBuildSettings(this.jekyllized, "lsi", "true", done); - }); + it("_config.yml contains the correct settings", function () { + var expected = [ + ["_config.yml", /title\: Mocha Test/], + ["_config.yml", /description\: Mocha tests for Jekyllized/], + ["_config.yml", /tagline\: Better hope this doesn\"t blow up/], + ["_config.yml", /name\: Ola Nordmann/], + ["_config.yml", /email\: ola\.nordmann\@email\.com/], + ["_config.yml", /bio\: Just your average Norwegian/], + ["_config.yml", /twitter\: olanordmann123123/] + ]; - it("_config.build.yml contains the corrent setting for limiting posts", function (done) { - tasks.assertJekyllBuildSettings(this.jekyllized, "limit_posts", "0", done); + assert.fileContent(expected); }); - it("_config.build.yml contains the corrent setting for source dir", function (done) { - tasks.assertJekyllBuildSettings(this.jekyllized, "source", "src", done); - }); + it("_config.build.yml contains the correct settings", function () { + var expected = [ + ["_config.build.yml", /future\: false/], + ["_config.build.yml", /show_drafts\: false/], + ["_config.build.yml", /lsi\: true/], + ["_config.build.yml", /limit_posts\: 0/], + ["_config.build.yml", /source\: src/], + ["_config.build.yml", /destination\: dist/] + ]; - it("_config.build.yml contains the corrent setting for destination dir", function (done) { - tasks.assertJekyllBuildSettings(this.jekyllized, "destination", "dist", done); + assert.fileContent(expected); }); }); - describe("test pretty permalinks and 10 pages", function () { + describe("test with setting pretty permalinks and 10 posts per page", function () { before(function (done) { helpers.run(path.join(__dirname, "../app")) .inDir(path.join(__dirname, "./temp/test-jekyll-pagination")) @@ -114,17 +88,17 @@ describe("Jekyllized generator", function () { .on("end", done); }); - it("_config.yml permalink setting is 'pretty'", function (done) { - tasks.assertJekyllSettings(this.jekyllized, "permalink", "pretty", done); + it("_config.yml permalink setting is 'pretty'", function () { + assert.fileContent("_config.yml", /permalink\: pretty/); }); - it("_config.yml pagination setting is '10'", function (done) { - tasks.assertJekyllSettings(this.jekyllized, "paginate", "10", done); + it("_config.yml pagination is '10' posts per page", function () { + assert.fileContent("_config.yml", /paginate\: 10/); }); }); - describe("test date permalinks and all pages", function () { + describe("test with setting date permalinks and all posts on the same page", function () { before(function (done) { helpers.run(path.join(__dirname, "../app")) .inDir(path.join(__dirname, "./temp/test-jekyll-pagination-1")) @@ -137,17 +111,17 @@ describe("Jekyllized generator", function () { .on("end", done); }); - it("_config.yml permalink setting is 'date'", function (done) { - tasks.assertJekyllSettings(this.jekyllized, "permalink", "date", done); + it("_config.yml permalink setting is 'date'", function () { + assert.fileContent("_config.yml", /permalink\: date/); }); - it("_config.yml pagination setting is 'all'", function (done) { - tasks.assertJekyllSettings(this.jekyllized, "paginate", "all", done); + it("_config.yml pagination is 'all' posts per page", function () { + assert.fileContent("_config.yml", /paginate\: all/); }); }); - describe("test no permalinks and 1 page", function () { + describe("test with no permalinks setting and 1 post per page", function () { before(function (done) { helpers.run(path.join(__dirname, "../app")) .inDir(path.join(__dirname, "./temp/test-jekyll-pagination-2")) @@ -160,12 +134,12 @@ describe("Jekyllized generator", function () { .on("end", done); }); - it("_config.yml permalink setting is 'none'", function (done) { - tasks.assertJekyllSettings(this.jekyllized, "permalink", "none", done); + it("_config.yml permalink setting is 'none'", function () { + assert.fileContent("_config.yml", /permalink\: none/); }); - it("_config.yml pagination setting is '1'", function (done) { - tasks.assertJekyllSettings(this.jekyllized, "paginate", "1", done); + it("_config.yml pagination is '1' posts per page", function () { + assert.fileContent("_config.yml", /paginate\: 1/); }); }); diff --git a/test/test-load.js b/test/test-load.js index 8ac30f6..8b49714 100644 --- a/test/test-load.js +++ b/test/test-load.js @@ -3,7 +3,7 @@ var assert = require("assert"); -describe("jekyll generator", function () { +describe("Jekyllized generator", function () { it("can be imported without blowing up", function () { var app = require("../app"); assert(app !== undefined); diff --git a/test/test-package.js b/test/test-package.js new file mode 100644 index 0000000..45f6ccd --- /dev/null +++ b/test/test-package.js @@ -0,0 +1,38 @@ +/*global describe, before, it*/ +"use strict"; + +var path = require("path"); +var assert = require("assert"); +var helpers = require("yeoman-generator").test; + +describe("Jekyllized generator test for package.json", function () { + before(function (done) { + helpers.run(path.join(__dirname, "../app")) + .inDir(path.join(__dirname, "./temp/test-package")) + .withArguments(["--skip-install"]) + .withPrompt({ + projectName: ["Package Test"], + projectDescription: ["Package tests for Jekyllized"], + projectTagline: ["Better hope this doesn\"t blow up"], + projectURL: ["testing.com"], + authorName: ["Ola Nordmann"], + authorEmail: ["ola.nordmann@email.com"], + authorBio: ["Just your average Norwegian"], + authorTwitter: ["olanordmann123123"], + jekyllPermalinks: ["pretty"], + jekyllPaginate: ["10"], + uploadChoices: ["noUpload"] + }) + .on("end", done); + }); + + it("should contain the proper names and version", function () { + var expected = [ + ["package.json", /\"name\"\: \"test-package\"/], + ["package.json", /\"description\"\: \"Yeoman workflow for test package\"/] + ]; + + assert.fileContent(expected); + }); + +});