Skip to content

Commit

Permalink
[Tests] switch from jest to tape
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ljharb committed Sep 3, 2024
1 parent deac4fd commit a284cbf
Show file tree
Hide file tree
Showing 40 changed files with 1,723 additions and 1,315 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node-4+.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ jobs:
skip-ls-check: true
- run: rm __tests__/src/util/getComputedRole-test.js
if: ${{ matrix.node-version < 7 }}
- run: npm run test:ci
- run: npm run tests-only
- uses: codecov/[email protected]

node:
Expand Down
3 changes: 0 additions & 3 deletions __tests__/__util__/nodeReexports/assert.js

This file was deleted.

3 changes: 0 additions & 3 deletions __tests__/__util__/nodeReexports/fs-promises.js

This file was deleted.

3 changes: 0 additions & 3 deletions __tests__/__util__/nodeReexports/fs.js

This file was deleted.

3 changes: 0 additions & 3 deletions __tests__/__util__/nodeReexports/path.js

This file was deleted.

3 changes: 0 additions & 3 deletions __tests__/__util__/nodeReexports/url.js

This file was deleted.

3 changes: 0 additions & 3 deletions __tests__/__util__/nodeReexports/util.js

This file was deleted.

39 changes: 21 additions & 18 deletions __tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,39 @@

import fs from 'fs';
import path from 'path';
import expect from 'expect';
import test from 'tape';

import plugin from '../src';

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

describe('all rule files should be exported by the plugin', () => {
test('all rule files should be exported by the plugin', (t) => {
rules.forEach((ruleName) => {
it(`should export ${ruleName}`, () => {
expect(plugin.rules[ruleName]).toEqual(
require(path.join('../src/rules', ruleName)) // eslint-disable-line
);
});
t.equal(
plugin.rules[ruleName],
require(path.join('../src/rules', ruleName)), // eslint-disable-line import/no-dynamic-require
`exports ${ruleName}`,
);
});

t.end();
});

describe('configurations', () => {
it('should export a \'recommended\' configuration', () => {
expect(plugin.configs.recommended).toBeDefined();
});
test('configurations', (t) => {
t.notEqual(plugin.configs.recommended, undefined, 'exports a \'recommended\' configuration');

t.end();
});

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

expect(type).toEqual('object');
});
t.equal(type, 'object', `${ruleName} exports a schema with type object`);
});

