Skip to content

Commit 2061f08

Browse files
committed
chore: refactor tests to vitest
1 parent 650b4d7 commit 2061f08

File tree

60 files changed

+636
-596
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+636
-596
lines changed

.eslintignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 8 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,28 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
node-version: [18.x]
13+
node-version: [22]
1414

1515
steps:
16-
- uses: actions/checkout@v4
16+
- uses: actions/checkout@v4
1717

18-
- name: Use Node.js ${{ matrix.node-version }}
19-
uses: actions/setup-node@v4
20-
with:
21-
node-version: ${{ matrix.node-version }}
18+
- name: Install pnpm
19+
uses: pnpm/action-setup@v4
2220

23-
- name: Get Yarn cache directory
24-
id: yarn-cache-dir-path
25-
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
21+
- name: Use Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
cache: 'pnpm'
2626

27-
- name: Use Yarn cache
28-
uses: actions/cache@v4
29-
id: yarn-cache
30-
with:
31-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
32-
key: ${{ runner.os }}-yarn-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}
27+
- name: Install dependencies
28+
run: pnpm i --frozen-lockfile
3329

34-
- name: Install dependencies
35-
run: yarn install --prefer-offline --frozen-lockfile
30+
- name: Test
31+
run: pnpm test
3632

37-
- name: Test
38-
run: yarn run test
33+
- name: Lint
34+
run: pnpm lint
3935

40-
- name: Lint
41-
run: yarn run lint
42-
43-
- name: Build
44-
run: yarn run build
36+
- name: Build
37+
run: pnpm build

.github/workflows/release.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ jobs:
2222
steps:
2323
- name: Checkout Repo
2424
uses: actions/checkout@v4
25-
25+
2626
- name: Use Node.js
2727
uses: actions/setup-node@v4
2828

2929
- name: Install dependencies
30-
run: yarn install --frozen-lockfile
30+
run: pnpm install --frozen-lockfile
3131

3232
- name: Build packages
33-
run: yarn build
33+
run: pnpm build
3434

3535
- name: PR or Publish
3636
id: changesets
3737
uses: changesets/action@v1
3838
with:
39-
version: yarn run changeset version
40-
publish: yarn run changeset publish
39+
version: pnpm changeset version
40+
publish: pnpm changeset publish
4141
env:
4242
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4343
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
npm-debug.log
88
/src
99
/reports
10-
yarn-error.log
1110
/.vscode
1211
/docs
1312
/.github

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v23.10.0
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { RuleTester } from 'eslint';
2+
import deepmerge from 'deepmerge';
3+
4+
const defaultLanguageOptions = {
5+
ecmaVersion: 2020,
6+
parserOptions: {
7+
ecmaFeatures: {
8+
jsx: true,
9+
},
10+
},
11+
};
12+
13+
const languageOptionsMapper = (
14+
testCase: RuleTester.ValidTestCase | RuleTester.InvalidTestCase,
15+
) => ({
16+
...testCase,
17+
errors: (<RuleTester.InvalidTestCase>testCase).errors,
18+
options: testCase.options ?? [],
19+
languageOptions: deepmerge(
20+
defaultLanguageOptions,
21+
testCase.languageOptions ?? {},
22+
),
23+
});
24+
25+
export default languageOptionsMapper;

__tests__/__util__/parserOptionsMapper.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

__tests__/__util__/ruleOptionsMapperFactory.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

__tests__/index.test.ts

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,46 @@
1-
/* eslint-env jest */
2-
/* eslint global-require: 0 */
3-
4-
import assert from 'assert';
5-
import fs from 'fs';
6-
import path from 'path';
71
import plugin from '../src';
2+
import type { Rule } from 'eslint';
83

9-
const rules = fs
10-
.readdirSync(path.resolve(__dirname, '../src/rules/'))
11-
.map((f) => path.basename(f, '.js'));
4+
const rules = import.meta.glob<true, string, { default: Rule.RuleModule }>(
5+
'../src/rules/*.ts',
6+
{ eager: true },
7+
);
128

