Skip to content

Commit

Permalink
test(28): Ditch karma and mocha for AVA
Browse files Browse the repository at this point in the history
  • Loading branch information
philipjscott committed Oct 27, 2018
1 parent c23307e commit 9a7aa9d
Show file tree
Hide file tree
Showing 14 changed files with 1,962 additions and 2,695 deletions.
11 changes: 0 additions & 11 deletions .babelrc

This file was deleted.

4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
node_modules/
coverage/
dist/
.nyc_output/
.cache/
dist/
*.swo
*.swp
*.log
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The generator function takes in arguments (models) and returns an object with vi
```js
const gen = (model1, model2) => ({
jump () {
console.log('Jump! Models: ', model1, model2)
console.log(`Jump! Models: ${model1}, ${model2}`)
}
})
```
Expand Down Expand Up @@ -73,7 +73,7 @@ const generator = (model) => {
model.isDancing = false
},
keydown () {
model.isDancing = !model.isDancing
model.isDancing = true
}
},
// the "_" virtual key is special;
Expand Down
37 changes: 0 additions & 37 deletions karma.config.js

This file was deleted.

20 changes: 12 additions & 8 deletions lib/invert.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ function invert (json) {
let swapped = {}

for (const key in json) {
if (swapped[json[key]]) {
if (swapped[json[key]] !== undefined) {
throw json[key]
}

if (Array.isArray(json[key])) {
json[key].forEach((value) => {
if (swapped[value] !== undefined) {
throw value
}

swapped[value] = key
})
} else {
if (Array.isArray(json[key])) {
json[key].forEach((value) => {
swapped[value] = key
})
} else {
swapped[json[key]] = key
}
swapped[json[key]] = key
}
}

Expand Down
42 changes: 23 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,37 @@
"scripts": {
"fix": "standard --fix",
"lint": "standard",
"test": "standard && karma start --single-run --browsers ChromeHeadless karma.config.js",
"coverage": "cat coverage/HeadlessChrome\\ 0.0.0\\ \\(Linux\\ 0.0.0\\)/lcov.info | coveralls",
"test": "standard && nyc ava",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"demo": "parcel ./demo/index.html --open",
"semantic-release": "semantic-release",
"travis-deploy-once": "travis-deploy-once"
},
"ava": {
"files": [
"test/**/*.js",
"!test/helpers/**/*.js"
],
"sources": [
"lib/**/*.js"
],
"require": [
"babel-register",
"./test/helpers/setup-browser-env.js"
]
},
"babel": {
"plugins": ["transform-es2015-modules-commonjs"]
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2017": "^6.24.1",
"babelify": "^8.0.0",
"browserify": "^16.2.2",
"browserify-istanbul": "^3.0.1",
"chai": "^4.1.2",
"ava": "^1.0.0-rc.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"babel-register": "^6.26.0",
"browser-env": "^3.2.5",
"coveralls": "^3.0.2",
"dirty-chai": "^2.0.1",
"karma": "^2.0.4",
"karma-browserify": "^5.3.0",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.2",
"karma-mocha": "^1.3.0",
"mocha": "^5.2.0",
"nyc": "^13.1.0",
"parcel-bundler": "^1.9.6",
"puppeteer": "^1.6.0",
"semantic-release": "^15.8.1",
"sinon": "^6.1.4",
"standard": "^11.0.1",
"travis-deploy-once": "^5.0.1"
}
Expand Down
99 changes: 49 additions & 50 deletions test/compound.test.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,56 @@
/* global describe, it, KeyboardEvent */

'use strict'

/* global KeyboardEvent */

import test from 'ava'
import { decorate, desensitize } from '../lib/compound'
import { expect } from 'chai'

describe('Compound library handles compound keys', () => {
describe('decorate decorates KeyboardEvent.key', () => {
it('prepends peripheral active keys, in alphabetical order', () => {
const event = new KeyboardEvent('keydown', {
key: 'A',
ctrlKey: true,
altKey: true,
metaKey: true
})

expect(decorate(event)).to.equal('alt+ctrl+meta+A')
})

it('does not account for the shift key', () => {
const event = new KeyboardEvent('keydown', {
key: '+',
ctrlKey: true,
altKey: true,
shiftKey: true
})

expect(decorate(event)).to.equal('alt+ctrl++')
})

test('maps keyboard events to keyboard key strings', t => {
const event = new KeyboardEvent('keydown', {
key: 'A',
ctrlKey: true,
altKey: true,
metaKey: true
})

t.is(decorate(event), 'alt+ctrl+meta+A')
})

test('ignores the shift key', t => {
const event = new KeyboardEvent('keydown', {
key: 'p',
ctrlKey: true,
altKey: true,
shiftKey: true
})

describe('desensitize normalizes case and ordering of compound keys', () => {
it('normalizes case, calling toLowerCase()', () => {
expect(desensitize('ALT+CTRL+p')).to.equal('alt+ctrl+p')
expect(desensitize('Ctrl+Meta+ArrowLeft')).to.equal('ctrl+meta+ArrowLeft')
})

it('ensures the peripheral keys are in alphabetical order', () => {
expect(desensitize('ctrl+meta+alt+p')).to.equal('alt+ctrl+meta+p')
expect(desensitize('meta+ctrl+2')).to.equal('ctrl+meta+2')
})

it('does not modify primitive keys', () => {
expect(desensitize('A')).to.equal('A')
expect(desensitize('Space')).to.equal('Space')
expect(desensitize('ArrowLeft')).to.equal('ArrowLeft')
expect(desensitize('+')).to.equal('+')
})

it('normalizes both case and ordering simultaneously', () => {
expect(desensitize('cTRl+META+alt+p')).to.equal('alt+ctrl+meta+p')
expect(desensitize('ctrl+aLT+Space')).to.equal('alt+ctrl+Space')
expect(desensitize('meta+Ctrl+2')).to.equal('ctrl+meta+2')
})
t.is(decorate(event), 'alt+ctrl+p')
})

test('normalizes case', t => {
t.is(desensitize('ALT+CTRL+p'), 'alt+ctrl+p')
t.is(desensitize('Ctrl+Meta+ArrowLeft'), 'ctrl+meta+ArrowLeft')
})

test('ensures the peripheral keys are in alphabetical order', t => {
t.is(desensitize('ctrl+meta+alt+p'), 'alt+ctrl+meta+p')
t.is(desensitize('meta+ctrl+2'), 'ctrl+meta+2')
})

test('does not modify primitive keys', t => {
t.is(desensitize('A'), 'A')
t.is(desensitize('Space'), 'Space')
t.is(desensitize('ArrowLeft'), 'ArrowLeft')
t.is(desensitize('+'), '+')
})

test('decorate and desensitize work together', t => {
const event = new KeyboardEvent('keydown', {
key: '+',
ctrlKey: true,
altKey: true,
shiftKey: true
})

t.is(desensitize(decorate(event)), 'alt+ctrl++')
})
Loading

0 comments on commit 9a7aa9d

Please sign in to comment.