diff --git a/.travis.yml b/.travis.yml index e58e9be..1e10c44 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ language: node_js node_js: + - '7' - '6' - - '5' - '4' - - '0.12' - - '0.10' diff --git a/package.json b/package.json index 7b5f98c..dc6a0e2 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,8 @@ "babel-types": "^6.7.2" }, "devDependencies": { - "ava": "^0.14.0", + "ava": "^0.17.0", "babel-core": "^6.7.5", - "xo": "^0.15.1" + "xo": "^0.17.0" } } diff --git a/test.js b/test.js index c1a193d..b975040 100644 --- a/test.js +++ b/test.js @@ -33,43 +33,38 @@ function addExample(input, output) { ); } -const HELPER = [ - 'function _avaThrowsHelper(fn, data) {', - ' try {', - ' return fn();', - ' } catch (e) {', - ' var type = typeof e;', - '', - ' if (e !== null && (type === "object" || type === "function")) {', - ' try {', - ' Object.defineProperty(e, "_avaThrowsHelperData", {', - ' value: data', - ' });', - ' } catch (e) {}', - ' }', - '', - ' throw e;', - ' }', - '}', - '' -].join('\n'); +const HELPER = `function _avaThrowsHelper(fn, data) { + try { + return fn(); + } catch (e) { + var type = typeof e; + + if (e !== null && (type === "object" || type === "function")) { + try { + Object.defineProperty(e, "_avaThrowsHelperData", { + value: data + }); + } catch (e) {} + } + + throw e; + } +}\n`; function wrapped(throws, expression, line, column) { - return [ - `t.${throws}(_avaThrowsHelper(function () {`, - ` return ${expression};`, - '}, {', - ` line: ${line},`, - ` column: ${column},`, - ` source: "${expression}",`, - ` filename: "some-file.js"`, - '}));' - ].join('\n'); + return `t.${throws}(_avaThrowsHelper(function () { + return ${expression}; +}, { + line: ${line}, + column: ${column}, + source: "${expression}", + filename: "some-file.js" +}));`; } test('creates a helper', t => { - const input = `t.throws(foo())`; - const code = transform(input).code; + const input = 't.throws(foo())'; + const {code} = transform(input); const expected = [ HELPER, @@ -81,8 +76,8 @@ test('creates a helper', t => { }); test('creates the helper only once', t => { - const input = `t.throws(foo());\nt.throws(bar());`; - const code = transform(input).code; + const input = 't.throws(foo());\nt.throws(bar());'; + const {code} = transform(input); const expected = [ HELPER, @@ -96,15 +91,15 @@ test('creates the helper only once', t => { test('does nothing if it does not match', t => { const input = 't.is(foo());'; - const code = transform(input).code; + const {code} = transform(input); t.is(code, input); addExample(input, code); }); test('helps notThrows', t => { - const input = `t.notThrows(baz())`; - const code = transform(input).code; + const input = 't.notThrows(baz())'; + const {code} = transform(input); const expected = [ HELPER,