Skip to content

Conversation

@alumni
Copy link
Collaborator

@alumni alumni commented Nov 24, 2025

Description of change

Enforce all test files to have the .test.ts extension, so that they are better separated from other files in the test folder. This will allow our test runner (currently mocha) to search for less files. This is also a prerequisite to replacing mocha with e.g. vitest in the future, as other test runners will complain about test files that don't contain tests.

I will update the PR if we decide for .spec.ts instead of .test.ts. Please check the poll in our technical discussion channel.

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • This pull request links relevant issues as Fixes #00000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change

@alumni alumni force-pushed the refactor/rename-tests branch 2 times, most recently from f8fab92 to 46de81b Compare November 24, 2025 21:20
@alumni alumni marked this pull request as ready for review November 24, 2025 23:19
@qodo-free-for-open-source-projects

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Import Change

The import of BaseEntity was changed from ../../../src to ./entity/BaseEntity. This could be a breaking change if BaseEntity in the local entity folder is different from the one in the src folder. Verify that the correct BaseEntity is being imported and that tests still pass.

import { BaseEntity } from "./entity/BaseEntity"
Test Scope Reduction

The addition of enabledDrivers: ["postgres"] restricts this benchmark test to only run on PostgreSQL. Verify this is intentional and that the benchmark is not meant to test performance across multiple database drivers.

    enabledDrivers: ["postgres"],
})
Coverage Config Change

Removed node_modules from the exclude list. While node_modules is typically excluded by default in most coverage tools, verify that this removal doesn't cause coverage reports to include node_modules files, which could slow down coverage generation.

"exclude": ["**/*.d.ts"],
"exclude-after-remap": true,

@qodo-free-for-open-source-projects
Copy link

qodo-free-for-open-source-projects bot commented Nov 24, 2025

PR Code Suggestions ✨

Latest suggestions up to acedb7d

CategorySuggestion                                                                                                                                    Impact
General
Verify intentional database driver restriction

Verify that restricting the benchmark test to only the postgres driver is
intentional, as it may reduce test coverage.

test/benchmark/bulk-sql-build/bulk-sql-build.test.ts [13-16]

 dataSources = await createTestingConnections({
     __dirname,
-    enabledDrivers: ["postgres"],
 })
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies that the test is now limited to a single database driver and asks for verification, which is a valid and important check to prevent accidental reduction of test coverage.

Medium
Remove TypeScript extension from test pattern

Update the spec pattern in .mocharc.json to only include .js files, as Mocha
runs on compiled JavaScript, not TypeScript source files.

.mocharc.json [8]

-"spec": ["./build/compiled/test/**/*.test.{js,ts}"],
+"spec": ["./build/compiled/test/**/*.test.js"],
  • Apply / Chat
Suggestion importance[1-10]: 5

__

Why: The suggestion correctly points out that the test spec pattern for compiled files should not include .ts files, improving the configuration's accuracy.

Low
  • More

Previous suggestions

Suggestions up to commit 30bf024
CategorySuggestion                                                                                                                                    Impact
Possible issue
Remove TypeScript from test pattern

In .mocharc.json, update the spec pattern to only include .js files, as tests
are run on compiled JavaScript, not TypeScript source files.

.mocharc.json [8]

-"spec": ["./build/compiled/test/**/*.test.{js,ts}"],
+"spec": ["./build/compiled/test/**/*.test.js"],
Suggestion importance[1-10]: 4

__

Why: The suggestion correctly points out that test files are compiled to JavaScript, so the .ts extension in the spec pattern is unnecessary and potentially confusing.

Low
Suggestions up to commit 46de81b
CategorySuggestion                                                                                                                                    Impact
General
Extract shared constants to a file

To improve maintainability, move the shared constants testTableName,
testColumnName, and nonExistentColumnName to a new dedicated file like
constants.ts and import them where needed.

test/github-issues/6195/migrations/MigrationToFakeRun.ts [3-5]

 import { MigrationInterface, QueryRunner, TableColumn } from "../../../../src"
-
-export const testTableName = "test_table"
-export const testColumnName = "test_column"
-export const nonExistentColumnName = "nonexistent_column"
+import { testTableName, testColumnName } from "../constants"
 
 export class MigrationToFakeRun implements MigrationInterface {
     name = "MigrationToFakeRun" + Date.now()
 
     public async up(queryRunner: QueryRunner): Promise<any> {
         await queryRunner.addColumn(
             testTableName,
             new TableColumn({
                 name: testColumnName,
                 type: "varchar",
             }),
         )
     }
 
     public async down(queryRunner: QueryRunner): Promise<any> {
         await queryRunner.dropColumn(testTableName, testColumnName)
     }
 }
Suggestion importance[1-10]: 2

__

Why: The PR already centralizes the constants in MigrationToFakeRun.ts. Creating a separate constants file is a minor architectural preference with little impact.

Low

@@ -10,7 +10,8 @@ import { ViewA } from "./entity/ViewA"
import { ViewB } from "./entity/ViewB"
import { TestEntity } from "./entity/Test"

describe("views dependencies", () => {
// TODO: Implement topological sorting for view dependencies https://github.com/typeorm/typeorm/issues/8240
describe.skip("views dependencies", () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this test started to fail after this change, and for very good reason: this feature was not implemented correctly.

Since the purpose of this PR is to simply fix the file names, I will leave the feature to be fixed separately.

Copy link
Collaborator

@OSA413 OSA413 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you use some tool to rename the files?

@@ -1,10 +1,10 @@
{
"__comment": "TODO: remove --exit flag: https://mochajs.org/#-exit",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to document the current use of the exit flag?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, we could change the file format to jsonc for comments, but then we'd have to adjust the lintstaged config to handle that too.

Maybe the comment is not really needed, and since we were anyway discussing to move to something else (vitest was one of the proposal), probably this file won't exist for too long.

I was hoping the json schema for mocha has documentation (it doesn't), but honestly, seeing the commit message from your PR was more helpful why we added the option than the documentation/comment.

@alumni
Copy link
Collaborator Author

alumni commented Nov 25, 2025

Yes, grep and a one-line while loop :)

I noticed some files are named bla-bla-test.test.ts, that's because they were named bla-bla-test.ts before. I'll adjust them.

Will change test.ts to spec.ts if the popular vote goes that way.

If we pick the BDD style (or not), we could also ask for new tests to be in the Given-When-Then (aka Arrange-Act-Assert). Existing tests don't necessarily follow the format.

@alumni alumni force-pushed the refactor/rename-tests branch 2 times, most recently from 30bf024 to 95e668f Compare November 29, 2025 11:12
@qodo-free-for-open-source-projects

PR Code Suggestions ✨

No code suggestions found for the PR.

@alumni alumni requested a review from gioboa November 30, 2025 19:25
Copy link
Collaborator

@gioboa gioboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great 👍

@alumni alumni force-pushed the refactor/rename-tests branch from 95e668f to acedb7d Compare November 30, 2025 19:36
@alumni alumni force-pushed the refactor/rename-tests branch from acedb7d to 55dbffb Compare November 30, 2025 20:11
@qodo-free-for-open-source-projects

PR Code Suggestions ✨

No code suggestions found for the PR.

@alumni alumni merged commit c4f5d12 into typeorm:master Nov 30, 2025
61 checks passed
ThbltLmr pushed a commit to ThbltLmr/typeorm that referenced this pull request Dec 2, 2025
mgohin pushed a commit to mgohin/typeorm that referenced this pull request Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants