Skip to content

Commit 25b79f1

Browse files
committed
add e2e tests
1 parent 1521e1a commit 25b79f1

File tree

11 files changed

+1696
-5
lines changed

11 files changed

+1696
-5
lines changed

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,39 @@ 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+
pnpm eslint index.jsx
43+
output="tate" # $(pnpm eslint index.jsx)
44+
echo "$output"
45+
46+
expected="Class component should be written as a function react-prefer-function-component/react-prefer-function-component"
47+
if [[ "$output" != *"$expected"* ]]; then
48+
echo "❌ Fail"
49+
else
50+
echo "✅ Pass"
51+
fi
52+
e2e-flat-config:
53+
name: E2E Flat Config
54+
runs-on: ubuntu-latest
55+
steps:
56+
- uses: tatethurston/github-actions/build@main
57+
- name: pnpm eslint
58+
run: |
59+
cd packages/flat-config
60+
output="tate" #$(pnpm eslint index.jsx)
61+
echo "$output"
62+
63+
expected="Class component should be written as a function react-prefer-function-component/react-prefer-function-component"
64+
if [[ "$output" != *"$expected"* ]]; then
65+
echo "❌ Fail"
66+
# exit 1
67+
else
68+
echo "✅ Pass"
69+
fi

jest.config.cjs

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

jest.config.mjs

Lines changed: 15 additions & 0 deletions
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+
};
Lines changed: 17 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 17 additions & 0 deletions
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+
}
Lines changed: 11 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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)