Skip to content

Commit a284cbf

Browse files
committed
[Tests] switch from jest to tape
This allows us to: - drop all the jest mocks - no longer be stuck on an EOL version nor be forced to raise the engines.node threshold - run tests 4x faster: jest takes 27.365s, tape takes 7.086s
1 parent deac4fd commit a284cbf

40 files changed

+1723
-1315
lines changed

.github/workflows/node-4+.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ jobs:
128128
skip-ls-check: true
129129
- run: rm __tests__/src/util/getComputedRole-test.js
130130
if: ${{ matrix.node-version < 7 }}
131-
- run: npm run test:ci
131+
- run: npm run tests-only
132132
- uses: codecov/[email protected]
133133

134134
node:

__tests__/__util__/nodeReexports/assert.js

-3
This file was deleted.

__tests__/__util__/nodeReexports/fs-promises.js

-3
This file was deleted.

__tests__/__util__/nodeReexports/fs.js

-3
This file was deleted.

__tests__/__util__/nodeReexports/path.js

-3
This file was deleted.

__tests__/__util__/nodeReexports/url.js

-3
This file was deleted.

__tests__/__util__/nodeReexports/util.js

-3
This file was deleted.

__tests__/index-test.js

+21-18
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,39 @@
22

33
import fs from 'fs';
44
import path from 'path';
5-
import expect from 'expect';
5+
import test from 'tape';
6+
67
import plugin from '../src';
78

89
const rules = fs.readdirSync(path.resolve(__dirname, '../src/rules/'))
910
.map((f) => path.basename(f, '.js'));
1011

