Skip to content

Commit 7f0a606

Browse files
committed
[Tests] switch from jest to tape
1 parent 62ff3d9 commit 7f0a606

12 files changed

+8551
-10112
lines changed

.babelrc

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
{
22
"presets": [
3-
[
4-
"@babel/preset-env", {
5-
"useBuiltIns": false
6-
}
7-
],
3+
"@babel/preset-env",
84
"@babel/preset-flow"
95
],
106
"plugins": [
11-
"@babel/plugin-transform-flow-strip-types"
12-
]
7+
"@babel/plugin-transform-flow-strip-types",
8+
],
9+
"env": {
10+
"test": {
11+
"plugins": [
12+
["module-resolver", {
13+
"root": ["./__tests__"],
14+
"alias": {
15+
"^aria-query/src/(.*)": "./lib/\\1",
16+
}
17+
}]
18+
]
19+
},
20+
"development": {
21+
"plugins": [
22+
["module-resolver", {
23+
"root": ["./src"],
24+
"alias": {
25+
"^aria-query/src/(.*)": "./src/\\1",
26+
}
27+
}]
28+
]
29+
},
30+
}
1331
}

.eslintrc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@
3535
],
3636
"extends": [
3737
"eslint:recommended",
38-
"plugin:jest/recommended"
3938
],
4039
"env": {
41-
"jest": true,
4240
"node": true
4341
}
4442
}

.nycrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"all": true,
3+
"check-coverage": false,
4+
"reporter": ["text-summary", "text", "html", "json"],
5+
"lines": 86,
6+
"statements": 85.93,
7+
"functions": 82.43,
8+
"branches": 76.06,
9+
"exclude": [
10+
"coverage",
11+
"test"
12+
]
13+
}

__tests__/src/ariaPropsMaps-test.js

Lines changed: 68 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import expect from 'expect';
1+
import test from 'tape';
2+
import deepEqual from 'deep-equal-json';
3+
import inspect from 'object-inspect';
4+
25
import ariaPropsMap from '../../src/ariaPropsMap';
36
import rolesMap from '../../src/rolesMap';
47

@@ -56,20 +59,36 @@ const entriesList = [
5659
['aria-valuetext', {'type': 'string'}],
5760
];
5861

