Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial typescript config and use it for eslint,vitest,playwright #31186

Merged
merged 24 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
055e590
Add initial typescript config for eslint
silverwind May 30, 2024
8b33534
move vitest config to typescript
silverwind May 30, 2024
cea7be7
add lint-typescript
silverwind May 30, 2024
09e2dac
move tsc to lint-js
silverwind May 30, 2024
108f5fa
move playwright to typescript
silverwind May 31, 2024
bf9d3b4
move to bottom
silverwind May 31, 2024
e55a5cc
fix playwright
silverwind May 31, 2024
c1bae71
don't exclude node_modules as typscript apparently may need it for ty…
silverwind Jun 2, 2024
d0020df
Merge branch 'main' into tsconfig
silverwind Jun 2, 2024
1794b8e
Merge branch 'main' into tsconfig
silverwind Jun 3, 2024
576e78f
Merge branch 'main' into tsconfig
silverwind Jun 4, 2024
0d40c0b
Merge branch 'main' into tsconfig
silverwind Jun 17, 2024
22ee0ab
update @typescript-eslint/parser
silverwind Jun 17, 2024
5d14bfa
remove unnecessary exclude
silverwind Jun 17, 2024
de4c6a9
set target to same version as webpack
silverwind Jun 18, 2024
8b429c1
use node 16 identifier
silverwind Jun 18, 2024
afa931e
Merge remote-tracking branch 'origin/main' into tsconfig
silverwind Jun 21, 2024
1f5a379
remove unnecessary moduleDetection
silverwind Jun 21, 2024
5e71fa1
use longhand array syntax
silverwind Jun 21, 2024
c8affb2
Merge branch 'main' into tsconfig
silverwind Jun 26, 2024
35824ea
use type import for playwright config
silverwind Jun 26, 2024
b89a6a3
upgrade to typescript 5.5
silverwind Jun 26, 2024
1a81590
remove unnecessary @ts-check
silverwind Jun 28, 2024
1d5577d
Merge branch 'main' into tsconfig
GiteaBot Jun 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@ ignorePatterns:
- /web_src/fomantic
- /public/assets/js

parser: "@typescript-eslint/parser"

parserOptions:
sourceType: module
ecmaVersion: latest
project: true
extraFileExtensions: [".vue"]

settings:
import/extensions: [".js", ".ts"]
import/parsers:
"@typescript-eslint/parser": [".js", ".ts"]
import/resolver:
typescript: true

plugins:
- "@eslint-community/eslint-plugin-eslint-comments"
Expand Down Expand Up @@ -103,6 +114,21 @@ overrides:
- files: ["web_src/js/modules/fetch.js", "web_src/js/standalone/**/*"]
rules:
no-restricted-syntax: [2, WithStatement, ForInStatement, LabeledStatement, SequenceExpression]
- files: ["**/*.vue"]
plugins:
- eslint-plugin-vue
- eslint-plugin-vue-scoped-css
extends:
- plugin:vue/vue3-recommended
- plugin:vue-scoped-css/vue3-recommended
rules:
vue/attributes-order: [0]
vue/html-closing-bracket-spacing: [2, {startTag: never, endTag: never, selfClosingTag: never}]
vue/max-attributes-per-line: [0]
vue/singleline-html-element-content-newline: [0]
- files: ["tests/e2e/**"]
plugins: [eslint-plugin-playwright]
extends: plugin:playwright/recommended

rules:
"@eslint-community/eslint-comments/disable-enable-pair": [2]
Expand Down Expand Up @@ -264,7 +290,7 @@ rules:
i/no-internal-modules: [0]
i/no-mutable-exports: [0]
i/no-named-as-default-member: [0]
i/no-named-as-default: [2]
i/no-named-as-default: [0]
i/no-named-default: [0]
i/no-named-export: [0]
i/no-namespace: [0]
Expand All @@ -274,7 +300,7 @@ rules:
i/no-restricted-paths: [0]
i/no-self-import: [2]
i/no-unassigned-import: [0]
i/no-unresolved: [2, {commonjs: true, ignore: ["\\?.+$", ^vitest/]}]
i/no-unresolved: [2, {commonjs: true, ignore: ["\\?.+$"]}]
i/no-unused-modules: [2, {unusedExports: true}]
i/no-useless-path-segments: [2, {commonjs: true}]
i/no-webpack-loader-syntax: [2]
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,13 @@ lint-backend-fix: lint-go-fix lint-go-vet lint-editorconfig

