From e554c5e2c8b2a6d99ed6fcda5711a25ccd73f88d Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Tue, 5 Jan 2016 22:42:43 -0700 Subject: [PATCH 1/4] Upgrade to babel 6, migrate tests to mocha --- .babelrc | 3 +++ .gitignore | 2 ++ package.json | 23 ++++++++++++-------- src/index.test.js | 55 +++++++++++++++++++++-------------------------- 4 files changed, 44 insertions(+), 39 deletions(-) create mode 100644 .babelrc diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..0558174 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["es2015", "stage-2"] +} diff --git a/.gitignore b/.gitignore index ba2a97b..f890f12 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules coverage +.nyc_output + diff --git a/package.json b/package.json index b0e5ec0..3c5c3fc 100644 --- a/package.json +++ b/package.json @@ -8,11 +8,12 @@ "build": "babel src/index.js -o dist/index.js", "postbuild": "cp src/starwars-names.json dist/starwars-names.json", "commit": "git-cz", - "check-coverage": "istanbul check-coverage --statements 100 --branches 100 --functions 100 --lines 100", - "report-coverage": "cat ./coverage/lcov.info | codecov", + "check-coverage": "nyc check-coverage --statements 100 --branches 100 --functions 100 --lines 100", + "report-coverage": "nyc report --reporter=text-lcov | codecov", "start": "npm run test", - "test": "mocha src/index.test.js -w --compilers js:babel/register", - "test:single": "istanbul cover -x *.test.js _mocha -- -R spec src/index.test.js --compilers js:babel/register", + "test": "ava src/**/*.test.js --require babel-register", + "test:watch": "nodemon -w src --exec 'npm t -- --verbose'", + "test:cover": "nyc --reporter=lcov --reporter=text npm t", "semantic-release": "semantic-release pre && npm publish && semantic-release post" }, "repository": { @@ -34,14 +35,18 @@ "unique-random-array": "1.0.0" }, "devDependencies": { - "babel": "5.8.21", - "chai": "3.3.0", + "ava": "0.9.1", + "babel-core": "6.3.26", + "babel-preset-es2015": "6.3.13", + "babel-preset-stage-2": "6.3.13", + "babel-register": "6.3.13", "codecov.io": "0.1.6", "commitizen": "1.0.5", "cz-conventional-changelog": "1.1.2", "ghooks": "0.3.2", - "istanbul": "0.3.21", - "mocha": "2.2.5", + "is_js": "0.7.6", + "nodemon": "1.8.1", + "nyc": "5.3.0", "semantic-release": "4.3.5" }, "czConfig": { @@ -49,7 +54,7 @@ }, "config": { "ghooks": { - "pre-commit": "npm run test:single && npm run check-coverage" + "pre-commit": "npm run test && npm run check-coverage" } } } diff --git a/src/index.test.js b/src/index.test.js index e2177c4..f4fbfda 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -1,35 +1,30 @@ -import {expect} from 'chai'; -import starWars from './index'; +import starWars from './index' +import test from 'ava' +import is from 'is_js' -describe('starwars-names', function() { - describe('all', function() { - it('should be an array of strings', function() { - expect(starWars.all).to.satisfy(isArrayOfStrings); +test('all is an array of strings', t => { + t.true( + starWars.all.every(item => typeof item === 'string') + ) +}) - function isArrayOfStrings(array) { - return array.every(function(item) { - return typeof item === 'string'; - }); - } - }); +test(`all should contain 'Luke Skywalker'`, t => { + t.true( + is.inArray('Luke Skywalker', starWars.all) + ) +}) - it('should contain `Luke Skywalker`', function() { - expect(starWars.all).to.include('Luke Skywalker'); - }); - }); +test('random should return a random item from the starWars.all', t => { + t.true( + is.inArray(starWars.random(), starWars.all) + ) +}) - describe('random', function() { - it('should return a random item from the starWars.all', function() { - var randomItem = starWars.random(); - expect(starWars.all).to.include(randomItem); - }); +test('random should return an array of random items when passed a number', t => { + const items = starWars.random(3) + t.true(items.length === 3) + t.true( + items.every(item => is.inArray(item, starWars.all)) + ) +}) - it('should return an array of random items if passed a number', function() { - var randomItems = starWars.random(3); - expect(randomItems).to.have.length(3); - randomItems.forEach(function(item) { - expect(starWars.all).to.include(item); - }); - }); - }); -}); From e8f3d1f57aca4c57c77ae5f2da2fdda44fa8dca2 Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Tue, 5 Jan 2016 22:48:15 -0700 Subject: [PATCH 2/4] Update travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 560045b..efe9572 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ before_install: before_script: - npm prune script: - - npm run test:single + - npm run test - npm run check-coverage - npm run build after_success: From 5b5c0e14339cf4bea3f46626f85ec63a1b24968c Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Tue, 5 Jan 2016 22:50:52 -0700 Subject: [PATCH 3/4] Test with coverage --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index efe9572..52732c7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ before_install: before_script: - npm prune script: - - npm run test + - npm run test:cover - npm run check-coverage - npm run build after_success: From 85c53b83bd54293d20613826e030bc010031f61d Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Wed, 6 Jan 2016 08:47:23 -0700 Subject: [PATCH 4/4] Add babel-cli as a dependency (another thing you need to do when upgrading to ES6) --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 3c5c3fc..e9d551f 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ }, "devDependencies": { "ava": "0.9.1", + "babel-cli": "6.3.17", "babel-core": "6.3.26", "babel-preset-es2015": "6.3.13", "babel-preset-stage-2": "6.3.13",