From e130cb4c276d490423bc1826137dbd7556249927 Mon Sep 17 00:00:00 2001 From: Erik Vold Date: Wed, 29 Apr 2015 00:37:20 -0700 Subject: [PATCH] Bug 1147741 Part 1 - Add travis tests that the jetpack-addon.ini file is up to date --- bin/jpm-test.js | 3 ++- bin/node-scripts/test.ini.js | 39 ++++++++++++++++++++++++++++++++++ bin/node-scripts/update-ini.js | 20 ++++++++++++----- gulpfile.js | 11 ++++++++++ 4 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 bin/node-scripts/test.ini.js diff --git a/bin/jpm-test.js b/bin/jpm-test.js index 833391064..40f65d8c9 100644 --- a/bin/jpm-test.js +++ b/bin/jpm-test.js @@ -26,7 +26,8 @@ exports.run = function(type, options) { (!isDebug && /^(modules)?$/.test(type)) && require.resolve("../bin/node-scripts/test.modules"), (!isDebug && /^(addons)?$/.test(type)) && require.resolve("../bin/node-scripts/test.addons"), (/^(examples)?$/.test(type)) && require.resolve("../bin/node-scripts/test.examples"), - (/^(docs)?$/.test(type)) && require.resolve("../bin/node-scripts/test.docs"), + (!isDebug && /^(docs)?$/.test(type)) && require.resolve("../bin/node-scripts/test.docs"), + (!isDebug && /^(ini)?$/.test(type)) && require.resolve("../bin/node-scripts/test.ini"), ].sort().forEach(function(filepath) { filepath && mocha.addFile(filepath); }) diff --git a/bin/node-scripts/test.ini.js b/bin/node-scripts/test.ini.js new file mode 100644 index 000000000..5b8f76e7a --- /dev/null +++ b/bin/node-scripts/test.ini.js @@ -0,0 +1,39 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +var fs = require("fs"); +var path = require("path"); +var Promise = require("promise"); +var chai = require("chai"); +var expect = chai.expect; +var ini = require("./update-ini"); + +var addonINI = path.resolve("./test/addons/jetpack-addon.ini"); + +describe("Checking ini files", function () { + + it("Check test/addons/jetpack-addon.ini", function (done) { + + fs.readFile(addonINI, function (err, data) { + if (err) { + throw err; + } + var text = data.toString(); + var expected = ""; + + ini.makeAddonIniContent() + .then(function(contents) { + expected = contents; + + setTimeout(function end() { + expect(expected.trim()).to.be.equal(text.trim()); + done(); + }); + }); + }); + + }); + +}); diff --git a/bin/node-scripts/update-ini.js b/bin/node-scripts/update-ini.js index da9fad750..250d7da01 100644 --- a/bin/node-scripts/update-ini.js +++ b/bin/node-scripts/update-ini.js @@ -16,6 +16,18 @@ function updateAddonINI() { return new Promise(function(resolve) { console.log("Start updating " + addonINI); + makeAddonIniContent(). + then(function(contents) { + fs.writeFileSync(addonINI, contents, { encoding: "utf8" }); + console.log("Done updating " + addonINI); + resolve(); + }); + }) +} +exports.updateAddonINI = updateAddonINI; + +function makeAddonIniContent() { + return new Promise(function(resolve) { var data = parser.parse(fs.readFileSync(addonINI, { encoding: "utf8" }).toString()); var result = {}; @@ -39,10 +51,8 @@ function updateAddonINI() { }); contents = contents.join("\n") + "\n"; - fs.writeFileSync(addonINI, contents, { encoding: "utf8" }); - console.log("Done updating " + addonINI); - resolve(); + return resolve(contents); }); - }) + }); } -exports.updateAddonINI = updateAddonINI; +exports.makeAddonIniContent = makeAddonIniContent; diff --git a/gulpfile.js b/gulpfile.js index c48816820..b738495ae 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -51,6 +51,13 @@ gulp.task('travis', function(done) { return test("docs"); }). + then(function() { + if (filtersExist) { + return resolve(); + } + + return test("ini"); + }). then(function() { if (filtersExist && !filters["modules"]) { return resolve(); @@ -83,6 +90,10 @@ gulp.task('test:modules', function(done) { test("modules").catch(console.error).then(done); }); +gulp.task('test:ini', function(done) { + test("ini").catch(console.error).then(done); +}); + gulp.task('patch:clean', function(done) { patch.clean().catch(console.error).then(done); });