.PHONY: lint-js
lint-js: node_modules
npx eslint --color --max-warnings=0 --ext js,vue $(ESLINT_FILES)
npx eslint --color --max-warnings=0 --ext js,ts,vue $(ESLINT_FILES)
npx tsc

.PHONY: lint-js-fix
lint-js-fix: node_modules
npx eslint --color --max-warnings=0 --ext js,vue $(ESLINT_FILES) --fix
npx eslint --color --max-warnings=0 --ext js,ts,vue $(ESLINT_FILES) --fix
npx tsc

.PHONY: lint-css
lint-css: node_modules
Expand Down
155 changes: 147 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,17 @@
"@stoplight/spectral-cli": "6.11.1",
"@stylistic/eslint-plugin-js": "2.1.0",
"@stylistic/stylelint-plugin": "2.1.2",
"@typescript-eslint/parser": "7.11.0",
"@vitejs/plugin-vue": "5.0.4",
"eslint": "8.57.0",
"eslint-import-resolver-typescript": "3.6.1",
"eslint-plugin-array-func": "4.0.0",
"eslint-plugin-github": "5.0.0-2",
"eslint-plugin-i": "2.29.1",
"eslint-plugin-jquery": "1.5.1",
"eslint-plugin-no-jquery": "2.7.0",
"eslint-plugin-no-use-extend-native": "0.5.0",
"eslint-plugin-playwright": "1.6.2",
"eslint-plugin-regexp": "2.6.0",
"eslint-plugin-sonarjs": "1.0.3",
"eslint-plugin-unicorn": "53.0.0",
Expand All @@ -91,6 +94,7 @@
"stylelint-declaration-strict-value": "1.10.4",
"stylelint-value-no-unknown-custom-properties": "6.0.1",
"svgo": "3.3.2",
"typescript": "5.4.5",
"updates": "16.1.1",
"vite-string-plugin": "1.3.1",
"vitest": "1.6.0"
Expand Down
16 changes: 6 additions & 10 deletions playwright.config.js → playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
// @ts-check
import {devices} from '@playwright/test';
import {env} from 'node:process';

const BASE_URL = process.env.GITEA_URL?.replace?.(/\/$/g, '') || 'http://localhost:3000';
const BASE_URL = env.GITEA_URL?.replace?.(/\/$/g, '') || 'http://localhost:3000';

/**
* @see https://playwright.dev/docs/test-configuration
* @type {import('@playwright/test').PlaywrightTestConfig}
*/
export default {
testDir: './tests/e2e/',
testMatch: /.*\.test\.e2e\.js/, // Match any .test.e2e.js files
testMatch: /.*\.test\.e2e\.ts/, // Match any .test.e2e.ts files

/* Maximum time one test can run for. */
timeout: 30 * 1000,
Expand All @@ -24,13 +20,13 @@ export default {
},

/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: Boolean(process.env.CI),
forbidOnly: Boolean(env.CI),

/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
retries: env.CI ? 2 : 0,

/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: process.env.CI ? 'list' : [['list'], ['html', {outputFolder: 'tests/e2e/reports/', open: 'never'}]],
reporter: env.CI ? 'list' : [['list'], ['html', {outputFolder: 'tests/e2e/reports/', open: 'never'}]],

/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ TEST_MSSQL_HOST=localhost:1433 TEST_MSSQL_DBNAME=gitea_test TEST_MSSQL_USERNAME=

## Running individual tests

Example command to run `example.test.e2e.js` test file:
Example command to run `example.test.e2e.ts` test file:

_Note: unlike integration tests, this filtering is at the file level, not function_

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ func TestMain(m *testing.M) {
os.Exit(exitVal)
}

// TestE2e should be the only test e2e necessary. It will collect all "*.test.e2e.js" files in this directory and build a test for each.
// TestE2e should be the only test e2e necessary. It will collect all "*.test.e2e.ts" files in this directory and build a test for each.
func TestE2e(t *testing.T) {
// Find the paths of all e2e test files in test directory.
searchGlob := filepath.Join(filepath.Dir(setting.AppPath), "tests", "e2e", "*.test.e2e.js")
searchGlob := filepath.Join(filepath.Dir(setting.AppPath), "tests", "e2e", "*.test.e2e.ts")
paths, err := filepath.Glob(searchGlob)
if err != nil {
t.Fatal(err)
Expand Down
Loading