139
describe('all rule files should be exported by the plugin', () => {
14-
rules.forEach((ruleName) => {
15-
it(`should export ${ruleName}`, () => {
16-
assert.equal(
17-
plugin.rules[ruleName],
18-
require(path.join('../src/rules', ruleName)) // eslint-disable-line
10+
it.each(Object.entries(rules))(
11+
`exports %s`,
12+
(rulePath, { default: ruleModule }) => {
13+
const ruleName = rulePath.split('/').at(-1)?.replace('.ts', '');
14+
expect(plugin.rules[ruleName as keyof typeof plugin.rules]).toEqual(
15+
ruleModule,
1916
);
20-
});
21-
});
17+
},
18+
);
2219
});
2320

24-
describe('configurations', () => {
25-
const configs = ['basic', 'ios', 'android', 'all'];
26-
27-
configs.forEach((name) => {
28-
it(`should export a '${name}' configuration`, () => {
29-
assert(plugin.configs[name]);
30-
});
31-
});
21+
describe('configs', () => {
22+
it.each(['basic', 'ios', 'android', 'all'])(
23+
`exports a %s config`,
24+
(config) => {
25+
expect(
26+
plugin.configs[config as keyof typeof plugin.configs],
27+
).toBeTruthy();
28+
},
29+
);
3230
});
3331

3432
describe('schemas', () => {
35-
rules.forEach((ruleName) => {
36-
it(`${ruleName} should export a schema with type object`, () => {
37-
const rule = require(path.join('../src/rules', ruleName)); // eslint-disable-line
38-
const schema = rule.meta && rule.meta.schema && rule.meta.schema[0];
39-
const { type } = schema;
33+
it.each(
34+
Object.entries(rules).filter(([filename]) => !filename.includes('index')),
35+
)(
36+
`%s exports a schema with type object`,
37+
async (_, { default: ruleModule }) => {
38+
const schema =
39+
ruleModule.meta &&
40+
ruleModule.meta.schema &&
41+
(ruleModule.meta.schema as { type: string }[])[0];
4042

41-
assert.deepEqual(type, 'object');
42-
});
43-
});
43+
expect((schema as { type: string }).type).toBe('object');
44+
},
45+
);
4446
});

__tests__/src/rules/has-accessibility-hint.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// -----------------------------------------------------------------------------
1010

1111
import { RuleTester } from 'eslint';
12-
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
12+
import languageOptionsMapper from '../../__util__/languageOptionsMapper';
1313
import rule from '../../../src/rules/has-accessibility-hint';
1414

1515
// -----------------------------------------------------------------------------
@@ -39,13 +39,13 @@ ruleTester.run('has-accessibility-hint', rule, {
3939
accessibilityHint="Navigates to the previous screen"
4040
/>`,
4141
},
42-
].map(parserOptionsMapper),
42+
].map(languageOptionsMapper),
4343
invalid: [
4444
{
4545
code: `<TouchableOpacity
4646
accessibilityLabel="Go back"
4747
/>`,
4848
errors: [expectedError],
4949
},
50-
].map(parserOptionsMapper),
50+
].map(languageOptionsMapper),
5151
});

__tests__/src/rules/has-accessibility-props.test.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// -----------------------------------------------------------------------------
1010

1111
import { RuleTester } from 'eslint';
12-
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
12+
import languageOptionsMapper from '../../__util__/languageOptionsMapper';
1313
import rule from '../../../src/rules/has-accessibility-props';
1414

1515
// -----------------------------------------------------------------------------
@@ -18,7 +18,7 @@ import rule from '../../../src/rules/has-accessibility-props';
1818

1919
const ruleTester = new RuleTester();
2020

21-
const expectedError = (touchable) => ({
21+
const expectedError = (touchable: string) => ({
2222
message: `<${touchable}> must only have either the accessibilityRole prop or both accessibilityTraits and accessibilityComponentType props set`,
2323
type: 'JSXOpeningElement',
2424
});
@@ -67,9 +67,6 @@ ruleTester.run('has-accessibility-props', rule, {
6767
{
6868
code: '<TouchableWithoutFeedback />;',
6969
},
70-
{
71-
code: '<TouchableNativeFeedback />;',
72-
},
7370
{
7471
code: '<div><TouchableOpacity /></div>;',
7572
},
@@ -92,7 +89,7 @@ ruleTester.run('has-accessibility-props', rule, {
9289
},
9390
],
9491
},
95-
].map(parserOptionsMapper),
92+
].map(languageOptionsMapper),
9693
invalid: [
9794
{
9895
code: '<TouchableOpacity accessibilityTraits="none"/>;',
@@ -106,14 +103,6 @@ ruleTester.run('has-accessibility-props', rule, {
106103
code: '<TouchableHighlight accessibilityComponentType="none"/>;',
107104
errors: [expectedError('TouchableHighlight')],
108105
},
109-
{
110-
code: '<TouchableHighlight accessibilityComponentType="none"/>;',
111-
errors: [expectedError('TouchableHighlight')],
112-
},
113-
{
114-
code: '<TouchableWithoutFeedback accessibilityComponentType="none"/>;',
115-
errors: [expectedError('TouchableWithoutFeedback')],
116-
},
117106
{
118107
code: '<TouchableWithoutFeedback accessibilityComponentType="none"/>;',
119108
errors: [expectedError('TouchableWithoutFeedback')],
@@ -122,10 +111,6 @@ ruleTester.run('has-accessibility-props', rule, {
122111
code: '<TouchableNativeFeedback accessibilityComponentType="none"/>;',
123112
errors: [expectedError('TouchableNativeFeedback')],
124113
},
125-
{
126-
code: '<TouchableNativeFeedback accessibilityComponentType="none"/>;',
127-
errors: [expectedError('TouchableNativeFeedback')],
128-
},
129114
{
130115
code: '<TouchableOpacity accessibilityRole="none" accessibilityComponentType="none" />;',
131116
errors: [expectedError('TouchableOpacity')],
@@ -138,5 +123,5 @@ ruleTester.run('has-accessibility-props', rule, {
138123
code: '<TouchableOpacity accessibilityRole="none" accessibilityComponentType="none" accessibilityTraits="none" />;',
139124
errors: [expectedError('TouchableOpacity')],
140125
},
141-
].map(parserOptionsMapper),
126+
].map(languageOptionsMapper),
142127
});

__tests__/src/rules/has-valid-accessibility-actions.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// -----------------------------------------------------------------------------
1010

1111
import { RuleTester } from 'eslint';
12-
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
12+
import languageOptionsMapper from '../../__util__/languageOptionsMapper';
1313
import rule from '../../../src/rules/has-valid-accessibility-actions';
1414

1515
// -----------------------------------------------------------------------------
@@ -86,7 +86,7 @@ ruleTester.run('has-valid-accessibility-actions', rule, {
8686
onAccessibilityAction={this.props.onAccessibilityAction}
8787
/>`,
8888
},
89-
].map(parserOptionsMapper),
89+
].map(languageOptionsMapper),
9090
invalid: [
9191
{
9292
code: `<View
@@ -220,5 +220,5 @@ ruleTester.run('has-valid-accessibility-actions', rule, {
220220
},
221221
],
222222
},
223-
].map(parserOptionsMapper),
223+
].map(languageOptionsMapper),
224224
});

0 commit comments

Comments
 (0)