t.end();
});
1 change: 0 additions & 1 deletion __tests__/src/rules/anchor-ambiguous-text-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-env jest */
/**
* @fileoverview Enforce `<a>` text to not exactly match "click here", "here", "link", or "a link".
* @author Matt Wang
Expand Down
18 changes: 10 additions & 8 deletions __tests__/src/rules/aria-proptypes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

import { aria } from 'aria-query';
import { RuleTester } from 'eslint';
import expect from 'expect';
import test from 'tape';

import parserOptionsMapper from '../../__util__/parserOptionsMapper';
import parsers from '../../__util__/helpers/parsers';
import rule from '../../../src/rules/aria-proptypes';
Expand Down Expand Up @@ -51,13 +52,14 @@ tokens from the following: ${permittedValues}.`,
}
};

describe('validityCheck', () => {
it('should false for an unknown expected type', () => {
expect(validityCheck(
null,
null,
)).toBe(false);
});
test('validityCheck', (t) => {
t.equal(
validityCheck(null, null),
false,
'is false for an unknown expected type',
);

t.end();
});

ruleTester.run('aria-proptypes', rule, {
Expand Down
196 changes: 86 additions & 110 deletions __tests__/src/util/attributesComparator-test.js
Original file line number Diff line number Diff line change
@@ -1,115 +1,91 @@
import expect from 'expect';
import test from 'tape';

import attributesComparator from '../../../src/util/attributesComparator';
import JSXAttributeMock from '../../../__mocks__/JSXAttributeMock';
import JSXElementMock from '../../../__mocks__/JSXElementMock';

describe('attributesComparator', () => {
describe('base attributes', () => {
let baseAttributes;
let attributes;
describe('are undefined', () => {
describe('and attributes are undefined', () => {
it('should return true', () => {
expect(attributesComparator()).toBe(true);
});
});
});
describe('are empty', () => {
beforeEach(() => {
baseAttributes = [];
});
describe('and attributes', () => {
describe('are empty', () => {
attributes = [];
it('should return true', () => {
expect(attributesComparator(baseAttributes, attributes))
.toBe(true);
});
});
describe('have values', () => {
attributes = [
JSXAttributeMock('foo', 0),
JSXAttributeMock('bar', 'baz'),
];
it('should return true', () => {
expect(attributesComparator(baseAttributes, attributes))
.toBe(true);
});
});
});
});
describe('have values', () => {
beforeEach(() => {
baseAttributes = [
{
name: 'biz',
value: 1,
}, {
name: 'fizz',
value: 'pop',
}, {
name: 'fuzz',
value: 'lolz',
},
];
});
describe('and attributes', () => {
describe('are empty', () => {
attributes = [];
it('should return false', () => {
expect(attributesComparator(baseAttributes, attributes))
.toBe(false);
});
});
describe('have values', () => {
describe('and the values are the different', () => {
it('should return false', () => {
attributes = [
JSXElementMock(),
JSXAttributeMock('biz', 2),
JSXAttributeMock('ziff', 'opo'),
JSXAttributeMock('far', 'lolz'),
];
expect(attributesComparator(baseAttributes, attributes))
.toBe(false);
});
});
describe('and the values are a subset', () => {
it('should return true', () => {
attributes = [
JSXAttributeMock('biz', 1),
JSXAttributeMock('fizz', 'pop'),
JSXAttributeMock('goo', 'gazz'),
];
expect(attributesComparator(baseAttributes, attributes))
.toBe(false);
});
});
describe('and the values are the same', () => {
it('should return true', () => {
attributes = [
JSXAttributeMock('biz', 1),
JSXAttributeMock('fizz', 'pop'),
JSXAttributeMock('fuzz', 'lolz'),
];
expect(attributesComparator(baseAttributes, attributes))
.toBe(true);
});
});
describe('and the values are a superset', () => {
it('should return true', () => {
attributes = [
JSXAttributeMock('biz', 1),
JSXAttributeMock('fizz', 'pop'),
JSXAttributeMock('fuzz', 'lolz'),
JSXAttributeMock('dar', 'tee'),
];
expect(attributesComparator(baseAttributes, attributes))
.toBe(true);
});
});
});
});
});
});
test('attributesComparator', (t) => {
t.equal(
attributesComparator(),
true,
'baseAttributes are undefined and attributes are undefined -> true',
);

t.equal(
attributesComparator([], []),
true,
'baseAttributes are empty and attributes are empty -> true',
);

t.equal(
attributesComparator([], [
JSXAttributeMock('foo', 0),
JSXAttributeMock('bar', 'baz'),
]),
true,
'baseAttributes are empty and attributes have values -> true',
);

const baseAttributes = [
{
name: 'biz',
value: 1,
}, {
name: 'fizz',
value: 'pop',
}, {
name: 'fuzz',
value: 'lolz',
},
];

t.equal(
attributesComparator(baseAttributes, []),
false,
'baseAttributes have values and attributes are empty -> false',
);

t.equal(
attributesComparator(baseAttributes, [
JSXElementMock(),
JSXAttributeMock('biz', 2),
JSXAttributeMock('ziff', 'opo'),
JSXAttributeMock('far', 'lolz'),
]),
false,
'baseAttributes have values and attributes have values, and the values are different -> false',
);

t.equal(
attributesComparator(baseAttributes, [
JSXAttributeMock('biz', 1),
JSXAttributeMock('fizz', 'pop'),
JSXAttributeMock('goo', 'gazz'),
]),
false,
'baseAttributes have values and attributes have values, and the values are a subset -> false',
);

t.equal(
attributesComparator(baseAttributes, [
JSXAttributeMock('biz', 1),
JSXAttributeMock('fizz', 'pop'),
JSXAttributeMock('fuzz', 'lolz'),
]),
true,
'baseAttributes have values and attributes have values, and the values are the same -> true',
);

t.equal(
attributesComparator(baseAttributes, [
JSXAttributeMock('biz', 1),
JSXAttributeMock('fizz', 'pop'),
JSXAttributeMock('fuzz', 'lolz'),
JSXAttributeMock('dar', 'tee'),
]),
true,
'baseAttributes have values and attributes have values, and the values are a superset -> true',
);

t.end();
});
Loading

0 comments on commit a284cbf

Please sign in to comment.