mirror of
https://github.com/n8n-io/n8n.git
synced 2026-05-12 16:10:30 +02:00
test: Enhance test discovery to support dynamic titles (#28782)
This commit is contained in:
parent
b9c4618270
commit
c8bdd26100
|
|
@ -69,6 +69,21 @@ describe('TestDiscoveryAnalyzer', () => {
|
|||
|
||||
expect(report.specs.map((s) => s.path)).toEqual(['tests/a.spec.ts', 'tests/b.spec.ts']);
|
||||
});
|
||||
|
||||
it('discovers tests whose titles are template literals with substitutions', () => {
|
||||
const file = createFile(
|
||||
'tests/dynamic.spec.ts',
|
||||
`
|
||||
for (const path of ['a', 'b']) {
|
||||
test(\`handles \${path}\`, async () => {});
|
||||
}
|
||||
`,
|
||||
);
|
||||
const report = discoverWith([file]);
|
||||
|
||||
expect(report.specs).toHaveLength(1);
|
||||
expect(report.specs[0].path).toBe('tests/dynamic.spec.ts');
|
||||
});
|
||||
});
|
||||
|
||||
describe('skip and fixme detection', () => {
|
||||
|
|
|
|||
|
|
@ -199,7 +199,10 @@ export class TestDiscoveryAnalyzer {
|
|||
|
||||
/**
|
||||
* Extract the title string from the first argument of a test/describe call.
|
||||
* Returns null for calls without a string title (e.g., test.fixme() with no args).
|
||||
* Returns null for calls without a title argument (e.g., test.fixme() with no args).
|
||||
* Dynamic titles (template literals with substitutions, concatenation, identifiers)
|
||||
* return the raw source text so the call still counts as a real test and tags inside
|
||||
* the static portions can be extracted.
|
||||
*/
|
||||
private extractTitle(call: CallExpression): string | null {
|
||||
const args = call.getArguments();
|
||||
|
|
@ -207,14 +210,13 @@ export class TestDiscoveryAnalyzer {
|
|||
|
||||
const firstArg = args[0];
|
||||
|
||||
// Handle string literals: 'title', "title", `title`
|
||||
const asString = firstArg.asKind(SyntaxKind.StringLiteral);
|
||||
if (asString) return asString.getLiteralText();
|
||||
|
||||
const asTemplate = firstArg.asKind(SyntaxKind.NoSubstitutionTemplateLiteral);
|
||||
if (asTemplate) return asTemplate.getLiteralText();
|
||||
|
||||
return null;
|
||||
return firstArg.getText();
|
||||
}
|
||||
|
||||
private parseTags(title: string): string[] {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ test.describe(
|
|||
];
|
||||
|
||||
const expectedCSP =
|
||||
'sandbox allow-downloads allow-forms allow-modals allow-orientation-lock allow-pointer-lock allow-popups allow-presentation allow-scripts allow-top-navigation-by-user-activation allow-top-navigation-to-custom-protocols';
|
||||
'sandbox allow-downloads allow-forms allow-modals allow-orientation-lock allow-pointer-lock allow-popups allow-popups-to-escape-sandbox allow-presentation allow-scripts allow-top-navigation-by-user-activation allow-top-navigation-to-custom-protocols';
|
||||
|
||||
for (const webhookPath of webhookPaths) {
|
||||
test(`Webhook responses should include the correct response headers for ${webhookPath}`, async ({
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user