From be9cc83fc559bfb99da7dcf71e685f8838e33e64 Mon Sep 17 00:00:00 2001 From: Benjamin Coe Date: Sat, 4 Jun 2016 12:13:52 -0700 Subject: [PATCH 1/2] chore: add unit tests for ES2015 edge-cases --- .babelrc | 6 +++++- package.json | 4 ++++ test/fixtures/es2015/asyncawait.js | 13 +++++++++++++ test/src/es2015.js | 20 ++++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/es2015/asyncawait.js create mode 100644 test/src/es2015.js diff --git a/.babelrc b/.babelrc index c13c5f627..7970da36a 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,7 @@ { - "presets": ["es2015"] + "presets": ["es2015"], + "plugins": [ + "transform-async-to-generator", + "transform-runtime" + ] } diff --git a/package.json b/package.json index 872507365..26a2cb48f 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,10 @@ }, "devDependencies": { "any-path": "^1.3.0", + "babel-core": "^6.9.1", + "babel-plugin-transform-async-to-generator": "^6.8.0", + "babel-plugin-transform-runtime": "^6.9.0", + "babel-preset-es2015": "^6.9.0", "chai": "^3.0.0", "coveralls": "^2.11.4", "exists-sync": "0.0.3", diff --git a/test/fixtures/es2015/asyncawait.js b/test/fixtures/es2015/asyncawait.js new file mode 100644 index 000000000..4c7c4fe2e --- /dev/null +++ b/test/fixtures/es2015/asyncawait.js @@ -0,0 +1,13 @@ +const foo = async (opts, opts2) => { + let snuh = await bar() +} + +const bar = () => { + return new Promise(function (resolve, reject) { + setTimeout(() => { + resolve(33) + }, 10) + }) +} + +foo() diff --git a/test/src/es2015.js b/test/src/es2015.js new file mode 100644 index 000000000..7ced4c939 --- /dev/null +++ b/test/src/es2015.js @@ -0,0 +1,20 @@ +/* global describe, it */ + +var NYC + +try { + NYC = require('../../index.covered.js') +} catch (e) { + NYC = require('../../') +} + +(new NYC()).wrap() + +require('babel-core/register') +require('tap').mochaGlobals() + +describe('es2015 coverage', function () { + it('covers async/await branch', function () { + require('../fixtures/es2015/asyncawait') + }) +}) From a878af490efda860092b8880490e2063ae07cb98 Mon Sep 17 00:00:00 2001 From: Benjamin Coe Date: Sat, 4 Jun 2016 12:39:05 -0700 Subject: [PATCH 2/2] fix: exclude es2015 files --- test/fixtures/package.json | 3 ++- test/src/nyc-test.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/fixtures/package.json b/test/fixtures/package.json index 13746bfb3..fd362fec0 100644 --- a/test/fixtures/package.json +++ b/test/fixtures/package.json @@ -10,7 +10,8 @@ "nyc": { "exclude": [ "**/blarg", - "**/blerg" + "**/blerg", + "**/es2015" ] } } diff --git a/test/src/nyc-test.js b/test/src/nyc-test.js index 5a12d8d34..0f7b8c6ec 100644 --- a/test/src/nyc-test.js +++ b/test/src/nyc-test.js @@ -69,7 +69,7 @@ describe('nyc', function () { cwd: path.resolve(__dirname, '../fixtures') }) - nyc.exclude.length.should.eql(5) + nyc.exclude.length.should.eql(7) }) it("loads 'extension' patterns from package.json#nyc", function () {