Skip to content

Commit

Permalink
[Tests] switch from jest to tape
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jun 21, 2024
1 parent 3a89d8c commit cad5c6a
Show file tree
Hide file tree
Showing 11 changed files with 4,758 additions and 5,820 deletions.
2 changes: 0 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
],
"extends": [
"eslint:recommended",
"plugin:jest/recommended"
],
"env": {
"mocha": true,
"node": true
}
}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ node_modules/
lib/
reports/
docs/
.nyc_output/
coverage/
13 changes: 13 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"all": true,
"check-coverage": false,
"reporter": ["text-summary", "text", "html", "json"],
"lines": 86,
"statements": 85.93,
"functions": 82.43,
"branches": 76.06,
"exclude": [
"coverage",
"test"
]
}
270 changes: 142 additions & 128 deletions __tests__/src/AXObjectElementMap-test.js

Large diffs are not rendered by default.

281 changes: 148 additions & 133 deletions __tests__/src/AXObjectRoleMap-test.js

Large diffs are not rendered by default.

635 changes: 325 additions & 310 deletions __tests__/src/AXObjectsMap-test.js

Large diffs are not rendered by default.

297 changes: 157 additions & 140 deletions __tests__/src/elementAXObjectMap-test.js

Large diffs are not rendered by default.

80 changes: 32 additions & 48 deletions __tests__/src/util/iterationDecorator-test.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,45 @@
/* eslint-env mocha */
import expect from 'expect';
import test from 'tape';
import values from 'object.values';
import mockProperty from 'mock-property';

import iterationDecorator from '../../../src/util/iterationDecorator';

describe('iterationDecorator', function () {
describe('should add a Symbol.iterator property to a collection', function () {
it('should return the values when iterated', function () {
test('iterationDecorator', (t) => {
t.test('adds a Symbol.iterator property to a collection', async (st) => {
// const collection = {a: 'apple', b: 'banana', c: 'cantaloupe'};
const collection = {
'a': 'apple',
'b': 'banana',
'c': 'cantaloupe',
};
const arr = ['apple', 'banana', 'cantaloupe'];
const iter = iterationDecorator(collection, Object.values(collection));
expect([...iter]).toEqual(expect.arrayContaining(arr));
});
const iter = iterationDecorator(collection, values(collection));
st.deepEqual([...iter], arr, 'returns the values when iterated');
});
describe('when Symbol is not defined in the global space', function () {
beforeEach(function () {
global.originalSymbol = global.Symbol
global.originalSymbolIterator = global.Symbol.iterator;
global.Symbol = undefined;
});
it('should not add a Symbol.iterator property to a collection', function () {
const collection = {
'a': 'apple',
'b': 'banana',
'c': 'cantaloupe',
};
const iter = iterationDecorator(collection, []);
expect(iter[global.originalSymbolIterator]).not.toBeDefined();
});
afterEach(function () {
global.Symbol = global.originalSymbol;
global.originalSymbol = undefined;
global.originalSymbolIterator = undefined;
});

t.test('when Symbol is not defined in the global space', async (st) => {
const originalSymbolIterator = typeof Symbol === 'function' ? Symbol.iterator : null;
st.teardown(mockProperty(global, 'Symbol', { value: undefined }));

const collection = {
'a': 'apple',
'b': 'banana',
'c': 'cantaloupe',
};
const iter = iterationDecorator(collection, []);
st.equal(iter[originalSymbolIterator], undefined, 'does not add a Symbol.iterator property to a collection');
});
describe('when Symbol.iterator is not defined in the global space', function () {
beforeEach(function () {
global.originalSymbol = global.Symbol
global.originalSymbolIterator = global.Symbol.iterator;
global.Symbol = function () {};
});
it('should not add a Symbol.iterator property to a collection', function () {
const collection = {
'a': 'apple',
'b': 'banana',
'c': 'cantaloupe',
};
const iter = iterationDecorator(collection, []);
expect(iter[global.originalSymbolIterator]).not.toBeDefined();
});
afterEach(function () {
global.Symbol = global.originalSymbol;
global.originalSymbol = undefined;
global.originalSymbolIterator = undefined;
});

t.test('when Symbol.iterator is not defined in the global space', async (st) => {
const originalSymbolIterator = typeof Symbol === 'function' ? Symbol.iterator : null;
st.teardown(mockProperty(global, 'Symbol', { value: function () {} }));

const collection = {
'a': 'apple',
'b': 'banana',
'c': 'cantaloupe',
};
const iter = iterationDecorator(collection, []);
st.equal(iter[originalSymbolIterator], undefined, 'does not add a Symbol.iterator property to a collection');
});
});
19 changes: 9 additions & 10 deletions __tests__/src/util/iteratorProxy-test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/* eslint-env mocha */
import expect from 'expect';
import test from 'tape';

import iteratorProxy from '../../../src/util/iteratorProxy';

describe('iteratorProxy', function () {
it('should create an iterator for the bound array', function () {
const arr = ['a', 'b', 'c'];
const iter = {
[Symbol.iterator]: iteratorProxy.bind(arr)
};
expect([...iter]).toEqual(expect.arrayContaining(arr));
});
test('iteratorProxy', async (t) => {
const arr = ['a', 'b', 'c'];
const iter = {
[Symbol.iterator]: iteratorProxy.bind(arr)
};

t.deepEqual([...iter], arr, 'creates an iterator for the bound array');
});
Loading

0 comments on commit cad5c6a

Please sign in to comment.