diff --git a/.github/actions/catch-install-pnpm/action.yml b/.github/actions/catch-install-pnpm/action.yml index 28115c5ed..38efe0144 100644 --- a/.github/actions/catch-install-pnpm/action.yml +++ b/.github/actions/catch-install-pnpm/action.yml @@ -16,4 +16,4 @@ runs: - name: Install dependencies shell: bash - run: pnpm install + run: pnpm install --frozen-lockfile diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b1559d986..188b669b6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,6 +10,9 @@ on: jobs: checker: runs-on: ubuntu-latest + env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} if: ${{ !contains(github.event.pull_request.title, '[skip checker]') }} steps: - name: Checkout repository @@ -18,15 +21,22 @@ jobs: - name: Install dependencies uses: ./.github/actions/catch-install-pnpm + - name: Build dms-kit (required for checker) + run: pnpm turbo run build --filter=@actiontech/dms-kit + - name: Code lint checker - run: pnpm checker + run: pnpm run checker test-ee: runs-on: ubuntu-latest + env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} + JEST_TEST_VERSION_ENV: ee if: ${{ !contains(github.event.pull_request.title, '[skip checker]') }} strategy: matrix: - shard: [1, 2, 3, 4] + package: [base, '@actiontech/dms-kit', '@actiontech/shared', sqle] steps: - name: Checkout repository uses: actions/checkout@v4 @@ -34,17 +44,71 @@ jobs: - name: Install dependencies uses: ./.github/actions/catch-install-pnpm - - name: Coverage test report ee - run: sh ./scripts/jest/run-ci-ee.sh ${{ matrix.shard }} ${{ strategy.job-total }} + - name: Build dms-kit (required for tests) + run: pnpm turbo run build --filter=@actiontech/dms-kit + + - name: Coverage test report ee - ${{ matrix.package }} + run: pnpm turbo run test:coverage:ci --filter=${{ matrix.package }} + + - name: Collect coverage artifacts + if: always() + run: | + mkdir -p coverage-artifacts + # Map package names to directory names + PACKAGE_DIR="" + case "${{ matrix.package }}" in + "base") + PACKAGE_DIR="base" + ;; + "@actiontech/dms-kit") + PACKAGE_DIR="dms-kit" + ;; + "@actiontech/shared") + PACKAGE_DIR="shared" + ;; + "sqle") + PACKAGE_DIR="sqle" + ;; + esac + # Copy coverage files from package directory or root coverage directory + if [ -n "$PACKAGE_DIR" ] && [ -d "packages/$PACKAGE_DIR/coverage" ]; then + cp -r packages/$PACKAGE_DIR/coverage/* coverage-artifacts/ 2>/dev/null || true + fi + if [ -d "coverage" ]; then + find coverage -maxdepth 1 -type f -name "*.json" -exec cp {} coverage-artifacts/ \; 2>/dev/null || true + fi + # Rename files to include package name (sanitize for filename) + PACKAGE_NAME_SANITIZED=$(echo "${{ matrix.package }}" | tr '/' '-' | tr '@' '') + if [ -f "coverage-artifacts/report.json" ]; then + mv coverage-artifacts/report.json coverage-artifacts/report-${PACKAGE_NAME_SANITIZED}-ee.json + fi + if [ -f "coverage-artifacts/coverage-final.json" ]; then + mv coverage-artifacts/coverage-final.json coverage-artifacts/coverage-final-${PACKAGE_NAME_SANITIZED}-ee.json + fi + + - name: Set artifact name + if: always() + id: set-artifact-name + run: | + PACKAGE_NAME_SANITIZED=$(echo "${{ matrix.package }}" | tr '/' '-' | tr '@' '') + echo "name=coverage-artifacts-${PACKAGE_NAME_SANITIZED}-ee" >> $GITHUB_OUTPUT - uses: actions/upload-artifact@v4 + if: always() with: - name: coverage-artifacts-${{ matrix.shard }} - path: coverage/ + name: ${{ steps.set-artifact-name.outputs.name }} + path: coverage-artifacts/ test-ce: runs-on: ubuntu-latest + env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} + JEST_TEST_VERSION_ENV: ce if: ${{ !contains(github.event.pull_request.title, '[skip checker]') }} + strategy: + matrix: + package: [base, '@actiontech/dms-kit', '@actiontech/shared', sqle] steps: - name: Checkout repository uses: actions/checkout@v4 @@ -52,51 +116,81 @@ jobs: - name: Install dependencies uses: ./.github/actions/catch-install-pnpm - - name: Coverage test report ce - run: sh ./scripts/jest/run-ci-ce.sh + - name: Build dms-kit (required for tests) + run: pnpm turbo run build --filter=@actiontech/dms-kit + + - name: Coverage test report ce - ${{ matrix.package }} + run: pnpm turbo run test:coverage:ci --filter=${{ matrix.package }} + + - name: Collect coverage artifacts + if: always() + run: | + mkdir -p coverage-artifacts + # Map package names to directory names + PACKAGE_DIR="" + case "${{ matrix.package }}" in + "base") + PACKAGE_DIR="base" + ;; + "@actiontech/dms-kit") + PACKAGE_DIR="dms-kit" + ;; + "@actiontech/shared") + PACKAGE_DIR="shared" + ;; + "sqle") + PACKAGE_DIR="sqle" + ;; + esac + # Copy coverage files from package directory or root coverage directory + if [ -n "$PACKAGE_DIR" ] && [ -d "packages/$PACKAGE_DIR/coverage" ]; then + cp -r packages/$PACKAGE_DIR/coverage/* coverage-artifacts/ 2>/dev/null || true + fi + if [ -d "coverage" ]; then + find coverage -maxdepth 1 -type f -name "*.json" -exec cp {} coverage-artifacts/ \; 2>/dev/null || true + fi + if [ -d "ce_coverage" ]; then + find ce_coverage -maxdepth 1 -type f -name "*.json" -exec cp {} coverage-artifacts/ \; 2>/dev/null || true + fi + # Rename files to include package name (sanitize for filename) + PACKAGE_NAME_SANITIZED=$(echo "${{ matrix.package }}" | tr '/' '-' | tr '@' '') + if [ -f "coverage-artifacts/report.json" ]; then + mv coverage-artifacts/report.json coverage-artifacts/report-${PACKAGE_NAME_SANITIZED}-ce.json + fi + if [ -f "coverage-artifacts/coverage-final.json" ]; then + mv coverage-artifacts/coverage-final.json coverage-artifacts/coverage-final-${PACKAGE_NAME_SANITIZED}-ce.json + fi + + - name: Set artifact name + if: always() + id: set-artifact-name + run: | + PACKAGE_NAME_SANITIZED=$(echo "${{ matrix.package }}" | tr '/' '-' | tr '@' '') + echo "name=coverage-artifacts-${PACKAGE_NAME_SANITIZED}-ce" >> $GITHUB_OUTPUT - uses: actions/upload-artifact@v4 + if: always() with: - name: ce-coverage-artifacts - path: ce_coverage/ + name: ${{ steps.set-artifact-name.outputs.name }} + path: coverage-artifacts/ report: runs-on: ubuntu-latest + env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} if: ${{ !contains(github.event.pull_request.title, '[skip checker]') }} needs: [test-ee, test-ce] steps: - name: Checkout repository uses: actions/checkout@v4 - - name: Get CE Coverage - uses: actions/download-artifact@v4 - with: - name: ce-coverage-artifacts - path: ce_coverage - - - name: Get EE Coverage 1 - uses: actions/download-artifact@v4 - with: - name: coverage-artifacts-1 - path: coverage - - - name: Get EE Coverage 2 - uses: actions/download-artifact@v4 - with: - name: coverage-artifacts-2 - path: coverage - - - name: Get EE Coverage 3 - uses: actions/download-artifact@v4 - with: - name: coverage-artifacts-3 - path: coverage - - - name: Get EE Coverage 4 + - name: Download all coverage artifacts uses: actions/download-artifact@v4 with: - name: coverage-artifacts-4 - path: coverage + pattern: coverage-artifacts-* + path: coverage-all + merge-multiple: false - name: Install dependencies uses: ./.github/actions/catch-install-pnpm @@ -111,12 +205,16 @@ jobs: base-coverage-file: coverage-merged.json coverage-file: coverage-merged.json - - name: Delete artifact + - name: Delete artifacts uses: geekyeggo/delete-artifact@v5 + continue-on-error: true with: name: | - ce-coverage-artifacts - coverage-artifacts-1 - coverage-artifacts-2 - coverage-artifacts-3 - coverage-artifacts-4 + coverage-artifacts-base-ce + coverage-artifacts-base-ee + coverage-artifacts-actiontech-dms-kit-ce + coverage-artifacts-actiontech-dms-kit-ee + coverage-artifacts-actiontech-shared-ce + coverage-artifacts-actiontech-shared-ee + coverage-artifacts-sqle-ce + coverage-artifacts-sqle-ee diff --git a/.gitignore b/.gitignore index 4dbb2d65d..f0242d3fc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ # dependencies /packages/*/node_modules -/scripts/**/node_modules +/cli/**/node_modules /node_modules /.pnpm-store /.pnp @@ -15,7 +15,7 @@ dist # testing /ce_coverage -/coverage +**/coverage/* /report.json /coverage-merged /coverage-merged.json @@ -53,4 +53,5 @@ verdaccio ftp-data -/scripts/cli/dms-kit-publish/docs \ No newline at end of file +/scripts/cli/dms-kit-publish/docs +.turbo \ No newline at end of file diff --git a/Makefile b/Makefile index 58996cf14..ee0b38459 100644 --- a/Makefile +++ b/Makefile @@ -38,13 +38,13 @@ docker_clean: $(DOCKER) run -v $(MAIN_MODULE):/usr/src/app -w /usr/src/app --rm $(DOCKER_IMAGE) sh -c "git config --global --add safe.directory /usr/src/app && git clean -dfx" docker_build_ce: pull_image docker_install_node_modules - $(DOCKER) run -v $(MAIN_MODULE):/usr/src/app --user $(UID):$(GID) -w /usr/src/app --rm $(DOCKER_IMAGE) sh -c "pnpm build" + $(DOCKER) run -v $(MAIN_MODULE):/usr/src/app --user $(UID):$(GID) -w /usr/src/app --rm $(DOCKER_IMAGE) sh -c "node scripts/getGitVersion.mjs ce && pnpm build" docker_build_ee: pull_image docker_install_node_modules - $(DOCKER) run -v $(MAIN_MODULE):/usr/src/app --user $(UID):$(GID) -w /usr/src/app --rm $(DOCKER_IMAGE) sh -c "pnpm build:ee" + $(DOCKER) run -v $(MAIN_MODULE):/usr/src/app --user $(UID):$(GID) -w /usr/src/app --rm $(DOCKER_IMAGE) sh -c "node scripts/getGitVersion.mjs ee && pnpm build:ee" docker_build_demo: pull_image docker_install_node_modules - $(DOCKER) run -v $(MAIN_MODULE):/usr/src/app --user $(UID):$(GID) -w /usr/src/app --rm $(DOCKER_IMAGE) sh -c "pnpm build:demo" + $(DOCKER) run -v $(MAIN_MODULE):/usr/src/app --user $(UID):$(GID) -w /usr/src/app --rm $(DOCKER_IMAGE) sh -c "node scripts/getGitVersion.mjs trial && pnpm build:demo" docker_dms_kit_publish: docker_install_node_modules $(DOCKER) run -v $(MAIN_MODULE):/usr/src/app --user $(UID):$(GID) -w /usr/src/app --rm \ diff --git a/scripts/cli/create-dms-page/README.md b/cli/create-dms-page/README.md similarity index 100% rename from scripts/cli/create-dms-page/README.md rename to cli/create-dms-page/README.md diff --git a/scripts/cli/create-dms-page/bin/core.js b/cli/create-dms-page/bin/core.js similarity index 100% rename from scripts/cli/create-dms-page/bin/core.js rename to cli/create-dms-page/bin/core.js diff --git a/cli/create-dms-page/eslint.config.mjs b/cli/create-dms-page/eslint.config.mjs new file mode 100644 index 000000000..221157cac --- /dev/null +++ b/cli/create-dms-page/eslint.config.mjs @@ -0,0 +1,10 @@ +import node from '@actiontech/dms-eslint-config/node'; + +/** @type {import("eslint").Linter.Config[]} */ +export default [ + ...node, + { + files: ['src/**/*.{ts}'] + // 可以在此处添加本包特有的覆盖规则 + } +]; diff --git a/scripts/cli/create-dms-page/package.json b/cli/create-dms-page/package.json similarity index 72% rename from scripts/cli/create-dms-page/package.json rename to cli/create-dms-page/package.json index f15923848..50513a934 100644 --- a/scripts/cli/create-dms-page/package.json +++ b/cli/create-dms-page/package.json @@ -10,13 +10,18 @@ ], "scripts": { "build:watch": "tsc -w", - "build": "tsc" + "build": "tsc", + "eslint": "eslint src", + "eslint:fix": "eslint src --fix", + "ts-check": "tsc --noEmit" }, "keywords": [], "license": "ISC", "devDependencies": { "@types/babel__generator": "^7.6.8", - "@types/babel__traverse": "^7.20.6" + "@types/babel__traverse": "^7.20.6", + "@actiontech/dms-eslint-config": "workspace:^", + "@actiontech/dms-typescript-config": "workspace:^" }, "dependencies": { "@babel/generator": "^7.25.0", diff --git a/scripts/cli/create-dms-page/src/common/Task.ts b/cli/create-dms-page/src/common/Task.ts similarity index 100% rename from scripts/cli/create-dms-page/src/common/Task.ts rename to cli/create-dms-page/src/common/Task.ts diff --git a/scripts/cli/create-dms-page/src/create-dms-page.ts b/cli/create-dms-page/src/create-dms-page.ts similarity index 100% rename from scripts/cli/create-dms-page/src/create-dms-page.ts rename to cli/create-dms-page/src/create-dms-page.ts diff --git a/scripts/cli/create-dms-page/src/index.ts b/cli/create-dms-page/src/index.ts similarity index 100% rename from scripts/cli/create-dms-page/src/index.ts rename to cli/create-dms-page/src/index.ts diff --git a/scripts/cli/create-dms-page/src/module/icon-manager/index.ts b/cli/create-dms-page/src/module/icon-manager/index.ts similarity index 100% rename from scripts/cli/create-dms-page/src/module/icon-manager/index.ts rename to cli/create-dms-page/src/module/icon-manager/index.ts diff --git a/scripts/cli/create-dms-page/src/module/icon-manager/interface.ts b/cli/create-dms-page/src/module/icon-manager/interface.ts similarity index 100% rename from scripts/cli/create-dms-page/src/module/icon-manager/interface.ts rename to cli/create-dms-page/src/module/icon-manager/interface.ts diff --git a/scripts/cli/create-dms-page/src/module/interface.ts b/cli/create-dms-page/src/module/interface.ts similarity index 100% rename from scripts/cli/create-dms-page/src/module/interface.ts rename to cli/create-dms-page/src/module/interface.ts diff --git a/scripts/cli/create-dms-page/src/module/locale-manager/index.ts b/cli/create-dms-page/src/module/locale-manager/index.ts similarity index 100% rename from scripts/cli/create-dms-page/src/module/locale-manager/index.ts rename to cli/create-dms-page/src/module/locale-manager/index.ts diff --git a/scripts/cli/create-dms-page/src/module/locale-manager/interface.ts b/cli/create-dms-page/src/module/locale-manager/interface.ts similarity index 100% rename from scripts/cli/create-dms-page/src/module/locale-manager/interface.ts rename to cli/create-dms-page/src/module/locale-manager/interface.ts diff --git a/scripts/cli/create-dms-page/src/module/menu-manager/index.ts b/cli/create-dms-page/src/module/menu-manager/index.ts similarity index 100% rename from scripts/cli/create-dms-page/src/module/menu-manager/index.ts rename to cli/create-dms-page/src/module/menu-manager/index.ts diff --git a/scripts/cli/create-dms-page/src/module/menu-manager/interface.ts b/cli/create-dms-page/src/module/menu-manager/interface.ts similarity index 100% rename from scripts/cli/create-dms-page/src/module/menu-manager/interface.ts rename to cli/create-dms-page/src/module/menu-manager/interface.ts diff --git a/scripts/cli/create-dms-page/src/module/module-orchestrator.ts b/cli/create-dms-page/src/module/module-orchestrator.ts similarity index 100% rename from scripts/cli/create-dms-page/src/module/module-orchestrator.ts rename to cli/create-dms-page/src/module/module-orchestrator.ts diff --git a/scripts/cli/create-dms-page/src/module/page-component-manager/index.ts b/cli/create-dms-page/src/module/page-component-manager/index.ts similarity index 100% rename from scripts/cli/create-dms-page/src/module/page-component-manager/index.ts rename to cli/create-dms-page/src/module/page-component-manager/index.ts diff --git a/scripts/cli/create-dms-page/src/module/page-component-manager/interface.ts b/cli/create-dms-page/src/module/page-component-manager/interface.ts similarity index 100% rename from scripts/cli/create-dms-page/src/module/page-component-manager/interface.ts rename to cli/create-dms-page/src/module/page-component-manager/interface.ts diff --git a/scripts/cli/create-dms-page/src/module/route-path-config-manager/index.ts b/cli/create-dms-page/src/module/route-path-config-manager/index.ts similarity index 100% rename from scripts/cli/create-dms-page/src/module/route-path-config-manager/index.ts rename to cli/create-dms-page/src/module/route-path-config-manager/index.ts diff --git a/scripts/cli/create-dms-page/src/module/route-path-config-manager/interface.ts b/cli/create-dms-page/src/module/route-path-config-manager/interface.ts similarity index 100% rename from scripts/cli/create-dms-page/src/module/route-path-config-manager/interface.ts rename to cli/create-dms-page/src/module/route-path-config-manager/interface.ts diff --git a/scripts/cli/create-dms-page/src/template/index.ts b/cli/create-dms-page/src/template/index.ts similarity index 100% rename from scripts/cli/create-dms-page/src/template/index.ts rename to cli/create-dms-page/src/template/index.ts diff --git a/scripts/cli/create-dms-page/src/types.d.ts b/cli/create-dms-page/src/types.d.ts similarity index 100% rename from scripts/cli/create-dms-page/src/types.d.ts rename to cli/create-dms-page/src/types.d.ts diff --git a/scripts/cli/create-dms-page/src/utils/babel-utils.ts b/cli/create-dms-page/src/utils/babel-utils.ts similarity index 100% rename from scripts/cli/create-dms-page/src/utils/babel-utils.ts rename to cli/create-dms-page/src/utils/babel-utils.ts diff --git a/scripts/cli/create-dms-page/src/utils/handle-error.ts b/cli/create-dms-page/src/utils/handle-error.ts similarity index 100% rename from scripts/cli/create-dms-page/src/utils/handle-error.ts rename to cli/create-dms-page/src/utils/handle-error.ts diff --git a/scripts/cli/create-dms-page/src/utils/logger.ts b/cli/create-dms-page/src/utils/logger.ts similarity index 100% rename from scripts/cli/create-dms-page/src/utils/logger.ts rename to cli/create-dms-page/src/utils/logger.ts diff --git a/scripts/cli/create-dms-page/src/utils/path-utils.ts b/cli/create-dms-page/src/utils/path-utils.ts similarity index 100% rename from scripts/cli/create-dms-page/src/utils/path-utils.ts rename to cli/create-dms-page/src/utils/path-utils.ts diff --git a/scripts/cli/create-dms-page/src/utils/platform.ts b/cli/create-dms-page/src/utils/platform.ts similarity index 100% rename from scripts/cli/create-dms-page/src/utils/platform.ts rename to cli/create-dms-page/src/utils/platform.ts diff --git a/scripts/cli/create-dms-page/src/utils/spawn-util.ts b/cli/create-dms-page/src/utils/spawn-util.ts similarity index 100% rename from scripts/cli/create-dms-page/src/utils/spawn-util.ts rename to cli/create-dms-page/src/utils/spawn-util.ts diff --git a/scripts/cli/create-dms-page/src/utils/str-utils.ts b/cli/create-dms-page/src/utils/str-utils.ts similarity index 100% rename from scripts/cli/create-dms-page/src/utils/str-utils.ts rename to cli/create-dms-page/src/utils/str-utils.ts diff --git a/scripts/cli/create-dms-page/src/utils/writer-utils.ts b/cli/create-dms-page/src/utils/writer-utils.ts similarity index 100% rename from scripts/cli/create-dms-page/src/utils/writer-utils.ts rename to cli/create-dms-page/src/utils/writer-utils.ts diff --git a/cli/create-dms-page/tsconfig.json b/cli/create-dms-page/tsconfig.json new file mode 100644 index 000000000..691d3de44 --- /dev/null +++ b/cli/create-dms-page/tsconfig.json @@ -0,0 +1,21 @@ +{ + "extends": "@actiontech/dms-typescript-config/base", + "include": ["./src"], + "exclude": ["node_modules", "dist", "./bin"], + "compilerOptions": { + "target": "ES6", + "module": "CommonJS" /* Specify what module code is generated. */, + "rootDir": "./src" /* Specify the root folder within your source files. */, + "moduleResolution": "Node" /* Specify how TypeScript looks up a file from a given module specifier. */, + "baseUrl": "./" /* Specify the base directory to resolve non-relative module names. */, + "resolveJsonModule": true /* Enable importing .json files */, + "allowJs": true /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */, + "sourceMap": true /* Create source map files for emitted JavaScript files. */, + "outDir": "./dist" /* Specify an output folder for all emitted files. */, + "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipDefaultLibCheck": true, + "skipLibCheck": true + } +} diff --git a/scripts/cli/dms-kit-publish/.env.example b/cli/dms-kit-publish/.env.example similarity index 100% rename from scripts/cli/dms-kit-publish/.env.example rename to cli/dms-kit-publish/.env.example diff --git a/scripts/cli/dms-kit-publish/bin/core.js b/cli/dms-kit-publish/bin/core.js similarity index 100% rename from scripts/cli/dms-kit-publish/bin/core.js rename to cli/dms-kit-publish/bin/core.js diff --git a/cli/dms-kit-publish/eslint.config.mjs b/cli/dms-kit-publish/eslint.config.mjs new file mode 100644 index 000000000..905eff995 --- /dev/null +++ b/cli/dms-kit-publish/eslint.config.mjs @@ -0,0 +1,13 @@ +import node from '@actiontech/dms-eslint-config/node'; + +/** @type {import("eslint").Linter.Config[]} */ +export default [ + ...node, + { + files: ['src/**/*.{ts,js}'] + // 可以在此处添加本包特有的覆盖规则,例如: + // rules: { + // 'no-console': 'off' + // } + } +]; diff --git a/scripts/cli/dms-kit-publish/package.json b/cli/dms-kit-publish/package.json similarity index 69% rename from scripts/cli/dms-kit-publish/package.json rename to cli/dms-kit-publish/package.json index 08ad5444c..e838f208b 100644 --- a/scripts/cli/dms-kit-publish/package.json +++ b/cli/dms-kit-publish/package.json @@ -11,7 +11,10 @@ "scripts": { "build:watch": "tsc -w", "build": "tsc", - "start": "tsc && node dist/index.js" + "start": "tsc && node dist/index.js", + "eslint": "eslint src", + "eslint:fix": "eslint src --fix", + "ts-check": "tsc --noEmit" }, "dependencies": { "@octokit/rest": "^20.1.2", @@ -27,6 +30,8 @@ "@types/archiver": "^6.0.3", "@types/node": "^18.0.4", "@types/nodemailer": "^7.0.3", - "@types/semver": "^7.7.1" + "@types/semver": "^7.7.1", + "@actiontech/dms-eslint-config": "workspace:^", + "@actiontech/dms-typescript-config": "workspace:^" } } \ No newline at end of file diff --git a/scripts/cli/dms-kit-publish/scripts/setup-local-test.sh b/cli/dms-kit-publish/scripts/setup-local-test.sh similarity index 100% rename from scripts/cli/dms-kit-publish/scripts/setup-local-test.sh rename to cli/dms-kit-publish/scripts/setup-local-test.sh diff --git a/scripts/cli/dms-kit-publish/scripts/stop-local-test.sh b/cli/dms-kit-publish/scripts/stop-local-test.sh similarity index 100% rename from scripts/cli/dms-kit-publish/scripts/stop-local-test.sh rename to cli/dms-kit-publish/scripts/stop-local-test.sh diff --git a/scripts/cli/dms-kit-publish/src/config/environment.ts b/cli/dms-kit-publish/src/config/environment.ts similarity index 100% rename from scripts/cli/dms-kit-publish/src/config/environment.ts rename to cli/dms-kit-publish/src/config/environment.ts diff --git a/scripts/cli/dms-kit-publish/src/config/index.ts b/cli/dms-kit-publish/src/config/index.ts similarity index 100% rename from scripts/cli/dms-kit-publish/src/config/index.ts rename to cli/dms-kit-publish/src/config/index.ts diff --git a/scripts/cli/dms-kit-publish/src/constants/packages.ts b/cli/dms-kit-publish/src/constants/packages.ts similarity index 100% rename from scripts/cli/dms-kit-publish/src/constants/packages.ts rename to cli/dms-kit-publish/src/constants/packages.ts diff --git a/scripts/cli/dms-kit-publish/src/index.ts b/cli/dms-kit-publish/src/index.ts similarity index 100% rename from scripts/cli/dms-kit-publish/src/index.ts rename to cli/dms-kit-publish/src/index.ts diff --git a/scripts/cli/dms-kit-publish/src/services/deploy.ts b/cli/dms-kit-publish/src/services/deploy.ts similarity index 100% rename from scripts/cli/dms-kit-publish/src/services/deploy.ts rename to cli/dms-kit-publish/src/services/deploy.ts diff --git a/scripts/cli/dms-kit-publish/src/services/notification.ts b/cli/dms-kit-publish/src/services/notification.ts similarity index 100% rename from scripts/cli/dms-kit-publish/src/services/notification.ts rename to cli/dms-kit-publish/src/services/notification.ts diff --git a/scripts/cli/dms-kit-publish/src/services/validator.ts b/cli/dms-kit-publish/src/services/validator.ts similarity index 100% rename from scripts/cli/dms-kit-publish/src/services/validator.ts rename to cli/dms-kit-publish/src/services/validator.ts diff --git a/scripts/cli/dms-kit-publish/src/types/config.ts b/cli/dms-kit-publish/src/types/config.ts similarity index 100% rename from scripts/cli/dms-kit-publish/src/types/config.ts rename to cli/dms-kit-publish/src/types/config.ts diff --git a/scripts/cli/dms-kit-publish/src/types/error.ts b/cli/dms-kit-publish/src/types/error.ts similarity index 100% rename from scripts/cli/dms-kit-publish/src/types/error.ts rename to cli/dms-kit-publish/src/types/error.ts diff --git a/scripts/cli/dms-kit-publish/src/types/index.ts b/cli/dms-kit-publish/src/types/index.ts similarity index 100% rename from scripts/cli/dms-kit-publish/src/types/index.ts rename to cli/dms-kit-publish/src/types/index.ts diff --git a/scripts/cli/dms-kit-publish/src/types/package.ts b/cli/dms-kit-publish/src/types/package.ts similarity index 100% rename from scripts/cli/dms-kit-publish/src/types/package.ts rename to cli/dms-kit-publish/src/types/package.ts diff --git a/scripts/cli/dms-kit-publish/src/utils/changelog.ts b/cli/dms-kit-publish/src/utils/changelog.ts similarity index 100% rename from scripts/cli/dms-kit-publish/src/utils/changelog.ts rename to cli/dms-kit-publish/src/utils/changelog.ts diff --git a/scripts/cli/dms-kit-publish/src/utils/compress.ts b/cli/dms-kit-publish/src/utils/compress.ts similarity index 100% rename from scripts/cli/dms-kit-publish/src/utils/compress.ts rename to cli/dms-kit-publish/src/utils/compress.ts diff --git a/scripts/cli/dms-kit-publish/src/utils/exec.ts b/cli/dms-kit-publish/src/utils/exec.ts similarity index 100% rename from scripts/cli/dms-kit-publish/src/utils/exec.ts rename to cli/dms-kit-publish/src/utils/exec.ts diff --git a/scripts/cli/dms-kit-publish/src/utils/logger.ts b/cli/dms-kit-publish/src/utils/logger.ts similarity index 100% rename from scripts/cli/dms-kit-publish/src/utils/logger.ts rename to cli/dms-kit-publish/src/utils/logger.ts diff --git a/cli/dms-kit-publish/tsconfig.json b/cli/dms-kit-publish/tsconfig.json new file mode 100644 index 000000000..9e016fe9a --- /dev/null +++ b/cli/dms-kit-publish/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "@actiontech/dms-typescript-config/base", + "include": ["./src"], + "exclude": ["node_modules", "dist", "./bin"], + "compilerOptions": { + "target": "ES6", + "module": "CommonJS", + "lib": [], + "allowJs": true, + "rootDir": "./src", + "baseUrl": "./", + "sourceMap": true, + "outDir": "./dist", + "noEmit": false + } +} diff --git a/eslint.config.mjs b/eslint.config.mjs deleted file mode 100644 index b92397d45..000000000 --- a/eslint.config.mjs +++ /dev/null @@ -1,101 +0,0 @@ -import { defineConfig, globalIgnores } from 'eslint/config'; -import globals from 'globals'; -import tseslint from 'typescript-eslint'; -import pluginReact from 'eslint-plugin-react'; -import pluginImport from 'eslint-plugin-import'; -import pluginReactHooks from 'eslint-plugin-react-hooks'; -import pluginNode from 'eslint-plugin-node'; - -export default defineConfig([ - tseslint.configs.recommended, - { - files: ['**/scripts/**/*.{js,mjs,cjs,ts,jsx,tsx}'], - plugins: { - import: pluginImport, - node: pluginNode - }, - languageOptions: { - globals: { - ...globals.node - } - }, - rules: { - '@typescript-eslint/no-unused-vars': 'warn', - '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/no-require-imports': 'warn', - '@typescript-eslint/no-empty-object-type': 'off' - } - }, - { - files: ['**/packages/**/*.{js,mjs,cjs,ts,jsx,tsx}'], - ...pluginReact.configs.flat.recommended, - plugins: { - import: pluginImport, - react: pluginReact, - 'react-hooks': pluginReactHooks - }, - languageOptions: { - ...pluginReact.configs.flat.recommended.languageOptions, - globals: { - ...globals.browser - } - }, - settings: { - react: { - pragma: 'React', - version: 'detect' - } - }, - rules: { - ...pluginReactHooks.configs.recommended.rules, - 'no-shadow': 'off', - '@typescript-eslint/no-shadow': 'error', - 'no-shadow-restricted-names': 'error', - 'testing-library/render-result-naming-convention': 0, - 'prefer-const': 'warn', - '@typescript-eslint/no-non-null-asserted-optional-chain': 0, - '@typescript-eslint/no-non-null-assertion': 0, - 'no-extra-boolean-cast': 'off', - 'import/no-anonymous-default-export': [2, { allowNew: true }], - '@typescript-eslint/no-empty-interface': [ - 'error', - { - allowSingleExtends: true - } - ], - '@typescript-eslint/no-explicit-any': 'off', - 'react/display-name': 0, - 'react/prop-types': 'off', - 'react/require-default-props': 'off', - 'no-console': 'warn', - '@typescript-eslint/no-unused-vars': 'warn', - 'no-template-curly-in-string': 'warn', - '@typescript-eslint/no-empty-object-type': 'off', - '@typescript-eslint/no-empty-function': 'warn', - 'import/no-anonymous-default-export': 'warn' - } - }, - globalIgnores([ - 'jest.config.js', - 'eslint.config.mjs', - '**/packages/**/*.test.ts', - '**/packages/**/*.test.tsx', - '**/packages/shared/lib/api/*', - '**/packages/**/mockApi/*', - '**/packages/**/testUtil/*', - '**/packages/**/demo/*', - '**/packages/**/demos/*', - 'jest-setup.ts', - 'node_modules/*', - '**/packages/*/node_modules/*', - '**/scripts/jest/*.js', - '/**/node_modules/*', - 'dist', - 'packages/*/dist', - 'packages/*/scripts', - '# config', - 'vite.config.ts', - '.eslintrc.json', - 'es' - ]) -]); diff --git a/jest.config.js b/jest.config.js index 631a7d8b7..20cbc09fc 100644 --- a/jest.config.js +++ b/jest.config.js @@ -2,7 +2,9 @@ process.env.TZ = 'Asia/Shanghai'; const path = require('path'); -const { compilerOptions } = require('./tsconfig.json'); +const { + compilerOptions +} = require('./packages/typescript-config/react-lib.json'); const { pathsToModuleNameMapper } = require('ts-jest'); compilerOptions.paths['~/*'][0] = path.resolve(compilerOptions.paths['~/*'][0]); diff --git a/package.json b/package.json index 793e9cf06..840310263 100644 --- a/package.json +++ b/package.json @@ -9,22 +9,22 @@ }, "scripts": { "preinstall": "npx only-allow pnpm", - "start": "concurrently \"pnpm --filter base start\" \"pnpm --filter @actiontech/dms-kit dev\"", - "start:ee": "concurrently \"pnpm --filter base start:ee\" \"pnpm --filter @actiontech/dms-kit dev\"", - "start:demo": "concurrently \"pnpm --filter base start:demo\" \"pnpm --filter @actiontech/dms-kit dev\"", - "build": "pnpm --filter @actiontech/dms-kit build && pnpm --filter base build", - "build:ee": "pnpm --filter @actiontech/dms-kit build && pnpm --filter base build:ee", - "build:demo": "pnpm --filter @actiontech/dms-kit build && pnpm --filter base build:demo", - "prettier:w": "prettier -w packages/*/src/ packages/shared/lib/ scripts/cli/*/src", - "prettier:c": "prettier -c packages/*/src/ packages/shared/lib/ scripts/cli/*/src", - "eslint": "eslint packages/*/src/ packages/shared/lib/ scripts/cli/*/src", + "start": "turbo run dev dev:ce --filter=@actiontech/dms-kit --filter=base", + "start:ee": "turbo run dev dev:ee --filter=@actiontech/dms-kit --filter=base", + "start:demo": "turbo run dev dev:demo --filter=@actiontech/dms-kit --filter=base", + "build": "turbo run build --filter=base", + "build:ee": "turbo run build:ee --filter=base", + "build:demo": "turbo run build:demo --filter=base", + "prettier:w": "prettier -w packages/*/src/ packages/shared/lib/ cli/*/src", + "prettier:c": "prettier -c packages/*/src/ packages/shared/lib/ cli/*/src", + "eslint": "turbo run eslint", + "eslint:fix": "turbo run eslint:fix", "stylelint": "stylelint packages/*/{src,lib}/**/{*.less,style.ts,element.ts}", - "ts-check": "tsc --noEmit", - "checker": "concurrently \"pnpm ts-check\" \"pnpm eslint\" \"pnpm stylelint\" \"pnpm prettier:c\"", - "test": "sh ./scripts/jest/run.sh", - "test:c": "sh ./scripts/jest/run-coverage.sh", - "test:ci": "sh ./scripts/jest/run-ci-ee.sh && sh ./scripts/jest/run-ci-ce.sh && node ./scripts/jest/merge-report-json.js", - "test:clean": "jest --clearCache", + "ts-check": "turbo run ts-check", + "checker": "concurrently \"turbo run ts-check\" \"turbo run eslint\" \"pnpm run stylelint\" \"pnpm run prettier:c\"", + "test": "turbo run test", + "test:c": "turbo run test:coverage --concurrency=1", + "test:clean": "turbo run test:clean", "icon:g": "pnpm --filter @actiontech/icons icon:g", "icon:docs:g": "pnpm --filter @actiontech/icons docs:g", "icon:docs": "pnpm --filter @actiontech/icons start", @@ -34,7 +34,6 @@ "api_client:g": "cross-env npm_config_registry=http://10.186.18.19:4873 pnpx @actiontech/cli api-client -y", "api_mocks:g": "cross-env npm_config_registry=http://10.186.18.19:4873 pnpx @actiontech/cli api-mocks -y", "ai-doc": "cross-env npm_config_registry=http://10.186.18.19:4873 pnpx @actiontech/cli ai-doc", - "postinstall": "pnpm --filter @actiontech/dms-kit build", "dms-kit:publish": "pnpm --filter @actiontech/cli-dms-kit-publish build && dms-kit-publish" }, "keywords": [], @@ -95,9 +94,10 @@ "stylelint-prettier": "^4.0.2", "ts-jest": "27.1.5", "tsx": "^4.20.5", + "turbo": "^2.5.6", "typescript": "^5.0.2", "typescript-eslint": "^8.28.0", - "vite": "^5.2.6", + "vite": "^7", "vite-plugin-conditional-compile": "1.4.3", "vite-plugin-eslint": "^1.8.1", "vite-plugin-html": "^3.2.2" @@ -149,4 +149,4 @@ "@babel/core": "^7.22.0", "@ant-design/cssinjs": "1.17.0" } -} +} \ No newline at end of file diff --git a/packages/base/eslint.config.mjs b/packages/base/eslint.config.mjs new file mode 100644 index 000000000..24eb3a4fb --- /dev/null +++ b/packages/base/eslint.config.mjs @@ -0,0 +1,9 @@ +import react from '@actiontech/dms-eslint-config/react'; + +/** @type {import("eslint").Linter.Config[]} */ +export default [ + ...react, + { + files: ['src/**/*.{ts,tsx,js,jsx}'] + } +]; diff --git a/packages/base/jest.config.js b/packages/base/jest.config.js new file mode 100644 index 000000000..c86c83ba2 --- /dev/null +++ b/packages/base/jest.config.js @@ -0,0 +1,42 @@ +process.env.TZ = 'Asia/Shanghai'; + +const path = require('path'); +const reactConfig = require('@actiontech/dms-jest-config/react'); +const { + compilerOptions +} = require('@actiontech/dms-typescript-config/react-lib'); +const { pathsToModuleNameMapper } = require('ts-jest'); + +// 处理包的路径别名 +const tsPaths = { ...compilerOptions.paths }; +if (tsPaths['~/*']) { + tsPaths['~/*'][0] = path.resolve( + __dirname, + tsPaths['~/*'][0].replace('./packages/provision/src/*', './src/*') + ); +} + +module.exports = { + ...reactConfig, + rootDir: __dirname, + displayName: 'base', + testMatch: [ + '/src/**/__tests__/**/*.{ts,tsx}', + '/src/**/*.{test,spec}.{ts,tsx}' + ], + collectCoverageFrom: [ + 'src/{page,components,hooks,global,store,utils}/**/*.{ts,tsx}', + 'src/App.tsx', + '!src/**/index.type.ts', + '!src/**/index.enum.ts' + ], + moduleNameMapper: { + ...reactConfig.moduleNameMapper, + ...pathsToModuleNameMapper(tsPaths) + }, + testPathIgnorePatterns: [ + ...reactConfig.testPathIgnorePatterns, + '/dist/', + '/node_modules/' + ] +}; diff --git a/packages/base/package.json b/packages/base/package.json index b0aa6eb18..dea0fce74 100644 --- a/packages/base/package.json +++ b/packages/base/package.json @@ -3,16 +3,20 @@ "private": true, "version": "0.0.0", "scripts": { - "start": "cross-env buildType=ce,SQLE vite --port=3020", - "start:ee": "cross-env buildType=ee,SQLE vite --port=3020", - "start:demo": "cross-env buildType=ce,SQLE,DEMO vite --port=3020", - "build": "node ../../scripts/getGitVersion.mjs ce && tsc && cross-env NODE_OPTIONS=--max_old_space_size=102400 buildType=ce,SQLE vite build", - "build:ee": "node ../../scripts/getGitVersion.mjs ee && tsc && cross-env NODE_OPTIONS=--max_old_space_size=102400 buildType=ee,SQLE vite build", - "build:demo": "node ../../scripts/getGitVersion.mjs trial && tsc && cross-env NODE_OPTIONS=--max_old_space_size=102400 buildType=ce,SQLE,DEMO vite build", + "dev:ce": "cross-env buildType=ce,SQLE vite --port=3020", + "dev:ee": "cross-env buildType=ee,SQLE vite --port=3020", + "dev:demo": "cross-env buildType=ce,SQLE,DEMO vite --port=3020", + "build": "tsc && cross-env NODE_OPTIONS=--max_old_space_size=102400 buildType=ce,SQLE vite build", + "build:ee": "tsc && cross-env NODE_OPTIONS=--max_old_space_size=102400 buildType=ee,SQLE vite build", + "build:demo": "tsc && cross-env NODE_OPTIONS=--max_old_space_size=102400 buildType=ce,SQLE,DEMO vite build", "preview": "vite preview", - "test": "jest --watchAll=true", - "test:c": "jest --coverage", - "test:ci": "jest --ci --watchAll=false --coverage --color --silent --testLocationInResults" + "eslint": "eslint src", + "eslint:fix": "eslint src --fix", + "ts-check": "tsc --noEmit", + "test": "sh ../../scripts/jest/run.sh", + "test:coverage": "sh ../../scripts/jest/run-coverage.sh", + "test:coverage:ci": "sh ../../scripts/jest/run-coverage-ci.sh", + "test:clean": "jest --clearCache" }, "dependencies": { "@actiontech/shared": "workspace:^", @@ -20,5 +24,10 @@ "babel-preset-react-app": "^10.0.1", "sqle": "workspace:^", "@actiontech/icons": "workspace:^" + }, + "devDependencies": { + "@actiontech/dms-jest-config": "workspace:^", + "@actiontech/dms-eslint-config": "workspace:^", + "@actiontech/dms-typescript-config": "workspace:^" } -} +} \ No newline at end of file diff --git a/packages/base/src/hooks/useProjectTips/index.test.ts b/packages/base/src/hooks/useProjectTips/index.test.ts index 38036d9ac..cdb1ae4b4 100644 --- a/packages/base/src/hooks/useProjectTips/index.test.ts +++ b/packages/base/src/hooks/useProjectTips/index.test.ts @@ -33,9 +33,9 @@ describe('useProjectTips', () => { await act(async () => jest.advanceTimersByTime(3000)); expect(result.current.projectList).toEqual(mockProjectList); expect(result.current.projectIDOptions).toEqual( - mockProjectList.map((project) => ({ - label: project.name, - value: project.uid + mockProjectList.map((p) => ({ + label: p.name, + value: p.uid })) ); expect(result.current.loading).toBeFalsy(); diff --git a/packages/base/src/page/Account/PersonalSMS/__tests__/index.test.tsx b/packages/base/src/page/Account/PersonalSMS/__tests__/index.test.tsx index e0eab7e2b..10c5fe452 100644 --- a/packages/base/src/page/Account/PersonalSMS/__tests__/index.test.tsx +++ b/packages/base/src/page/Account/PersonalSMS/__tests__/index.test.tsx @@ -12,7 +12,7 @@ describe('base/System/GlobalSetting/PersonalSMS', () => { let updateCurrentUserSpy: jest.SpyInstance; let sendSmsCodeSpy: jest.SpyInstance; let verifySmsCodeSpy: jest.SpyInstance; - let getUserInfoSpy = jest.fn(); + const getUserInfoSpy = jest.fn(); const customRender = ({ phone = mockUserInfo.userInfo.phone, enabled = true diff --git a/packages/base/src/page/Account/components/__tests__/UserWechat.test.tsx b/packages/base/src/page/Account/components/__tests__/UserWechat.test.tsx index 30b8e74d8..90bc101d1 100644 --- a/packages/base/src/page/Account/components/__tests__/UserWechat.test.tsx +++ b/packages/base/src/page/Account/components/__tests__/UserWechat.test.tsx @@ -1,4 +1,3 @@ -import { superRender } from '@actiontech/shared/lib/testUtil/superRender'; import UserWechat from '../UserWechat'; import { act, fireEvent } from '@testing-library/react'; import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; diff --git a/packages/base/src/page/Account/index.test.tsx b/packages/base/src/page/Account/index.test.tsx index ac6dd4d08..15b4902fc 100644 --- a/packages/base/src/page/Account/index.test.tsx +++ b/packages/base/src/page/Account/index.test.tsx @@ -15,10 +15,9 @@ jest.mock('react-redux', () => { describe('test base/page/Account', () => { const scopeDispatch = jest.fn(); - let updateCurrentUserSpy: jest.SpyInstance; beforeEach(() => { (useDispatch as jest.Mock).mockImplementation(() => scopeDispatch); - updateCurrentUserSpy = account.updateCurrentUser(); + account.updateCurrentUser(); jest.useFakeTimers(); }); afterEach(() => { diff --git a/packages/base/src/page/AvailabilityZone/AvailabilityZoneWrapper/__tests__/index.test.tsx b/packages/base/src/page/AvailabilityZone/AvailabilityZoneWrapper/__tests__/index.test.tsx index 5756da674..afa019778 100644 --- a/packages/base/src/page/AvailabilityZone/AvailabilityZoneWrapper/__tests__/index.test.tsx +++ b/packages/base/src/page/AvailabilityZone/AvailabilityZoneWrapper/__tests__/index.test.tsx @@ -7,7 +7,6 @@ import { mockUseRecentlySelectedZoneData } from '../../../../testUtils/mockHooks import { mockUseRecentlyOpenedProjects } from '../../../Nav/SideMenu/testUtils/mockUseRecentlyOpenedProjects'; import { baseMockApi } from '@actiontech/shared/lib/testUtil'; import { useSelector } from 'react-redux'; -import { mockUseUserInfo } from '@actiontech/shared/lib/testUtil'; jest.mock('react-redux', () => { return { @@ -32,11 +31,6 @@ describe('base/AvailabilityZone/AvailabilityZoneWrapper', () => { let getCurrentUserSpy: jest.SpyInstance; const useParamsSpy: jest.Mock = useParams as jest.Mock; - const mockAvailabilityZoneOptions = [ - { value: 'zone-123', label: 'Test Zone' }, - { value: 'zone-456', label: 'Another Zone' } - ]; - beforeEach(() => { jest.useFakeTimers(); getCurrentUserSpy = baseMockApi.global.getCurrentUser(); diff --git a/packages/base/src/page/DataExportManagement/Create/components/CreateTask/ExportSourceForm/__tests__/ExportSourceFormItem.test.tsx b/packages/base/src/page/DataExportManagement/Create/components/CreateTask/ExportSourceForm/__tests__/ExportSourceFormItem.test.tsx index 89c0d3617..7afe88970 100644 --- a/packages/base/src/page/DataExportManagement/Create/components/CreateTask/ExportSourceForm/__tests__/ExportSourceFormItem.test.tsx +++ b/packages/base/src/page/DataExportManagement/Create/components/CreateTask/ExportSourceForm/__tests__/ExportSourceFormItem.test.tsx @@ -2,13 +2,7 @@ import { baseSuperRender } from '../../../../../../../testUtils/superRender'; import dbServices from '@actiontech/shared/lib/testUtil/mockApi/base/dbServices'; import instance from '@actiontech/shared/lib/testUtil/mockApi/sqle/instance'; import ExportSourceFormItem from '../ExportSourceFormItem'; -import { - act, - cleanup, - fireEvent, - renderHook, - screen -} from '@testing-library/react'; +import { act, renderHook } from '@testing-library/react'; import { useForm } from 'antd/es/form/Form'; import { Form } from 'antd'; import { mockUseCurrentProject } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentProject'; diff --git a/packages/base/src/page/DataExportManagement/Create/hooks/__tests__/useCreateExportTaskForm.test.tsx b/packages/base/src/page/DataExportManagement/Create/hooks/__tests__/useCreateExportTaskForm.test.tsx index f75715113..df07fd6cf 100644 --- a/packages/base/src/page/DataExportManagement/Create/hooks/__tests__/useCreateExportTaskForm.test.tsx +++ b/packages/base/src/page/DataExportManagement/Create/hooks/__tests__/useCreateExportTaskForm.test.tsx @@ -10,7 +10,6 @@ import useCreateExportTaskForm from '../useCreateExportTaskForm'; import { Button, Form, Input, Switch } from 'antd'; import { mockUseCurrentProject } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentProject'; import { mockUseCreateDataExportReduxManage } from '../../testUtils/mockUseCreateDataExportReduxManage'; -import dbServices from '@actiontech/shared/lib/testUtil/mockApi/base/dbServices'; import { DBServicesList } from '@actiontech/shared/lib/testUtil/mockApi/base/global/data'; import { mockProjectInfo } from '@actiontech/shared/lib/testUtil/mockHook/data'; import dataExport from '@actiontech/shared/lib/testUtil/mockApi/base/dataExport'; diff --git a/packages/base/src/page/DataExportManagement/Detail/components/ExportDetail/__tests__/index.test.tsx b/packages/base/src/page/DataExportManagement/Detail/components/ExportDetail/__tests__/index.test.tsx index ed3ffdb39..32de57512 100644 --- a/packages/base/src/page/DataExportManagement/Detail/components/ExportDetail/__tests__/index.test.tsx +++ b/packages/base/src/page/DataExportManagement/Detail/components/ExportDetail/__tests__/index.test.tsx @@ -1,4 +1,4 @@ -import { act, fireEvent, screen, waitFor } from '@testing-library/react'; +import { act, fireEvent, screen } from '@testing-library/react'; import ExportDetail from '..'; import { baseSuperRender } from '../../../../../../testUtils/superRender'; import dataExport from '@actiontech/shared/lib/testUtil/mockApi/base/dataExport'; diff --git a/packages/base/src/page/DataSource/components/AddDataSource/index.test.tsx b/packages/base/src/page/DataSource/components/AddDataSource/index.test.tsx index b0ce653ce..563ad11a6 100644 --- a/packages/base/src/page/DataSource/components/AddDataSource/index.test.tsx +++ b/packages/base/src/page/DataSource/components/AddDataSource/index.test.tsx @@ -8,8 +8,7 @@ import { mockUseCurrentProject, mockProjectInfo, getAllBySelector, - getBySelector, - selectOptionByIndex + getBySelector } from '@actiontech/shared/lib/testUtil'; import EmitterKey from '../../../../data/EmitterKey'; import EventEmitter from '../../../../utils/EventEmitter'; diff --git a/packages/base/src/page/DataSource/components/BatchImportDataSource/index.test.tsx b/packages/base/src/page/DataSource/components/BatchImportDataSource/index.test.tsx index 6e88c73fb..afb6526f1 100644 --- a/packages/base/src/page/DataSource/components/BatchImportDataSource/index.test.tsx +++ b/packages/base/src/page/DataSource/components/BatchImportDataSource/index.test.tsx @@ -21,7 +21,6 @@ describe('base/DataSource/BatchImportDataSource', () => { let importDBServicesOfOneProjectSpy: jest.SpyInstance; let getImportDBServicesTemplateSpy: jest.SpyInstance; let importDBServicesOfOneProjectCheckSpy: jest.SpyInstance; - let dbServicesConnectionSpy: jest.SpyInstance; let checkDBServicesPrivilegesSpy: jest.SpyInstance; beforeEach(() => { @@ -30,7 +29,7 @@ describe('base/DataSource/BatchImportDataSource', () => { getImportDBServicesTemplateSpy = project.getImportDBServicesTemplate(); importDBServicesOfOneProjectCheckSpy = project.importDBServicesOfOneProjectCheck(); - dbServicesConnectionSpy = project.dbServicesConnection(); + project.dbServicesConnection(); checkDBServicesPrivilegesSpy = project.checkDBServicesPrivileges(); mockUseCurrentProject(); }); diff --git a/packages/base/src/page/GlobalDataSource/BatchImportDataSource/__tests__/index.test.tsx b/packages/base/src/page/GlobalDataSource/BatchImportDataSource/__tests__/index.test.tsx index e47d6a3df..56da656f1 100644 --- a/packages/base/src/page/GlobalDataSource/BatchImportDataSource/__tests__/index.test.tsx +++ b/packages/base/src/page/GlobalDataSource/BatchImportDataSource/__tests__/index.test.tsx @@ -19,7 +19,6 @@ describe('base/GlobalDataSource/BatchImportDataSource', () => { let importDBServicesOfProjectsSpy: jest.SpyInstance; let getImportDBServicesTemplateSpy: jest.SpyInstance; let importDBServicesOfProjectsCheckSpy: jest.SpyInstance; - let dbServicesConnectionSpy: jest.SpyInstance; let checkDBServicesPrivilegesSpy: jest.SpyInstance; beforeEach(() => { @@ -28,7 +27,7 @@ describe('base/GlobalDataSource/BatchImportDataSource', () => { getImportDBServicesTemplateSpy = project.getImportDBServicesTemplate(); importDBServicesOfProjectsCheckSpy = project.importDBServicesOfProjectsCheck(); - dbServicesConnectionSpy = project.dbServicesConnection(); + project.dbServicesConnection(); checkDBServicesPrivilegesSpy = project.checkDBServicesPrivileges(); }); diff --git a/packages/base/src/page/Login/components/OAuth2LoginForm.test.tsx b/packages/base/src/page/Login/components/OAuth2LoginForm.test.tsx index f8d347a71..d04a2bf41 100644 --- a/packages/base/src/page/Login/components/OAuth2LoginForm.test.tsx +++ b/packages/base/src/page/Login/components/OAuth2LoginForm.test.tsx @@ -3,7 +3,7 @@ import OAuth2LoginForm from './OAuth2LoginForm'; import { screen } from '@testing-library/react'; import { useSearchParams } from 'react-router-dom'; import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; -import { DMS_REDIRECT_KEY_PARAMS_NAME, ROUTE_PATHS } from '@actiontech/dms-kit'; +import { DMS_REDIRECT_KEY_PARAMS_NAME } from '@actiontech/dms-kit'; jest.mock('react-router-dom', () => { return { diff --git a/packages/base/src/page/Member/__tests__/index.test.tsx b/packages/base/src/page/Member/__tests__/index.test.tsx index 197e6a249..bc8f18d20 100644 --- a/packages/base/src/page/Member/__tests__/index.test.tsx +++ b/packages/base/src/page/Member/__tests__/index.test.tsx @@ -77,7 +77,7 @@ describe('base/Member', () => { it('should render add button when current user is admin or project manager', async () => { const mockUseCurrentUserSpy = mockUseCurrentUser(); - const { baseElement } = superRender(); + superRender(); await act(async () => jest.advanceTimersByTime(3000)); expect(screen.queryAllByText('添加成员')).toHaveLength(1); fireEvent.click(screen.getByText('添加成员')); diff --git a/packages/base/src/page/Nav/SideMenu/MenuList/index.test.tsx b/packages/base/src/page/Nav/SideMenu/MenuList/index.test.tsx index 11cdef782..0812e4725 100644 --- a/packages/base/src/page/Nav/SideMenu/MenuList/index.test.tsx +++ b/packages/base/src/page/Nav/SideMenu/MenuList/index.test.tsx @@ -2,7 +2,6 @@ import { cleanup, act } from '@testing-library/react'; import MenuList from '.'; import { baseSuperRender } from '../../../../testUtils/superRender'; import { useNavigate } from 'react-router-dom'; -import { SystemRole } from '@actiontech/dms-kit'; import { ignoreConsoleErrors, UtilsConsoleErrorStringsEnum @@ -22,7 +21,7 @@ jest.mock('react-router-dom', () => ({ describe.skip('base/page/Nav/SideMenu/MenuList', () => { const navigateSpy = jest.fn(); - const customRender = (role: SystemRole | '' = '') => { + const customRender = () => { return baseSuperRender(); }; @@ -46,7 +45,7 @@ describe.skip('base/page/Nav/SideMenu/MenuList', () => { }); it('render snap when is admin', async () => { - const { baseElement } = customRender(SystemRole.admin); + const { baseElement } = customRender(); await act(async () => jest.advanceTimersByTime(500)); expect(baseElement).toMatchSnapshot(); diff --git a/packages/base/src/page/Nav/SideMenu/UserMenu/Modal/VersionModal/test/__snapshots__/BasicVersionModal.test.tsx.snap b/packages/base/src/page/Nav/SideMenu/UserMenu/Modal/VersionModal/test/__snapshots__/BasicVersionModal.test.tsx.snap index 5e617ad54..71dcbc4a8 100644 --- a/packages/base/src/page/Nav/SideMenu/UserMenu/Modal/VersionModal/test/__snapshots__/BasicVersionModal.test.tsx.snap +++ b/packages/base/src/page/Nav/SideMenu/UserMenu/Modal/VersionModal/test/__snapshots__/BasicVersionModal.test.tsx.snap @@ -110,7 +110,7 @@ exports[`base/Nav/SideMenu/UserMenu/BasicVersionModal render snap when open is t class="ant-typography" > UI: - feature/add-make-command ba9c9c5 + feature/use-turbo 72cb26c5d
UI: - feature/add-make-command ba9c9c5 + feature/use-turbo 72cb26c5d
UI: - feature/add-make-command ba9c9c5 + feature/use-turbo 72cb26c5d
UI: - feature/add-make-command ba9c9c5 + feature/use-turbo 72cb26c5d
UI: - feature/add-make-command ba9c9c5 + feature/use-turbo 72cb26c5d
UI: - feature/add-make-command ba9c9c5 + feature/use-turbo 72cb26c5d
{ const versionModalOpenFn = jest.fn(); const navigateSpy = jest.fn(); const scopeDispatch = jest.fn(); - let requestDelSession: jest.SpyInstance; const customRender = () => { return baseSuperRender( @@ -50,7 +49,7 @@ describe('base/page/Nav/SideMenu/UserNavigate-ce', () => { (useNavigate as jest.Mock).mockImplementation(() => navigateSpy); (useDispatch as jest.Mock).mockImplementation(() => scopeDispatch); jest.useFakeTimers(); - requestDelSession = dms.delSession(); + dms.delSession(); mockUseUserInfo(); }); diff --git a/packages/base/src/page/Nav/SideMenu/__tests__/index.test.tsx b/packages/base/src/page/Nav/SideMenu/__tests__/index.test.tsx index 1a6b83a51..fb5cff426 100644 --- a/packages/base/src/page/Nav/SideMenu/__tests__/index.test.tsx +++ b/packages/base/src/page/Nav/SideMenu/__tests__/index.test.tsx @@ -21,8 +21,6 @@ import { mockUseRecentlySelectedZone } from '../../../../testUtils/mockHooks/moc import gateway from '@actiontech/shared/lib/testUtil/mockApi/base/gateway'; import { mockGatewayTipsData } from '@actiontech/shared/lib/testUtil/mockApi/base/gateway/data'; import userCenter from '@actiontech/shared/lib/testUtil/mockApi/base/userCenter'; -import sharedEmitterKey from '@actiontech/dms-kit/es/data/EmitterKey'; -import { eventEmitter as sharedEventEmitter } from '@actiontech/dms-kit/es/utils/EventEmitter'; jest.mock('react-redux', () => { return { diff --git a/packages/base/src/page/Nav/SideMenu/__tests__/useRecentlyOpenedProjects.test.ts b/packages/base/src/page/Nav/SideMenu/__tests__/useRecentlyOpenedProjects.test.ts index a6a3dfad2..c5281e552 100644 --- a/packages/base/src/page/Nav/SideMenu/__tests__/useRecentlyOpenedProjects.test.ts +++ b/packages/base/src/page/Nav/SideMenu/__tests__/useRecentlyOpenedProjects.test.ts @@ -1,9 +1,9 @@ +/* eslint-disable @typescript-eslint/no-empty-function */ import { LocalStorageWrapper } from '@actiontech/dms-kit'; import { act, renderHook } from '@testing-library/react'; import useRecentlyOpenedProjects from '../useRecentlyOpenedProjects'; import { mockUseCurrentUser } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentUser'; import { StorageKey } from '@actiontech/dms-kit'; -import { mockCurrentUserReturn } from '@actiontech/shared/lib/testUtil/mockHook/data'; import eventEmitter from '../../../../utils/EventEmitter'; import EmitterKey from '../../../../data/EmitterKey'; import EventEmitter from '../../../../utils/EventEmitter'; diff --git a/packages/base/src/page/Nav/UserGuideModal/__tests__/UserGuideModal.test.tsx b/packages/base/src/page/Nav/UserGuideModal/__tests__/UserGuideModal.test.tsx index 22605c568..f6a43061d 100644 --- a/packages/base/src/page/Nav/UserGuideModal/__tests__/UserGuideModal.test.tsx +++ b/packages/base/src/page/Nav/UserGuideModal/__tests__/UserGuideModal.test.tsx @@ -2,8 +2,7 @@ import { fireEvent, screen, act } from '@testing-library/react'; import { superRender } from '@actiontech/shared/lib/testUtil/superRender'; import { mockUseCurrentUser, - baseMockApi, - createSpySuccessResponse + baseMockApi } from '@actiontech/shared/lib/testUtil'; import { useDispatch, useSelector } from 'react-redux'; import { GetUserSystemEnum } from '@actiontech/shared/lib/api/base/service/common.enum'; diff --git a/packages/base/src/page/Project/BatchImportDataSource/UploadForm/index.test.tsx b/packages/base/src/page/Project/BatchImportDataSource/UploadForm/index.test.tsx index 3b885f2b6..680e72d58 100644 --- a/packages/base/src/page/Project/BatchImportDataSource/UploadForm/index.test.tsx +++ b/packages/base/src/page/Project/BatchImportDataSource/UploadForm/index.test.tsx @@ -6,7 +6,6 @@ import project from '@actiontech/shared/lib/testUtil/mockApi/base/project'; import { BatchImportDataSourceFormValueType } from '../index.type'; import { Form } from 'antd'; import { IDBService } from '@actiontech/shared/lib/api/base/service/common'; -import { mockBatchImportDBCheckData } from '@actiontech/shared/lib/testUtil/mockApi/base/project/data'; import { FileUploadCheckStatusType } from '../index.type'; describe('base/Project/BatchImportDataSourceForm', () => { diff --git a/packages/base/src/page/Project/BatchImportDataSource/index.test.tsx b/packages/base/src/page/Project/BatchImportDataSource/index.test.tsx index 5248fd0fc..1970144d6 100644 --- a/packages/base/src/page/Project/BatchImportDataSource/index.test.tsx +++ b/packages/base/src/page/Project/BatchImportDataSource/index.test.tsx @@ -19,7 +19,6 @@ describe('base/Project/BatchImportDataSource', () => { let importDBServicesOfProjectsSpy: jest.SpyInstance; let getImportDBServicesTemplateSpy: jest.SpyInstance; let importDBServicesOfProjectsCheckSpy: jest.SpyInstance; - let dbServicesConnectionSpy: jest.SpyInstance; let checkDBServicesPrivilegesSpy: jest.SpyInstance; beforeEach(() => { @@ -28,7 +27,7 @@ describe('base/Project/BatchImportDataSource', () => { getImportDBServicesTemplateSpy = project.getImportDBServicesTemplate(); importDBServicesOfProjectsCheckSpy = project.importDBServicesOfProjectsCheck(); - dbServicesConnectionSpy = project.dbServicesConnection(); + project.dbServicesConnection(); checkDBServicesPrivilegesSpy = project.checkDBServicesPrivileges(); }); diff --git a/packages/base/src/page/Project/List/index.test.tsx b/packages/base/src/page/Project/List/index.test.tsx index 185119447..097caa48f 100644 --- a/packages/base/src/page/Project/List/index.test.tsx +++ b/packages/base/src/page/Project/List/index.test.tsx @@ -1,4 +1,3 @@ -import { superRender } from '@actiontech/shared/lib/testUtil/superRender'; import { mockUseCurrentUser } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentUser'; import { mockUseUserInfo } from '@actiontech/shared/lib/testUtil/mockHook/mockUseUserInfo'; import project from '@actiontech/shared/lib/testUtil/mockApi/base/project'; @@ -234,7 +233,7 @@ describe('test base/project/list', () => { cleanup(); jest.clearAllMocks(); - let mockIsProjectManager = jest.fn(); + const mockIsProjectManager = jest.fn(); mockUseCurrentUser({ isAdmin: false, isProjectManager: mockIsProjectManager diff --git a/packages/base/src/page/System/License/index.test.tsx b/packages/base/src/page/System/License/index.test.tsx index 8da3a4b5b..b7ecb3da7 100644 --- a/packages/base/src/page/System/License/index.test.tsx +++ b/packages/base/src/page/System/License/index.test.tsx @@ -7,7 +7,6 @@ import { superRender } from '@actiontech/shared/lib/testUtil/superRender'; import { createSpySuccessResponse } from '@actiontech/shared/lib/testUtil/mockApi'; import { AxiosResponse } from 'axios'; import 'blob-polyfill'; -import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; import { mockUseCurrentUser } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentUser'; jest.mock('react-redux', () => ({ diff --git a/packages/base/src/page/System/LoginConnection/LDAPSetting/components/ConfigField.test.tsx b/packages/base/src/page/System/LoginConnection/LDAPSetting/components/ConfigField.test.tsx index 0e6898d11..94ca5daa5 100644 --- a/packages/base/src/page/System/LoginConnection/LDAPSetting/components/ConfigField.test.tsx +++ b/packages/base/src/page/System/LoginConnection/LDAPSetting/components/ConfigField.test.tsx @@ -1,4 +1,4 @@ -import { cleanup, fireEvent, act, screen } from '@testing-library/react'; +import { cleanup, fireEvent, act } from '@testing-library/react'; import { superRender } from '@actiontech/shared/lib/testUtil/superRender'; import { getBySelector, diff --git a/packages/base/src/page/System/LoginConnection/index.test.tsx b/packages/base/src/page/System/LoginConnection/index.test.tsx index ccd7da48c..208c52d69 100644 --- a/packages/base/src/page/System/LoginConnection/index.test.tsx +++ b/packages/base/src/page/System/LoginConnection/index.test.tsx @@ -3,7 +3,6 @@ import { cleanup, act, screen, fireEvent } from '@testing-library/react'; import LoginConnection from '.'; import { mockUseCurrentUser } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentUser'; import { superRender } from '@actiontech/shared/lib/testUtil/superRender'; -import { getAllBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; import { LDAPConfig, oauthConfig diff --git a/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.test.tsx b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.test.tsx index 55c968ec9..bec8c62e4 100644 --- a/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.test.tsx +++ b/packages/base/src/page/System/PushNotification/Wechat/components/ConfigField.test.tsx @@ -1,5 +1,5 @@ import { superRender } from '@actiontech/shared/lib/testUtil/superRender'; -import { cleanup, fireEvent, act, screen } from '@testing-library/react'; +import { cleanup, fireEvent, act } from '@testing-library/react'; import { getBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; import { Form } from 'antd'; diff --git a/packages/base/src/page/Transit/index.test.tsx b/packages/base/src/page/Transit/index.test.tsx index e405dc92e..ceecaa765 100644 --- a/packages/base/src/page/Transit/index.test.tsx +++ b/packages/base/src/page/Transit/index.test.tsx @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ import { mockUseCurrentUser } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentUser'; import Transit from '.'; import { superRender } from '@actiontech/shared/lib/testUtil/superRender'; diff --git a/packages/base/src/page/UserCenter/Drawer/Role/UpdateRole/index.test.tsx b/packages/base/src/page/UserCenter/Drawer/Role/UpdateRole/index.test.tsx index 47d62d93c..70098a715 100644 --- a/packages/base/src/page/UserCenter/Drawer/Role/UpdateRole/index.test.tsx +++ b/packages/base/src/page/UserCenter/Drawer/Role/UpdateRole/index.test.tsx @@ -6,10 +6,7 @@ import { ModalName } from '../../../../../data/ModalName'; import UpdateRole from '.'; import EventEmitter from '../../../../../utils/EventEmitter'; import EmitterKey from '../../../../../data/EmitterKey'; -import { - getAllBySelector, - queryBySelector -} from '@actiontech/shared/lib/testUtil/customQuery'; +import { queryBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; jest.mock('react-redux', () => ({ ...jest.requireActual('react-redux'), diff --git a/packages/base/src/router/test/router.ce.sqle.test.tsx b/packages/base/src/router/test/router.ce.sqle.test.tsx index 981fecd69..1196d59a8 100644 --- a/packages/base/src/router/test/router.ce.sqle.test.tsx +++ b/packages/base/src/router/test/router.ce.sqle.test.tsx @@ -3,7 +3,7 @@ */ import { MemoryRouterProps } from 'react-router-dom'; import { act, screen, cleanup } from '@testing-library/react'; -import mockUseRoutes, { RenderRouterComponent } from './data'; +import { RenderRouterComponent } from './data'; import { baseSuperRender } from '../../testUtils/superRender'; import { mockProjectInfo } from '@actiontech/shared/lib/testUtil/mockHook/data'; import userCenter from '@actiontech/shared/lib/testUtil/mockApi/base/userCenter'; diff --git a/packages/base/src/scripts/version.ts b/packages/base/src/scripts/version.ts index 2bf915458..47bc944b3 100644 --- a/packages/base/src/scripts/version.ts +++ b/packages/base/src/scripts/version.ts @@ -1 +1 @@ -export const UI_VERSION = 'feature/add-make-command ba9c9c5'; +export const UI_VERSION = 'feature/use-turbo 72cb26c5d'; diff --git a/packages/base/tsconfig.json b/packages/base/tsconfig.json index 740aafa02..dd8e4282a 100644 --- a/packages/base/tsconfig.json +++ b/packages/base/tsconfig.json @@ -1,10 +1,9 @@ { - "extends": "../../tsconfig.json", - "include": ["src"], + "extends": "@actiontech/dms-typescript-config/react-lib", "compilerOptions": { "paths": { "~/*": ["./src/*"] - }, - "skipLibCheck": true - } + } + }, + "include": ["src"] } diff --git a/packages/base/tsconfig.test.json b/packages/base/tsconfig.test.json deleted file mode 100644 index 7b9149578..000000000 --- a/packages/base/tsconfig.test.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "esModuleInterop": true - } -} diff --git a/packages/dms-kit/eslint.config.mjs b/packages/dms-kit/eslint.config.mjs new file mode 100644 index 000000000..2424a1664 --- /dev/null +++ b/packages/dms-kit/eslint.config.mjs @@ -0,0 +1,11 @@ +import react from '@actiontech/dms-eslint-config/react'; +import { globalIgnores } from 'eslint/config'; + +/** @type {import("eslint").Linter.Config[]} */ +export default [ + ...react, + { + files: ['src/**/*.{ts,tsx,js,jsx}'] + }, + globalIgnores(['src/**/demo/**', 'src/**/demos/**']) +]; diff --git a/packages/dms-kit/jest.config.js b/packages/dms-kit/jest.config.js new file mode 100644 index 000000000..acdf862fc --- /dev/null +++ b/packages/dms-kit/jest.config.js @@ -0,0 +1,49 @@ +process.env.TZ = 'Asia/Shanghai'; + +const path = require('path'); +const reactConfig = require('@actiontech/dms-jest-config/react'); +const { + compilerOptions +} = require('@actiontech/dms-typescript-config/react-lib'); +const { pathsToModuleNameMapper } = require('ts-jest'); + +// 处理包的路径别名 +const tsPaths = { ...compilerOptions.paths }; +if (tsPaths['~/*']) { + tsPaths['~/*'][0] = path.resolve( + __dirname, + tsPaths['~/*'][0].replace('./packages/provision/src/*', './src/*') + ); +} +// dms-kit 有自己的路径别名 +if (tsPaths['@actiontech/dms-kit']) { + tsPaths['@actiontech/dms-kit'][0] = path.resolve(__dirname, './src'); +} + +module.exports = { + ...reactConfig, + rootDir: __dirname, + displayName: 'dms-kit', + testMatch: [ + '/src/**/__tests__/**/*.{ts,tsx}', + '/src/**/*.{test,spec}.{ts,tsx}' + ], + collectCoverageFrom: [ + 'src/{components,features,hooks,utils}/**/*.{ts,tsx}', + '!src/**/index.type.ts', + '!src/**/index.enum.ts', + '!src/**/demo/**', + '!src/**/demos/**' + ], + moduleNameMapper: { + ...reactConfig.moduleNameMapper, + ...pathsToModuleNameMapper(tsPaths) + }, + testPathIgnorePatterns: [ + ...reactConfig.testPathIgnorePatterns, + '/dist/', + '/es/', + '/lib/', + '/node_modules/' + ] +}; diff --git a/packages/dms-kit/package.json b/packages/dms-kit/package.json index 4736ab03b..a7aefa7a1 100644 --- a/packages/dms-kit/package.json +++ b/packages/dms-kit/package.json @@ -19,9 +19,13 @@ "docs:dev": "dumi dev", "docs:build": "dumi build", "docs:preview": "dumi preview", - "test": "jest --watchAll=true", - "test:c": "jest --watchAll=false --coverage", - "test:ci": "jest --ci --watchAll=false --coverage --color --silent --testLocationInResults" + "eslint": "eslint src", + "eslint:fix": "eslint src --fix", + "ts-check": "tsc --noEmit", + "test": "sh ../../scripts/jest/run.sh", + "test:coverage": "sh ../../scripts/jest/run-coverage.sh", + "test:coverage:ci": "sh ../../scripts/jest/run-coverage-ci.sh", + "test:clean": "jest --clearCache" }, "dependencies": { "ahooks": "^3.7.0", @@ -56,6 +60,9 @@ "devDependencies": { "father": "^4.5.2", "dumi": "^2.3.8", - "babel-plugin-import": "^1.13.8" + "babel-plugin-import": "^1.13.8", + "@actiontech/dms-eslint-config": "workspace:^", + "@actiontech/dms-typescript-config": "workspace:^", + "@actiontech/dms-jest-config": "workspace:^" } -} +} \ No newline at end of file diff --git a/packages/dms-kit/src/components/BasicEmpty/BasicEmpty.test.tsx b/packages/dms-kit/src/components/BasicEmpty/BasicEmpty.test.tsx index ac78a082c..dfdd62a43 100644 --- a/packages/dms-kit/src/components/BasicEmpty/BasicEmpty.test.tsx +++ b/packages/dms-kit/src/components/BasicEmpty/BasicEmpty.test.tsx @@ -111,7 +111,7 @@ describe('lib/BasicEmpty', () => { }); it('should render custom children content', () => { - const { container } = customRender({ + customRender({ loading: false, dataLength: 0, children:
自定义内容
diff --git a/packages/dms-kit/src/components/CronInput/CronInput.test.tsx b/packages/dms-kit/src/components/CronInput/CronInput.test.tsx index e3ea8da32..8885b89c2 100644 --- a/packages/dms-kit/src/components/CronInput/CronInput.test.tsx +++ b/packages/dms-kit/src/components/CronInput/CronInput.test.tsx @@ -188,7 +188,6 @@ describe('lib/CronInputCom', () => { }); it('should handle and display error states correctly', async () => { - const updateErrorMessageSpy = jest.fn(); const { baseElement } = customRender({ inputMode: CronInputModeEnum.Manual, value: '0 0 0 0 0', diff --git a/packages/dms-kit/src/components/EditText/EditText.test.tsx b/packages/dms-kit/src/components/EditText/EditText.test.tsx index cd672ad7e..bda11d98a 100644 --- a/packages/dms-kit/src/components/EditText/EditText.test.tsx +++ b/packages/dms-kit/src/components/EditText/EditText.test.tsx @@ -1,5 +1,5 @@ import { superRender } from '../../testUtil/superRender'; -import { fireEvent, act, cleanup, screen } from '@testing-library/react'; +import { fireEvent, act, cleanup } from '@testing-library/react'; import EditText from './EditText'; import { EditTypeProps } from './EditText.types'; import { getBySelector } from '../../testUtil/customQuery'; diff --git a/packages/dms-kit/src/components/ModeSwitcher/ModeSwitcher.test.tsx b/packages/dms-kit/src/components/ModeSwitcher/ModeSwitcher.test.tsx index df8fbf1ba..d9e95baac 100644 --- a/packages/dms-kit/src/components/ModeSwitcher/ModeSwitcher.test.tsx +++ b/packages/dms-kit/src/components/ModeSwitcher/ModeSwitcher.test.tsx @@ -1,7 +1,6 @@ import { fireEvent, screen } from '@testing-library/dom'; import ModeSwitcher from './ModeSwitcher'; import { superRender } from '../../testUtil/superRender'; -import { useState } from 'react'; const list_1 = ['key1', 'key2', 'key3']; const list_2 = [ diff --git a/packages/dms-kit/src/features/useRecentlySelectedZone/__tests__/index.test.ts b/packages/dms-kit/src/features/useRecentlySelectedZone/__tests__/index.test.ts index cce7bb22f..6eedbcf3f 100644 --- a/packages/dms-kit/src/features/useRecentlySelectedZone/__tests__/index.test.ts +++ b/packages/dms-kit/src/features/useRecentlySelectedZone/__tests__/index.test.ts @@ -1,4 +1,4 @@ -import { act, cleanup } from '@testing-library/react'; +import { act } from '@testing-library/react'; import { superRenderHook } from '../../../testUtil/superRender'; import useRecentlySelectedZone, { DEFAULT_MAX_SELECTED_ZONE_NUMBER diff --git a/packages/dms-kit/tsconfig.json b/packages/dms-kit/tsconfig.json index 83e2e925a..f2fec7a77 100644 --- a/packages/dms-kit/tsconfig.json +++ b/packages/dms-kit/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../tsconfig.json", + "extends": "@actiontech/dms-typescript-config/react-lib", "include": ["./src"], "compilerOptions": { "paths": { @@ -11,5 +11,5 @@ "emitDeclarationOnly": false, "noEmit": false }, - "exclude": ["node_modules", "es", "lib"] + "exclude": ["node_modules", "es", "lib", "**/demo/**", "**/demos/**"] } diff --git a/packages/eslint-config/base.mjs b/packages/eslint-config/base.mjs new file mode 100644 index 000000000..9109303b9 --- /dev/null +++ b/packages/eslint-config/base.mjs @@ -0,0 +1,90 @@ +import { defineConfig, globalIgnores } from 'eslint/config'; +import globals from 'globals'; +import tseslint from 'typescript-eslint'; +import pluginReact from 'eslint-plugin-react'; +import pluginImport from 'eslint-plugin-import'; +import pluginReactHooks from 'eslint-plugin-react-hooks'; + +// 基础 TS 配置(不包含环境/框架) +export const tsBaseConfigs = tseslint.configs.recommended; + +// React / 浏览器通用配置片段 +const reactConfig = { + files: ['**/*.{ts,tsx,js,jsx}'], + ...pluginReact.configs.flat.recommended, + plugins: { + import: pluginImport, + react: pluginReact, + 'react-hooks': pluginReactHooks + }, + languageOptions: { + ...pluginReact.configs.flat.recommended.languageOptions, + globals: { + ...globals.browser + } + }, + settings: { + react: { + pragma: 'React', + version: 'detect' + } + }, + rules: { + ...pluginReactHooks.configs.recommended.rules, + 'no-shadow': 'off', + '@typescript-eslint/no-shadow': 'error', + 'no-shadow-restricted-names': 'error', + 'testing-library/render-result-naming-convention': 0, + 'prefer-const': 'warn', + '@typescript-eslint/no-non-null-asserted-optional-chain': 0, + '@typescript-eslint/no-non-null-assertion': 0, + 'no-extra-boolean-cast': 'off', + 'import/no-anonymous-default-export': [2, { allowNew: true }], + '@typescript-eslint/no-empty-interface': [ + 'error', + { + allowSingleExtends: true + } + ], + '@typescript-eslint/no-explicit-any': 'off', + 'react/display-name': 0, + 'react/prop-types': 'off', + 'react/require-default-props': 'off', + 'no-console': 'warn', + '@typescript-eslint/no-unused-vars': 'warn', + 'no-template-curly-in-string': 'warn', + '@typescript-eslint/no-empty-object-type': 'off', + '@typescript-eslint/no-empty-function': 'warn', + 'import/no-anonymous-default-export': 'warn' + } +}; + +// 通用忽略列表 +export const ignores = globalIgnores([ + 'jest.config.js', + 'eslint.config.mjs', + '**/packages/**/*.test.ts', + '**/packages/**/*.test.tsx', + '**/packages/shared/lib/api/*', + '**/packages/**/mockApi/*', + '**/packages/**/testUtil/*', + '**/packages/**/demo/*', + '**/packages/**/demos/*', + 'jest-setup.ts', + 'node_modules/*', + '**/packages/*/node_modules/*', + '**/scripts/jest/*.js', + '/**/node_modules/*', + 'dist', + 'packages/*/dist', + 'packages/*/scripts', + '# config', + 'vite.config.ts', + '.eslintrc.json', + 'es' +]); + +/** @type {import("eslint").Linter.Config[]} */ +export const base = defineConfig([...tsBaseConfigs, ignores]); + +export default base; diff --git a/packages/eslint-config/node.mjs b/packages/eslint-config/node.mjs new file mode 100644 index 000000000..67e64187d --- /dev/null +++ b/packages/eslint-config/node.mjs @@ -0,0 +1,28 @@ +import globals from 'globals'; +import pluginImport from 'eslint-plugin-import'; +import { tsBaseConfigs, ignores } from './base.mjs'; +import pluginNode from 'eslint-plugin-node'; +import { defineConfig } from 'eslint/config'; + +const nodeConfig = { + files: ['**/*.{js,mjs,cjs,ts}'], + plugins: { + import: pluginImport, + node: pluginNode + }, + languageOptions: { + globals: { + ...globals.node + } + }, + rules: { + '@typescript-eslint/no-unused-vars': 'warn', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-require-imports': 'warn', + '@typescript-eslint/no-empty-object-type': 'off' + } +}; +const node = defineConfig([...tsBaseConfigs, nodeConfig, ignores]); + +/** @type {import("eslint").Linter.Config[]} */ +export default node; diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json new file mode 100644 index 000000000..825a663bc --- /dev/null +++ b/packages/eslint-config/package.json @@ -0,0 +1,11 @@ +{ + "name": "@actiontech/dms-eslint-config", + "version": "0.0.0", + "type": "module", + "private": true, + "exports": { + "./base": "./base.mjs", + "./react": "./react.mjs", + "./node": "./node.mjs" + } +} \ No newline at end of file diff --git a/packages/eslint-config/react.mjs b/packages/eslint-config/react.mjs new file mode 100644 index 000000000..7c9c2f026 --- /dev/null +++ b/packages/eslint-config/react.mjs @@ -0,0 +1,61 @@ +import { defineConfig } from 'eslint/config'; +import globals from 'globals'; +import pluginReact from 'eslint-plugin-react'; +import pluginImport from 'eslint-plugin-import'; +import pluginReactHooks from 'eslint-plugin-react-hooks'; +import { tsBaseConfigs, ignores } from './base.mjs'; + +const reactConfig = { + files: ['**/*.{ts,tsx,js,jsx}'], + ...pluginReact.configs.flat.recommended, + plugins: { + import: pluginImport, + react: pluginReact, + 'react-hooks': pluginReactHooks + }, + languageOptions: { + ...pluginReact.configs.flat.recommended.languageOptions, + globals: { + ...globals.browser + } + }, + settings: { + react: { + pragma: 'React', + version: 'detect' + } + }, + rules: { + ...pluginReactHooks.configs.recommended.rules, + 'no-shadow': 'off', + '@typescript-eslint/no-shadow': 'error', + 'no-shadow-restricted-names': 'error', + 'testing-library/render-result-naming-convention': 0, + 'prefer-const': 'warn', + '@typescript-eslint/no-non-null-asserted-optional-chain': 0, + '@typescript-eslint/no-non-null-assertion': 0, + 'no-extra-boolean-cast': 'off', + 'import/no-anonymous-default-export': [2, { allowNew: true }], + '@typescript-eslint/no-empty-interface': [ + 'error', + { + allowSingleExtends: true + } + ], + '@typescript-eslint/no-explicit-any': 'off', + 'react/display-name': 0, + 'react/prop-types': 'off', + 'react/require-default-props': 'off', + 'no-console': 'warn', + '@typescript-eslint/no-unused-vars': 'warn', + 'no-template-curly-in-string': 'warn', + '@typescript-eslint/no-empty-object-type': 'off', + '@typescript-eslint/no-empty-function': 'warn', + 'import/no-anonymous-default-export': 'warn' + } +}; + +const react = defineConfig([...tsBaseConfigs, reactConfig, ignores]); + +/** @type {import("eslint").Linter.Config[]} */ +export default react; diff --git a/packages/icons/eslint.config.mjs b/packages/icons/eslint.config.mjs new file mode 100644 index 000000000..24eb3a4fb --- /dev/null +++ b/packages/icons/eslint.config.mjs @@ -0,0 +1,9 @@ +import react from '@actiontech/dms-eslint-config/react'; + +/** @type {import("eslint").Linter.Config[]} */ +export default [ + ...react, + { + files: ['src/**/*.{ts,tsx,js,jsx}'] + } +]; diff --git a/packages/icons/package.json b/packages/icons/package.json index 48cf230af..0a9718e12 100644 --- a/packages/icons/package.json +++ b/packages/icons/package.json @@ -10,7 +10,10 @@ "docs:preview": "dumi preview", "build": "father build", "icon:g": "svgr --template template/template.cjs -d src svg/ ", - "docs:g": "node scripts/generate.js" + "docs:g": "node scripts/generate.js", + "eslint": "eslint src", + "eslint:fix": "eslint src --fix", + "ts-check": "tsc --noEmit" }, "keywords": [], "author": "", @@ -19,6 +22,8 @@ "@babel/preset-react": "^7.24.7", "@svgr/cli": "^8.1.0", "dumi": "^2.3.8", - "father": "^4.1.0" + "father": "^4.1.0", + "@actiontech/dms-eslint-config": "workspace:^", + "@actiontech/dms-typescript-config": "workspace:^" } } \ No newline at end of file diff --git a/packages/icons/package_publish.json b/packages/icons/package_publish.json index c2bfb7ffc..4b3191d6c 100644 --- a/packages/icons/package_publish.json +++ b/packages/icons/package_publish.json @@ -37,7 +37,9 @@ "@svgr/cli": "8.1.0", "@babel/preset-react": "^7.24.7", "dumi": "2.3.8", - "father": "4.1.0" + "father": "4.1.0", + "@actiontech/dms-eslint-config": "workspace:^", + "@actiontech/dms-typescript-config": "workspace:^" }, "peerDependencies": { "react": ">=17" diff --git a/packages/icons/tsconfig.json b/packages/icons/tsconfig.json index 6cec366d2..d4b882628 100644 --- a/packages/icons/tsconfig.json +++ b/packages/icons/tsconfig.json @@ -1,17 +1,13 @@ { + "extends": "@actiontech/dms-typescript-config/react-lib", + "include": [".dumirc.ts", "src/**/*"], "compilerOptions": { - "strict": true, "declaration": true, - "skipLibCheck": true, - "esModuleInterop": true, - "resolveJsonModule": true, - "jsx": "react-jsx", "baseUrl": "./", "paths": { "@@/*": [".dumi/tmp/*"], "@actiontech/icons": ["src"], "@actiontech/icons/*": ["src/*", "*"] } - }, - "include": [".dumirc.ts", "src/**/*"] + } } diff --git a/packages/jest-config/base.js b/packages/jest-config/base.js new file mode 100644 index 000000000..b495103fd --- /dev/null +++ b/packages/jest-config/base.js @@ -0,0 +1,55 @@ +const path = require('path'); + +/** + * 基础 Jest 配置 + * 包含通用的 transform、moduleNameMapper、setupFilesAfterEnv 等配置 + */ +module.exports = { + transform: { + '^.+\\.(ts|tsx|js|jsx)$': path.resolve( + __dirname, + '../../scripts/jest/custom-transform.js' + ), + '^.+\\.(png|jpg|jpeg|css|json)$': path.resolve( + __dirname, + '../../scripts/jest/file-transform.js' + ) + }, + transformIgnorePatterns: [ + '/dist/', + 'node_modules/(?!(?:.pnpm/)?(@react-sigma|.+/es))[^/]+?/(?!(es|node_modules)/)' + ], + moduleFileExtensions: ['ts', 'tsx', 'js', 'json', 'jsx', 'node'], + testEnvironment: 'jest-environment-jsdom', + resetMocks: true, + moduleNameMapper: { + '.+\\.(css|style|less|sass|scss|ttf|woff|woff2)$': 'identity-obj-proxy', + '@ant-design/plots': + '/../../packages/shared/lib/testUtil/mockModule/mockAntDesignPlots.jsx', + 'monaco-editor': + '/../../packages/shared/lib/testUtil/mockModule/mockEditor.jsx', + '@monaco-editor/react': + '/../../packages/shared/lib/testUtil/mockModule/mockEditor.jsx', + '@uiw/react-md-editor': + '/../../packages/shared/lib/testUtil/mockModule/mockEditor.jsx', + '@react-sigma/core(.*)$': + '/../../packages/shared/lib/testUtil/mockModule/mockSigmaCore.tsx', + '@react-sigma/graph-search$': + '/../../packages/shared/lib/testUtil/mockModule/mockSigmaGraphSearch.tsx' + }, + setupFilesAfterEnv: [path.resolve(__dirname, '../../jest-setup.ts')], + testPathIgnorePatterns: ['/node_modules/', '/demo/', '/demos/'], + reporters: [ + 'default', + [ + 'jest-slow-test-reporter', + { + numTests: 8, + outputDirectory: 'reports', + outputName: 'report.xml', + color: true, + warnSlowerThan: 6000 + } + ] + ] +}; diff --git a/packages/jest-config/package.json b/packages/jest-config/package.json new file mode 100644 index 000000000..7077f3790 --- /dev/null +++ b/packages/jest-config/package.json @@ -0,0 +1,10 @@ +{ + "name": "@actiontech/dms-jest-config", + "version": "0.0.0", + "private": true, + "license": "MIT", + "exports": { + "./base": "./base.js", + "./react": "./react.js" + } +} \ No newline at end of file diff --git a/packages/jest-config/react.js b/packages/jest-config/react.js new file mode 100644 index 000000000..500b6d4cf --- /dev/null +++ b/packages/jest-config/react.js @@ -0,0 +1,27 @@ +const path = require('path'); +const { pathsToModuleNameMapper } = require('ts-jest'); +const baseConfig = require('./base.js'); + +// 读取 TypeScript 配置以获取路径映射 +const { + compilerOptions +} = require('@actiontech/dms-typescript-config/react-lib'); + +// 处理路径映射 +const tsPaths = { ...compilerOptions.paths }; +if (tsPaths['~/*']) { + tsPaths['~/*'][0] = path.resolve(__dirname, '../../', tsPaths['~/*'][0]); +} + +/** + * React 项目的 Jest 配置 + * 继承 base 配置并添加 React 特定的配置(如路径别名) + */ +module.exports = { + ...baseConfig, + moduleNameMapper: { + ...baseConfig.moduleNameMapper, + '@actiontech/(.*)': '/../../packages/$1', + ...pathsToModuleNameMapper(tsPaths) + } +}; diff --git a/packages/shared/eslint.config.mjs b/packages/shared/eslint.config.mjs new file mode 100644 index 000000000..c978ea5d5 --- /dev/null +++ b/packages/shared/eslint.config.mjs @@ -0,0 +1,11 @@ +import react from '@actiontech/dms-eslint-config/react'; +import { globalIgnores } from 'eslint/config'; + +/** @type {import("eslint").Linter.Config[]} */ +export default [ + ...react, + { + files: ['lib/**/*.{ts,tsx,js,jsx}'] + }, + globalIgnores(['lib/api/**', 'lib/testUtil/**']) +]; diff --git a/packages/shared/jest.config.js b/packages/shared/jest.config.js new file mode 100644 index 000000000..f5b5d894a --- /dev/null +++ b/packages/shared/jest.config.js @@ -0,0 +1,45 @@ +process.env.TZ = 'Asia/Shanghai'; + +const path = require('path'); +const reactConfig = require('@actiontech/dms-jest-config/react'); +const { + compilerOptions +} = require('@actiontech/dms-typescript-config/react-lib'); +const { pathsToModuleNameMapper } = require('ts-jest'); + +// 处理包的路径别名 +const tsPaths = { ...compilerOptions.paths }; +if (tsPaths['~/*']) { + tsPaths['~/*'][0] = path.resolve( + __dirname, + tsPaths['~/*'][0].replace('./packages/provision/src/*', './lib/*') + ); +} + +module.exports = { + ...reactConfig, + rootDir: __dirname, + displayName: 'shared', + testMatch: [ + '/lib/**/__tests__/**/*.{ts,tsx}', + '/lib/**/*.{test,spec}.{ts,tsx}' + ], + collectCoverageFrom: [ + 'lib/{page,components,hooks,global,store,utils}/**/*.{ts,tsx}', + 'api/common/**/*.{ts,tsx}', + '!lib/**/index.type.ts', + '!lib/**/index.enum.ts', + '!lib/hooks/usePrompt/index.tsx', + '!lib/**/demo/**', + '!lib/**/demos/**' + ], + moduleNameMapper: { + ...reactConfig.moduleNameMapper, + ...pathsToModuleNameMapper(tsPaths) + }, + testPathIgnorePatterns: [ + ...reactConfig.testPathIgnorePatterns, + '/dist/', + '/node_modules/' + ] +}; diff --git a/packages/shared/lib/components/MonacoEditor/monacoEditorConfig.ts b/packages/shared/lib/components/MonacoEditor/monacoEditorConfig.ts index 5154e23fa..b92cb364e 100644 --- a/packages/shared/lib/components/MonacoEditor/monacoEditorConfig.ts +++ b/packages/shared/lib/components/MonacoEditor/monacoEditorConfig.ts @@ -1,10 +1,13 @@ +// eslint-disable-next-line @typescript-eslint/triple-slash-reference +/// + import * as monaco from 'monaco-editor'; import editorWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker'; import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker'; import { loader } from '@monaco-editor/react'; self.MonacoEnvironment = { - getWorker(_, label) { + getWorker(_: unknown, label: string) { if (label === 'json') { return new jsonWorker(); } diff --git a/packages/shared/lib/components/TypedRouter/__tests__/useTypedParams.test.ts b/packages/shared/lib/components/TypedRouter/__tests__/useTypedParams.test.ts index 23ee2fd04..01a0be953 100644 --- a/packages/shared/lib/components/TypedRouter/__tests__/useTypedParams.test.ts +++ b/packages/shared/lib/components/TypedRouter/__tests__/useTypedParams.test.ts @@ -10,12 +10,14 @@ describe('useTypedParams', () => { it('should handle params correctly', () => { (useParams as jest.Mock).mockReturnValue({ id: '1', postId: '2' }); + // eslint-disable-next-line @typescript-eslint/no-unused-vars const pathConfig = { prefix: '/app', path: 'user/:id/posts/:postId', query: 'view&filter' } as const; - const { result } = renderHook(() => useTypedParams()); + type PathConfig = typeof pathConfig; + const { result } = renderHook(() => useTypedParams()); expect(result.current.id).toBe('1'); expect(result.current.postId).toBe('2'); diff --git a/packages/shared/lib/components/TypedRouter/__tests__/utils.test.ts b/packages/shared/lib/components/TypedRouter/__tests__/utils.test.ts index c855145ae..6fdbd7de3 100644 --- a/packages/shared/lib/components/TypedRouter/__tests__/utils.test.ts +++ b/packages/shared/lib/components/TypedRouter/__tests__/utils.test.ts @@ -38,6 +38,7 @@ describe('utils', () => { }); it('should format path values with queries only', () => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const path = { path: '/', query: 'sort&page' } as const; const result = getFormatPathValues({ queries: { sort: 'asc', page: '1' } @@ -49,6 +50,7 @@ describe('utils', () => { }); it('should format path values with both params and queries', () => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const path = { path: '/home/:id', query: 'view' } as const; const result = getFormatPathValues({ diff --git a/packages/shared/package.json b/packages/shared/package.json index f78ab4c84..a1f516e59 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -4,16 +4,22 @@ "main": "lib/index.ts", "license": "MIT", "scripts": { - "build": "tsup", - "test": "jest --watchAll=true", - "test:c": "jest --watchAll=false --coverage", - "test:ci": "jest --ci --watchAll=false --coverage --color --silent --testLocationInResults" + "build": "echo 'shared has no build output'", + "eslint": "eslint lib", + "eslint:fix": "eslint lib --fix", + "ts-check": "tsc --noEmit", + "test": "sh ../../scripts/jest/run.sh", + "test:coverage": "sh ../../scripts/jest/run-coverage.sh", + "test:coverage:ci": "sh ../../scripts/jest/run-coverage-ci.sh", + "test:clean": "jest --clearCache" }, "dependencies": { "@actiontech/icons": "workspace:^", "@actiontech/dms-kit": "workspace:^" }, "devDependencies": { - "tsup": "^8.5.0" + "@actiontech/dms-eslint-config": "workspace:^", + "@actiontech/dms-typescript-config": "workspace:^", + "@actiontech/dms-jest-config": "workspace:^" } } \ No newline at end of file diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json index ee6467a89..174fff8e0 100644 --- a/packages/shared/tsconfig.json +++ b/packages/shared/tsconfig.json @@ -1,9 +1,4 @@ { - "extends": "../../tsconfig.json", - "include": ["./lib"], - "compilerOptions": { - "paths": { - "~/*": ["./src/*"] - } - } + "extends": "@actiontech/dms-typescript-config/react-lib", + "include": ["./lib"] } diff --git a/packages/sqle/Makefile b/packages/sqle/Makefile deleted file mode 100644 index 949d4242d..000000000 --- a/packages/sqle/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -test: - docker pull docker-registry:5000/actiontech/sqle-ui-unit-test && \ - docker run --rm -v ${shell pwd}:/app docker-registry:5000/actiontech/sqle-ui-unit-test diff --git a/packages/sqle/eslint.config.mjs b/packages/sqle/eslint.config.mjs new file mode 100644 index 000000000..24eb3a4fb --- /dev/null +++ b/packages/sqle/eslint.config.mjs @@ -0,0 +1,9 @@ +import react from '@actiontech/dms-eslint-config/react'; + +/** @type {import("eslint").Linter.Config[]} */ +export default [ + ...react, + { + files: ['src/**/*.{ts,tsx,js,jsx}'] + } +]; diff --git a/packages/sqle/jest.config.js b/packages/sqle/jest.config.js new file mode 100644 index 000000000..00999ce20 --- /dev/null +++ b/packages/sqle/jest.config.js @@ -0,0 +1,46 @@ +process.env.TZ = 'Asia/Shanghai'; + +const path = require('path'); +const reactConfig = require('@actiontech/dms-jest-config/react'); +const { + compilerOptions +} = require('@actiontech/dms-typescript-config/react-lib'); +const { pathsToModuleNameMapper } = require('ts-jest'); + +// 处理包的路径别名 +const tsPaths = { ...compilerOptions.paths }; +if (tsPaths['~/*']) { + tsPaths['~/*'][0] = path.resolve( + __dirname, + tsPaths['~/*'][0].replace('./packages/provision/src/*', './src/*') + ); +} + +module.exports = { + ...reactConfig, + rootDir: __dirname, + displayName: 'sqle', + testMatch: [ + '/src/**/__tests__/**/*.{ts,tsx}', + '/src/**/*.{test,spec}.{ts,tsx}' + ], + collectCoverageFrom: [ + 'src/{page,components,hooks,global,store,utils}/**/*.{ts,tsx}', + 'src/App.tsx', + '!src/**/index.type.ts', + '!src/**/index.enum.ts', + '!src/page/SqlAnalyze/SqlAnalyze/ProcessListCom/**', + '!src/page/Knowledge/Graph/components/**', + '!src/**/demo/**', + '!src/**/demos/**' + ], + moduleNameMapper: { + ...reactConfig.moduleNameMapper, + ...pathsToModuleNameMapper(tsPaths) + }, + testPathIgnorePatterns: [ + ...reactConfig.testPathIgnorePatterns, + '/dist/', + '/node_modules/' + ] +}; diff --git a/packages/sqle/package.json b/packages/sqle/package.json index 68dacf6a5..074221c31 100644 --- a/packages/sqle/package.json +++ b/packages/sqle/package.json @@ -3,6 +3,16 @@ "version": "1.0.0", "private": true, "main": "src/App.tsx", + "scripts": { + "build": "echo 'sqle has no build output'", + "eslint": "eslint src", + "eslint:fix": "eslint src --fix", + "ts-check": "tsc --noEmit", + "test": "sh ../../scripts/jest/run.sh", + "test:coverage": "sh ../../scripts/jest/run-coverage.sh", + "test:coverage:ci": "sh ../../scripts/jest/run-coverage-ci.sh", + "test:clean": "jest --clearCache" + }, "dependencies": { "@actiontech/icons": "workspace:^", "@actiontech/shared": "workspace:^1.0.0", @@ -14,7 +24,6 @@ "graphology": "^0.25.4", "graphology-communities-louvain": "^2.0.2", "iwanthue": "^2.0.0", - "react-grid-layout": "^1.3.4", "react-infinite-scroll-component": "^6.1.0", "rehype-rewrite": "^4.0.2", "rehype-sanitize": "^6.0.0", @@ -23,32 +32,10 @@ "web-vitals": "^0.2.4" }, "devDependencies": { - "@types/react-grid-layout": "^1.3.2", "graphology-types": "^0.24.8", - "jest-canvas-mock": "^2.2.0" - }, - "scripts": { - "start": "PORT=3030 craco start", - "build": "craco build", - "test": "jest --watchAll=true", - "test:c": "jest --watchAll=false --coverage", - "test:ci": "jest --ci --watchAll=false --coverage --color --silent --testLocationInResults", - "eject": "react-scripts eject" - }, - "browserslist": { - "production": [ - ">0.2%", - "not dead", - "not op_mini all" - ], - "development": [ - "last 1 chrome version", - "last 1 firefox version", - "last 1 safari version" - ] - }, - "engines": { - "node": ">=12.0.0" - }, - "proxy": "http://10.186.62.5:10000" -} + "jest-canvas-mock": "^2.2.0", + "@actiontech/dms-eslint-config": "workspace:^", + "@actiontech/dms-typescript-config": "workspace:^", + "@actiontech/dms-jest-config": "workspace:^" + } +} \ No newline at end of file diff --git a/packages/sqle/scripts/getGitVersion.js b/packages/sqle/scripts/getGitVersion.js deleted file mode 100644 index dbda091bb..000000000 --- a/packages/sqle/scripts/getGitVersion.js +++ /dev/null @@ -1,15 +0,0 @@ -const child_process = require('child_process'); -const path = require('path'); -const fs = require('fs'); -let version = ''; -let branch = child_process.execSync('git rev-parse --abbrev-ref HEAD', { - encoding: 'utf8', -}); -let commitId = child_process.execSync('git rev-parse --short HEAD', { - encoding: 'utf8', -}); -version = `${branch.split('\n')[0]} ${commitId.split('\n')[0]}`; -const filePath = path.resolve(process.cwd(), './src/scripts/version.ts'); - -const command = `export const UI_VERSION="${version}"`; -fs.writeFileSync(filePath, command); diff --git a/packages/sqle/scripts/jest/babelTransform.js b/packages/sqle/scripts/jest/babelTransform.js deleted file mode 100644 index 87c0570bd..000000000 --- a/packages/sqle/scripts/jest/babelTransform.js +++ /dev/null @@ -1,3 +0,0 @@ -const commonBabelTransForm = require('@actiontech/shared/scripts/jest/babelTransform'); - -module.exports = commonBabelTransForm; \ No newline at end of file diff --git a/packages/sqle/scripts/jest/fileTransform.js b/packages/sqle/scripts/jest/fileTransform.js deleted file mode 100644 index c84f7627f..000000000 --- a/packages/sqle/scripts/jest/fileTransform.js +++ /dev/null @@ -1,3 +0,0 @@ -const commonFileTransform = require('@actiontech/shared/scripts/jest/fileTransform') - -module.exports = commonFileTransform; diff --git a/packages/sqle/scripts/moveAntdCss.js b/packages/sqle/scripts/moveAntdCss.js deleted file mode 100644 index 39358e939..000000000 --- a/packages/sqle/scripts/moveAntdCss.js +++ /dev/null @@ -1,26 +0,0 @@ -const path = require('path'); -const fs = require('fs'); - -const cwd = process.cwd(); - -const antdStyle = path.resolve(cwd, './node_modules/antd/dist'); -const lightCss = path.resolve(antdStyle, './antd.min.css'); -const lightCssMap = path.resolve(antdStyle, './antd.min.css.map'); -const darkCss = path.resolve(antdStyle, './antd.dark.min.css'); -const darkCssMap = path.resolve(antdStyle, './antd.dark.min.css.map'); - -const publicPath = path.resolve(cwd, './public/static/css'); - -const pathSet = [lightCss, lightCssMap, darkCss, darkCssMap, publicPath]; - -for (const p of pathSet) { - if (!fs.existsSync(p)) { - console.error(`not find file by ${p}`); - process.exit(1); - } -} - -fs.copyFileSync(lightCss, `${publicPath}/antd.min.css`); -fs.copyFileSync(lightCssMap, `${publicPath}/antd.min.css.map`); -fs.copyFileSync(darkCss, `${publicPath}/antd.dark.min.css`); -fs.copyFileSync(darkCssMap, `${publicPath}/antd.dark.min.css.map`); diff --git a/packages/sqle/src/components/ChartCom/TableTopList/index.test.tsx b/packages/sqle/src/components/ChartCom/TableTopList/index.test.tsx index 6b639296a..4e781b3d8 100644 --- a/packages/sqle/src/components/ChartCom/TableTopList/index.test.tsx +++ b/packages/sqle/src/components/ChartCom/TableTopList/index.test.tsx @@ -1,6 +1,5 @@ import TableTopList, { ITableTopList } from '.'; - -import { act, cleanup, fireEvent } from '@testing-library/react'; +import { cleanup } from '@testing-library/react'; import { sqleSuperRender } from '../../../testUtils/superRender'; import { mockThemeStyleData } from '../../../testUtils/mockHooks/mockThemeStyleData'; diff --git a/packages/sqle/src/components/SqlRewrittenDrawer/__tests__/components/BusinessRewrittenSuggestion.test.tsx b/packages/sqle/src/components/SqlRewrittenDrawer/__tests__/components/BusinessRewrittenSuggestion.test.tsx index 61ad43c5c..490def203 100644 --- a/packages/sqle/src/components/SqlRewrittenDrawer/__tests__/components/BusinessRewrittenSuggestion.test.tsx +++ b/packages/sqle/src/components/SqlRewrittenDrawer/__tests__/components/BusinessRewrittenSuggestion.test.tsx @@ -1,7 +1,6 @@ import { fireEvent, screen } from '@testing-library/dom'; import { sqleSuperRender } from '../../../../testUtils/superRender'; import BusinessRewrittenSuggestion from '../../components/BusinessRewrittenSuggestion'; -import { IRewriteSuggestion } from '@actiontech/shared/lib/api/sqle/service/common'; import { SqlRewrittenMockDataNoDDL } from '@actiontech/shared/lib/testUtil/mockApi/sqle/task/data'; import { RewriteSuggestionTypeEnum } from '@actiontech/shared/lib/api/sqle/service/common.enum'; import BusinessRewrittenDetails from '../../components/BusinessRewrittenSuggestion/BusinessRewrittenDetails'; diff --git a/packages/sqle/src/components/SqlRewrittenDrawer/__tests__/components/DependDatabaseStructure.test.tsx b/packages/sqle/src/components/SqlRewrittenDrawer/__tests__/components/DependDatabaseStructure.test.tsx index 7aa003f00..c8b13d135 100644 --- a/packages/sqle/src/components/SqlRewrittenDrawer/__tests__/components/DependDatabaseStructure.test.tsx +++ b/packages/sqle/src/components/SqlRewrittenDrawer/__tests__/components/DependDatabaseStructure.test.tsx @@ -54,7 +54,7 @@ describe('DependDatabaseStructure', () => { sqleSuperRender( {}} + toggleEnableStructureOptimizeAction={jest.fn()} /> ); @@ -67,7 +67,7 @@ describe('DependDatabaseStructure', () => { sqleSuperRender( {}} + toggleEnableStructureOptimizeAction={jest.fn()} /> ); diff --git a/packages/sqle/src/components/SqlRewrittenDrawer/__tests__/components/RewrittenSuggestionDetails.test.tsx b/packages/sqle/src/components/SqlRewrittenDrawer/__tests__/components/RewrittenSuggestionDetails.test.tsx index e5de733d6..2c21899b4 100644 --- a/packages/sqle/src/components/SqlRewrittenDrawer/__tests__/components/RewrittenSuggestionDetails.test.tsx +++ b/packages/sqle/src/components/SqlRewrittenDrawer/__tests__/components/RewrittenSuggestionDetails.test.tsx @@ -114,19 +114,19 @@ LIMIT 1000 OFFSET 500; }); it('should display combined SQL for subsequent items', () => { - const mockDataSource = SqlRewrittenMockDataNoDDL.suggestions?.filter( + const mockDataSourceParam = SqlRewrittenMockDataNoDDL.suggestions?.filter( (v) => v.type === RewriteSuggestionTypeEnum.statement )!; const { container } = sqleSuperRender( ); - fireEvent.click(screen.getByText(mockDataSource[0].rule_name!)); + fireEvent.click(screen.getByText(mockDataSourceParam[0].rule_name!)); expect(container).toMatchSnapshot(); }); diff --git a/packages/sqle/src/components/SqlRewrittenDrawer/__tests__/hooks/useAsyncRewriteProgress.test.ts b/packages/sqle/src/components/SqlRewrittenDrawer/__tests__/hooks/useAsyncRewriteProgress.test.ts index 12f4fb71a..7bc7bd420 100644 --- a/packages/sqle/src/components/SqlRewrittenDrawer/__tests__/hooks/useAsyncRewriteProgress.test.ts +++ b/packages/sqle/src/components/SqlRewrittenDrawer/__tests__/hooks/useAsyncRewriteProgress.test.ts @@ -10,10 +10,7 @@ import { useAsyncRewriteProgress, buildRewriteTaskResult } from '../../components/RewriteProgressDisplay/hooks'; -import { - getSqlRewriteCache, - saveSqlRewriteCache -} from '../../utils/sqlRewriteCache'; +import { getSqlRewriteCache } from '../../utils/sqlRewriteCache'; import { createSpySuccessResponse } from '@actiontech/shared/lib/testUtil'; // Mock 缓存模块 @@ -889,11 +886,9 @@ describe('useAsyncRewriteProgress', () => { describe('Cache Functionality', () => { let mockGetSqlRewriteCache: jest.Mock; - let mockSaveSqlRewriteCache: jest.Mock; beforeEach(() => { mockGetSqlRewriteCache = getSqlRewriteCache as jest.Mock; - mockSaveSqlRewriteCache = saveSqlRewriteCache as jest.Mock; }); afterEach(() => { @@ -1344,7 +1339,7 @@ describe('useAsyncRewriteProgress', () => { describe('Reset Functionality', () => { it('should reset all states when resetAllState is called', async () => { - const mockRewriteSQL = taskMockApi.getTaskSQLRewritten(); + taskMockApi.getTaskSQLRewritten(); const { result } = renderHook(() => useAsyncRewriteProgress()); diff --git a/packages/sqle/src/components/SqlRewrittenDrawer/utils/sqlRewriteCache.test.ts b/packages/sqle/src/components/SqlRewrittenDrawer/utils/sqlRewriteCache.test.ts index 843f62c7e..a5c1bac8f 100644 --- a/packages/sqle/src/components/SqlRewrittenDrawer/utils/sqlRewriteCache.test.ts +++ b/packages/sqle/src/components/SqlRewrittenDrawer/utils/sqlRewriteCache.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ import { saveSqlRewriteCache, getSqlRewriteCache, @@ -77,7 +78,7 @@ describe('sqlRewriteCache', () => { // 保存第一次 saveSqlRewriteCache(taskId, sqlNumber, firstResult, false); - const firstCached = getSqlRewriteCache(taskId, sqlNumber); + getSqlRewriteCache(taskId, sqlNumber); // 推进时间 MockDate.set(dayjs('2023-12-18 12:00:10').valueOf()); diff --git a/packages/sqle/src/hooks/useRuleTemplateForm/test/useUpdateRuleTemplateForm.test.tsx b/packages/sqle/src/hooks/useRuleTemplateForm/test/useUpdateRuleTemplateForm.test.tsx index b1e65f014..856cb8733 100644 --- a/packages/sqle/src/hooks/useRuleTemplateForm/test/useUpdateRuleTemplateForm.test.tsx +++ b/packages/sqle/src/hooks/useRuleTemplateForm/test/useUpdateRuleTemplateForm.test.tsx @@ -2,8 +2,6 @@ import { cleanup, act } from '@testing-library/react'; import { superRenderHook } from '@actiontech/shared/lib/testUtil/superRender'; import useUpdateRuleTemplateForm from '../useUpdateRuleTemplateForm'; import rule_template from '@actiontech/shared/lib/testUtil/mockApi/sqle/rule_template'; -import EventEmitter from '../../../utils/EventEmitter'; -import EmitterKey from '../../../data/EmitterKey'; describe('sqle/hooks/useRuleTemplateForm/useUpdateRuleTemplateForm', () => { let getRulesSpy: jest.SpyInstance; diff --git a/packages/sqle/src/hooks/useRuleVersionTips/index.test.tsx b/packages/sqle/src/hooks/useRuleVersionTips/index.test.tsx index cd0a04783..f642f5e89 100644 --- a/packages/sqle/src/hooks/useRuleVersionTips/index.test.tsx +++ b/packages/sqle/src/hooks/useRuleVersionTips/index.test.tsx @@ -21,7 +21,6 @@ describe('useRuleVersionTips', () => { }); it('should get rule version tips when call updateRuleVersionTips', async () => { - const requestSpy = rule_template.mockGetDriverRuleVersionTips(); const { result } = renderHook(() => useRuleVersionTips()); expect(result.current.ruleVersionTips).toEqual([]); expect(result.current.loading).toBeFalsy(); diff --git a/packages/sqle/src/page/CustomRule/CustomRuleList/index.test.tsx b/packages/sqle/src/page/CustomRule/CustomRuleList/index.test.tsx index d8a48edf1..2a42e1609 100644 --- a/packages/sqle/src/page/CustomRule/CustomRuleList/index.test.tsx +++ b/packages/sqle/src/page/CustomRule/CustomRuleList/index.test.tsx @@ -10,7 +10,6 @@ import { customRuleMockData } from '@actiontech/shared/lib/testUtil/mockApi/sqle import configuration from '@actiontech/shared/lib/testUtil/mockApi/sqle/configuration'; import { createSpySuccessResponse } from '@actiontech/shared/lib/testUtil/mockApi'; import { useNavigate } from 'react-router-dom'; -import { mockUsePermission } from '@actiontech/shared/lib/testUtil/mockHook/mockUsePermission'; import { RuleManagerSegmentedKey } from '../../RuleManager/index.type'; import { useSelector } from 'react-redux'; import { mockUseCurrentUser } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentUser'; diff --git a/packages/sqle/src/page/DataSourceComparison/ComparisonEntry/__tests__/ModifedSqlAuditResult.test.tsx b/packages/sqle/src/page/DataSourceComparison/ComparisonEntry/__tests__/ModifedSqlAuditResult.test.tsx index e67c6c6ca..af2e965ea 100644 --- a/packages/sqle/src/page/DataSourceComparison/ComparisonEntry/__tests__/ModifedSqlAuditResult.test.tsx +++ b/packages/sqle/src/page/DataSourceComparison/ComparisonEntry/__tests__/ModifedSqlAuditResult.test.tsx @@ -155,10 +155,10 @@ describe('ModifiedSqlAuditResult', () => { ]; describe('index', () => { - const customRender = (dataSource?: IDatabaseDiffModifySQL[]) => { + const customRender = (dataSourceParam?: IDatabaseDiffModifySQL[]) => { return sqleSuperRender( { describe('list', () => { const customRender = ( - dataSource?: ISQLStatementWithAuditResult[], + dataSourceParam?: ISQLStatementWithAuditResult[], auditError?: string ) => { return sqleSuperRender( { let getInstanceTipsSpy: jest.SpyInstance; - let getInstanceSchemaTipsSpy: jest.SpyInstance; beforeEach(() => { jest.clearAllMocks(); getInstanceTipsSpy = instance.getInstanceTipList(); - getInstanceSchemaTipsSpy = instance.getInstanceSchemas(); + instance.getInstanceSchemas(); jest.useFakeTimers(); mockUseCurrentProject(); mockDatabaseType(); diff --git a/packages/sqle/src/page/GlobalDashboard/__tests__/index.ce.test.tsx b/packages/sqle/src/page/GlobalDashboard/__tests__/index.ce.test.tsx index 05272a2a0..2bf78584c 100644 --- a/packages/sqle/src/page/GlobalDashboard/__tests__/index.ce.test.tsx +++ b/packages/sqle/src/page/GlobalDashboard/__tests__/index.ce.test.tsx @@ -7,7 +7,6 @@ import { mockUseCurrentUser } from '@actiontech/shared/lib/testUtil/mockHook/moc import { mockUseDbServiceDriver } from '@actiontech/shared/lib/testUtil/mockHook/mockUseDbServiceDriver'; import workflow from '@actiontech/shared/lib/testUtil/mockApi/sqle/execWorkflow'; import sqlManage from '@actiontech/shared/lib/testUtil/mockApi/sqle/sqlManage'; -import instance from '@actiontech/shared/lib/testUtil/mockApi/sqle/instance'; import { sqleSuperRender } from '../../../testUtils/superRender'; import GlobalDashboard from '../index'; diff --git a/packages/sqle/src/page/GlobalDashboard/__tests__/index.test.tsx b/packages/sqle/src/page/GlobalDashboard/__tests__/index.test.tsx index 0e5addb67..21265e082 100644 --- a/packages/sqle/src/page/GlobalDashboard/__tests__/index.test.tsx +++ b/packages/sqle/src/page/GlobalDashboard/__tests__/index.test.tsx @@ -16,8 +16,6 @@ describe('sqle/GlobalDashboard', () => { let getInstanceTipListSpy: jest.SpyInstance; let getGlobalSqlManageStatisticsSpy: jest.SpyInstance; let getGlobalWorkflowStatisticsSpy: jest.SpyInstance; - let getGlobalDataExportWorkflowsSpy: jest.SpyInstance; - let getGlobalDataExportWorkflowStatisticsSpy: jest.SpyInstance; beforeEach(() => { jest.useFakeTimers(); @@ -29,9 +27,8 @@ describe('sqle/GlobalDashboard', () => { getGlobalSqlManageList = sqlManage.getGlobalSqlManageList(); getGlobalSqlManageStatisticsSpy = sqlManage.getGlobalSqlManageStatistics(); getInstanceTipListSpy = instance.getInstanceTipList(); - getGlobalDataExportWorkflowsSpy = workflow.getGlobalDataExportWorkflows(); - getGlobalDataExportWorkflowStatisticsSpy = - workflow.getGlobalDataExportWorkflowStatistics(); + workflow.getGlobalDataExportWorkflows(); + workflow.getGlobalDataExportWorkflowStatistics(); }); afterEach(() => { @@ -70,10 +67,10 @@ describe('sqle/GlobalDashboard', () => { await act(async () => jest.advanceTimersByTime(0)); fireEvent.click(getBySelector('div[title="default"]')); - const instance = instanceTipsMockData[0]; + const instanceInfo = instanceTipsMockData[0]; fireEvent.click( getBySelector( - `div[title="${instance.instance_name}(${instance.host}:${instance.port})"]` + `div[title="${instanceInfo.instance_name}(${instanceInfo.host}:${instanceInfo.port})"]` ) ); await act(async () => jest.advanceTimersByTime(0)); diff --git a/packages/sqle/src/page/GlobalRuleTemplate/ImportRuleTemplate/index.test.tsx b/packages/sqle/src/page/GlobalRuleTemplate/ImportRuleTemplate/index.test.tsx index e355530c6..e62349e8c 100644 --- a/packages/sqle/src/page/GlobalRuleTemplate/ImportRuleTemplate/index.test.tsx +++ b/packages/sqle/src/page/GlobalRuleTemplate/ImportRuleTemplate/index.test.tsx @@ -14,7 +14,6 @@ import { import rule_template from '@actiontech/shared/lib/testUtil/mockApi/sqle/rule_template'; import { ruleType, - ruleListData, importRuleTemplateMockData } from '@actiontech/shared/lib/testUtil/mockApi/sqle/rule_template/data'; import configuration from '@actiontech/shared/lib/api/sqle/service/configuration'; @@ -45,7 +44,6 @@ describe('sqle/GlobalRuleTemplate/ImportRuleTemplate', () => { let createRuleTemplateSpy: jest.SpyInstance; let importProjectRuleTemplateSpy: jest.SpyInstance; let getCategoryStatisticsSpy: jest.SpyInstance; - let getRuleVersionTipsSpy: jest.SpyInstance; beforeEach(() => { (useNavigate as jest.Mock).mockImplementation(() => navigateSpy); (useDispatch as jest.Mock).mockImplementation(() => dispatchSpy); @@ -67,7 +65,7 @@ describe('sqle/GlobalRuleTemplate/ImportRuleTemplate', () => { } ); mockUseDbServiceDriver(); - getRuleVersionTipsSpy = rule_template.mockGetDriverRuleVersionTips(); + rule_template.mockGetDriverRuleVersionTips(); getAllRuleSpy = rule_template.getRuleList(); getDriversSpy = jest.spyOn(configuration, 'getDriversV2'); createRuleTemplateSpy = rule_template.createRuleTemplate(); diff --git a/packages/sqle/src/page/GlobalRuleTemplate/RuleTemplateList/Drawer/CloneRuleTemplate/index.test.tsx b/packages/sqle/src/page/GlobalRuleTemplate/RuleTemplateList/Drawer/CloneRuleTemplate/index.test.tsx index cef0838d8..d5385d4de 100644 --- a/packages/sqle/src/page/GlobalRuleTemplate/RuleTemplateList/Drawer/CloneRuleTemplate/index.test.tsx +++ b/packages/sqle/src/page/GlobalRuleTemplate/RuleTemplateList/Drawer/CloneRuleTemplate/index.test.tsx @@ -85,7 +85,7 @@ describe('sqle/GlobalRuleTemplate/CloneRuleTemplate', () => { it('should send clone project rule template request when click submit button with desc', async () => { const eventEmitSpy = jest.spyOn(EventEmitter, 'emit'); - const { baseElement } = customRender(); + customRender(); await act(async () => jest.advanceTimersByTime(3000)); expect(screen.getByText('正在克隆审核规则模板')).toBeInTheDocument(); fireEvent.input(screen.getByLabelText('模板名称'), { diff --git a/packages/sqle/src/page/Knowledge/Graph/__tests__/index.test.tsx b/packages/sqle/src/page/Knowledge/Graph/__tests__/index.test.tsx index 704cf7186..1438faf23 100644 --- a/packages/sqle/src/page/Knowledge/Graph/__tests__/index.test.tsx +++ b/packages/sqle/src/page/Knowledge/Graph/__tests__/index.test.tsx @@ -8,8 +8,6 @@ describe('KnowledgeGraph', () => { edges: [] }; - beforeEach(() => {}); - afterEach(() => { jest.clearAllMocks(); jest.clearAllTimers(); diff --git a/packages/sqle/src/page/Knowledge/Graph/hooks/__tests__/useGraph.test.ts b/packages/sqle/src/page/Knowledge/Graph/hooks/__tests__/useGraph.test.ts index c219867b0..5636636eb 100644 --- a/packages/sqle/src/page/Knowledge/Graph/hooks/__tests__/useGraph.test.ts +++ b/packages/sqle/src/page/Knowledge/Graph/hooks/__tests__/useGraph.test.ts @@ -1,4 +1,4 @@ -import Graph, { MultiDirectedGraph } from 'graphology'; +import Graph from 'graphology'; import louvain from 'graphology-communities-louvain'; import iwanthue from 'iwanthue'; import useGraph from '../useGraph'; @@ -11,18 +11,6 @@ jest.mock('graphology-communities-louvain', () => ({ jest.mock('iwanthue', () => jest.fn()); describe('useGraph', () => { - const mockTheme = { - sqleTheme: { - knowledgeTheme: { - graph: { - edge: { - color: '#666666' - } - } - } - } - }; - beforeEach(() => { (iwanthue as jest.Mock).mockReturnValue(['#FF0000', '#00FF00']); }); @@ -112,7 +100,7 @@ describe('useGraph', () => { edges: [{ from_id: '1', to_id: '2' }] }; - // @ts-ignore + // @ts-expect-error(This is a mock implementation) louvain.assign.mockImplementation((graph) => { graph.forEachNode((node: string) => { graph.setNodeAttribute(node, 'community', '0'); diff --git a/packages/sqle/src/page/PipelineConfiguration/Common/ConfigurationForm/PipelineNodeField/__tests__/index.test.tsx b/packages/sqle/src/page/PipelineConfiguration/Common/ConfigurationForm/PipelineNodeField/__tests__/index.test.tsx index 33e87187a..b2a984d3e 100644 --- a/packages/sqle/src/page/PipelineConfiguration/Common/ConfigurationForm/PipelineNodeField/__tests__/index.test.tsx +++ b/packages/sqle/src/page/PipelineConfiguration/Common/ConfigurationForm/PipelineNodeField/__tests__/index.test.tsx @@ -194,11 +194,11 @@ describe('sqle/PipelineConfiguration/PipelineNodeField', () => { expect(getInstanceTipListSpy).toHaveBeenCalledTimes(1); fireEvent.mouseDown(getBySelector('#instance_name')); await act(async () => jest.advanceTimersByTime(0)); - const instance = instanceTipsMockData[0]; + const instanceInfo = instanceTipsMockData[0]; await act(async () => { fireEvent.click( getBySelector( - `div[title="${instance.instance_name}(${instance.host}:${instance.port})"]` + `div[title="${instanceInfo.instance_name}(${instanceInfo.host}:${instanceInfo.port})"]` ) ); await act(async () => jest.advanceTimersByTime(0)); diff --git a/packages/sqle/src/page/PipelineConfiguration/Create/__tests__/index.test.tsx b/packages/sqle/src/page/PipelineConfiguration/Create/__tests__/index.test.tsx index 12098ca9d..39c106f16 100644 --- a/packages/sqle/src/page/PipelineConfiguration/Create/__tests__/index.test.tsx +++ b/packages/sqle/src/page/PipelineConfiguration/Create/__tests__/index.test.tsx @@ -2,7 +2,7 @@ import CreatePipelineConfiguration from '../'; import { screen, cleanup, act, fireEvent } from '@testing-library/react'; import pipeline from '@actiontech/shared/lib/testUtil/mockApi/sqle/pipeline'; import { useNavigate } from 'react-router-dom'; -import { useDispatch, useSelector } from 'react-redux'; +import { useDispatch } from 'react-redux'; import { superRender } from '@actiontech/shared/lib/testUtil/superRender'; import { mockUseCurrentProject } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentProject'; import { mockProjectInfo } from '@actiontech/shared/lib/testUtil/mockHook/data'; @@ -169,11 +169,11 @@ describe('sqle//PipelineConfiguration/Create', () => { expect(getInstanceTipListSpy).toHaveBeenCalledTimes(1); fireEvent.mouseDown(getBySelector('#instance_name')); await act(async () => jest.advanceTimersByTime(0)); - const instance = instanceTipsMockData[0]; + const instanceInfo = instanceTipsMockData[0]; await act(async () => { fireEvent.click( getBySelector( - `div[title="${instance.instance_name}(${instance.host}:${instance.port})"]` + `div[title="${instanceInfo.instance_name}(${instanceInfo.host}:${instanceInfo.port})"]` ) ); await act(async () => jest.advanceTimersByTime(0)); diff --git a/packages/sqle/src/page/ProjectOverview/component/DataSourcePerformance/index.test.tsx b/packages/sqle/src/page/ProjectOverview/component/DataSourcePerformance/index.test.tsx index 73b94c947..426d002b5 100644 --- a/packages/sqle/src/page/ProjectOverview/component/DataSourcePerformance/index.test.tsx +++ b/packages/sqle/src/page/ProjectOverview/component/DataSourcePerformance/index.test.tsx @@ -1,4 +1,4 @@ -import { cleanup, act, fireEvent, screen } from '@testing-library/react'; +import { cleanup, act } from '@testing-library/react'; import { sqleSuperRenderHook, sqleSuperRender diff --git a/packages/sqle/src/page/PushRuleConfiguration/components/SqlManagementIssuePush/__tests__/index.test.tsx b/packages/sqle/src/page/PushRuleConfiguration/components/SqlManagementIssuePush/__tests__/index.test.tsx index 5c8e3fb20..3a67a543b 100644 --- a/packages/sqle/src/page/PushRuleConfiguration/components/SqlManagementIssuePush/__tests__/index.test.tsx +++ b/packages/sqle/src/page/PushRuleConfiguration/components/SqlManagementIssuePush/__tests__/index.test.tsx @@ -60,8 +60,7 @@ describe('test SqlManagementIssuePush', () => { push_user_Type: ReportPushConfigListPushUserTypeEnum.fixed, push_user_list: ['1739544663515205632', '1739544663515205633'], last_push_time: '0001-01-01T00:00:00Z' - }, - permission = true + } ) => { return sqleSuperRender( @@ -79,19 +78,16 @@ describe('test SqlManagementIssuePush', () => { }); it('should call onSubmit function correctly when enabling/disabling the configuration switch', async () => { - const { baseElement } = customRender( - { - report_push_config_id: '2', - type: 'sql_manage', - enabled: false, - trigger_type: ReportPushConfigListTriggerTypeEnum.timing, - push_frequency_cron: '1 * * * *', - push_user_Type: ReportPushConfigListPushUserTypeEnum.fixed, - push_user_list: ['1739544663515205632', '1739544663515205633'], - last_push_time: '0001-01-01T00:00:00Z' - }, - true - ); + const { baseElement } = customRender({ + report_push_config_id: '2', + type: 'sql_manage', + enabled: false, + trigger_type: ReportPushConfigListTriggerTypeEnum.timing, + push_frequency_cron: '1 * * * *', + push_user_Type: ReportPushConfigListPushUserTypeEnum.fixed, + push_user_list: ['1739544663515205632', '1739544663515205633'], + last_push_time: '0001-01-01T00:00:00Z' + }); expect(getBySelector('.config-field-wrapper', baseElement)).toHaveAttribute( 'hidden' @@ -136,19 +132,16 @@ describe('test SqlManagementIssuePush', () => { }); it('should set the form to edit state and fill in default values when the modify button is clicked', async () => { - const { baseElement } = customRender( - { - report_push_config_id: '2', - type: 'sql_manage', - enabled: false, - trigger_type: ReportPushConfigListTriggerTypeEnum.timing, - push_frequency_cron: '1 * 2 * *', - push_user_Type: ReportPushConfigListPushUserTypeEnum.fixed, - push_user_list: ['1739544663515205632', '1739544663515205633'], - last_push_time: '0001-01-01T00:00:00Z' - }, - true - ); + const { baseElement } = customRender({ + report_push_config_id: '2', + type: 'sql_manage', + enabled: false, + trigger_type: ReportPushConfigListTriggerTypeEnum.timing, + push_frequency_cron: '1 * 2 * *', + push_user_Type: ReportPushConfigListPushUserTypeEnum.fixed, + push_user_list: ['1739544663515205632', '1739544663515205633'], + last_push_time: '0001-01-01T00:00:00Z' + }); fireEvent.click(getBySelector('.system-config-switch')); await act(async () => jest.advanceTimersByTime(0)); @@ -156,19 +149,16 @@ describe('test SqlManagementIssuePush', () => { }); it('should restore the form to its initial state when the cancel button is clicked', async () => { - const { baseElement } = customRender( - { - report_push_config_id: '2', - type: 'sql_manage', - enabled: false, - trigger_type: ReportPushConfigListTriggerTypeEnum.timing, - push_frequency_cron: '1 * * * *', - push_user_Type: ReportPushConfigListPushUserTypeEnum.fixed, - push_user_list: ['1739544663515205632', '1739544663515205633'], - last_push_time: '0001-01-01T00:00:00Z' - }, - true - ); + const { baseElement } = customRender({ + report_push_config_id: '2', + type: 'sql_manage', + enabled: false, + trigger_type: ReportPushConfigListTriggerTypeEnum.timing, + push_frequency_cron: '1 * * * *', + push_user_Type: ReportPushConfigListPushUserTypeEnum.fixed, + push_user_list: ['1739544663515205632', '1739544663515205633'], + last_push_time: '0001-01-01T00:00:00Z' + }); fireEvent.click(getBySelector('.system-config-switch')); await act(async () => jest.advanceTimersByTime(0)); diff --git a/packages/sqle/src/page/ReportStatistics/EEIndex/component/charts/LicenseStatistics/LicenseColumn.test.tsx b/packages/sqle/src/page/ReportStatistics/EEIndex/component/charts/LicenseStatistics/LicenseColumn.test.tsx index 832aaac0d..e255bed20 100644 --- a/packages/sqle/src/page/ReportStatistics/EEIndex/component/charts/LicenseStatistics/LicenseColumn.test.tsx +++ b/packages/sqle/src/page/ReportStatistics/EEIndex/component/charts/LicenseStatistics/LicenseColumn.test.tsx @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ import { cleanup } from '@testing-library/react'; import { sqleSuperRenderHook, diff --git a/packages/sqle/src/page/ReportStatistics/EEIndex/hooks/usePanelCommonRequest.test.ts b/packages/sqle/src/page/ReportStatistics/EEIndex/hooks/usePanelCommonRequest.test.ts index 491b2c38e..2dd43ded8 100644 --- a/packages/sqle/src/page/ReportStatistics/EEIndex/hooks/usePanelCommonRequest.test.ts +++ b/packages/sqle/src/page/ReportStatistics/EEIndex/hooks/usePanelCommonRequest.test.ts @@ -15,10 +15,12 @@ describe('ReportStatistics/usePanelCommonRequest', () => { const successFn = jest.fn(); const mockPromiseAPI = (url: string) => { - return new Promise>((resolve, reject) => { - url.includes('success') - ? resolve(createSpySuccessResponse({ data: {} })) - : resolve(createSpyFailResponse({ message: 'error-info' })); + return new Promise>((resolve) => { + if (url.includes('success')) { + resolve(createSpySuccessResponse({ data: {} })); + } else { + resolve(createSpyFailResponse({ message: 'error-info' })); + } }); }; diff --git a/packages/sqle/src/page/Rule/index.test.tsx b/packages/sqle/src/page/Rule/index.test.tsx index 9587272f6..549dd44ce 100644 --- a/packages/sqle/src/page/Rule/index.test.tsx +++ b/packages/sqle/src/page/Rule/index.test.tsx @@ -4,7 +4,6 @@ import { mockUseDbServiceDriver } from '@actiontech/shared/lib/testUtil/mockHook import Rule from '.'; import rule_template from '@actiontech/shared/lib/testUtil/mockApi/sqle/rule_template'; import { - getAllBySelector, getBySelector, queryBySelector } from '@actiontech/shared/lib/testUtil/customQuery'; diff --git a/packages/sqle/src/page/RuleManager/__tests__/index.test.tsx b/packages/sqle/src/page/RuleManager/__tests__/index.test.tsx index 5a1d7f703..496160f2c 100644 --- a/packages/sqle/src/page/RuleManager/__tests__/index.test.tsx +++ b/packages/sqle/src/page/RuleManager/__tests__/index.test.tsx @@ -9,7 +9,7 @@ import { mockUseCurrentUser } from '@actiontech/shared/lib/testUtil/mockHook/moc import { mockUseDbServiceDriver } from '@actiontech/shared/lib/testUtil/mockHook/mockUseDbServiceDriver'; import rule_template from '@actiontech/shared/lib/testUtil/mockApi/sqle/rule_template'; import { publicRuleTemplateListMockData } from '@actiontech/shared/lib/testUtil/mockApi/sqle/rule_template/data'; -import { useNavigate, BrowserRouter } from 'react-router-dom'; +import { useNavigate } from 'react-router-dom'; import { ModalName } from '../../../data/ModalName'; import { useDispatch, useSelector } from 'react-redux'; import { RuleManagerSegmentedKey } from '../index.type'; @@ -34,12 +34,11 @@ describe('sqle/RuleManager', () => { const navigateSpy = jest.fn(); const dispatchSpy = jest.fn(); let getRuleTemplateListSpy: jest.SpyInstance; - let mockUseCurrentUserSpy: jest.SpyInstance; beforeEach(() => { jest.useFakeTimers(); mockUseCurrentProject(); - mockUseCurrentUserSpy = mockUseCurrentUser(); + mockUseCurrentUser(); mockUseDbServiceDriver(); (useNavigate as jest.Mock).mockImplementation(() => navigateSpy); (useDispatch as jest.Mock).mockImplementation(() => dispatchSpy); diff --git a/packages/sqle/src/page/RuleTemplate/CloneRuleTemplate/index.test.tsx b/packages/sqle/src/page/RuleTemplate/CloneRuleTemplate/index.test.tsx index 178550d5c..450e18431 100644 --- a/packages/sqle/src/page/RuleTemplate/CloneRuleTemplate/index.test.tsx +++ b/packages/sqle/src/page/RuleTemplate/CloneRuleTemplate/index.test.tsx @@ -91,7 +91,7 @@ describe('sqle/RuleTemplate/CloneRuleTemplate', () => { it('should send clone project rule template request when click submit button with desc', async () => { const eventEmitSpy = jest.spyOn(EventEmitter, 'emit'); - const { baseElement } = customRender(); + customRender(); await act(async () => jest.advanceTimersByTime(3000)); expect(screen.getByText('正在克隆审核规则模板')).toBeInTheDocument(); fireEvent.input(screen.getByLabelText('模板名称'), { diff --git a/packages/sqle/src/page/RuleTemplate/ImportRuleTemplate/index.test.tsx b/packages/sqle/src/page/RuleTemplate/ImportRuleTemplate/index.test.tsx index 911ea2ab4..d4920084e 100644 --- a/packages/sqle/src/page/RuleTemplate/ImportRuleTemplate/index.test.tsx +++ b/packages/sqle/src/page/RuleTemplate/ImportRuleTemplate/index.test.tsx @@ -44,7 +44,6 @@ describe('sqle/RuleTemplate/ImportRuleTemplate', () => { let createProjectRuleTemplateSpy: jest.SpyInstance; let importProjectRuleTemplateSpy: jest.SpyInstance; let getCategoryStatisticsSpy: jest.SpyInstance; - let getRuleVersionTipsSpy: jest.SpyInstance; beforeEach(() => { (useNavigate as jest.Mock).mockImplementation(() => navigateSpy); (useDispatch as jest.Mock).mockImplementation(() => dispatchSpy); @@ -61,7 +60,7 @@ describe('sqle/RuleTemplate/ImportRuleTemplate', () => { mockUsePermission(undefined, { useSpyOnMockHooks: true }); - getRuleVersionTipsSpy = rule_template.mockGetDriverRuleVersionTips(); + rule_template.mockGetDriverRuleVersionTips(); getAllRuleSpy = rule_template.getRuleList(); getDriversSpy = jest.spyOn(configuration, 'getDriversV2'); createProjectRuleTemplateSpy = rule_template.createProjectRuleTemplate(); diff --git a/packages/sqle/src/page/RuleTemplate/RuleTemplateForm/index.test.tsx b/packages/sqle/src/page/RuleTemplate/RuleTemplateForm/index.test.tsx index 568973927..d214ba655 100644 --- a/packages/sqle/src/page/RuleTemplate/RuleTemplateForm/index.test.tsx +++ b/packages/sqle/src/page/RuleTemplate/RuleTemplateForm/index.test.tsx @@ -25,7 +25,6 @@ jest.mock('react-redux', () => ({ describe('sqle/RuleTemplate/RuleTemplateForm', () => { const dispatchSpy = jest.fn(); let getDriversSpy: jest.SpyInstance; - let getRuleVersionTipsSpy: jest.SpyInstance; beforeEach(() => { (useDispatch as jest.Mock).mockImplementation(() => dispatchSpy); mockUseCurrentProject(); @@ -34,7 +33,7 @@ describe('sqle/RuleTemplate/RuleTemplateForm', () => { mockUsePermission(undefined, { useSpyOnMockHooks: true }); - getRuleVersionTipsSpy = rule_template.mockGetDriverRuleVersionTips(); + rule_template.mockGetDriverRuleVersionTips(); getDriversSpy = configuration.getDrivers(); jest.useFakeTimers(); }); diff --git a/packages/sqle/src/page/RuleTemplate/RuleTemplateList/ProjectTable/index.test.tsx b/packages/sqle/src/page/RuleTemplate/RuleTemplateList/ProjectTable/index.test.tsx index 9ba298d6e..d4d94a24a 100644 --- a/packages/sqle/src/page/RuleTemplate/RuleTemplateList/ProjectTable/index.test.tsx +++ b/packages/sqle/src/page/RuleTemplate/RuleTemplateList/ProjectTable/index.test.tsx @@ -39,10 +39,9 @@ describe('sqle/RuleTemplate/List/ProjectTable', () => { const dispatchSpy = jest.fn(); const templateName = projectRuleTemplateListMockData[0].rule_template_name; let getProjectRuleTemplateListSpy: jest.SpyInstance; - let mockUseCurrentProjectSpy: jest.SpyInstance; beforeEach(() => { jest.useFakeTimers(); - mockUseCurrentProjectSpy = mockUseCurrentProject(); + mockUseCurrentProject(); mockUseCurrentUser(); mockUseDbServiceDriver(); (useNavigate as jest.Mock).mockImplementation(() => navigateSpy); @@ -68,15 +67,14 @@ describe('sqle/RuleTemplate/List/ProjectTable', () => { cleanup(); }); - const customRender = (actionPermission?: boolean) => - superRender(); + const customRender = () => superRender(); it('should render empty tips when request not success', async () => { getProjectRuleTemplateListSpy.mockClear(); getProjectRuleTemplateListSpy.mockImplementation(() => createSpyErrorResponse({ data: [] }) ); - const { baseElement } = customRender(true); + const { baseElement } = customRender(); await act(async () => jest.advanceTimersByTime(3000)); expect(baseElement).toMatchSnapshot(); const element = queryBySelector('.ant-table-placeholder', baseElement); @@ -84,7 +82,7 @@ describe('sqle/RuleTemplate/List/ProjectTable', () => { }); it('should refresh table when emit "Refresh_Rule_Template_List" event', async () => { - customRender(true); + customRender(); await act(async () => jest.advanceTimersByTime(3000)); expect(getProjectRuleTemplateListSpy).toHaveBeenCalledTimes(1); await act(async () => @@ -99,7 +97,7 @@ describe('sqle/RuleTemplate/List/ProjectTable', () => { getProjectRuleTemplateListSpy.mockImplementation(() => createSpySuccessResponse({ data: [projectRuleTemplateListMockData[0]] }) ); - customRender(true); + customRender(); await act(async () => jest.advanceTimersByTime(3000)); fireEvent.click(screen.getByText('编 辑')); await act(async () => jest.advanceTimersByTime(100)); @@ -113,7 +111,7 @@ describe('sqle/RuleTemplate/List/ProjectTable', () => { ); const deleteProjectRuleTemplateSpy = rule_template.deleteProjectRuleTemplate(); - customRender(true); + customRender(); await act(async () => jest.advanceTimersByTime(3000)); fireEvent.click(screen.getByText('删 除')); await act(async () => jest.advanceTimersByTime(100)); @@ -144,7 +142,7 @@ describe('sqle/RuleTemplate/List/ProjectTable', () => { getProjectRuleTemplateListSpy.mockImplementation(() => createSpySuccessResponse({ data: [projectRuleTemplateListMockData[0]] }) ); - const { baseElement } = customRender(true); + const { baseElement } = customRender(); await act(async () => jest.advanceTimersByTime(3000)); expect(dispatchSpy).toHaveBeenCalledTimes(1); expect(dispatchSpy).toHaveBeenNthCalledWith(1, { @@ -184,7 +182,7 @@ describe('sqle/RuleTemplate/List/ProjectTable', () => { getProjectRuleTemplateListSpy.mockImplementation(() => createSpySuccessResponse({ data: [projectRuleTemplateListMockData[0]] }) ); - const { baseElement } = customRender(true); + const { baseElement } = customRender(); await act(async () => jest.advanceTimersByTime(3000)); expect(dispatchSpy).toHaveBeenCalledTimes(1); expect(dispatchSpy).toHaveBeenNthCalledWith(1, { diff --git a/packages/sqle/src/page/RuleTemplate/UpdateRuleTemplate/index.test.tsx b/packages/sqle/src/page/RuleTemplate/UpdateRuleTemplate/index.test.tsx index 9047a7d0f..ccd8caac2 100644 --- a/packages/sqle/src/page/RuleTemplate/UpdateRuleTemplate/index.test.tsx +++ b/packages/sqle/src/page/RuleTemplate/UpdateRuleTemplate/index.test.tsx @@ -39,7 +39,6 @@ describe('sqle/RuleTemplate/UpdateRuleTemplate', () => { let updateProjectRuleTemplateSpy: jest.SpyInstance; let getProjectRuleTemplateSpy: jest.SpyInstance; let getCategoryStatisticsSpy: jest.SpyInstance; - let getRuleVersionTipsSpy: jest.SpyInstance; const useParamsMock: jest.Mock = useParams as jest.Mock; beforeEach(() => { (useNavigate as jest.Mock).mockImplementation(() => navigateSpy); @@ -58,7 +57,7 @@ describe('sqle/RuleTemplate/UpdateRuleTemplate', () => { useSpyOnMockHooks: true }); getAllRuleSpy = rule_template.getRuleList(); - getRuleVersionTipsSpy = rule_template.mockGetDriverRuleVersionTips(); + rule_template.mockGetDriverRuleVersionTips(); getDriversSpy = jest.spyOn(configuration, 'getDriversV2'); updateProjectRuleTemplateSpy = rule_template.updateProjectRuleTemplate(); getProjectRuleTemplateSpy = rule_template.getProjectRuleTemplate(); diff --git a/packages/sqle/src/page/SqlAnalyze/ManagementConf/index.test.tsx b/packages/sqle/src/page/SqlAnalyze/ManagementConf/index.test.tsx index 6864f1355..e6cb89ca8 100644 --- a/packages/sqle/src/page/SqlAnalyze/ManagementConf/index.test.tsx +++ b/packages/sqle/src/page/SqlAnalyze/ManagementConf/index.test.tsx @@ -16,7 +16,6 @@ import instance_audit_plan from '@actiontech/shared/lib/api/sqle/service/instanc import { mockUseCurrentProject } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentProject'; import MockDate from 'mockdate'; import dayjs from 'dayjs'; -import sqlManage from '@actiontech/shared/lib/testUtil/mockApi/sqle/sqlManage'; import { translateTimeForRequest } from '@actiontech/dms-kit'; import { mockUsePermission, @@ -51,7 +50,7 @@ describe('SqlAnalyze/ManagementConfAnalyze', () => { let getInstanceTipListSpy: jest.SpyInstance; let getSqlManageSqlAnalysisChartSpy: jest.SpyInstance; - let currentTime = dayjs('2025-01-09 12:00:00'); + const currentTime = dayjs('2025-01-09 12:00:00'); beforeEach(() => { MockDate.set(dayjs('2025-01-09 12:00:00').valueOf()); jest.useFakeTimers({ legacyFakeTimers: true }); diff --git a/packages/sqle/src/page/SqlAnalyze/SqlManage/index.test.tsx b/packages/sqle/src/page/SqlAnalyze/SqlManage/index.test.tsx index 7e4b5b565..29562d40d 100644 --- a/packages/sqle/src/page/SqlAnalyze/SqlManage/index.test.tsx +++ b/packages/sqle/src/page/SqlAnalyze/SqlManage/index.test.tsx @@ -51,7 +51,7 @@ describe('SqlAnalyze/SQLManage', () => { let getInstanceTipListSpy: jest.SpyInstance; let getSqlManageSqlAnalysisChartSpy: jest.SpyInstance; - let currentTime = dayjs('2025-01-09 12:00:00'); + const currentTime = dayjs('2025-01-09 12:00:00'); beforeEach(() => { MockDate.set(currentTime.valueOf()); jest.useFakeTimers({ legacyFakeTimers: true }); diff --git a/packages/sqle/src/page/SqlAnalyze/hooks/__tests__/useSqlExecPlanCost.test.tsx b/packages/sqle/src/page/SqlAnalyze/hooks/__tests__/useSqlExecPlanCost.test.tsx index 2523f4177..ff5b4e0ce 100644 --- a/packages/sqle/src/page/SqlAnalyze/hooks/__tests__/useSqlExecPlanCost.test.tsx +++ b/packages/sqle/src/page/SqlAnalyze/hooks/__tests__/useSqlExecPlanCost.test.tsx @@ -17,7 +17,7 @@ describe('SqlAnalyze/useSqlExecPlanCost', () => { ...i, x: formatTime(i.x) })); - let currentTime = dayjs('2025-01-09 12:00:00'); + const currentTime = dayjs('2025-01-09 12:00:00'); beforeEach(() => { MockDate.set(currentTime.valueOf()); jest.useFakeTimers({ legacyFakeTimers: true }); diff --git a/packages/sqle/src/page/SqlAudit/Create/index.test.tsx b/packages/sqle/src/page/SqlAudit/Create/index.test.tsx index 130dce052..cfe59a672 100644 --- a/packages/sqle/src/page/SqlAudit/Create/index.test.tsx +++ b/packages/sqle/src/page/SqlAudit/Create/index.test.tsx @@ -351,7 +351,7 @@ describe('sqle/SqlAudit/Create', () => { await act(async () => jest.advanceTimersByTime(300)); expect(baseElement).toMatchSnapshot(); const file = new File([''], 'test.xml'); - let uploader = getBySelector('#mybatisFile', baseElement); + const uploader = getBySelector('#mybatisFile', baseElement); fireEvent.change(uploader, { target: { files: [file] } }); @@ -395,7 +395,7 @@ describe('sqle/SqlAudit/Create', () => { await act(async () => jest.advanceTimersByTime(300)); expect(baseElement).toMatchSnapshot(); const file = new File([''], 'test.xml'); - let uploader = getBySelector('#zipFile', baseElement); + const uploader = getBySelector('#zipFile', baseElement); fireEvent.change(uploader, { target: { files: [file] } }); @@ -723,7 +723,7 @@ describe('sqle/SqlAudit/Create', () => { }; it('should switch between different git protocols', async () => { - const { baseElement } = await setupGitRepositoryTest(); + await setupGitRepositoryTest(); // 默认为 HTTP 协议 expect(screen.getByLabelText('用户名')).toBeInTheDocument(); diff --git a/packages/sqle/src/page/SqlAudit/Detail/index.test.tsx b/packages/sqle/src/page/SqlAudit/Detail/index.test.tsx index 1ca96ef4d..71e22c20f 100644 --- a/packages/sqle/src/page/SqlAudit/Detail/index.test.tsx +++ b/packages/sqle/src/page/SqlAudit/Detail/index.test.tsx @@ -21,8 +21,6 @@ jest.mock('react-redux', () => { }); describe('sqle/SqlAudit/Detail', () => { - let mockUseCurrentProjectSpy: jest.SpyInstance; - ignoreConsoleErrors([UtilsConsoleErrorStringsEnum['UNIQUE_KEY_REQUIRED']]); beforeEach(() => { @@ -37,7 +35,7 @@ describe('sqle/SqlAudit/Detail', () => { } }) ); - mockUseCurrentProjectSpy = mockUseCurrentProject(); + mockUseCurrentProject(); }); beforeAll(() => { diff --git a/packages/sqle/src/page/SqlAudit/List/component/SqlAuditTags/index.test.tsx b/packages/sqle/src/page/SqlAudit/List/component/SqlAuditTags/index.test.tsx index 9d97d0f31..dbe8cdb5e 100644 --- a/packages/sqle/src/page/SqlAudit/List/component/SqlAuditTags/index.test.tsx +++ b/packages/sqle/src/page/SqlAudit/List/component/SqlAuditTags/index.test.tsx @@ -25,7 +25,7 @@ describe('sqle/SqlAudit/SqlAuditTags', () => { Promise.resolve().then(updateTagsSpy)} + updateTags={() => Promise.resolve().then(updateTagsSpy)} /> ); }; diff --git a/packages/sqle/src/page/SqlAudit/List/index.test.tsx b/packages/sqle/src/page/SqlAudit/List/index.test.tsx index 21e8b87d9..a7b733104 100644 --- a/packages/sqle/src/page/SqlAudit/List/index.test.tsx +++ b/packages/sqle/src/page/SqlAudit/List/index.test.tsx @@ -28,12 +28,11 @@ jest.mock('react-redux', () => { describe('sqle/SqlAudit/List', () => { let sqlAuditRecordsSpy: jest.SpyInstance; - let mockUseCurrentProjectSpy: jest.SpyInstance; beforeEach(() => { jest.useFakeTimers(); instance.mockAllApi(); sqlAuditRecordsSpy = sqlAuditRecord.getSQLAuditRecords(); - mockUseCurrentProjectSpy = mockUseCurrentProject(); + mockUseCurrentProject(); mockUseCurrentUser(); (useSelector as jest.Mock).mockImplementation((selector) => { diff --git a/packages/sqle/src/page/SqlExecWorkflow/Common/AuditResultList/Table/__tests__/index.ce.test.tsx b/packages/sqle/src/page/SqlExecWorkflow/Common/AuditResultList/Table/__tests__/index.ce.test.tsx index 495250c6c..c31438080 100644 --- a/packages/sqle/src/page/SqlExecWorkflow/Common/AuditResultList/Table/__tests__/index.ce.test.tsx +++ b/packages/sqle/src/page/SqlExecWorkflow/Common/AuditResultList/Table/__tests__/index.ce.test.tsx @@ -22,7 +22,6 @@ jest.mock('react-redux', () => { }); describe('sqle/ExecWorkflow/Common/AuditResultList', () => { - let requestUpdateAuditTaskSQLs: jest.SpyInstance; let requestGetAuditTaskSQLs: jest.SpyInstance; const customRender = (params: AuditResultTableProps) => { @@ -32,7 +31,7 @@ describe('sqle/ExecWorkflow/Common/AuditResultList', () => { beforeEach(() => { mockUseCurrentUser(); jest.useFakeTimers(); - requestUpdateAuditTaskSQLs = execWorkflow.updateAuditTaskSQLs(); + execWorkflow.updateAuditTaskSQLs(); requestGetAuditTaskSQLs = execWorkflow.getAuditTaskSQLs(); execWorkflow.mockAllApi(); (useSelector as jest.Mock).mockImplementation((e) => diff --git a/packages/sqle/src/page/SqlExecWorkflow/Common/DownloadRecord/__tests__/index.test.tsx b/packages/sqle/src/page/SqlExecWorkflow/Common/DownloadRecord/__tests__/index.test.tsx index f5023a0f8..626f8bea6 100644 --- a/packages/sqle/src/page/SqlExecWorkflow/Common/DownloadRecord/__tests__/index.test.tsx +++ b/packages/sqle/src/page/SqlExecWorkflow/Common/DownloadRecord/__tests__/index.test.tsx @@ -4,12 +4,10 @@ import execWorkflow from '@actiontech/shared/lib/testUtil/mockApi/sqle/execWorkf import { DownloadRecordProps } from '../index.type'; import { fireEvent, act, cleanup, screen } from '@testing-library/react'; import { mockUseCurrentProject } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentProject'; -import { mockProjectInfo } from '@actiontech/shared/lib/testUtil/mockHook/data'; describe('sqle/ExecWorkflow/Common/DownloadRecord', () => { let requestDownloadFile: jest.SpyInstance; let requestDownloadReport: jest.SpyInstance; - let downloadBackupFileSpy: jest.SpyInstance; const customRender = (params: DownloadRecordProps) => { return sqleSuperRender(); }; @@ -18,7 +16,7 @@ describe('sqle/ExecWorkflow/Common/DownloadRecord', () => { jest.useFakeTimers(); requestDownloadFile = execWorkflow.downloadAuditTaskSQLFile(); requestDownloadReport = execWorkflow.downloadAuditTaskSQLReport(); - downloadBackupFileSpy = execWorkflow.downloadBackupFile(); + execWorkflow.downloadBackupFile(); mockUseCurrentProject(); }); diff --git a/packages/sqle/src/page/SqlExecWorkflow/Common/InstanceSegmentedLabel/__tests__/index.test.tsx b/packages/sqle/src/page/SqlExecWorkflow/Common/InstanceSegmentedLabel/__tests__/index.test.tsx index b432d0865..996c1f4f2 100644 --- a/packages/sqle/src/page/SqlExecWorkflow/Common/InstanceSegmentedLabel/__tests__/index.test.tsx +++ b/packages/sqle/src/page/SqlExecWorkflow/Common/InstanceSegmentedLabel/__tests__/index.test.tsx @@ -1,5 +1,5 @@ import { AuditTaskResV1AuditLevelEnum } from '@actiontech/shared/lib/api/sqle/service/common.enum'; -import InstanceSegmentedLabel, { InstanceSegmentedLabelProps } from '..'; +import InstanceSegmentedLabel from '..'; import { sqleSuperRender } from '../../../../../testUtils/superRender'; describe('sqle/ExecWorkflow/Common/InstanceSegmentedLabel', () => { diff --git a/packages/sqle/src/page/SqlExecWorkflow/Common/SqlStatementFormController/SqlStatementFormItem/__tests__/SqlExecModeSelector.ce.test.tsx b/packages/sqle/src/page/SqlExecWorkflow/Common/SqlStatementFormController/SqlStatementFormItem/__tests__/SqlExecModeSelector.ce.test.tsx index 88db6c6cc..56c0415ce 100644 --- a/packages/sqle/src/page/SqlExecWorkflow/Common/SqlStatementFormController/SqlStatementFormItem/__tests__/SqlExecModeSelector.ce.test.tsx +++ b/packages/sqle/src/page/SqlExecWorkflow/Common/SqlStatementFormController/SqlStatementFormItem/__tests__/SqlExecModeSelector.ce.test.tsx @@ -6,7 +6,7 @@ import { Form } from 'antd'; import { sqleSuperRender } from '../../../../../../testUtils/superRender'; import task from '@actiontech/shared/lib/testUtil/mockApi/sqle/task'; import SqlExecModeSelector from '../components/SqlExecModeSelector'; -import { act, fireEvent, renderHook, screen } from '@testing-library/react'; +import { fireEvent, renderHook, screen } from '@testing-library/react'; import { AuditTaskResV1SqlSourceEnum } from '@actiontech/shared/lib/api/sqle/service/common.enum'; import { SqlExecModeSelectorProps } from '../components/index.type'; diff --git a/packages/sqle/src/page/SqlExecWorkflow/Common/SqlStatementFormController/SqlStatementFormItem/__tests__/SqlExecModeSelector.test.tsx b/packages/sqle/src/page/SqlExecWorkflow/Common/SqlStatementFormController/SqlStatementFormItem/__tests__/SqlExecModeSelector.test.tsx index 42451e9b8..abf3f9dec 100644 --- a/packages/sqle/src/page/SqlExecWorkflow/Common/SqlStatementFormController/SqlStatementFormItem/__tests__/SqlExecModeSelector.test.tsx +++ b/packages/sqle/src/page/SqlExecWorkflow/Common/SqlStatementFormController/SqlStatementFormItem/__tests__/SqlExecModeSelector.test.tsx @@ -37,7 +37,7 @@ describe('test SqlExecModeSelector', () => { }; it('should disabled the execute mode selector when file mode execute SQL is not supported', async () => { - const { baseElement } = customRender({ + customRender({ currentSqlUploadType: AuditTaskResV1SqlSourceEnum.zip_file }); expect(screen.queryByText('选择上线模式')).toBeInTheDocument(); diff --git a/packages/sqle/src/page/SqlExecWorkflow/Common/SqlStatementFormController/__tests__/index.ce.test.tsx b/packages/sqle/src/page/SqlExecWorkflow/Common/SqlStatementFormController/__tests__/index.ce.test.tsx index e7c2dfe05..03af2794e 100644 --- a/packages/sqle/src/page/SqlExecWorkflow/Common/SqlStatementFormController/__tests__/index.ce.test.tsx +++ b/packages/sqle/src/page/SqlExecWorkflow/Common/SqlStatementFormController/__tests__/index.ce.test.tsx @@ -6,7 +6,6 @@ import { Form } from 'antd'; import SqlStatementFormController from '..'; import { sqleSuperRender } from '../../../../../testUtils/superRender'; import { renderHook } from '@testing-library/react'; -import { mockUseCurrentUser } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentUser'; import { mockUseCurrentProject } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentProject'; import { UtilsConsoleErrorStringsEnum, diff --git a/packages/sqle/src/page/SqlExecWorkflow/Create/components/FormStep/SqlAuditInfoForm/SqlAuditInfoFormItem/__tests__/index.test.tsx b/packages/sqle/src/page/SqlExecWorkflow/Create/components/FormStep/SqlAuditInfoForm/SqlAuditInfoFormItem/__tests__/index.test.tsx index cdf043252..2917da9a7 100644 --- a/packages/sqle/src/page/SqlExecWorkflow/Create/components/FormStep/SqlAuditInfoForm/SqlAuditInfoFormItem/__tests__/index.test.tsx +++ b/packages/sqle/src/page/SqlExecWorkflow/Create/components/FormStep/SqlAuditInfoForm/SqlAuditInfoFormItem/__tests__/index.test.tsx @@ -5,7 +5,7 @@ import execWorkflow from '@actiontech/shared/lib/testUtil/mockApi/sqle/execWorkf import { MockSharedStepDetail } from '../../../../../hooks/mockData'; import { SharedStepDetails } from '../../../../../index.type'; import { Form } from 'antd'; -import { act, renderHook } from '@testing-library/react'; +import { renderHook } from '@testing-library/react'; import { mockUseCurrentProject } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentProject'; import { mockUseDbServiceDriver } from '@actiontech/shared/lib/testUtil/mockHook/mockUseDbServiceDriver'; import { useSelector } from 'react-redux'; diff --git a/packages/sqle/src/page/SqlExecWorkflow/Create/hooks/__tests__/useAllowAuditLevel.test.ts b/packages/sqle/src/page/SqlExecWorkflow/Create/hooks/__tests__/useAllowAuditLevel.test.ts index abea3e316..1a33057eb 100644 --- a/packages/sqle/src/page/SqlExecWorkflow/Create/hooks/__tests__/useAllowAuditLevel.test.ts +++ b/packages/sqle/src/page/SqlExecWorkflow/Create/hooks/__tests__/useAllowAuditLevel.test.ts @@ -47,7 +47,7 @@ describe('sqle/useAllowAuditLevel', () => { ); await act(async () => jest.advanceTimersByTime(3000)); }); - expect(requestGetWorkflowTemplate).toHaveBeenCalled; + expect(requestGetWorkflowTemplate).toHaveBeenCalled(); expect(resetBtnDisabledFn).toHaveBeenCalled(); expect(result.current.submitWorkflowConfirmationMessage).toBe(''); }); diff --git a/packages/sqle/src/page/SqlExecWorkflow/Detail/components/AuditExecResultPanel/TaskResultList/Common/FileModeHeader/__tests__/index.ce.test.tsx b/packages/sqle/src/page/SqlExecWorkflow/Detail/components/AuditExecResultPanel/TaskResultList/Common/FileModeHeader/__tests__/index.ce.test.tsx index 126003307..8443a3fd6 100644 --- a/packages/sqle/src/page/SqlExecWorkflow/Detail/components/AuditExecResultPanel/TaskResultList/Common/FileModeHeader/__tests__/index.ce.test.tsx +++ b/packages/sqle/src/page/SqlExecWorkflow/Detail/components/AuditExecResultPanel/TaskResultList/Common/FileModeHeader/__tests__/index.ce.test.tsx @@ -5,7 +5,7 @@ import { useParams } from 'react-router-dom'; import { sqleSuperRender } from '../../../../../../../../../testUtils/superRender'; import FileModeHeader from '..'; -import { fireEvent, screen } from '@testing-library/dom'; +import { screen } from '@testing-library/dom'; import { mockUseCurrentProject } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentProject'; jest.mock('react-router-dom', () => ({ diff --git a/packages/sqle/src/page/SqlExecWorkflow/Detail/components/AuditExecResultPanel/__tests__/index.test.tsx b/packages/sqle/src/page/SqlExecWorkflow/Detail/components/AuditExecResultPanel/__tests__/index.test.tsx index 1a981e508..fbc001e35 100644 --- a/packages/sqle/src/page/SqlExecWorkflow/Detail/components/AuditExecResultPanel/__tests__/index.test.tsx +++ b/packages/sqle/src/page/SqlExecWorkflow/Detail/components/AuditExecResultPanel/__tests__/index.test.tsx @@ -7,8 +7,7 @@ import { sqleSuperRender } from '../../../../../../testUtils/superRender'; import { AuditTaskResData, WorkflowTasksItemData, - WorkflowsOverviewListData, - workflowsDetailData + WorkflowsOverviewListData } from '@actiontech/shared/lib/testUtil/mockApi/sqle/execWorkflow/data'; import { mockUseCurrentProject } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentProject'; import { WORKFLOW_OVERVIEW_TAB_KEY } from '../../../hooks/useAuditExecResultPanelSetup'; diff --git a/packages/sqle/src/page/SqlExecWorkflow/Detail/components/PageHeaderExtra/__test__/index.ce.test.tsx b/packages/sqle/src/page/SqlExecWorkflow/Detail/components/PageHeaderExtra/__test__/index.ce.test.tsx index c25bb1429..49d556441 100644 --- a/packages/sqle/src/page/SqlExecWorkflow/Detail/components/PageHeaderExtra/__test__/index.ce.test.tsx +++ b/packages/sqle/src/page/SqlExecWorkflow/Detail/components/PageHeaderExtra/__test__/index.ce.test.tsx @@ -9,7 +9,6 @@ import { WorkflowRecordResV2StatusEnum, WorkflowStepResV2TypeEnum } from '@actiontech/shared/lib/api/sqle/service/common.enum'; -import { mockUseCurrentProject } from '@actiontech/shared/lib/testUtil/mockHook/mockUseCurrentProject'; import { mockUsePermission } from '@actiontech/shared/lib/testUtil/mockHook/mockUsePermission'; import MockDate from 'mockdate'; diff --git a/packages/sqle/src/page/SqlExecWorkflow/Detail/components/SqlRollback/__tests__/index.test.tsx b/packages/sqle/src/page/SqlExecWorkflow/Detail/components/SqlRollback/__tests__/index.test.tsx index 1ab893acc..dc3343d7d 100644 --- a/packages/sqle/src/page/SqlExecWorkflow/Detail/components/SqlRollback/__tests__/index.test.tsx +++ b/packages/sqle/src/page/SqlExecWorkflow/Detail/components/SqlRollback/__tests__/index.test.tsx @@ -135,7 +135,7 @@ describe('sqle/ExecWorkflow/Detail/SqlRollback', () => { }); it('render navigate to create workflow', async () => { - const { baseElement } = customRender(); + customRender(); await act(async () => jest.advanceTimersByTime(3000)); const createWorkflowBtn = screen.getByText('创建工单').closest('button'); expect(createWorkflowBtn).toBeDisabled(); diff --git a/packages/sqle/src/page/SqlExecWorkflow/List/__tests__/__snapshots__/index.test.tsx.snap b/packages/sqle/src/page/SqlExecWorkflow/List/__tests__/__snapshots__/index.test.tsx.snap index e815d9364..abf1296a5 100644 --- a/packages/sqle/src/page/SqlExecWorkflow/List/__tests__/__snapshots__/index.test.tsx.snap +++ b/packages/sqle/src/page/SqlExecWorkflow/List/__tests__/__snapshots__/index.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`sqle/Workflow/List render click batch cancel btn when has not closed 1`] = ` +exports[`sqle/Workflow/List render btn batchCancel when is not Admin 1`] = `
@@ -683,110 +684,23 @@ exports[`sqle/Workflow/List render click batch cancel btn when has not closed 1
- name1 + mysql-1_20240105013651
-
- desc demo -
- - - -
- - -
+ - -
-
- - v1-test - -
-
+ - - - + 2024-01-05 13:36:57 + > +
+
+ + + T + + +
+
+
+
+ + + A + + +
+
+
@@ -878,88 +829,13 @@ exports[`sqle/Workflow/List render click batch cancel btn when has not closed 1
- name2 + mysql-1_20240105013149
-
- desc demo2 -
- - - -
- - -
+ - - - + 2024-01-05 13:32:02 admin - test + - 待审核 + 上线成功 + > + - +