11-
describe('all rule files should be exported by the plugin', () => {
12+
test('all rule files should be exported by the plugin', (t) => {
1213
rules.forEach((ruleName) => {
13-
it(`should export ${ruleName}`, () => {
14-
expect(plugin.rules[ruleName]).toEqual(
15-
require(path.join('../src/rules', ruleName)) // eslint-disable-line
16-
);
17-
});
14+
t.equal(
15+
plugin.rules[ruleName],
16+
require(path.join('../src/rules', ruleName)), // eslint-disable-line import/no-dynamic-require
17+
`exports ${ruleName}`,
18+
);
1819
});
20+
21+
t.end();
1922
});
2023

21-
describe('configurations', () => {
22-
it('should export a \'recommended\' configuration', () => {
23-
expect(plugin.configs.recommended).toBeDefined();
24-
});
24+
test('configurations', (t) => {
25+
t.notEqual(plugin.configs.recommended, undefined, 'exports a \'recommended\' configuration');
26+
27+
t.end();
2528
});
2629

27-
describe('schemas', () => {
30+
test('schemas', (t) => {
2831
rules.forEach((ruleName) => {
29-
it(`${ruleName} should export a schema with type object`, () => {
30-
const rule = require(path.join('../src/rules', ruleName)); // eslint-disable-line
31-
const schema = rule.meta && rule.meta.schema && rule.meta.schema[0];
32-
const { type } = schema;
32+
const rule = require(path.join('../src/rules', ruleName)); // eslint-disable-line import/no-dynamic-require
33+
const schema = rule.meta && rule.meta.schema && rule.meta.schema[0];
34+
const { type } = schema;
3335

34-
expect(type).toEqual('object');
35-
});
36+
t.equal(type, 'object', `${ruleName} exports a schema with type object`);
3637
});
38+
39+
t.end();
3740
});

__tests__/src/rules/anchor-ambiguous-text-test.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-env jest */
21
/**
32
* @fileoverview Enforce `<a>` text to not exactly match "click here", "here", "link", or "a link".
43
* @author Matt Wang

__tests__/src/rules/aria-proptypes-test.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
import { aria } from 'aria-query';
1111
import { RuleTester } from 'eslint';
12-
import expect from 'expect';
12+
import test from 'tape';
13+
1314
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
1415
import parsers from '../../__util__/helpers/parsers';
1516
import rule from '../../../src/rules/aria-proptypes';
@@ -51,13 +52,14 @@ tokens from the following: ${permittedValues}.`,
5152
}
5253
};
5354

54-
describe('validityCheck', () => {
55-
it('should false for an unknown expected type', () => {
56-
expect(validityCheck(
57-
null,
58-
null,
59-
)).toBe(false);
60-
});
55+
test('validityCheck', (t) => {
56+
t.equal(
57+
validityCheck(null, null),
58+
false,
59+
'is false for an unknown expected type',
60+
);
61+
62+
t.end();
6163
});
6264

6365
ruleTester.run('aria-proptypes', rule, {
+86-110
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,91 @@
1-
import expect from 'expect';
1+
import test from 'tape';
2+
23
import attributesComparator from '../../../src/util/attributesComparator';
34
import JSXAttributeMock from '../../../__mocks__/JSXAttributeMock';
45
import JSXElementMock from '../../../__mocks__/JSXElementMock';
56

6-
describe('attributesComparator', () => {
7-
describe('base attributes', () => {
8-
let baseAttributes;
9-
let attributes;
10-
describe('are undefined', () => {
11-
describe('and attributes are undefined', () => {
12-
it('should return true', () => {
13-
expect(attributesComparator()).toBe(true);
14-
});
15-
});
16-
});
17-
describe('are empty', () => {
18-
beforeEach(() => {
19-
baseAttributes = [];
20-
});
21-
describe('and attributes', () => {
22-
describe('are empty', () => {
23-
attributes = [];
24-
it('should return true', () => {
25-
expect(attributesComparator(baseAttributes, attributes))
26-
.toBe(true);
27-
});
28-
});
29-
describe('have values', () => {
30-
attributes = [
31-
JSXAttributeMock('foo', 0),
32-
JSXAttributeMock('bar', 'baz'),
33-
];
34-
it('should return true', () => {
35-
expect(attributesComparator(baseAttributes, attributes))
36-
.toBe(true);
37-
});
38-
});
39-
});
40-
});
41-
describe('have values', () => {
42-
beforeEach(() => {
43-
baseAttributes = [
44-
{
45-
name: 'biz',
46-
value: 1,
47-
}, {
48-
name: 'fizz',
49-
value: 'pop',
50-
}, {
51-
name: 'fuzz',
52-
value: 'lolz',
53-
},
54-
];
55-
});
56-
describe('and attributes', () => {
57-
describe('are empty', () => {
58-
attributes = [];
59-
it('should return false', () => {
60-
expect(attributesComparator(baseAttributes, attributes))
61-
.toBe(false);
62-
});
63-
});
64-
describe('have values', () => {
65-
describe('and the values are the different', () => {
66-
it('should return false', () => {
67-
attributes = [
68-
JSXElementMock(),
69-
JSXAttributeMock('biz', 2),
70-
JSXAttributeMock('ziff', 'opo'),
71-
JSXAttributeMock('far', 'lolz'),
72-
];
73-
expect(attributesComparator(baseAttributes, attributes))
74-
.toBe(false);
75-
});
76-
});
77-
describe('and the values are a subset', () => {
78-
it('should return true', () => {
79-
attributes = [
80-
JSXAttributeMock('biz', 1),
81-
JSXAttributeMock('fizz', 'pop'),
82-
JSXAttributeMock('goo', 'gazz'),
83-
];
84-
expect(attributesComparator(baseAttributes, attributes))
85-
.toBe(false);
86-
});
87-
});
88-
describe('and the values are the same', () => {
89-
it('should return true', () => {
90-
attributes = [
91-
JSXAttributeMock('biz', 1),
92-
JSXAttributeMock('fizz', 'pop'),
93-
JSXAttributeMock('fuzz', 'lolz'),
94-
];
95-
expect(attributesComparator(baseAttributes, attributes))
96-
.toBe(true);
97-
});
98-
});
99-
describe('and the values are a superset', () => {
100-
it('should return true', () => {
101-
attributes = [
102-
JSXAttributeMock('biz', 1),
103-
JSXAttributeMock('fizz', 'pop'),
104-
JSXAttributeMock('fuzz', 'lolz'),
105-
JSXAttributeMock('dar', 'tee'),
106-
];
107-
expect(attributesComparator(baseAttributes, attributes))
108-
.toBe(true);
109-
});
110-
});
111-
});
112-
});
113-
});
114-
});
7+
test('attributesComparator', (t) => {
8+
t.equal(
9+
attributesComparator(),
10+
true,
11+
'baseAttributes are undefined and attributes are undefined -> true',
12+
);
13+
14+
t.equal(
15+
attributesComparator([], []),
16+
true,
17+
'baseAttributes are empty and attributes are empty -> true',
18+
);
19+
20+
t.equal(
21+
attributesComparator([], [
22+
JSXAttributeMock('foo', 0),
23+
JSXAttributeMock('bar', 'baz'),
24+
]),
25+
true,
26+
'baseAttributes are empty and attributes have values -> true',
27+
);
28+
29+
const baseAttributes = [
30+
{
31+
name: 'biz',
32+
value: 1,
33+
}, {
34+
name: 'fizz',
35+
value: 'pop',
36+
}, {
37+
name: 'fuzz',
38+
value: 'lolz',
39+
},
40+
];
41+
42+
t.equal(
43+
attributesComparator(baseAttributes, []),
44+
false,
45+
'baseAttributes have values and attributes are empty -> false',
46+
);
47+
48+
t.equal(
49+
attributesComparator(baseAttributes, [
50+
JSXElementMock(),
51+
JSXAttributeMock('biz', 2),
52+
JSXAttributeMock('ziff', 'opo'),
53+
JSXAttributeMock('far', 'lolz'),
54+
]),
55+
false,
56+
'baseAttributes have values and attributes have values, and the values are different -> false',
57+
);
58+
59+
t.equal(
60+
attributesComparator(baseAttributes, [
61+
JSXAttributeMock('biz', 1),
62+
JSXAttributeMock('fizz', 'pop'),
63+
JSXAttributeMock('goo', 'gazz'),
64+
]),
65+
false,
66+
'baseAttributes have values and attributes have values, and the values are a subset -> false',
67+
);
68+
69+
t.equal(
70+
attributesComparator(baseAttributes, [
71+
JSXAttributeMock('biz', 1),
72+
JSXAttributeMock('fizz', 'pop'),
73+
JSXAttributeMock('fuzz', 'lolz'),
74+
]),
75+
true,
76+
'baseAttributes have values and attributes have values, and the values are the same -> true',
77+
);
78+
79+
t.equal(
80+
attributesComparator(baseAttributes, [
81+
JSXAttributeMock('biz', 1),
82+
JSXAttributeMock('fizz', 'pop'),
83+
JSXAttributeMock('fuzz', 'lolz'),
84+
JSXAttributeMock('dar', 'tee'),
85+
]),
86+
true,
87+
'baseAttributes have values and attributes have values, and the values are a superset -> true',
88+
);
89+
90+
t.end();
11591
});

0 commit comments

Comments
 (0)