Skip to content

[test optimization] Fix cypress report of typescript test files#7680

Merged
juan-fernandez merged 8 commits intomasterfrom
juan-fernandez/cypress-typescript-source-line
Mar 9, 2026
Merged

[test optimization] Fix cypress report of typescript test files#7680
juan-fernandez merged 8 commits intomasterfrom
juan-fernandez/cypress-typescript-source-line

Conversation

@juan-fernandez
Copy link
Copy Markdown
Collaborator

@juan-fernandez juan-fernandez commented Mar 5, 2026

What does this PR do?

Improves Cypress test source-line resolution by making the fallback algorithm explicit and more robust:

  • Keeps invocationDetails.line for plain JS specs without source maps.
  • For mapped/transformed specs, tries stack-based source-map resolution first.
  • Falls back to declaration-name scanning (it/test/specify) and source-map mapping.
  • Keeps original invocationDetails.line if no resolution path succeeds.

Also updates comments/docs around this flow and adds deterministic regression coverage for the stack-resolution branch in integration-tests/cypress/cypress.spec.js.

Motivation

Pre-compiled/bundled TypeScript specs can report bundle-context lines in invocationDetails.line. We need better source-line recovery while preserving fast-path behavior for plain JS and avoiding regressions in edge cases where mapping is unavailable.

Additional Notes

  • Full Cypress integration coverage for the stack-resolution branch is not reliably reproducible end-to-end; a deterministic non-sandbox test was added in cypress.spec.js to cover that branch.
  • Existing targeted Cypress integration source-line tests continue to pass.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.35%. Comparing base (34bf8e5) to head (08b42ce).
⚠️ Report is 35 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7680      +/-   ##
==========================================
+ Coverage   80.30%   80.35%   +0.05%     
==========================================
  Files         739      741       +2     
  Lines       31926    32004      +78     
