-
Notifications
You must be signed in to change notification settings - Fork 643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: replace hardcoded entry list with dynamically created one #6491
base: main
Are you sure you want to change the base?
fix: replace hardcoded entry list with dynamically created one #6491
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6491 +/- ##
=======================================
Coverage 95.30% 95.30%
=======================================
Files 575 575
Lines 43279 43283 +4
Branches 6467 6467
=======================================
+ Hits 41247 41251 +4
Misses 1993 1993
Partials 39 39 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nits. This could be a little over-engineered and contains other changes that don't pertain to the main objective of the PR.
export function isTestFile(filePath: string): boolean { | ||
if (!filePath.endsWith("test.ts")) return false; | ||
const source = Deno.readTextFileSync(filePath); | ||
const sourceFile = ts.createSourceFile( | ||
filePath, | ||
source, | ||
ts.ScriptTarget.Latest, | ||
); | ||
|
||
let result = true; | ||
|
||
function visitNode(node: ts.Node) { | ||
if (!result) return; | ||
if ( | ||
ts.isExportSpecifier(node) || | ||
ts.isExportAssignment(node) || | ||
ts.isExportDeclaration(node) || | ||
node.kind === ts.SyntaxKind.ExportKeyword | ||
) { | ||
result = false; | ||
} else { | ||
ts.forEachChild(node, visitNode); | ||
} | ||
} | ||
|
||
visitNode(sourceFile); | ||
return result; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems extraneous. What about this?
export function isTestFile(filePath: string): boolean {
return filePath.endsWith("test.ts");
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole point of this function is to distinguish between test.ts
which is used for testing (calling Deno.test()
) and test.ts
which is part of an api (like in @std/front-matter/test
. This cannot be done by filename alone. I figured the best way was to check whether the file has exports or not, if so it must be part of an api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe Deno.readTextFileSync(filePath).includes("\nDeno.test")
would suffice? (leading \n
ensures it's at the beginning of the line)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could lead to unintentional behaviour if Deno.test
was wrapped in a function and therefore not at the beginning of the line (for example jsonc/testdata/JSONTestSuite/test.ts
).
Also leads to unintentional behaviour when mentioned in a comment with unlucky line breaks:
/* bla bla bla...
Deno.test bla bla bla...
bla bla bla... */
So while this might work sometimes, it is not very robust.
Co-authored-by: Asher Gomez <[email protected]>
This PR removes the hardcoded entry list. Apparently some files were accidentally excluded by not updating the list.