Skip to content
This repository was archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Switch from Ava to Jest (#258)
Browse files Browse the repository at this point in the history
Since:
* Jest is used more elsewhere in the community, so people are likely
  more familiar with it
* Ava seems to make more breaking changes (which has meant we've fallen
  behind the latest version as-is) - including dropping Node 8 in v3
* I find the Jest docs easier to follow
* Neutrino is likely to switch to Jest (since it has to have it in the
  list of deps anyway, for the `@neutrinojs/jest` preset) and it doesn't
  make sense to have projects under the `neutrinojs` org using differnet
  test runners (it's going to confuse me)
  • Loading branch information
edmorley authored Apr 18, 2020
1 parent dd229b5 commit 83db406
Showing 19 changed files with 2,311 additions and 2,236 deletions.
5 changes: 3 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -11,9 +11,10 @@ module.exports = {
'eslint-config-airbnb-base',
'plugin:prettier/recommended',
'prettier/babel',
'plugin:ava/recommended',
'plugin:jest/recommended',
'plugin:jest/style',
],
plugins: ['eslint-plugin-babel', 'eslint-plugin-ava'],
plugins: ['eslint-plugin-babel'],
parser: 'babel-eslint',
env: {
es6: true,
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
testEnvironment: 'node',
testMatch: ['**/test/**/*.js'],
};
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -21,9 +21,9 @@
"author": "Eli Perelman <eli@eliperelman.com>",
"license": "MPL-2.0",
"scripts": {
"test": "ava test",
"test": "jest",
"test:types": "tsc -p ./types/test/tsconfig.json",
"lint": "eslint --cache --report-unused-disable-directives --format codeframe \".*.js\" src test",
"lint": "eslint --cache --report-unused-disable-directives --format codeframe \".*.js\" \"*.js\" src test",
"changelog": "auto-changelog --remote upstream --commit-limit false",
"version": "yarn changelog --package && git add CHANGELOG.md"
},
@@ -37,15 +37,15 @@
"@types/tapable": "^1.0.4",
"@types/webpack": "^4.41.0",
"auto-changelog": "^2.0.0",
"ava": "^1.4.1",
"babel-eslint": "^10.0.3",
"eslint": "^6.7.2",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^6.7.0",
"eslint-plugin-ava": "^9.0.0",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-jest": "^23.8.2",
"eslint-plugin-prettier": "^3.1.1",
"jest": "^25.3.0",
"prettier": "^2.0.4",
"typescript": "^3.7.3",
"webpack": "^4.41.2"
13 changes: 6 additions & 7 deletions test/Chainable.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import test from 'ava';
import Chainable from '../src/Chainable';
const Chainable = require('../src/Chainable');

test('Calling .end() returns parent', (t) => {
test('calling .end() returns parent', () => {
const parent = { parent: true };
const chain = new Chainable(parent);

t.is(chain.end(), parent);
expect(chain.end()).toBe(parent);
});

test('Using .batch() receives context', (t) => {
test('using .batch() receives context', () => {
const chain = new Chainable();
const context = chain.batch((current) => {
t.is(current, chain);
expect(current).toBe(chain);
});

t.is(context, chain);
expect(context).toBe(chain);
});
137 changes: 69 additions & 68 deletions test/ChainedMap.js
Original file line number Diff line number Diff line change
@@ -1,192 +1,193 @@
import test from 'ava';
import ChainedMap from '../src/ChainedMap';
const ChainedMap = require('../src/ChainedMap');

test('is Chainable', (t) => {
test('is Chainable', () => {
const parent = { parent: true };
const map = new ChainedMap(parent);

t.is(map.end(), parent);
expect(map.end()).toBe(parent);
});

test('creates a backing Map', (t) => {
test('creates a backing Map', () => {
const map = new ChainedMap();

t.true(map.store instanceof Map);
expect(map.store instanceof Map).toBe(true);
});

test('set', (t) => {
test('set', () => {
const map = new ChainedMap();

t.is(map.set('a', 'alpha'), map);
t.is(map.store.get('a'), 'alpha');
expect(map.set('a', 'alpha')).toBe(map);
expect(map.store.get('a')).toBe('alpha');
});

test('get', (t) => {
test('get', () => {
const map = new ChainedMap();

t.is(map.set('a', 'alpha'), map);
t.is(map.get('a'), 'alpha');
expect(map.set('a', 'alpha')).toBe(map);
expect(map.get('a')).toBe('alpha');
});

test('getOrCompute', (t) => {
test('getOrCompute', () => {
const map = new ChainedMap();

t.is(map.get('a'), undefined);
t.is(
map.getOrCompute('a', () => 'alpha'),
'alpha',
);
t.is(map.get('a'), 'alpha');
expect(map.get('a')).toBeUndefined();
expect(map.getOrCompute('a', () => 'alpha')).toBe('alpha');
expect(map.get('a')).toBe('alpha');
});

test('clear', (t) => {
test('clear', () => {
const map = new ChainedMap();

map.set('a', 'alpha');
map.set('b', 'beta');
map.set('c', 'gamma');

t.is(map.store.size, 3);
t.is(map.clear(), map);
t.is(map.store.size, 0);
expect(map.store.size).toBe(3);
expect(map.clear()).toBe(map);
expect(map.store.size).toBe(0);
});

test('delete', (t) => {
test('delete', () => {
const map = new ChainedMap();

map.set('a', 'alpha');
map.set('b', 'beta');
map.set('c', 'gamma');

t.is(map.delete('b'), map);
t.is(map.store.size, 2);
t.false(map.store.has('b'));
expect(map.delete('b')).toBe(map);
expect(map.store.size).toBe(2);
expect(map.store.has('b')).toBe(false);
});

test('has', (t) => {
test('has', () => {
const map = new ChainedMap();

map.set('a', 'alpha');
map.set('b', 'beta');
map.set('c', 'gamma');

t.true(map.has('b'));
t.false(map.has('d'));
t.is(map.has('b'), map.store.has('b'));
expect(map.has('b')).toBe(true);
expect(map.has('d')).toBe(false);
expect(map.has('b')).toBe(map.store.has('b'));
});

test('values', (t) => {
test('values', () => {
const map = new ChainedMap();

map.set('a', 'alpha');
map.set('b', 'beta');
map.set('c', 'gamma');

t.deepEqual(map.values(), ['alpha', 'beta', 'gamma']);
expect(map.values()).toStrictEqual(['alpha', 'beta', 'gamma']);
});

test('entries with values', (t) => {
test('entries with values', () => {
const map = new ChainedMap();

map.set('a', 'alpha');
map.set('b', 'beta');
map.set('c', 'gamma');

t.deepEqual(map.entries(), { a: 'alpha', b: 'beta', c: 'gamma' });
expect(map.entries()).toStrictEqual({ a: 'alpha', b: 'beta', c: 'gamma' });
});

test('entries with no values', (t) => {
test('entries with no values', () => {
const map = new ChainedMap();

t.is(map.entries(), undefined);
expect(map.entries()).toBeUndefined();
});

test('merge with no values', (t) => {
test('merge with no values', () => {
const map = new ChainedMap();
const obj = { a: 'alpha', b: 'beta', c: 'gamma' };

t.is(map.merge(obj), map);
t.deepEqual(map.entries(), obj);
expect(map.merge(obj)).toBe(map);
expect(map.entries()).toStrictEqual(obj);
});

test('merge with existing values', (t) => {
test('merge with existing values', () => {
const map = new ChainedMap();
const obj = { a: 'alpha', b: 'beta', c: 'gamma' };

map.set('d', 'delta');

t.is(map.merge(obj), map);
t.deepEqual(map.entries(), { a: 'alpha', b: 'beta', c: 'gamma', d: 'delta' });
expect(map.merge(obj)).toBe(map);
expect(map.entries()).toStrictEqual({
a: 'alpha',
b: 'beta',
c: 'gamma',
d: 'delta',
});
});

test('merge with overriding values', (t) => {
test('merge with overriding values', () => {
const map = new ChainedMap();
const obj = { a: 'alpha', b: 'beta', c: 'gamma' };

map.set('b', 'delta');

t.is(map.merge(obj), map);
t.deepEqual(map.entries(), { a: 'alpha', b: 'beta', c: 'gamma' });
expect(map.merge(obj)).toBe(map);
expect(map.entries()).toStrictEqual({ a: 'alpha', b: 'beta', c: 'gamma' });
});

test('merge with omitting keys', (t) => {
test('merge with omitting keys', () => {
const map = new ChainedMap();
const obj = { a: 'alpha', b: 'beta', c: 'gamma' };

map.merge(obj, ['b']);

t.deepEqual(map.entries(), { a: 'alpha', c: 'gamma' });
expect(map.entries()).toStrictEqual({ a: 'alpha', c: 'gamma' });
});

test('when true', (t) => {
test('when true', () => {
const map = new ChainedMap();
const right = (instance) => {
t.is(instance, map);
expect(instance).toBe(map);
instance.set('alpha', 'a');
};
const left = (instance) => {
instance.set('beta', 'b');
};

t.is(map.when(true, right, left), map);
t.true(map.has('alpha'));
t.false(map.has('beta'));
expect(map.when(true, right, left)).toBe(map);
expect(map.has('alpha')).toBe(true);
expect(map.has('beta')).toBe(false);
});

test('when false', (t) => {
test('when false', () => {
const map = new ChainedMap();
const right = (instance) => {
instance.set('alpha', 'a');
};
const left = (instance) => {
t.is(instance, map);
expect(instance).toBe(map);
instance.set('beta', 'b');
};

t.is(map.when(false, right, left), map);
t.false(map.has('alpha'));
t.true(map.has('beta'));
expect(map.when(false, right, left)).toBe(map);
expect(map.has('alpha')).toBe(false);
expect(map.has('beta')).toBe(true);
});

test('clean undefined', (t) => {
test('clean undefined', () => {
const map = new ChainedMap();
map.set('alpha', undefined);
map.set('beta', 'b');
t.true('alpha' in map.entries());
t.false('alpha' in map.clean(map.entries()));
t.true('beta' in map.clean(map.entries()));
expect('alpha' in map.entries()).toBe(true);
expect('alpha' in map.clean(map.entries())).toBe(false);
expect('beta' in map.clean(map.entries())).toBe(true);
});

test('clean empty array', (t) => {
test('clean empty array', () => {
const map = new ChainedMap();
map.set('alpha', []);
t.true('alpha' in map.entries());
t.false('alpha' in map.clean(map.entries()));
expect('alpha' in map.entries()).toBe(true);
expect('alpha' in map.clean(map.entries())).toBe(false);
});

test('clean empty object', (t) => {
test('clean empty object', () => {
const map = new ChainedMap();
map.set('alpha', {});
t.true('alpha' in map.entries());
t.false('alpha' in map.clean(map.entries()));
expect('alpha' in map.entries()).toBe(true);
expect('alpha' in map.clean(map.entries())).toBe(false);
});
Loading

0 comments on commit 83db406

Please sign in to comment.