==========================================
+ Hits        25638    25718      +80     
+ Misses       6288     6286       -2     
Flag Coverage Δ
aiguard-macos 39.01% <ø> (-0.03%) ⬇️
aiguard-ubuntu 39.13% <ø> (-0.03%) ⬇️
aiguard-windows 38.85% <ø> (?)
apm-capabilities-tracing-macos 48.73% <ø> (-0.06%) ⬇️
apm-capabilities-tracing-ubuntu 48.81% <ø> (-0.01%) ⬇️
apm-capabilities-tracing-windows 48.55% <ø> (-0.02%) ⬇️
apm-integrations-child-process 38.56% <ø> (-0.05%) ⬇️
apm-integrations-couchbase-18 37.47% <ø> (+0.07%) ⬆️
apm-integrations-couchbase-eol 37.80% <ø> (-0.22%) ⬇️
apm-integrations-oracledb 37.78% <ø> (-0.07%) ⬇️
appsec-express 55.30% <ø> (-0.14%) ⬇️
appsec-fastify 51.63% <ø> (-0.12%) ⬇️
appsec-graphql 51.81% <ø> (-0.12%) ⬇️
appsec-kafka 44.33% <ø> (-0.09%) ⬇️
appsec-ldapjs 44.03% <ø> (-0.09%) ⬇️
appsec-lodash 43.68% <ø> (-0.09%) ⬇️
appsec-macos 58.30% <ø> (-0.13%) ⬇️
appsec-mongodb-core 48.82% <ø> (-0.11%) ⬇️
appsec-mongoose 49.49% <ø> (-0.12%) ⬇️
appsec-mysql 50.87% <ø> (-0.10%) ⬇️
appsec-node-serialize 43.20% <ø> (-0.09%) ⬇️
appsec-passport 47.63% <ø> (-0.12%) ⬇️
appsec-postgres 50.63% <ø> (-0.09%) ⬇️
appsec-sourcing 42.61% <ø> (-0.08%) ⬇️
appsec-template 43.37% <ø> (-0.09%) ⬇️
appsec-ubuntu 58.37% <ø> (-0.13%) ⬇️
appsec-windows 58.13% <ø> (-0.15%) ⬇️
instrumentations-instrumentation-bluebird 32.39% <ø> (-0.03%) ⬇️
instrumentations-instrumentation-body-parser 40.50% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-child_process 37.87% <ø> (-0.07%) ⬇️
instrumentations-instrumentation-cookie-parser 34.37% <ø> (-0.04%) ⬇️
instrumentations-instrumentation-express 34.69% <ø> (-0.05%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 34.50% <ø> (-0.04%) ⬇️
instrumentations-instrumentation-express-session 40.14% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-fs 32.00% <ø> (-0.03%) ⬇️
instrumentations-instrumentation-generic-pool 29.91% <ø> (+0.16%) ⬆️
instrumentations-instrumentation-http 39.86% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-knex 32.39% <ø> (-0.03%) ⬇️
instrumentations-instrumentation-mongoose 33.52% <ø> (-0.03%) ⬇️
instrumentations-instrumentation-multer 40.25% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-mysql2 38.34% <ø> (-0.07%) ⬇️
instrumentations-instrumentation-passport 44.01% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-passport-http 43.69% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-passport-local 44.22% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-pg 37.77% <ø> (-0.07%) ⬇️
instrumentations-instrumentation-promise 32.32% <ø> (-0.03%) ⬇️
instrumentations-instrumentation-promise-js 32.33% <ø> (-0.03%) ⬇️
instrumentations-instrumentation-q 32.37% <ø> (-0.03%) ⬇️
instrumentations-instrumentation-url 32.29% <ø> (-0.03%) ⬇️
instrumentations-instrumentation-when 32.34% <ø> (-0.03%) ⬇️
llmobs-ai 42.34% <ø> (+0.28%) ⬆️
llmobs-anthropic 40.31% <ø> (-0.09%) ⬇️
llmobs-bedrock 39.27% <ø> (-0.06%) ⬇️
llmobs-google-genai 39.84% <ø> (-0.01%) ⬇️
llmobs-langchain 40.07% <ø> (+0.23%) ⬆️
llmobs-openai 44.06% <ø> (-0.18%) ⬇️
llmobs-vertex-ai 40.03% <ø> (-0.08%) ⬇️
platform-core 31.53% <ø> (ø)
platform-esbuild 34.48% <ø> (ø)
platform-instrumentations-misc 48.40% <ø> (+4.40%) ⬆️
platform-shimmer 37.63% <ø> (ø)
platform-unit-guardrails 32.95% <ø> (ø)
plugins-azure-event-hubs 25.83% <ø> (ø)
plugins-azure-service-bus 25.19% <ø> (ø)
plugins-bullmq 44.27% <ø> (+0.37%) ⬆️
plugins-cassandra 37.81% <ø> (-0.07%) ⬇️
plugins-cookie 26.89% <ø> (ø)
plugins-cookie-parser 26.67% <ø> (ø)
plugins-crypto 26.79% <ø> (ø)
plugins-dd-trace-api 38.39% <ø> (-0.08%) ⬇️
plugins-express-mongo-sanitize 26.82% <ø> (ø)
plugins-express-session 26.63% <ø> (ø)
plugins-fastify 42.23% <ø> (-0.10%) ⬇️
plugins-fetch 38.38% <ø> (-0.05%) ⬇️
plugins-fs 38.67% <ø> (-0.05%) ⬇️
plugins-generic-pool 25.87% <ø> (ø)
plugins-google-cloud-pubsub 45.37% <ø> (-0.09%) ⬇️
plugins-grpc 40.94% <ø> (-0.09%) ⬇️
plugins-handlebars 26.86% <ø> (ø)
plugins-hapi 40.14% <ø> (-0.09%) ⬇️
plugins-hono 40.40% <ø> (-0.09%) ⬇️
plugins-ioredis 38.47% <ø> (-0.05%) ⬇️
plugins-knex 26.50% <ø> (ø)
plugins-ldapjs 24.36% <ø> (ø)
plugins-light-my-request 26.23% <ø> (ø)
plugins-limitd-client 32.52% <ø> (-0.19%) ⬇️
plugins-lodash 25.96% <ø> (ø)
plugins-mariadb 39.53% <ø> (-0.06%) ⬇️
plugins-memcached 38.19% <ø> (-0.08%) ⬇️
plugins-microgateway-core 39.19% <ø> (-0.08%) ⬇️
plugins-moleculer 40.54% <ø> (-0.06%) ⬇️
plugins-mongodb 39.21% <ø> (-0.08%) ⬇️
plugins-mongodb-core 39.08% <ø> (-0.06%) ⬇️
plugins-mongoose 38.90% <ø> (-0.05%) ⬇️
plugins-multer 26.63% <ø> (ø)
plugins-mysql 39.21% <ø> (-0.06%) ⬇️
plugins-mysql2 39.31% <ø> (-0.06%) ⬇️
plugins-node-serialize 26.93% <ø> (ø)
plugins-opensearch 37.65% <ø> (-0.07%) ⬇️
plugins-passport-http 26.68% <ø> (ø)
plugins-postgres 35.75% <ø> (-0.05%) ⬇️
plugins-process 26.79% <ø> (ø)
plugins-pug 26.89% <ø> (ø)
plugins-redis 38.94% <ø> (-0.06%) ⬇️
plugins-router 42.95% <ø> (-0.11%) ⬇️
plugins-sequelize 25.47% <ø> (ø)
plugins-test-and-upstream-amqp10 38.51% <ø> (-0.08%) ⬇️
plugins-test-and-upstream-amqplib 43.83% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-apollo 39.04% <ø> (-0.08%) ⬇️
plugins-test-and-upstream-avsc 38.73% <ø> (-0.08%) ⬇️
plugins-test-and-upstream-bunyan 33.94% <ø> (-0.05%) ⬇️
plugins-test-and-upstream-connect 40.79% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-graphql 40.17% <ø> (-0.06%) ⬇️
plugins-test-and-upstream-koa 40.38% <ø> (-0.23%) ⬇️
plugins-test-and-upstream-protobufjs 38.95% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-rhea 44.03% <ø> (-0.09%) ⬇️
plugins-undici 39.15% <ø> (-0.05%) ⬇️
plugins-url 26.79% <ø> (ø)
plugins-valkey 38.14% <ø> (-0.05%) ⬇️
plugins-vm 26.79% <ø> (ø)
plugins-winston 34.13% <ø> (-0.05%) ⬇️
plugins-ws 41.90% <ø> (-0.07%) ⬇️
profiling-macos 39.84% <ø> (-0.09%) ⬇️
profiling-ubuntu 39.97% <ø> (-0.09%) ⬇️
profiling-windows 41.16% <ø> (-0.11%) ⬇️
serverless-azure-functions-client 25.54% <ø> (ø)
serverless-azure-functions-eventhubs 25.54% <ø> (ø)
serverless-azure-functions-servicebus 25.54% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 5, 2026

Overall package size

Self size: 4.94 MB
Deduped: 5.78 MB
No deduping: 5.78 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.0 | 81.15 kB | 815.98 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@datadog-official

This comment has been minimized.

@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Mar 5, 2026

Benchmarks

Benchmark execution time: 2026-03-09 12:22:20

Comparing candidate commit 08b42ce in PR branch juan-fernandez/cypress-typescript-source-line with baseline commit 34bf8e5 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 232 metrics, 28 unstable metrics.

@juan-fernandez juan-fernandez force-pushed the juan-fernandez/cypress-typescript-source-line branch 3 times, most recently from b187876 to 80c22b1 Compare March 5, 2026 10:58
…e-compiled specs

When users pre-compile TypeScript spec files to JavaScript before running
Cypress, TEST_SOURCE_FILE pointed to the compiled .js file instead of the
original .ts file, and TEST_SOURCE_START reflected the webpack bundle line
number rather than the TypeScript source line.

This fix reads the adjacent .js.map source map synchronously using a custom
VLQ decoder (no external dependencies), resolves the original TypeScript file
path for TEST_SOURCE_FILE, and scans the compiled JS to find the test's actual
line before mapping it through the source map for TEST_SOURCE_START.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@juan-fernandez juan-fernandez force-pushed the juan-fernandez/cypress-typescript-source-line branch from 80c22b1 to c573208 Compare March 5, 2026 11:16
juan-fernandez and others added 3 commits March 6, 2026 10:46
…y match

Extend source line resolution in resolveSourceLineForTest to cover
template literal test names (e.g. specify(`title ${VAR} end`, ...))
where the test name Cypress reports has the variables already evaluated
('title value end') and the source contains ${expr} placeholders.

- Add templateBodyToRegExp: converts ${expr} → .*? wildcard regex so the
  evaluated test name can be matched against the source template literal
- Add Step 2b in resolveSourceLineForTest: scans the spec file for
  it/test/specify calls with backtick strings and fuzzy-matches against
  the runtime test name, then maps via source map as usual
- Add readSourceMap/resolveSourcePath helpers: support inline data: URI
  source maps and webpack:// virtual paths in addition to adjacent .map files
- Add specify() with template literal to spec-source-line.cy.ts fixture
  and extend integration tests to assert TEST_SOURCE_START=16 and
  TEST_SOURCE_FILE points to the TypeScript source for both it() and specify()
- Remove DD_CYPRESS_PASSTHROUGH_PRECOMPILED_SPEC env var and the
  associated getPassThroughPreprocessor() method: no bundler-specific
  preprocessor needed since the name scan + source map approach works
  regardless of which bundler Cypress uses

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@juan-fernandez juan-fernandez marked this pull request as ready for review March 9, 2026 12:29
@juan-fernandez juan-fernandez requested a review from a team as a code owner March 9, 2026 12:29
@juan-fernandez juan-fernandez merged commit f49fafe into master Mar 9, 2026
844 of 846 checks passed
@juan-fernandez juan-fernandez deleted the juan-fernandez/cypress-typescript-source-line branch March 9, 2026 13:56
@dd-octo-sts dd-octo-sts bot mentioned this pull request Mar 10, 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.

2 participants