diff --git a/.gitignore b/.gitignore index 1e256ca8..c0997096 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ plugins/c9.ide.language.javascript.tern/util/sigs_ts plugins/c9.account.billing/node_modules/ plugins/c9.account/node_modules/ plugins/c9.api.project/coverage/ +plugins/c9.proxy.apps/coverage/ plugins/c9.db.redis/coverage/ scripts/build build/output @@ -67,6 +68,8 @@ plugins/c9.proxy/proxy.cfg plugins/c9.proxy/haproxy plugins/c9.proxy/haproxy-* **/.module-cache/ +plugins/c9.account.billing/node_modules/ +plugins/c9.account/node_modules/ .c9revisions .settings diff --git a/configs/standalone.js b/configs/standalone.js index 40a6cd7f..c301c96c 100644 --- a/configs/standalone.js +++ b/configs/standalone.js @@ -173,6 +173,7 @@ module.exports = function(config, optimist) { "./c9.vfs.server/download", "./c9.vfs.server/filelist", "./c9.vfs.server/statics", + "./c9.metrics/mock_metrics", { packagePath: "./c9.vfs.server/vfs.connect.standalone", workspaceDir: baseProc, diff --git a/node_modules/frontdoor/lib/api_test.js b/node_modules/frontdoor/lib/api_test.js index a6fc7b52..4f90ea1e 100644 --- a/node_modules/frontdoor/lib/api_test.js +++ b/node_modules/frontdoor/lib/api_test.js @@ -2,6 +2,9 @@ "use server"; +require("amd-loader"); + + var assert = require("assert"); var sinon = require("sinon"); @@ -284,14 +287,18 @@ module.exports = { root.handle({ method: "PUT", url: "/post/fab?age=34" - }, this.res, assert.fail); - sinon.assert.calledWith(this.res.writeHead, 422); - var errors = JSON.parse(this.res.end.args[0][0]).errors; - assert.equal(errors.length, 1); - assert.equal(errors[0].resource, "root"); - assert.equal(errors[0].field, "name"); - assert.equal(errors[0].code, "missing_field"); - + }, this.res, function(err){ + + assert.ok( err ); + + var errors = err.errors; + assert.equal(errors.length, 1); + assert.equal(errors[0].resource, "root"); + assert.equal(errors[0].field, "name"); + assert.equal(errors[0].code, "missing_field"); + }); + + this.res.writeHead.reset(); this.res.end.reset(); @@ -299,14 +306,19 @@ module.exports = { method: "PUT", url: "/post/fab?age=juhu", body: { name: "Fabian"} - }, this.res, assert.fail); - sinon.assert.calledWith(this.res.writeHead, 422); - var errors = JSON.parse(this.res.end.args[0][0]).errors; - assert.equal(errors.length, 1); - assert.equal(errors[0].resource, "root"); - assert.equal(errors[0].field, "age"); - assert.equal(errors[0].type_expected, "int"); - assert.equal(errors[0].code, "invalid"); + }, this.res, function(err){ + + assert.ok( err ); + + var errors = err.errors; + + assert.equal(errors.length, 1); + assert.equal(errors[0].resource, "root"); + assert.equal(errors[0].field, "age"); + assert.equal(errors[0].type_expected, "int"); + assert.equal(errors[0].code, "invalid"); + }); + }, "test custom type with register": function() { diff --git a/node_modules/frontdoor/lib/route_test.js b/node_modules/frontdoor/lib/route_test.js index 3d98b710..9e11be1c 100644 --- a/node_modules/frontdoor/lib/route_test.js +++ b/node_modules/frontdoor/lib/route_test.js @@ -2,6 +2,8 @@ "use server"; +require("amd-loader"); + var assert = require("assert"); var sinon = require("sinon"); diff --git a/node_modules/frontdoor/lib/types_test.js b/node_modules/frontdoor/lib/types_test.js index 1e15f5da..ce9ab8c5 100644 --- a/node_modules/frontdoor/lib/types_test.js +++ b/node_modules/frontdoor/lib/types_test.js @@ -2,6 +2,8 @@ "use server"; +require("amd-loader"); + var assert = require("assert"); var types = require("./types"); diff --git a/plugins/c9.cli.publish/publish_test.js b/plugins/c9.cli.publish/publish_test.js index f4090e71..22d46a7e 100644 --- a/plugins/c9.cli.publish/publish_test.js +++ b/plugins/c9.cli.publish/publish_test.js @@ -2,6 +2,7 @@ "use strict"; "use server"; "use mocha"; +"use blacklist"; require("c9/inline-mocha")(module); diff --git a/plugins/c9.metrics/mock_metrics.js b/plugins/c9.metrics/mock_metrics.js new file mode 100644 index 00000000..56a13241 --- /dev/null +++ b/plugins/c9.metrics/mock_metrics.js @@ -0,0 +1,19 @@ +/** + * Dummy implementation of metrics. + */ +"use strict"; + +plugin.consumes = []; +plugin.provides = ["metrics"]; + +module.exports = plugin; + +function plugin(options, imports, register) { + + register(null, { + "metrics": { + log: function() {}, + increment: function() {} + } + }); +} \ No newline at end of file diff --git a/plugins/c9.preview/preview.handler.js b/plugins/c9.preview/preview.handler.js index c307b04b..2a852a64 100644 --- a/plugins/c9.preview/preview.handler.js +++ b/plugins/c9.preview/preview.handler.js @@ -5,7 +5,8 @@ define(function(require, exports, module) { "connect.render", "connect.render.ejs", "connect.redirect", - "connect.static" + "connect.static", + "metrics" ]; main.provides = ["preview.handler"]; return main; @@ -15,6 +16,7 @@ define(function(require, exports, module) { var https = require("https"); var http = require("http"); var mime = require("mime"); + var metrics = imports.metrics; var parseUrl = require("url").parse; var debug = require("debug")("preview"); @@ -167,6 +169,7 @@ define(function(require, exports, module) { else serveFile(request); }).on("error", function(err) { + metrics.increment("preview.failed.error"); next(err); }); diff --git a/plugins/c9.vfs.client/endpoint.js b/plugins/c9.vfs.client/endpoint.js index 3bd55ca3..6da0c793 100644 --- a/plugins/c9.vfs.client/endpoint.js +++ b/plugins/c9.vfs.client/endpoint.js @@ -97,7 +97,9 @@ define(function(require, exports, module) { function getVfsEndpoint(version, callback) { getServers(function(err, _servers) { if (err) { - errorHandler.reportError(err); + if (err.code !== "EDISCONNECT") + errorHandler.reportError(new Error("Could not get list of VFS servers"), { cause: err }); + metrics.increment("vfs.failed.connect_getservers", 1, true); initDefaultServers(); _servers = servers; } diff --git a/plugins/c9.vfs.server/download_test.js b/plugins/c9.vfs.server/download_test.js index 0f99fdbf..7717a8be 100755 --- a/plugins/c9.vfs.server/download_test.js +++ b/plugins/c9.vfs.server/download_test.js @@ -1,8 +1,13 @@ #!/usr/bin/env node "use strict"; "use server"; +"use mocha"; + +require("c9/inline-mocha")(module); +if (typeof define === "undefined") { + require("amd-loader"); +} -require("amd-loader"); var assert = require("assert"); var fs = require("fs"); var tmp = require("tmp"); @@ -12,11 +17,10 @@ var download = require("./download"); var urlParse = require('url').parse; var execFile = require('child_process').execFile; -module.exports = { +describe(__filename, function(){ + this.timeout(4000); - timeout: 4000, - - setUp: function(next) { + beforeEach(function(next) { var that = this; var vfs = localfs({root: "/"}); download({}, { @@ -41,80 +45,85 @@ module.exports = { }); that.server.listen(8787, "0.0.0.0", next); }); - }, + }); - tearDown: function(next) { + afterEach(function(next) { this.server.close(next); - }, + }); - "test download": function(next) { - tmp.dir({unsafeCleanup: true}, function(err, path) { - var filename = path + "/download.tar.gz"; - var file = fs.createWriteStream(filename); - http.get("http://localhost:8787/?download=download.tar.gz", function(res) { - assert.equal(res.headers["content-type"], "application/x-gzip"); - assert.equal(res.headers["content-disposition"], "attachment; filename*=utf-8''download.tar.gz"); - - res.pipe(file); - - res.on("end", function() { - execFile("tar", ["-zxvf", filename, "c9.vfs.server/download.js"], {cwd: path}, function(err, stdout, stderr) { - assert.equal(err, null); - assert.equal( - fs.readFileSync(__dirname + "/download.js", "utf8"), - fs.readFileSync(path + "/c9.vfs.server/download.js", "utf8") - ); - next(); - }); - }); - }); - }); - }, + describe("download", function() { - "test download sub directory": function(next) { - tmp.dir({unsafeCleanup: true}, function(err, path) { - var filename = path + "/download.tar.gz"; - var file = fs.createWriteStream(filename); - http.get("http://localhost:8787/views?download=download.tar.gz", function(res) { - res.pipe(file); - - res.on("end", function() { - execFile("tar", ["-zxvf", filename, "views/status.html.ejs"], {cwd: path}, function(err) { - assert.equal(err, null); - assert.equal( - fs.readFileSync(__dirname + "/views/status.html.ejs", "utf8"), - fs.readFileSync(path + "/views/status.html.ejs", "utf8") - ); - next(); - }); - }); - }); - }); - }, + it("should download", function(next) { + tmp.dir({unsafeCleanup: true}, function(err, path) { + var filename = path + "/download.tar.gz"; + var file = fs.createWriteStream(filename); + http.get("http://localhost:8787/?download=download.tar.gz", function(res) { + assert.equal(res.headers["content-type"], "application/x-gzip"); + assert.equal(res.headers["content-disposition"], "attachment; filename*=utf-8''download.tar.gz"); - "test download without specifying a name": function(next) { - tmp.dir({unsafeCleanup: true}, function(err, path) { - var filename = path + "/download.tar.gz"; - var file = fs.createWriteStream(filename); - http.get("http://localhost:8787/views?download", function(res) { - assert.equal(res.headers["content-type"], "application/x-gzip"); - assert.equal(res.headers["content-disposition"], "attachment; filename*=utf-8''views.tar.gz"); - - res.pipe(file); - - res.on("end", function() { - execFile("tar", ["-zxvf", filename, "views/status.html.ejs"], {cwd: path}, function(err) { - assert.equal(err, null); - assert.equal( - fs.readFileSync(__dirname + "/views/status.html.ejs", "utf8"), - fs.readFileSync(path + "/views/status.html.ejs", "utf8") - ); - next(); + res.pipe(file); + + res.on("end", function() { + execFile("tar", ["-zxvf", filename, "c9.vfs.server/download.js"], {cwd: path}, function(err, stdout, stderr) { + assert.equal(err, null); + assert.equal( + fs.readFileSync(__dirname + "/download.js", "utf8"), + fs.readFileSync(path + "/c9.vfs.server/download.js", "utf8") + ); + next(); + }); }); }); }); }); - } -}; - -!module.parent && require("asyncjs").test.testcase(module.exports).exec(); \ No newline at end of file + + it("should download sub directory", function(next) { + tmp.dir({unsafeCleanup: true}, function(err, path) { + assert.equal(err, null); + + var filename = path + "/download.tar.gz"; + var file = fs.createWriteStream(filename); + http.get("http://localhost:8787/views?download=download.tar.gz", function(res) { + res.pipe(file); + + res.on("end", function() { + execFile("tar", ["-zxvf", filename, "views/status.html.ejs"], {cwd: path}, function(err) { + assert.equal(err, null); + assert.equal( + fs.readFileSync(__dirname + "/views/status.html.ejs", "utf8"), + fs.readFileSync(path + "/views/status.html.ejs", "utf8") + ); + next(); + }); + }); + }); + }); + }); + + it("should download without specifying a name", function(next) { + tmp.dir({unsafeCleanup: true}, function(err, path) { + assert.equal(err, null); + + var filename = path + "/download.tar.gz"; + var file = fs.createWriteStream(filename); + http.get("http://localhost:8787/views?download", function(res) { + assert.equal(res.headers["content-type"], "application/x-gzip"); + assert.equal(res.headers["content-disposition"], "attachment; filename*=utf-8''views.tar.gz"); + + res.pipe(file); + + res.on("end", function() { + execFile("tar", ["-zxvf", filename, "views/status.html.ejs"], {cwd: path}, function(err) { + assert.equal(err, null); + assert.equal( + fs.readFileSync(__dirname + "/views/status.html.ejs", "utf8"), + fs.readFileSync(path + "/views/status.html.ejs", "utf8") + ); + next(); + }); + }); + }); + }); + }); + }); +}); \ No newline at end of file