59-
describe('ariaPropsMap API', function () {
60-
describe('entries()', function () {
61-
test.each(ariaPropsMap.entries())('Testing prop: %s', (obj, roles) => {
62-
expect(entriesList).toEqual(
63-
expect.arrayContaining([[obj, roles]]),
64-
);
62+
test('ariaPropsMap API', async (t) => {
63+
t.test('iteration', async (st) => {
64+
st.notEqual(ariaPropsMap[Symbol.iterator], undefined, 'has an iterator defined');
65+
st.equal([...ariaPropsMap].length, 51, 'has a specific length');
66+
67+
st.test('supports the spread operator', async (s2t) => {
68+
[...ariaPropsMap].forEach(([obj, roles]) => {
69+
const found = entriesList.find(([o]) => deepEqual(o, obj));
70+
71+
s2t.ok(found, `spread has element: ${inspect(obj)}`);
72+
s2t.deepEqual(roles, found[1], `for-of has object elements`);
73+
});
6574
});
66-
test.each([...ariaPropsMap.entries()])('Testing prop: %s', (obj, roles) => {
67-
expect(entriesList).toEqual(
68-
expect.arrayContaining([[obj, roles]]),
69-
);
75+
76+
st.test('supports the for..of pattern', async (s2t) => {
77+
const output = [];
78+
for (const [key, value] of ariaPropsMap) {
79+
output.push([key, value]);
80+
}
81+
82+
output.forEach(([obj, roles]) => {
83+
const found = entriesList.find(([o]) => deepEqual(o, obj));
84+
85+
s2t.ok(found, `for-of has element: ${inspect(obj)}`);
86+
s2t.deepEqual(roles, found[1], `for-of has object elements`);
87+
});
7088
});
7189
});
72-
describe('forEach()', function () {
90+
91+
t.test('forEach()', async (st) => {
7392
const output = [];
7493
let context;
7594
ariaPropsMap.forEach((value, key, map) => {
@@ -78,81 +97,48 @@ describe('ariaPropsMap API', function () {
7897
context = map;
7998
}
8099
});
81-
test.each(output)('Testing prop: %s', (obj, roles) => {
82-
expect(entriesList).toEqual(
83-
expect.arrayContaining([[obj, roles]]),
84-
);
85-
});
86-
test.each(context)('Testing prop: %s', (obj, roles) => {
87-
expect(entriesList).toEqual(
88-
expect.arrayContaining([[obj, roles]]),
89-
);
90-
});
100+
101+
for (let i = 0; i < output.length; i++) {
102+
const [obj, roles] = output[i];
103+
const found = entriesList.find(([o]) => deepEqual(o, obj));
104+
105+
st.ok(found, `\`forEach\` has element: ${inspect(obj)}`);
106+
st.deepEqual(roles, found[1], `\`forEach\` has object elements`);
107+
}
91108
});
92-
it('get()', function () {
93-
expect(ariaPropsMap.get('aria-label')).toBeDefined();
94-
expect(ariaPropsMap.get('fake prop')).toBeUndefined();
109+
110+
t.test('get()', async (st) => {
111+
st.notEqual(ariaPropsMap.get('aria-label'), undefined, 'has a defined prop')
112+
st.equal(ariaPropsMap.get('fake prop'), undefined, 'returns undefined for a fake prop');
95113
});
96-
it('has()', function () {
97-
expect(ariaPropsMap.has('aria-label')).toEqual(true);
98-
expect(ariaPropsMap.has('fake prop')).toEqual(false);
114+
115+
t.test('has()', async (st) => {
116+
st.equal(ariaPropsMap.has('aria-label'), true, 'has a defined prop');
117+
st.equal(ariaPropsMap.has('fake prop'), false, 'returns false for a fake prop');
99118
});
100-
describe('keys()', function () {
119+
120+
t.test('keys(), iteration', async (st) => {
101121
const entriesKeys = entriesList.map(entry => entry[0]);
102-
test.each(ariaPropsMap.keys())('Testing key: %o', (key) => {
103-
expect(entriesKeys).toEqual(
104-
expect.arrayContaining([key]),
105-
);
106-
});
107-
test.each([...ariaPropsMap.keys()])('Testing key: %o', (key) => {
108-
expect(entriesKeys).toEqual(
109-
expect.arrayContaining([key]),
110-
);
111-
});
112-
});
113-
describe('values()', function () {
114-
const entriesValues = entriesList.map(entry => entry[1]);
115-
test.each(ariaPropsMap.values())('Testing value: %o', (value) => {
116-
expect(entriesValues).toEqual(
117-
expect.arrayContaining([value]),
118-
);
119-
});
120-
test.each([...ariaPropsMap.values()])('Testing value: %o', (value) => {
121-
expect(entriesValues).toEqual(
122-
expect.arrayContaining([value]),
123-
);
122+
for (const obj of ariaPropsMap.keys()) {
123+
st.ok(entriesKeys.find((k) => deepEqual(k, obj)), `for-of has key: ${inspect(obj)}`);
124+
}
125+
126+
[...ariaPropsMap.keys()].forEach((obj) => {
127+
st.ok(entriesKeys.find((k) => deepEqual(k, obj)), `spread has key: ${inspect(obj)}`);
124128
});
125129
});
126-
});
127130

128-
describe('ariaPropsMap', function () {
129-
describe('iteration', function () {
130-
it('should have an iterator defined', function () {
131-
expect(ariaPropsMap[Symbol.iterator]).not.toBeUndefined();
132-
});
133-
describe('spread operator', function () {
134-
it('should have a specific length', function () {
135-
expect(ariaPropsMap.entries().length).toEqual(51);
136-
});
137-
test.each([...ariaPropsMap])('Testing prop: %s', (obj, roles) => {
138-
expect(entriesList).toEqual(
139-
expect.arrayContaining([[obj, roles]]),
140-
);
141-
});
142-
});
143-
describe('for..of pattern', function () {
144-
const output = [];
145-
for (const [key, value] of ariaPropsMap) {
146-
output.push([key, value]);
147-
}
148-
test.each(output)('Testing prop: %s', (obj, roles) => {
149-
expect(entriesList).toEqual(
150-
expect.arrayContaining([[obj, roles]]),
151-
);
152-
});
131+
t.test('values(), iteration', async (st) => {
132+
for (const values of ariaPropsMap.values()) {
133+
st.ok(entriesList.some(([, x]) => deepEqual(x, values)), `for-of has object values: ${inspect(values)}`);
134+
}
135+
136+
[...ariaPropsMap.values()].forEach((values) => {
137+
st.ok(entriesList.some(([, x]) => deepEqual(x, values)), `spread has object values: ${inspect(values)}`);
153138
});
154139
});
155-
describe('props and role defintions', function () {
140+
141+
t.test('props and role defintions', async (st) => {
156142
const usedProps = [];
157143
for (const roleDefinition of rolesMap.values()) {
158144
for (const prop of Object.keys(roleDefinition.props)) {
@@ -168,11 +154,9 @@ describe('ariaPropsMap', function () {
168154
}
169155
}
170156
}
171-
test.each(ariaPropsMap.entries())(
172-
'The prop %s should be used in at least one role definition',
173-
(prop) => {
174-
expect(usedProps.find(p => p === prop)).toBeDefined();
175-
}
176-
);
157+
158+
ariaPropsMap.forEach((value, key) => {
159+
st.ok(usedProps.find(p => p === key), `has prop: ${key}`);
160+
});
177161
});
178162
});

0 commit comments

Comments
 (0)