From 5b694bdbefeae711f76fc4d0cd300bffc018f6bc Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Wed, 1 Oct 2014 11:04:13 +1000 Subject: [PATCH] update test constructor to deal with changed api --- test/index.js | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/test/index.js b/test/index.js index c0f17cb3b3..c6de791cb7 100644 --- a/test/index.js +++ b/test/index.js @@ -9,7 +9,7 @@ var humanise = function (val) { var readFile = function (filename) { if (fs.existsSync(filename)) { - return fs.readFileSync(filename); + return fs.readFileSync(filename, "utf8"); } else { return ""; } @@ -29,18 +29,25 @@ _.each(fs.readdirSync(fixturesDir), function (suiteName) { var taskDir = suiteDir + "/" + taskName; if (fs.statSync(taskDir).isFile()) return; - test(humanise(taskName), function () { - var actualLoc = taskDir + "/actual.js"; + var actualLoc = taskDir + "/actual.js"; + var expectLoc = taskDir + "/expected.js"; + var taskOptsLoc = taskDir + "/options.json"; + var taskOpts = _.merge({ filename: actualLoc }, _.cloneDeep(suiteOpts)); + if (fs.existsSync(taskOptsLoc)) _.merge(taskOpts, require(taskOptsLoc)); + + var body = function () { var actual = readFile(actualLoc); - var expect = readFile(taskDir + "/expected.js"); - - var taskOptsLoc = taskDir + "/options.json"; - var taskOpts = _.merge({ filename: actualLoc }, _.cloneDeep(suiteOpts)); - if (fs.existsSync(taskOptsLoc)) _.merge(taskOpts, require(taskOptsLoc)); + var expect = readFile(expectLoc); var test = function () { - transform.test(actual, expect, taskOpts); + transform.test({ + filename: actualLoc, + code: actual + }, { + filename: expectLoc, + code: expect + }, taskOpts); }; var throwMsg = taskOpts.throws; @@ -48,11 +55,16 @@ _.each(fs.readdirSync(fixturesDir), function (suiteName) { // internal api doesn't have this option but it's best not to pollute // the options object with useless options delete taskOpts.throws; + assert.throws(test, new RegExp(throwMsg)); } else { test(); } - }); + }; + + if (taskOpts.ignore) body = null; + + test(humanise(taskName), body); }); }); });