Skip to content

Commit e65ce41

Browse files
authored
add e2e tests (#25)
1 parent 1521e1a commit e65ce41

File tree

11 files changed

+1695
-5
lines changed

11 files changed

+1695
-5
lines changed

.github/workflows/ci.yml

+35
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,38 @@ jobs:
3131
with:
3232
fail_ci_if_error: true
3333
token: ${{ secrets.CODECOV_TOKEN }}
34+
e2e-legacy-config:
35+
name: E2E Legacy Config
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: tatethurston/github-actions/build@main
39+
- name: pnpm eslint
40+
run: |
41+
cd packages/legacy-config
42+
output=$(pnpm eslint index.jsx || true)
43+
echo "$output"
44+
45+
expected="Class component should be written as a function react-prefer-function-component/react-prefer-function-component"
46+
if [[ "$output" != *"$expected"* ]]; then
47+
echo "❌ Fail"
48+
else
49+
echo "✅ Pass"
50+
fi
51+
e2e-flat-config:
52+
name: E2E Flat Config
53+
runs-on: ubuntu-latest
54+
steps:
55+
- uses: tatethurston/github-actions/build@main
56+
- name: pnpm eslint
57+
run: |
58+
cd packages/flat-config
59+
output=$(pnpm eslint index.jsx || true)
60+
echo "$output"
61+
62+
expected="Class component should be written as a function react-prefer-function-component/react-prefer-function-component"
63+
if [[ "$output" != *"$expected"* ]]; then
64+
echo "❌ Fail"
65+
# exit 1
66+
else
67+
echo "✅ Pass"
68+
fi

jest.config.cjs

-5
This file was deleted.

jest.config.mjs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/** @type {import('jest').Config} */
2+
export default {
3+
clearMocks: true,
4+
coverageDirectory: "coverage",
5+
testEnvironment: "node",
6+
// TS ESM imports are referenced with .js extensions, but jest will fail to find
7+
// the uncompiled file because it ends with .ts and is looking for .js.
8+
moduleNameMapper: {
9+
"(.+)\\.jsx?": "$1",
10+
"(.+)\\.mjs": "$1.mts",
11+
},
12+
transform: {
13+
"^.+\\.(ts|tsx|js|jsx|mjs|mts)$": "babel-jest",
14+
},
15+
};

packages/flat-config/eslint.config.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import preferFunctionComponent from "eslint-plugin-react-prefer-function-component/config";
2+
3+
export default [
4+
{
5+
files: ["*.jsx"],
6+
languageOptions: {
7+
parserOptions: {
8+
ecmaVersion: "latest",
9+
sourceType: "module",
10+
ecmaFeatures: {
11+
jsx: true,
12+
},
13+
},
14+
},
15+
},
16+
preferFunctionComponent.configs.recommended,
17+
];

packages/flat-config/index.jsx

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Component } from "react";
2+
3+
export class Foo extends Component {
4+
render() {
5+
return <div>{this.props.foo}</div>;
6+
}
7+
}

packages/flat-config/package.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "flat-config",
3+
"type": "module",
4+
"version": "1.0.0",
5+
"description": "",
6+
"main": "index.js",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"devDependencies": {
14+
"eslint": "^9.22.0",
15+
"eslint-plugin-react-prefer-function-component": "workspace:^"
16+
}
17+
}

packages/legacy-config/.eslintrc.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// eslint-disable-next-line no-undef
2+
module.exports = {
3+
parserOptions: {
4+
ecmaVersion: "latest",
5+
sourceType: "module",
6+
ecmaFeatures: {
7+
jsx: true,
8+
},
9+
},
10+
extends: ["plugin:react-prefer-function-component/recommended"],
11+
};

packages/legacy-config/index.jsx

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Component } from "react";
2+
3+
export class Foo extends Component {
4+
render() {
5+
return <div>{this.props.foo}</div>;
6+
}
7+
}

0 commit comments

Comments
 (0)