diff --git a/CHANGELOG.md b/CHANGELOG.md index 51c7d655bf..2866703f24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -471,6 +471,7 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - A file in a `unittests/` folder, where llvm/llvm-project and google/breakpad keep their unit tests, or in a folder named like a unittest, such as `dcheck_unittest/` in google/glog, now counts as a test whatever its own name says, like LLVM's `CountCopyAndMove.h` helper. Before, such a file was taken for production code unless its name said test, and none of them were kept apart from the program the way a `tests/` folder is: search and `codegraph_explore` ranked them alongside production code, `codegraph affected` missed them, and production code linked to a unit test's own declarations, as LLVM's `Ctx` and `OpInfo` variables did to ones its unit tests declare. A folder named just `unittest/`, like CPython's `Lib/unittest/`, is still production code. Re-index projects that have such folders after upgrading. - `codegraph_explore` now leaves out of its answers every file that search already treats as a test or an example: a C++ `FooTest.cpp` or `foo_test.cc`, a Google `foo_unittest.cc`, anything in an LLVM-style `unittests/` folder or an `e2e/` or `testing/` folder, and a project's `examples/`, `samples/` and `benchmarks/`. Before, explore went by a shorter list of its own, so a unit test or an example that called the code you asked about could take a place in the answer meant for that code: in protocolbuffers/protobuf, a question about `DescriptorPool` came back with three of its unit tests. The same files are no longer taken for a project's main routes file either, such as an end-to-end suite's mock server. No re-index is needed. +- A `__tests__/` folder at the top of a repository now counts as a test, as one below `src/` or any other folder already did. Before, a file like `__tests__/foo.ts` was taken for production code: search and `codegraph_explore` ranked it alongside production code, and it could be taken for a project's main routes file. Re-index projects with a top-level `__tests__/` folder after upgrading. - `codegraph sync` and the file watcher now link a file to a module it imports under a name of its own when the module is added after the file was indexed, comes back after being deleted, or gets the export in a later edit: a default import like `import tagsController from './tag/tag.controller'`, a namespace import like `import * as api from './api'`, or an aliased one like `import { Component as GroupsPageWrapper } from './groups_page'`, in JavaScript, TypeScript, Vue, Svelte and Astro. Before, the import and every use of the name, such as a call, `new`, a base class, a JSX or template tag or an Express `app.use` mount, stayed unlinked until the importing file changed or the project was re-indexed, so the module looked unused and `codegraph affected` missed the files that use it. Re-index after upgrading to pick up links an earlier version missed. - `codegraph sync` and the file watcher now do the same for a Python import under a name of its own, like `from .models import User as UserModel`, `from . import helpers as h` or `from app.pkg import sub as subpkg`: when the module or package is added after the importing file was indexed, comes back after being deleted, or gets the imported name in a later edit, the import and every use of the alias, such as a call, a base class or the class passed as a value, now link to it. Before, they stayed unlinked until the importing file changed or the project was re-indexed. Re-index Python projects after upgrading to pick up links an earlier version missed. - `codegraph sync` and the file watcher now also link a Python import of a name a package re-exports, like `from fastapi import FastAPI` through `fastapi/__init__.py`, when that `__init__.py` is added after the importing files were indexed or gains the re-export in a later edit. Before, calls through the name stayed unlinked until each importing file changed or the project was re-indexed. Large projects gain the most: sync also used to skip, in any language, a module or package that more than 500 references were waiting for, and now restoring Django's `django/urls/__init__.py` relinks every file that imports `path` from it. Re-index Python projects after upgrading to pick up links an earlier version missed. diff --git a/__tests__/is-test-file.test.ts b/__tests__/is-test-file.test.ts index 282bcf27cb..f3e5fde140 100644 --- a/__tests__/is-test-file.test.ts +++ b/__tests__/is-test-file.test.ts @@ -56,6 +56,14 @@ describe('isTestFile', () => { expect(isTestFile('project/tests/foo.rb')).toBe(true); }); + it('flags a repo-relative __tests__/ directory at the root, as it does one below src/', () => { + expect(isTestFile('__tests__/foo.ts')).toBe(true); + expect(isTestPath('__tests__/foo.ts')).toBe(true); + expect(isTestFile('src/__tests__/foo.ts')).toBe(true); + // (A directory that only ends in the name is no test directory.) + expect(isTestFile('my__tests__/foo.ts')).toBe(false); + }); + it("flags Google's unittest-named files as tests", () => { // protobuf's 62 and Chromium's: `wire_format_unittest.cc` is a suite, not // the code it tests, even with no `test/` directory above it. diff --git a/src/search/query-utils.ts b/src/search/query-utils.ts index bc2a6482b4..a3bf02d71a 100644 --- a/src/search/query-utils.ts +++ b/src/search/query-utils.ts @@ -337,7 +337,7 @@ export function isTestPath(filePath: string): boolean { lower.includes('/testing/') || lower.includes('/e2e/') || lower.startsWith('test/') || lower.startsWith('tests/') || lower.startsWith('spec/') || lower.startsWith('specs/') || - lower.startsWith('e2e/') || + lower.startsWith('e2e/') || lower.startsWith('__tests__/') || // CamelCase test source-set dirs (Kotlin Multiplatform / Gradle / Xcode): // jvmTest/, commonTest/, androidTest/, iosTest/, integrationTest/. Capital-led // so "latest/" / "manifest/" are not matched.