From c30f5f3bb2c0446dd10ef0d1553c11bde0e32264 Mon Sep 17 00:00:00 2001 From: nightwing Date: Tue, 7 Feb 2017 18:41:27 +0000 Subject: [PATCH] fix download_test --- plugins/c9.vfs.server/download_test.js | 45 +++++++++++++++++--------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/plugins/c9.vfs.server/download_test.js b/plugins/c9.vfs.server/download_test.js index 74722d1e..c70b7959 100755 --- a/plugins/c9.vfs.server/download_test.js +++ b/plugins/c9.vfs.server/download_test.js @@ -4,14 +4,12 @@ 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"); var http = require("http"); +var mkdirp = require("mkdirp"); var localfs = require("vfs-local"); var download = require("./download"); var urlParse = require('url').parse; @@ -20,8 +18,9 @@ var execFile = require('child_process').execFile; describe(__filename, function() { this.timeout(4000); var base; + var id = 0; - beforeEach(function(next) { + before(function(next) { var that = this; var vfs = localfs({ root: "/" }); download({}, { @@ -58,14 +57,30 @@ describe(__filename, function() { }); }); - afterEach(function(next) { + after(function(next) { this.server.close(next); }); + + before(cleanup); + after(cleanup); + + function cleanup(next) { + execFile("rm", ["-rf", __dirname + "/_test"], function() { + next(); + }); + } + + function tmpDir(callback) { + var path = __dirname + "/_test/" + id++; + mkdirp(path, function(err) { + callback(err, path); + }); + } describe("download", function() { it("should download as tar", function(next) { - tmp.dir({ unsafeCleanup: true }, function(err, path) { + tmpDir(function(err, path) { assert.equal(err, null); var filename = "download.tar.gz"; var file = fs.createWriteStream(path + "/" + filename); @@ -90,7 +105,7 @@ describe(__filename, function() { }); it("should download sub directory as tar", function(next) { - tmp.dir({ unsafeCleanup: true }, function(err, path) { + tmpDir(function(err, path) { assert.equal(err, null); var filename = "download.tar.gz"; @@ -113,7 +128,7 @@ describe(__filename, function() { }); it("should download without specifying a name", function(next) { - tmp.dir({ unsafeCleanup: true }, function(err, path) { + tmpDir(function(err, path) { assert.equal(err, null); var filename = "download.tar.gz"; @@ -139,7 +154,7 @@ describe(__filename, function() { }); it("should download several files in same directory as tar", function(next) { - tmp.dir({ unsafeCleanup: true }, function(err, path) { + tmpDir(function(err, path) { assert.equal(err, null); var filename = "download.tar.gz"; @@ -165,7 +180,7 @@ describe(__filename, function() { }); it("should download several files in different directories as tar", function(next) { - tmp.dir({ unsafeCleanup: true }, function(err, path) { + tmpDir(function(err, path) { assert.equal(err, null); var filename = "download.tar.gz"; @@ -191,7 +206,7 @@ describe(__filename, function() { }); it("should download as zip", function(next) { - tmp.dir({ unsafeCleanup: true }, function(err, path) { + tmpDir(function(err, path) { assert.equal(err, null); var filename = "download.zip"; var file = fs.createWriteStream(path + "/" + filename); @@ -216,7 +231,7 @@ describe(__filename, function() { }); it("should download sub directory as zip", function(next) { - tmp.dir({ unsafeCleanup: true }, function(err, path) { + tmpDir(function(err, path) { assert.equal(err, null); var filename = "download.zip"; @@ -239,7 +254,7 @@ describe(__filename, function() { }); it("should download several files in same directory as zip", function(next) { - tmp.dir({ unsafeCleanup: true }, function(err, path) { + tmpDir(function(err, path) { assert.equal(err, null); var filename = "download.zip"; @@ -265,7 +280,7 @@ describe(__filename, function() { }); it("should download several files in different directories as zip", function(next) { - tmp.dir({ unsafeCleanup: true }, function(err, path) { + tmpDir(function(err, path) { assert.equal(err, null); var filename = "download.zip";