This is an automated email from the ASF dual-hosted git repository.
young pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new 665ad24cc fix: e2e related tsconfig and eslint config (#3057)
665ad24cc is described below
commit 665ad24cc0504cce71eeb6b45aecc1d5d168a407
Author: YYYoung <[email protected]>
AuthorDate: Thu May 15 11:44:12 2025 +0800
fix: e2e related tsconfig and eslint config (#3057)
---
e2e/{ => tests}/auth.spec.ts | 5 +-
tsconfig.e2e.json => e2e/tsconfig.json | 10 +-
e2e/utils/req.ts | 75 ++++++++++++
e2e/utils/test.ts | 9 +-
eslint.config.ts | 214 ++++++++++++++++-----------------
playwright.config.ts | 1 -
tsconfig.json | 3 -
7 files changed, 192 insertions(+), 125 deletions(-)
diff --git a/e2e/auth.spec.ts b/e2e/tests/auth.spec.ts
similarity index 96%
rename from e2e/auth.spec.ts
rename to e2e/tests/auth.spec.ts
index 58cd14e4c..80c9e7e68 100644
--- a/e2e/auth.spec.ts
+++ b/e2e/tests/auth.spec.ts
@@ -15,10 +15,9 @@
* limitations under the License.
*/
+import { getAPISIXConf } from '@e2e/utils/common';
+import { test } from '@e2e/utils/test';
import { expect } from '@playwright/test';
-import { test } from '@utils/test';
-
-import { getAPISIXConf } from './utils/common';
// use empty storage state to avoid auth
test.use({ storageState: { cookies: [], origins: [] } });
diff --git a/tsconfig.e2e.json b/e2e/tsconfig.json
similarity index 77%
rename from tsconfig.e2e.json
rename to e2e/tsconfig.json
index beb40ddac..23ecbf242 100644
--- a/tsconfig.e2e.json
+++ b/e2e/tsconfig.json
@@ -15,13 +15,17 @@
"esModuleInterop": true,
"skipLibCheck": true,
"noImplicitAny": false,
+ "verbatimModuleSyntax": true,
"paths": {
- "@utils/*": [
- "./e2e/utils/*"
+ "@e2e/*": [
+ "./*"
+ ],
+ "@/*": [
+ "../src/*"
]
}
},
"include": [
- "e2e/**/*.ts",
+ "./**/*.ts",
]
}
diff --git a/e2e/utils/req.ts b/e2e/utils/req.ts
new file mode 100644
index 000000000..969cb477e
--- /dev/null
+++ b/e2e/utils/req.ts
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import { type APIRequestContext, request } from '@playwright/test';
+import axios, { type AxiosAdapter } from 'axios';
+import { stringify } from 'qs';
+
+import { API_HEADER_KEY, API_PREFIX, BASE_PATH } from '@/config/constant';
+
+import { getAPISIXConf } from './common';
+import { env } from './env';
+
+export const getPlaywrightRequestAdapter = (
+ ctx: APIRequestContext
+): AxiosAdapter => {
+ return async (config) => {
+ const { url, data, baseURL } = config;
+ if (typeof url === 'undefined') {
+ throw new Error('Need to provide a url');
+ }
+
+ type Payload = Parameters<APIRequestContext['fetch']>[1];
+ const payload: Payload = {
+ headers: config.headers,
+ method: config.method,
+ failOnStatusCode: true,
+ data,
+ };
+ const urlWithBase = `${baseURL}${url}`;
+ const res = await ctx.fetch(urlWithBase, payload);
+
+ try {
+ return {
+ ...res,
+ data: await res.json(),
+ config,
+ status: res.status(),
+ statusText: res.statusText(),
+ headers: res.headers(),
+ };
+ } finally {
+ await res.dispose();
+ }
+ };
+};
+
+export const getE2eReq = async (ctx: APIRequestContext) => {
+ const { adminKey } = await getAPISIXConf();
+ const API_URL = env.E2E_TARGET_URL.slice(0, -BASE_PATH.length - 1);
+
+ return axios.create({
+ adapter: getPlaywrightRequestAdapter(ctx),
+ baseURL: `${API_URL}${API_PREFIX}`,
+ paramsSerializer: (p) =>
+ stringify(p, {
+ arrayFormat: 'repeat',
+ }),
+ headers: { [API_HEADER_KEY]: adminKey },
+ });
+};
+
+export const e2eReq = await getE2eReq(await request.newContext());
diff --git a/e2e/utils/test.ts b/e2e/utils/test.ts
index 9f0ef0bce..b6ddd2e7c 100644
--- a/e2e/utils/test.ts
+++ b/e2e/utils/test.ts
@@ -14,13 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+import { existsSync } from 'node:fs';
+import path from 'node:path';
+
import { test as baseTest } from '@playwright/test';
+
import { getAPISIXConf } from './common';
-import path from 'node:path';
-import { existsSync } from 'node:fs';
import { env } from './env';
-export const test = baseTest.extend<{}, { workerStorageState: string }>({
+export const test = baseTest.extend<object, { workerStorageState: string }>({
storageState: ({ workerStorageState }, use) => use(workerStorageState),
workerStorageState: [
async ({ browser }, use) => {
@@ -54,7 +56,6 @@ export const test = baseTest.extend<{}, { workerStorageState:
string }>({
.click();
await page.reload();
- await page.waitForLoadState('networkidle');
}
await page.context().storageState({ path: fileName });
diff --git a/eslint.config.ts b/eslint.config.ts
index a48be4912..a65cb2d9b 100644
--- a/eslint.config.ts
+++ b/eslint.config.ts
@@ -32,18 +32,20 @@ const importRules = tseslint.config({
plugins: {
'unused-imports': unusedImports,
'simple-import-sort': simpleImportSort,
- 'import': importPlugin,
+ import: importPlugin,
},
rules: {
+ ...importPlugin.flatConfigs?.recommended.rules,
+ ...importPlugin.flatConfigs?.typescript.rules,
'no-unused-vars': 'off',
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
'warn',
{
- 'vars': 'all',
- 'varsIgnorePattern': '^_',
- 'args': 'after-used',
- 'argsIgnorePattern': '^_',
+ vars: 'all',
+ varsIgnorePattern: '^_',
+ args: 'after-used',
+ argsIgnorePattern: '^_',
},
],
'simple-import-sort/imports': 'error',
@@ -53,18 +55,48 @@ const importRules = tseslint.config({
'import/no-duplicates': 'error',
'import/no-unresolved': 'off',
'import/no-named-as-default-member': 'off',
- }
-})
+ },
+});
-const e2eRules = tseslint.config({
- extends: [importRules],
- ...playwright.configs['flat/recommended'],
- files: ['e2e/**/*.spec.ts'],
+const commonRules = tseslint.config({
+ extends: [
+ js.configs.recommended,
+ ...tseslint.configs.recommended,
+ importRules,
+ ],
+ plugins: {
+ headers: headers,
+ },
rules: {
- ...playwright.configs['flat/recommended'].rules,
+ 'headers/header-format': [
+ 'error',
+ {
+ source: 'file',
+ path: '.actions/ASFLicenseHeader.txt',
+ },
+ ],
+ quotes: [
+ 'error',
+ 'single',
+ {
+ avoidEscape: true,
+ allowTemplateLiterals: false,
+ },
+ ],
},
});
+const e2eRules = tseslint.config(
+ {
+ extends: [commonRules],
+ files: ['e2e/**/*.ts'],
+ },
+ {
+ files: ['e2e/**/*.spec.ts'],
+ ...playwright.configs['flat/recommended'],
+ }
+);
+
const i18nRules = tseslint.config({
files: ['src/**/*.{ts,tsx,js}'],
plugins: {
@@ -74,10 +106,7 @@ const i18nRules = tseslint.config({
rules: {
...i18next.configs['flat/recommended'].rules,
'i18n/no-unknown-key': 'error',
- 'i18n/no-text-as-children': [
- 'error',
- { ignorePattern: '^\\s?[/.]\\s?$' },
- ],
+ 'i18n/no-text-as-children': ['error', { ignorePattern: '^\\s?[/.]\\s?$' }],
'i18n/no-text-as-attribute': ['error', { attributes: ['alt', 'title'] }],
'i18n/interpolation-data': [
'error',
@@ -95,104 +124,67 @@ const i18nRules = tseslint.config({
functionName: 't',
},
},
-})
+});
+
+const srcRules = tseslint.config({
+ extends: [commonRules],
+ files: ['src/**/*.{ts,tsx}', 'eslint.config.ts'],
+ languageOptions: {
+ ecmaVersion: 2020,
+ globals: globals.browser,
+ sourceType: 'module',
+ },
+ plugins: {
+ 'react-hooks': reactHooks,
+ 'react-refresh': reactRefresh,
+ react: react,
+ },
+ settings: {
+ react: {
+ version: 'detect',
+ },
+ },
+ rules: {
+ ...react.configs.flat.recommended.rules,
+ ...react.configs.flat['jsx-runtime'].rules,
+ ...reactHooks.configs.recommended.rules,
+ 'no-console': 'warn',
+ 'react-refresh/only-export-components': [
+ 'warn',
+ { allowConstantExport: true },
+ ],
+ 'react/jsx-curly-brace-presence': [
+ 'error',
+ {
+ props: 'never',
+ children: 'never',
+ },
+ ],
+ 'react/no-unescaped-entities': [
+ 'error',
+ {
+ forbid: ['>', '}'],
+ },
+ ],
+ 'react/no-children-prop': [
+ 'error',
+ {
+ allowFunctions: true,
+ },
+ ],
+ 'react/self-closing-comp': [
+ 'error',
+ {
+ component: true,
+ html: true,
+ },
+ ],
+ },
+});
export default tseslint.config(
{ ignores: ['dist', 'src/routeTree.gen.ts'] },
e2eRules,
i18nRules,
- {
- extends: [js.configs.recommended, ...tseslint.configs.recommended,
importRules],
- files: ['src/**/*.{ts,tsx}', 'eslint.config.ts'],
- languageOptions: {
- ecmaVersion: 2020,
- globals: globals.browser,
- sourceType: 'module',
- },
- plugins: {
- 'react-hooks': reactHooks,
- 'react-refresh': reactRefresh,
- react: react,
- 'unused-imports': unusedImports,
- 'simple-import-sort': simpleImportSort,
- import: importPlugin,
- headers: headers,
- },
- settings: {
- react: {
- version: 'detect',
- },
- },
- rules: {
- ...react.configs.flat.recommended.rules,
- ...react.configs.flat['jsx-runtime'].rules,
- ...reactHooks.configs.recommended.rules,
- ...importPlugin.flatConfigs?.recommended.rules,
- ...importPlugin.flatConfigs?.typescript.rules,
- 'no-console': 'warn',
- 'no-unused-vars': 'off',
- 'unused-imports/no-unused-imports': 'error',
- 'unused-imports/no-unused-vars': [
- 'warn',
- {
- vars: 'all',
- varsIgnorePattern: '^_',
- args: 'after-used',
- argsIgnorePattern: '^_',
- },
- ],
- 'simple-import-sort/imports': 'error',
- 'simple-import-sort/exports': 'error',
- 'import/first': 'error',
- 'import/newline-after-import': 'error',
- 'import/no-duplicates': 'error',
- 'import/no-unresolved': 'off',
- 'import/no-named-as-default-member': 'off',
- 'react-refresh/only-export-components': [
- 'warn',
- { allowConstantExport: true },
- ],
- 'react/jsx-curly-brace-presence': [
- 'error',
- {
- props: 'never',
- children: 'never',
- },
- ],
- 'react/no-unescaped-entities': [
- 'error',
- {
- forbid: ['>', '}'],
- },
- ],
- 'react/no-children-prop': [
- 'error',
- {
- allowFunctions: true,
- },
- ],
- 'react/self-closing-comp': [
- 'error',
- {
- component: true,
- html: true,
- },
- ],
- 'headers/header-format': [
- 'error',
- {
- source: 'file',
- path: '.actions/ASFLicenseHeader.txt',
- },
- ],
- 'quotes': [
- 'error',
- 'single',
- {
- 'avoidEscape': true,
- 'allowTemplateLiterals': false
- }
- ],
- },
- }
+ srcRules
);
diff --git a/playwright.config.ts b/playwright.config.ts
index f517f239b..37c06212c 100644
--- a/playwright.config.ts
+++ b/playwright.config.ts
@@ -22,7 +22,6 @@ import { env } from './e2e/utils/env';
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
- tsconfig: './tsconfig.e2e.json',
testDir: './e2e',
outputDir: './test-results',
fullyParallel: true,
diff --git a/tsconfig.json b/tsconfig.json
index 7827100ee..10b4ebd5e 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -4,9 +4,6 @@
{ "path": "./tsconfig.app.json" },
{
"path": "./tsconfig.node.json"
- },
- {
- "path": "./tsconfig.e2e.json"
}
]
}