Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to babel 6, migrate tests to ava #12

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015", "stage-2"]
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
coverage
.nyc_output

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ before_install:
before_script:
- npm prune
script:
- npm run test:single
- npm run test:cover
- npm run check-coverage
- npm run build
after_success:
Expand Down
24 changes: 15 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -34,22 +35,27 @@
"unique-random-array": "1.0.0"
},
"devDependencies": {
"babel": "5.8.21",
"chai": "3.3.0",
"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",
"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": {
"path": "node_modules/cz-conventional-changelog"
},
"config": {
"ghooks": {
"pre-commit": "npm run test:single && npm run check-coverage"
"pre-commit": "npm run test && npm run check-coverage"
}
}
}
55 changes: 25 additions & 30 deletions src/index.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
});