@depup/dd-trace 5.96.0-depup.0 → 6.4.0-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-3rdparty.csv +89 -104
- package/README.md +9 -3
- package/changes.json +8 -3
- package/ci/init.js +25 -5
- package/ci/vitest-no-worker-init-setup.mjs +430 -0
- package/ext/exporters.js +1 -0
- package/ext/tags.js +3 -0
- package/index.d.ts +349 -244
- package/index.electron.js +3 -0
- package/initialize.mjs +9 -8
- package/loader-hook.mjs +154 -47
- package/package.json +121 -79
- package/packages/datadog-core/src/storage.js +47 -48
- package/packages/datadog-esbuild/index.js +52 -10
- package/packages/datadog-esbuild/src/utils.js +46 -3
- package/packages/datadog-instrumentations/src/aerospike.js +3 -3
- package/packages/datadog-instrumentations/src/ai.js +131 -76
- package/packages/datadog-instrumentations/src/amqplib.js +6 -7
- package/packages/datadog-instrumentations/src/anthropic.js +10 -10
- package/packages/datadog-instrumentations/src/apollo-server-core.js +3 -3
- package/packages/datadog-instrumentations/src/apollo-server.js +10 -18
- package/packages/datadog-instrumentations/src/avsc.js +6 -6
- package/packages/datadog-instrumentations/src/aws-durable-execution-sdk-js-context-methods.js +18 -0
- package/packages/datadog-instrumentations/src/aws-durable-execution-sdk-js.js +111 -0
- package/packages/datadog-instrumentations/src/aws-sdk.js +172 -72
- package/packages/datadog-instrumentations/src/azure-cosmos.js +7 -0
- package/packages/datadog-instrumentations/src/azure-durable-functions.js +8 -8
- package/packages/datadog-instrumentations/src/azure-functions.js +3 -0
- package/packages/datadog-instrumentations/src/bluebird.js +2 -2
- package/packages/datadog-instrumentations/src/body-parser.js +5 -2
- package/packages/datadog-instrumentations/src/cassandra-driver.js +12 -9
- package/packages/datadog-instrumentations/src/child_process.js +22 -32
- package/packages/datadog-instrumentations/src/claude-agent-sdk.js +587 -0
- package/packages/datadog-instrumentations/src/confluentinc-kafka-javascript.js +41 -24
- package/packages/datadog-instrumentations/src/connect.js +14 -12
- package/packages/datadog-instrumentations/src/cookie-parser.js +5 -4
- package/packages/datadog-instrumentations/src/cookie.js +9 -3
- package/packages/datadog-instrumentations/src/couchbase.js +73 -238
- package/packages/datadog-instrumentations/src/crypto.js +50 -6
- package/packages/datadog-instrumentations/src/cucumber-worker-threads.js +19 -0
- package/packages/datadog-instrumentations/src/cucumber.js +751 -188
- package/packages/datadog-instrumentations/src/cypress-config.js +432 -0
- package/packages/datadog-instrumentations/src/cypress.js +88 -4
- package/packages/datadog-instrumentations/src/dns.js +61 -61
- package/packages/datadog-instrumentations/src/elasticsearch.js +9 -12
- package/packages/datadog-instrumentations/src/electron/preload.js +42 -0
- package/packages/datadog-instrumentations/src/electron.js +240 -0
- package/packages/datadog-instrumentations/src/express-mongo-sanitize.js +11 -9
- package/packages/datadog-instrumentations/src/express-session.js +14 -13
- package/packages/datadog-instrumentations/src/express.js +56 -34
- package/packages/datadog-instrumentations/src/fastify.js +169 -86
- package/packages/datadog-instrumentations/src/fetch.js +5 -5
- package/packages/datadog-instrumentations/src/fs.js +47 -47
- package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +5 -7
- package/packages/datadog-instrumentations/src/google-genai.js +4 -4
- package/packages/datadog-instrumentations/src/graphql.js +26 -362
- package/packages/datadog-instrumentations/src/grpc/client.js +48 -32
- package/packages/datadog-instrumentations/src/grpc/server.js +20 -2
- package/packages/datadog-instrumentations/src/hapi.js +2 -2
- package/packages/datadog-instrumentations/src/helpers/bundler-register.js +41 -13
- package/packages/datadog-instrumentations/src/helpers/callback-instrumentor.js +74 -0
- package/packages/datadog-instrumentations/src/helpers/check-require-cache.js +85 -9
- package/packages/datadog-instrumentations/src/helpers/hook.js +34 -6
- package/packages/datadog-instrumentations/src/helpers/hooks.js +24 -19
- package/packages/datadog-instrumentations/src/helpers/instrument.js +61 -14
- package/packages/datadog-instrumentations/src/helpers/kafka.js +58 -0
- package/packages/datadog-instrumentations/src/helpers/optional-peer-bundler.js +65 -0
- package/packages/datadog-instrumentations/src/helpers/promise-instrumentor.js +42 -0
- package/packages/datadog-instrumentations/src/helpers/promise.js +2 -2
- package/packages/datadog-instrumentations/src/helpers/register.js +109 -146
- package/packages/datadog-instrumentations/src/helpers/require-optional-peer.js +17 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/compiler.js +13 -5
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +24 -7
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/ai.js +6 -6
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/aws-durable-execution-sdk-js.js +31 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/azure-cosmos.js +50 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/claude-agent-sdk.js +17 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +201 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +7 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/langgraph.js +4 -2
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/mercurius.js +31 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-sdk.js +35 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/playwright.js +85 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/loader.mjs +18 -2
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +49 -224
- package/packages/datadog-instrumentations/src/helpers/router-helper.js +8 -8
- package/packages/datadog-instrumentations/src/hono.js +71 -9
- package/packages/datadog-instrumentations/src/http/client.js +50 -27
- package/packages/datadog-instrumentations/src/http/server.js +77 -34
- package/packages/datadog-instrumentations/src/http2/client.js +16 -15
- package/packages/datadog-instrumentations/src/http2/server.js +156 -25
- package/packages/datadog-instrumentations/src/ioredis.js +17 -14
- package/packages/datadog-instrumentations/src/iovalkey.js +1 -2
- package/packages/datadog-instrumentations/src/jest/bail-reporter.js +42 -0
- package/packages/datadog-instrumentations/src/jest/coverage-backfill.js +163 -0
- package/packages/datadog-instrumentations/src/jest.js +1795 -404
- package/packages/datadog-instrumentations/src/kafkajs.js +284 -170
- package/packages/datadog-instrumentations/src/knex.js +17 -17
- package/packages/datadog-instrumentations/src/koa.js +15 -14
- package/packages/datadog-instrumentations/src/ldapjs.js +5 -5
- package/packages/datadog-instrumentations/src/light-my-request.js +2 -2
- package/packages/datadog-instrumentations/src/limitd-client.js +5 -5
- package/packages/datadog-instrumentations/src/lodash.js +4 -4
- package/packages/datadog-instrumentations/src/mariadb.js +18 -16
- package/packages/datadog-instrumentations/src/memcached.js +4 -3
- package/packages/datadog-instrumentations/src/mercurius.js +11 -0
- package/packages/datadog-instrumentations/src/microgateway-core.js +2 -2
- package/packages/datadog-instrumentations/src/mocha/common.js +7 -4
- package/packages/datadog-instrumentations/src/mocha/main.js +557 -118
- package/packages/datadog-instrumentations/src/mocha/utils.js +531 -128
- package/packages/datadog-instrumentations/src/mocha/worker.js +27 -9
- package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +254 -0
- package/packages/datadog-instrumentations/src/mongodb-core.js +43 -31
- package/packages/datadog-instrumentations/src/mongodb.js +79 -5
- package/packages/datadog-instrumentations/src/mongoose.js +43 -34
- package/packages/datadog-instrumentations/src/mquery.js +5 -5
- package/packages/datadog-instrumentations/src/multer.js +5 -4
- package/packages/datadog-instrumentations/src/mysql.js +17 -17
- package/packages/datadog-instrumentations/src/mysql2.js +39 -5
- package/packages/datadog-instrumentations/src/nats.js +182 -0
- package/packages/datadog-instrumentations/src/net.js +21 -19
- package/packages/datadog-instrumentations/src/next.js +44 -10
- package/packages/datadog-instrumentations/src/nyc.js +43 -6
- package/packages/datadog-instrumentations/src/openai.js +124 -38
- package/packages/datadog-instrumentations/src/oracledb.js +12 -7
- package/packages/datadog-instrumentations/src/otel-sdk-trace.js +27 -6
- package/packages/datadog-instrumentations/src/passport-utils.js +5 -5
- package/packages/datadog-instrumentations/src/path-to-regexp.js +44 -0
- package/packages/datadog-instrumentations/src/pg.js +58 -25
- package/packages/datadog-instrumentations/src/pino.js +26 -42
- package/packages/datadog-instrumentations/src/playwright-browser-scripts.js +27 -0
- package/packages/datadog-instrumentations/src/playwright.js +1090 -351
- package/packages/datadog-instrumentations/src/prisma.js +1 -2
- package/packages/datadog-instrumentations/src/protobufjs.js +16 -16
- package/packages/datadog-instrumentations/src/redis.js +28 -15
- package/packages/datadog-instrumentations/src/restify.js +6 -5
- package/packages/datadog-instrumentations/src/router.js +243 -87
- package/packages/datadog-instrumentations/src/selenium.js +5 -3
- package/packages/datadog-instrumentations/src/sequelize.js +1 -1
- package/packages/datadog-instrumentations/src/stripe.js +47 -33
- package/packages/datadog-instrumentations/src/tedious.js +28 -0
- package/packages/datadog-instrumentations/src/url.js +1 -3
- package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +1297 -0
- package/packages/datadog-instrumentations/src/vitest-main.js +1592 -0
- package/packages/datadog-instrumentations/src/vitest-util.js +251 -0
- package/packages/datadog-instrumentations/src/vitest-worker.js +822 -0
- package/packages/datadog-instrumentations/src/vitest.js +11 -1258
- package/packages/datadog-instrumentations/src/vm.js +1 -3
- package/packages/datadog-instrumentations/src/winston.js +4 -4
- package/packages/datadog-instrumentations/src/ws.js +7 -7
- package/packages/datadog-instrumentations/src/zlib.js +29 -0
- package/packages/datadog-plugin-ai/src/index.js +1 -1
- package/packages/datadog-plugin-ai/src/tracing.js +66 -3
- package/packages/datadog-plugin-ai/src/utils.js +17 -4
- package/packages/datadog-plugin-apollo/src/gateway/request.js +1 -21
- package/packages/datadog-plugin-avsc/src/schema_iterator.js +3 -3
- package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/checkpoint.js +31 -0
- package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/client.js +55 -0
- package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/context.js +123 -0
- package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/handler.js +129 -0
- package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/index.js +19 -0
- package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/trace-checkpoint.js +224 -0
- package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/util.js +79 -0
- package/packages/datadog-plugin-aws-sdk/src/base.js +90 -53
- package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js +1 -1
- package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +218 -4
- package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +1 -1
- package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +2 -1
- package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +59 -14
- package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +174 -75
- package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +34 -23
- package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +2 -1
- package/packages/datadog-plugin-aws-sdk/src/services/s3.js +1 -1
- package/packages/datadog-plugin-aws-sdk/src/services/sns.js +26 -26
- package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +187 -101
- package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +20 -18
- package/packages/datadog-plugin-azure-cosmos/src/index.js +144 -0
- package/packages/datadog-plugin-azure-event-hubs/src/producer.js +8 -15
- package/packages/datadog-plugin-azure-functions/src/index.js +7 -3
- package/packages/datadog-plugin-azure-service-bus/src/producer.js +5 -10
- package/packages/datadog-plugin-bullmq/src/consumer.js +5 -4
- package/packages/datadog-plugin-bullmq/src/filter.js +35 -0
- package/packages/datadog-plugin-bullmq/src/producer.js +121 -33
- package/packages/datadog-plugin-bunyan/src/index.js +28 -0
- package/packages/datadog-plugin-child_process/src/index.js +13 -2
- package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +6 -6
- package/packages/datadog-plugin-claude-agent-sdk/src/index.js +31 -0
- package/packages/datadog-plugin-claude-agent-sdk/src/tracing.js +107 -0
- package/packages/datadog-plugin-claude-agent-sdk/src/util.js +15 -0
- package/packages/datadog-plugin-couchbase/src/index.js +58 -52
- package/packages/datadog-plugin-cucumber/src/index.js +46 -24
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +1018 -97
- package/packages/datadog-plugin-cypress/src/index.js +104 -2
- package/packages/datadog-plugin-cypress/src/plugin.js +6 -14
- package/packages/datadog-plugin-cypress/src/source-map-utils.js +48 -1
- package/packages/datadog-plugin-cypress/src/support.js +180 -25
- package/packages/datadog-plugin-dd-trace-api/src/index.js +1 -1
- package/packages/datadog-plugin-dns/src/lookup.js +8 -6
- package/packages/datadog-plugin-elasticsearch/src/index.js +28 -8
- package/packages/datadog-plugin-electron/src/index.js +17 -0
- package/packages/datadog-plugin-electron/src/ipc.js +143 -0
- package/packages/datadog-plugin-electron/src/net.js +82 -0
- package/packages/datadog-plugin-express/src/code_origin.js +1 -1
- package/packages/datadog-plugin-fastify/src/code_origin.js +1 -1
- package/packages/datadog-plugin-fs/src/index.js +2 -1
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +2 -5
- package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +27 -18
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +5 -8
- package/packages/datadog-plugin-graphql/src/execute.js +706 -34
- package/packages/datadog-plugin-graphql/src/index.js +43 -9
- package/packages/datadog-plugin-graphql/src/parse.js +45 -4
- package/packages/datadog-plugin-graphql/src/request.js +135 -0
- package/packages/datadog-plugin-graphql/src/tools/signature.js +32 -7
- package/packages/datadog-plugin-graphql/src/tools/transforms.js +118 -100
- package/packages/datadog-plugin-graphql/src/utils.js +261 -3
- package/packages/datadog-plugin-graphql/src/validate.js +53 -7
- package/packages/datadog-plugin-grpc/src/client.js +7 -8
- package/packages/datadog-plugin-grpc/src/server.js +1 -1
- package/packages/datadog-plugin-grpc/src/util.js +57 -22
- package/packages/datadog-plugin-http/src/client.js +12 -14
- package/packages/datadog-plugin-http/src/index.js +6 -8
- package/packages/datadog-plugin-http/src/server.js +63 -20
- package/packages/datadog-plugin-http2/src/client.js +6 -3
- package/packages/datadog-plugin-http2/src/server.js +48 -8
- package/packages/datadog-plugin-jest/src/index.js +136 -68
- package/packages/datadog-plugin-jest/src/util.js +37 -16
- package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +31 -4
- package/packages/datadog-plugin-kafkajs/src/consumer.js +2 -9
- package/packages/datadog-plugin-kafkajs/src/producer.js +37 -8
- package/packages/datadog-plugin-langgraph/src/stream.js +1 -1
- package/packages/datadog-plugin-memcached/src/index.js +1 -1
- package/packages/datadog-plugin-mocha/src/index.js +66 -17
- package/packages/datadog-plugin-modelcontextprotocol-sdk/src/index.js +24 -0
- package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +173 -0
- package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +30 -0
- package/packages/datadog-plugin-mongodb-core/src/bulk-write.js +43 -0
- package/packages/datadog-plugin-mongodb-core/src/index.js +8 -206
- package/packages/datadog-plugin-mongodb-core/src/query.js +452 -0
- package/packages/datadog-plugin-mysql/src/index.js +9 -4
- package/packages/datadog-plugin-nats/src/consumer.js +43 -0
- package/packages/datadog-plugin-nats/src/index.js +20 -0
- package/packages/datadog-plugin-nats/src/producer.js +62 -0
- package/packages/datadog-plugin-nats/src/util.js +33 -0
- package/packages/datadog-plugin-next/src/index.js +14 -18
- package/packages/datadog-plugin-openai/src/services.js +5 -3
- package/packages/datadog-plugin-openai/src/tracing.js +27 -25
- package/packages/datadog-plugin-oracledb/src/index.js +13 -2
- package/packages/datadog-plugin-pg/src/index.js +13 -3
- package/packages/datadog-plugin-pino/src/index.js +42 -0
- package/packages/datadog-plugin-playwright/src/index.js +21 -11
- package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +3 -3
- package/packages/datadog-plugin-redis/src/index.js +54 -25
- package/packages/datadog-plugin-rhea/src/producer.js +1 -1
- package/packages/datadog-plugin-router/src/index.js +46 -44
- package/packages/datadog-plugin-selenium/src/index.js +1 -1
- package/packages/datadog-plugin-tedious/src/index.js +1 -1
- package/packages/datadog-plugin-undici/src/index.js +24 -2
- package/packages/datadog-plugin-vitest/src/index.js +160 -90
- package/packages/datadog-plugin-winston/src/index.js +30 -0
- package/packages/datadog-plugin-ws/src/close.js +3 -1
- package/packages/datadog-plugin-ws/src/producer.js +2 -0
- package/packages/datadog-plugin-ws/src/receiver.js +2 -1
- package/packages/datadog-shimmer/src/shimmer.js +101 -39
- package/packages/datadog-webpack/index.js +20 -4
- package/packages/datadog-webpack/src/optional-peer-loader.js +17 -0
- package/packages/dd-trace/index.electron.js +3 -0
- package/packages/dd-trace/index.js +2 -34
- package/packages/dd-trace/src/aiguard/channels.js +7 -0
- package/packages/dd-trace/src/aiguard/index.js +16 -34
- package/packages/dd-trace/src/aiguard/integrations/evaluate.js +46 -0
- package/packages/dd-trace/src/aiguard/integrations/index.js +34 -0
- package/packages/dd-trace/src/aiguard/integrations/openai.js +80 -0
- package/packages/dd-trace/src/aiguard/integrations/vercel-ai.js +92 -0
- package/packages/dd-trace/src/aiguard/messages/openai.js +382 -0
- package/packages/{datadog-instrumentations/src/helpers/ai-messages.js → dd-trace/src/aiguard/messages/vercel-ai.js} +30 -27
- package/packages/dd-trace/src/aiguard/sdk.js +151 -54
- package/packages/dd-trace/src/aiguard/tags.js +26 -10
- package/packages/dd-trace/src/appsec/api_security/index.js +55 -0
- package/packages/dd-trace/src/appsec/api_security/sampler.js +147 -0
- package/packages/dd-trace/src/appsec/blocked_templates.js +4 -3
- package/packages/dd-trace/src/appsec/blocking.js +84 -41
- package/packages/dd-trace/src/appsec/channels.js +5 -1
- package/packages/dd-trace/src/appsec/downstream_requests.js +116 -62
- package/packages/dd-trace/src/appsec/graphql.js +20 -17
- package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-password-rules.js +1 -1
- package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secret-rules.js +81 -81
- package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +23 -23
- package/packages/dd-trace/src/appsec/iast/iast-plugin.js +1 -1
- package/packages/dd-trace/src/appsec/iast/index.js +3 -2
- package/packages/dd-trace/src/appsec/iast/security-controls/index.js +4 -4
- package/packages/dd-trace/src/appsec/iast/taint-tracking/plugins/kafka.js +2 -2
- package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +4 -4
- package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +2 -2
- package/packages/dd-trace/src/appsec/iast/telemetry/index.js +2 -1
- package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/ldap-sensitive-analyzer.js +54 -12
- package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/url-sensitive-analyzer.js +5 -1
- package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +32 -5
- package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/index.js +1 -3
- package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +84 -49
- package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +1 -1
- package/packages/dd-trace/src/appsec/index.js +65 -47
- package/packages/dd-trace/src/appsec/lambda.js +135 -0
- package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -5
- package/packages/dd-trace/src/appsec/rasp/lfi.js +8 -4
- package/packages/dd-trace/src/appsec/rasp/sql_injection.js +5 -10
- package/packages/dd-trace/src/appsec/rasp/ssrf.js +26 -18
- package/packages/dd-trace/src/appsec/recommended.json +2438 -13
- package/packages/dd-trace/src/appsec/remote_config.js +1 -0
- package/packages/dd-trace/src/appsec/reporter.js +87 -28
- package/packages/dd-trace/src/appsec/rule_manager.js +4 -2
- package/packages/dd-trace/src/appsec/sdk/index.js +4 -0
- package/packages/dd-trace/src/appsec/sdk/set_user.js +1 -1
- package/packages/dd-trace/src/appsec/sdk/track_event.js +5 -5
- package/packages/dd-trace/src/appsec/sdk/user_blocking.js +7 -11
- package/packages/dd-trace/src/appsec/sdk/utils.js +5 -3
- package/packages/dd-trace/src/appsec/store.js +50 -0
- package/packages/dd-trace/src/appsec/telemetry/api_security.js +34 -0
- package/packages/dd-trace/src/appsec/telemetry/index.js +27 -1
- package/packages/dd-trace/src/appsec/user_tracking.js +5 -4
- package/packages/dd-trace/src/appsec/waf/index.js +19 -9
- package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +35 -20
- package/packages/dd-trace/src/appsec/waf/waf_manager.js +1 -1
- package/packages/dd-trace/src/azure_metadata.js +17 -6
- package/packages/dd-trace/src/baggage.js +32 -13
- package/packages/dd-trace/src/bootstrap.js +39 -0
- package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +36 -6
- package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +122 -24
- package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +22 -7
- package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +5 -2
- package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +2 -2
- package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +2 -2
- package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +6 -2
- package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +2 -2
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +148 -25
- package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +3 -4
- package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +28 -10
- package/packages/dd-trace/src/ci-visibility/exporters/test-worker/writer.js +22 -0
- package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +105 -22
- package/packages/dd-trace/src/ci-visibility/lage.js +2 -1
- package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +4 -5
- package/packages/dd-trace/src/ci-visibility/requests/fs-cache.js +4 -5
- package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +73 -55
- package/packages/dd-trace/src/ci-visibility/requests/request.js +14 -50
- package/packages/dd-trace/src/ci-visibility/requests/upload-coverage-report.js +4 -4
- package/packages/dd-trace/src/ci-visibility/requests/upload-test-screenshot.js +156 -0
- package/packages/dd-trace/src/ci-visibility/test-api-manual/test-api-manual-plugin.js +9 -3
- package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +24 -6
- package/packages/dd-trace/src/ci-visibility/test-optimization-cache.js +70 -6
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +128 -0
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +291 -0
- package/packages/dd-trace/src/config/config-types.d.ts +8 -6
- package/packages/dd-trace/src/config/defaults.js +341 -144
- package/packages/dd-trace/src/config/generated-config-types.d.ts +679 -131
- package/packages/dd-trace/src/config/git_properties.js +2 -2
- package/packages/dd-trace/src/config/helper.js +183 -28
- package/packages/dd-trace/src/config/index.js +565 -1515
- package/packages/dd-trace/src/config/major-overrides.js +100 -0
- package/packages/dd-trace/src/config/normalize-service.js +31 -0
- package/packages/dd-trace/src/config/parsers.js +384 -0
- package/packages/dd-trace/src/config/remote_config.js +59 -2
- package/packages/dd-trace/src/config/supported-configurations.json +638 -530
- package/packages/dd-trace/src/constants.js +15 -0
- package/packages/dd-trace/src/crashtracking/crashtracker.js +25 -7
- package/packages/dd-trace/src/crashtracking/index.js +1 -7
- package/packages/dd-trace/src/datastreams/checkpointer.js +6 -12
- package/packages/dd-trace/src/datastreams/context.js +4 -2
- package/packages/dd-trace/src/datastreams/encoding.js +39 -28
- package/packages/dd-trace/src/datastreams/index.js +2 -1
- package/packages/dd-trace/src/datastreams/manager.js +1 -1
- package/packages/dd-trace/src/datastreams/pathway.js +35 -30
- package/packages/dd-trace/src/datastreams/processor.js +31 -22
- package/packages/dd-trace/src/datastreams/size.js +6 -2
- package/packages/dd-trace/src/datastreams/writer.js +15 -6
- package/packages/dd-trace/src/debugger/config.js +9 -4
- package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +49 -35
- package/packages/dd-trace/src/debugger/devtools_client/condition.js +5 -8
- package/packages/dd-trace/src/debugger/devtools_client/config.js +3 -2
- package/packages/dd-trace/src/debugger/devtools_client/index.js +33 -71
- package/packages/dd-trace/src/debugger/devtools_client/probe_sampler.js +83 -0
- package/packages/dd-trace/src/debugger/devtools_client/send.js +27 -6
- package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +2 -2
- package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +5 -2
- package/packages/dd-trace/src/debugger/devtools_client/snapshot-pruner.js +1 -0
- package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
- package/packages/dd-trace/src/debugger/index.js +14 -10
- package/packages/dd-trace/src/debugger/probe_sampler.js +112 -0
- package/packages/dd-trace/src/debugger/probe_sampler_constants.js +19 -0
- package/packages/dd-trace/src/dogstatsd.js +45 -36
- package/packages/dd-trace/src/encode/0.4.js +830 -269
- package/packages/dd-trace/src/encode/0.5.js +158 -22
- package/packages/dd-trace/src/encode/agentless-ci-visibility.js +141 -65
- package/packages/dd-trace/src/encode/agentless-json.js +12 -6
- package/packages/dd-trace/src/encode/coverage-ci-visibility.js +52 -15
- package/packages/dd-trace/src/encode/span-stats.js +19 -16
- package/packages/dd-trace/src/encode/tags-processors.js +30 -25
- package/packages/dd-trace/src/exporter.js +3 -1
- package/packages/dd-trace/src/exporters/agent/index.js +4 -5
- package/packages/dd-trace/src/exporters/agent/writer.js +8 -3
- package/packages/dd-trace/src/exporters/agentless/index.js +12 -13
- package/packages/dd-trace/src/exporters/agentless/intake.js +43 -0
- package/packages/dd-trace/src/exporters/agentless/writer.js +12 -11
- package/packages/dd-trace/src/exporters/common/agents.js +3 -1
- package/packages/dd-trace/src/exporters/common/buffering-exporter.js +3 -3
- package/packages/dd-trace/src/exporters/common/request.js +55 -26
- package/packages/dd-trace/src/exporters/common/retry.js +104 -0
- package/packages/dd-trace/src/exporters/common/url.js +34 -0
- package/packages/dd-trace/src/exporters/common/util.js +2 -2
- package/packages/dd-trace/src/exporters/common/writer.js +29 -3
- package/packages/dd-trace/src/exporters/electron/index.js +49 -0
- package/packages/dd-trace/src/exporters/span-stats/index.js +1 -2
- package/packages/dd-trace/src/exporters/span-stats/writer.js +1 -3
- package/packages/dd-trace/src/external-logger/src/index.js +2 -1
- package/packages/dd-trace/src/feature-registry.js +22 -0
- package/packages/dd-trace/src/git_metadata.js +68 -0
- package/packages/dd-trace/src/git_metadata_tagger.js +13 -5
- package/packages/dd-trace/src/guardrails/index.js +11 -6
- package/packages/dd-trace/src/guardrails/telemetry.js +40 -3
- package/packages/dd-trace/src/heap_snapshots.js +7 -4
- package/packages/dd-trace/src/id.js +46 -27
- package/packages/dd-trace/src/index.js +6 -4
- package/packages/dd-trace/src/lambda/handler-paths.js +52 -0
- package/packages/dd-trace/src/lambda/handler.js +2 -6
- package/packages/dd-trace/src/lambda/index.js +62 -14
- package/packages/dd-trace/src/lambda/runtime/patch.js +21 -46
- package/packages/dd-trace/src/llmobs/constants/tags.js +13 -0
- package/packages/dd-trace/src/llmobs/index.js +41 -8
- package/packages/dd-trace/src/llmobs/plugins/ai/ddTelemetry.js +403 -0
- package/packages/dd-trace/src/llmobs/plugins/ai/index.js +8 -391
- package/packages/dd-trace/src/llmobs/plugins/ai/util.js +178 -18
- package/packages/dd-trace/src/llmobs/plugins/ai/vercelTelemetry.js +363 -0
- package/packages/dd-trace/src/llmobs/plugins/{anthropic.js → anthropic/index.js} +32 -79
- package/packages/dd-trace/src/llmobs/plugins/anthropic/util.js +109 -0
- package/packages/dd-trace/src/llmobs/plugins/base.js +4 -4
- package/packages/dd-trace/src/llmobs/plugins/bedrockruntime.js +92 -38
- package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +270 -0
- package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/utils.js +10 -0
- package/packages/dd-trace/src/llmobs/plugins/genai/index.js +5 -1
- package/packages/dd-trace/src/llmobs/plugins/genai/util.js +81 -16
- package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chain.js +3 -2
- package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chat_model.js +3 -2
- package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/embedding.js +2 -1
- package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/index.js +1 -50
- package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/vectorstore.js +2 -1
- package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +14 -8
- package/packages/dd-trace/src/llmobs/plugins/langchain/messages.js +76 -0
- package/packages/dd-trace/src/llmobs/plugins/langgraph/index.js +3 -28
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +68 -0
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +57 -0
- package/packages/dd-trace/src/llmobs/plugins/openai/index.js +21 -51
- package/packages/dd-trace/src/llmobs/sdk.js +66 -41
- package/packages/dd-trace/src/llmobs/span_processor.js +91 -12
- package/packages/dd-trace/src/llmobs/tagger.js +135 -7
- package/packages/dd-trace/src/llmobs/telemetry.js +31 -1
- package/packages/dd-trace/src/llmobs/util.js +202 -9
- package/packages/dd-trace/src/llmobs/writers/base.js +13 -5
- package/packages/dd-trace/src/llmobs/writers/spans.js +1 -1
- package/packages/dd-trace/src/llmobs/writers/util.js +4 -2
- package/packages/dd-trace/src/log/index.js +28 -69
- package/packages/dd-trace/src/log/writer.js +10 -20
- package/packages/dd-trace/src/msgpack/chunk.js +430 -11
- package/packages/dd-trace/src/msgpack/index.js +101 -2
- package/packages/dd-trace/src/noop/proxy.js +13 -4
- package/packages/dd-trace/src/noop/span.js +3 -1
- package/packages/dd-trace/src/openfeature/encoding.js +70 -0
- package/packages/dd-trace/src/openfeature/eval-metrics-hook.js +103 -0
- package/packages/dd-trace/src/openfeature/flagging_provider.js +26 -1
- package/packages/dd-trace/src/openfeature/noop.js +40 -36
- package/packages/dd-trace/src/openfeature/register.js +46 -0
- package/packages/dd-trace/src/openfeature/remote_config.js +6 -1
- package/packages/dd-trace/src/openfeature/span-enrichment-hook.js +143 -0
- package/packages/dd-trace/src/openfeature/span-enrichment.js +149 -0
- package/packages/dd-trace/src/openfeature/writers/base.js +3 -11
- package/packages/dd-trace/src/openfeature/writers/exposures.js +82 -70
- package/packages/dd-trace/src/openfeature/writers/util.js +1 -2
- package/packages/dd-trace/src/opentelemetry/active-span-proxy.js +42 -0
- package/packages/dd-trace/src/opentelemetry/bridge-span-base.js +107 -0
- package/packages/dd-trace/src/opentelemetry/context_manager.js +27 -13
- package/packages/dd-trace/src/opentelemetry/logs/index.js +7 -7
- package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +3 -2
- package/packages/dd-trace/src/opentelemetry/metrics/index.js +62 -13
- package/packages/dd-trace/src/opentelemetry/metrics/instruments.js +28 -14
- package/packages/dd-trace/src/opentelemetry/metrics/meter.js +7 -10
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +3 -2
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +40 -0
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_transformer.js +169 -0
- package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +99 -5
- package/packages/dd-trace/src/opentelemetry/metrics/time.js +19 -0
- package/packages/dd-trace/src/opentelemetry/otlp/common.proto +2 -2
- package/packages/dd-trace/src/opentelemetry/otlp/logs.proto +1 -1
- package/packages/dd-trace/src/opentelemetry/otlp/logs_service.proto +1 -1
- package/packages/dd-trace/src/opentelemetry/otlp/metrics.proto +1 -1
- package/packages/dd-trace/src/opentelemetry/otlp/metrics_service.proto +1 -1
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +56 -82
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +1 -2
- package/packages/dd-trace/src/opentelemetry/otlp/protobuf_loader.js +14 -2
- package/packages/dd-trace/src/opentelemetry/otlp/trace.proto +358 -0
- package/packages/dd-trace/src/opentelemetry/otlp/trace_service.proto +78 -0
- package/packages/dd-trace/src/opentelemetry/span-helpers.js +325 -0
- package/packages/dd-trace/src/opentelemetry/span.js +59 -109
- package/packages/dd-trace/src/opentelemetry/span_context.js +1 -0
- package/packages/dd-trace/src/opentelemetry/span_processor.js +7 -5
- package/packages/dd-trace/src/opentelemetry/trace/index.js +75 -0
- package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +75 -0
- package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +375 -0
- package/packages/dd-trace/src/opentelemetry/tracer.js +20 -69
- package/packages/dd-trace/src/opentelemetry/tracer_provider.js +33 -17
- package/packages/dd-trace/src/opentracing/propagation/log.js +28 -8
- package/packages/dd-trace/src/opentracing/propagation/text_map.js +280 -145
- package/packages/dd-trace/src/opentracing/propagation/text_map_dsm.js +11 -11
- package/packages/dd-trace/src/opentracing/propagation/tracestate.js +98 -32
- package/packages/dd-trace/src/opentracing/span.js +127 -73
- package/packages/dd-trace/src/opentracing/span_context.js +68 -3
- package/packages/dd-trace/src/opentracing/tracer.js +46 -19
- package/packages/dd-trace/src/payload-tagging/config/index.js +8 -7
- package/packages/dd-trace/src/plugin_manager.js +44 -20
- package/packages/dd-trace/src/plugins/apollo.js +3 -1
- package/packages/dd-trace/src/plugins/ci_plugin.js +391 -85
- package/packages/dd-trace/src/plugins/database.js +61 -18
- package/packages/dd-trace/src/plugins/index.js +14 -0
- package/packages/dd-trace/src/plugins/log_injection.js +56 -0
- package/packages/dd-trace/src/plugins/log_plugin.js +4 -44
- package/packages/dd-trace/src/plugins/outbound.js +1 -1
- package/packages/dd-trace/src/plugins/plugin.js +22 -28
- package/packages/dd-trace/src/plugins/storage.js +2 -2
- package/packages/dd-trace/src/plugins/tracing.js +70 -13
- package/packages/dd-trace/src/plugins/util/ci.js +127 -40
- package/packages/dd-trace/src/plugins/util/git-cache.js +23 -23
- package/packages/dd-trace/src/plugins/util/git.js +3 -1
- package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +276 -0
- package/packages/dd-trace/src/plugins/util/llm.js +6 -1
- package/packages/dd-trace/src/plugins/util/stacktrace.js +2 -2
- package/packages/dd-trace/src/plugins/util/test.js +894 -65
- package/packages/dd-trace/src/plugins/util/url.js +71 -5
- package/packages/dd-trace/src/plugins/util/user-provided-git.js +18 -16
- package/packages/dd-trace/src/plugins/util/web.js +116 -180
- package/packages/dd-trace/src/priority_sampler.js +12 -21
- package/packages/dd-trace/src/process-tags/index.js +3 -0
- package/packages/dd-trace/src/profiler.js +27 -2
- package/packages/dd-trace/src/profiling/config.js +145 -393
- package/packages/dd-trace/src/profiling/constants.js +4 -7
- package/packages/dd-trace/src/profiling/exporter_cli.js +10 -13
- package/packages/dd-trace/src/profiling/exporters/agent.js +61 -28
- package/packages/dd-trace/src/profiling/exporters/event_serializer.js +50 -15
- package/packages/dd-trace/src/profiling/exporters/file.js +16 -5
- package/packages/dd-trace/src/profiling/oom.js +71 -0
- package/packages/dd-trace/src/profiling/profiler.js +123 -132
- package/packages/dd-trace/src/profiling/profilers/event_plugins/crypto.js +32 -0
- package/packages/dd-trace/src/profiling/profilers/event_plugins/zlib.js +19 -0
- package/packages/dd-trace/src/profiling/profilers/events.js +57 -14
- package/packages/dd-trace/src/profiling/profilers/space.js +27 -16
- package/packages/dd-trace/src/profiling/profilers/wall.js +136 -39
- package/packages/dd-trace/src/profiling/ssi-heuristics.js +7 -4
- package/packages/dd-trace/src/propagation-hash/index.js +3 -2
- package/packages/dd-trace/src/proxy.js +82 -39
- package/packages/dd-trace/src/rate_limiter.js +1 -1
- package/packages/dd-trace/src/remote_config/index.js +9 -5
- package/packages/dd-trace/src/remote_config/scheduler.js +1 -1
- package/packages/dd-trace/src/require-package-json.js +8 -4
- package/packages/dd-trace/src/ritm.js +63 -28
- package/packages/dd-trace/src/runtime_metrics/client.js +30 -0
- package/packages/dd-trace/src/runtime_metrics/index.js +17 -4
- package/packages/dd-trace/src/runtime_metrics/otlp_runtime_metrics.js +284 -0
- package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +45 -41
- package/packages/dd-trace/src/sampler.js +1 -1
- package/packages/dd-trace/src/sampling_rule.js +7 -7
- package/packages/dd-trace/src/scope.js +10 -15
- package/packages/dd-trace/src/serverless.js +6 -7
- package/packages/dd-trace/src/service-naming/extra-services.js +14 -0
- package/packages/dd-trace/src/service-naming/index.js +1 -1
- package/packages/dd-trace/src/service-naming/schemas/definition.js +4 -1
- package/packages/dd-trace/src/service-naming/schemas/util.js +48 -3
- package/packages/dd-trace/src/service-naming/schemas/v0/graphql.js +6 -0
- package/packages/dd-trace/src/service-naming/schemas/v0/messaging.js +61 -2
- package/packages/dd-trace/src/service-naming/schemas/v0/serverless.js +12 -0
- package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +60 -0
- package/packages/dd-trace/src/service-naming/schemas/v0/web.js +25 -1
- package/packages/dd-trace/src/service-naming/schemas/v0/websocket.js +5 -0
- package/packages/dd-trace/src/service-naming/schemas/v1/graphql.js +8 -0
- package/packages/dd-trace/src/service-naming/schemas/v1/messaging.js +32 -0
- package/packages/dd-trace/src/service-naming/schemas/v1/serverless.js +12 -0
- package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +17 -0
- package/packages/dd-trace/src/service-naming/schemas/v1/web.js +23 -3
- package/packages/dd-trace/src/service-naming/schemas/v1/websocket.js +6 -0
- package/packages/dd-trace/src/service-naming/source-resolver.js +50 -0
- package/packages/dd-trace/src/span_format.js +269 -81
- package/packages/dd-trace/src/span_processor.js +13 -13
- package/packages/dd-trace/src/span_stats.js +101 -79
- package/packages/dd-trace/src/spanleak.js +1 -2
- package/packages/dd-trace/src/standalone/index.js +6 -25
- package/packages/dd-trace/src/startup-log.js +3 -3
- package/packages/dd-trace/src/tagger.js +2 -4
- package/packages/dd-trace/src/telemetry/dependencies.js +2 -2
- package/packages/dd-trace/src/telemetry/endpoints.js +7 -5
- package/packages/dd-trace/src/telemetry/index.js +2 -3
- package/packages/dd-trace/src/telemetry/logs/index.js +1 -1
- package/packages/dd-trace/src/telemetry/send-data.js +25 -39
- package/packages/dd-trace/src/telemetry/session-propagation.js +20 -45
- package/packages/dd-trace/src/telemetry/telemetry.js +42 -183
- package/packages/dd-trace/src/tracer.js +23 -9
- package/packages/dd-trace/src/tracer_metadata.js +1 -1
- package/packages/dd-trace/src/util.js +31 -9
- package/register.js +58 -1
- package/vendor/dist/@apm-js-collab/code-transformer/index.js +94 -42
- package/vendor/dist/@datadog/sketches-js/LICENSE +10 -36
- package/vendor/dist/@datadog/sketches-js/index.js +1 -1
- package/vendor/dist/pprof-format/index.js +1 -1
- package/vendor/dist/protobufjs/index.js +1 -1
- package/vendor/dist/protobufjs/minimal/index.js +1 -1
- package/vendor/dist/shell-quote/index.js +1 -1
- package/packages/datadog-plugin-graphql/src/resolve.js +0 -178
- package/packages/dd-trace/src/agent/url.js +0 -28
- package/packages/dd-trace/src/appsec/api_security_sampler.js +0 -117
- package/packages/dd-trace/src/lambda/runtime/ritm.js +0 -133
- package/packages/dd-trace/src/log/utils.js +0 -16
- package/packages/dd-trace/src/msgpack/encoder.js +0 -308
- package/packages/dd-trace/src/plugins/structured_log_plugin.js +0 -9
- package/scripts/preinstall.js +0 -34
- package/vendor/dist/ignore/LICENSE +0 -21
- package/vendor/dist/ignore/index.js +0 -1
- package/vendor/dist/opentracing/LICENSE +0 -201
- package/vendor/dist/opentracing/binary_carrier.d.ts +0 -11
- package/vendor/dist/opentracing/constants.d.ts +0 -61
- package/vendor/dist/opentracing/examples/demo/demo.d.ts +0 -2
- package/vendor/dist/opentracing/ext/tags.d.ts +0 -90
- package/vendor/dist/opentracing/functions.d.ts +0 -20
- package/vendor/dist/opentracing/global_tracer.d.ts +0 -14
- package/vendor/dist/opentracing/index.d.ts +0 -12
- package/vendor/dist/opentracing/index.js +0 -1
- package/vendor/dist/opentracing/mock_tracer/index.d.ts +0 -5
- package/vendor/dist/opentracing/mock_tracer/mock_context.d.ts +0 -13
- package/vendor/dist/opentracing/mock_tracer/mock_report.d.ts +0 -16
- package/vendor/dist/opentracing/mock_tracer/mock_span.d.ts +0 -50
- package/vendor/dist/opentracing/mock_tracer/mock_tracer.d.ts +0 -26
- package/vendor/dist/opentracing/noop.d.ts +0 -8
- package/vendor/dist/opentracing/reference.d.ts +0 -33
- package/vendor/dist/opentracing/span.d.ts +0 -147
- package/vendor/dist/opentracing/span_context.d.ts +0 -26
- package/vendor/dist/opentracing/test/api_compatibility.d.ts +0 -16
- package/vendor/dist/opentracing/test/mocktracer_implemenation.d.ts +0 -3
- package/vendor/dist/opentracing/test/noop_implementation.d.ts +0 -4
- package/vendor/dist/opentracing/test/opentracing_api.d.ts +0 -3
- package/vendor/dist/opentracing/test/unittest.d.ts +0 -2
- package/vendor/dist/opentracing/tracer.d.ts +0 -127
- package/vendor/dist/path-to-regexp/LICENSE +0 -21
- package/vendor/dist/path-to-regexp/index.js +0 -1
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
// Capture real timers at module load time, before any test can install fake timers.
|
|
4
|
+
const realSetTimeout = setTimeout
|
|
5
|
+
|
|
6
|
+
const { readFileSync } = require('node:fs')
|
|
7
|
+
const { builtinModules, createRequire } = require('node:module')
|
|
3
8
|
const path = require('path')
|
|
9
|
+
const satisfies = require('../../../vendor/dist/semifies')
|
|
10
|
+
const { DD_MAJOR } = require('../../../version')
|
|
4
11
|
const shimmer = require('../../datadog-shimmer')
|
|
12
|
+
const { getEnvironmentVariable } = require('../../dd-trace/src/config/helper')
|
|
5
13
|
const log = require('../../dd-trace/src/log')
|
|
6
14
|
const {
|
|
7
|
-
|
|
15
|
+
getCoveredFilesFromCoverage,
|
|
16
|
+
getExecutableFilesFromCoverage,
|
|
8
17
|
JEST_WORKER_TRACE_PAYLOAD_CODE,
|
|
9
18
|
JEST_WORKER_COVERAGE_PAYLOAD_CODE,
|
|
10
19
|
JEST_WORKER_TELEMETRY_PAYLOAD_CODE,
|
|
20
|
+
JEST_WORKER_QUARANTINE_PAYLOAD_CODE,
|
|
11
21
|
getTestLineStart,
|
|
12
22
|
getTestSuitePath,
|
|
13
23
|
getTestParametersString,
|
|
@@ -17,14 +27,25 @@ const {
|
|
|
17
27
|
isModifiedTest,
|
|
18
28
|
DYNAMIC_NAME_RE,
|
|
19
29
|
collectDynamicNamesFromTraces,
|
|
30
|
+
recordAttemptToFixExecution,
|
|
31
|
+
logAttemptToFixTestExecution,
|
|
32
|
+
logTestOptimizationSummary,
|
|
33
|
+
getEfdRetryCount,
|
|
34
|
+
getTestCoverageLinesPercentage,
|
|
35
|
+
applySkippedCoverageToCoverage,
|
|
36
|
+
getTestOptimizationRequestResults,
|
|
20
37
|
} = require('../../dd-trace/src/plugins/util/test')
|
|
21
38
|
const {
|
|
22
|
-
SEED_SUFFIX_RE,
|
|
23
39
|
getFormattedJestTestParameters,
|
|
24
40
|
getJestTestName,
|
|
41
|
+
getRawJestTestName,
|
|
25
42
|
getJestSuitesToRun,
|
|
26
|
-
|
|
43
|
+
removeSeedSuffixFromTestName,
|
|
27
44
|
} = require('../../datadog-plugin-jest/src/util')
|
|
45
|
+
const {
|
|
46
|
+
addCoverageBackfillUntestedFiles,
|
|
47
|
+
getCoverageBackfillFiles,
|
|
48
|
+
} = require('./jest/coverage-backfill')
|
|
28
49
|
const { addHook, channel } = require('./helpers/instrument')
|
|
29
50
|
|
|
30
51
|
const testSessionStartCh = channel('ci:jest:session:start')
|
|
@@ -65,16 +86,25 @@ const CHILD_MESSAGE_CALL = 1
|
|
|
65
86
|
|
|
66
87
|
// Maximum time we'll wait for the tracer to flush
|
|
67
88
|
const FLUSH_TIMEOUT = 10_000
|
|
89
|
+
const JEST_SESSION_STATE = Symbol.for('dd-trace:jest:session')
|
|
90
|
+
const JEST_BAIL_REPORTER_PATH = require.resolve('./jest/bail-reporter')
|
|
91
|
+
const DD_JEST_HANDLE_TEST_EVENT_WRAPPED = Symbol('dd-trace:jest:handle-test-event-wrapped')
|
|
92
|
+
const DD_JEST_HANDLE_TEST_EVENT_DATADOG = Symbol('dd-trace:jest:handle-test-event-datadog')
|
|
93
|
+
const DD_JEST_CONCURRENT_TEST_ORIGINAL = Symbol('dd-trace:jest:concurrent-test-original')
|
|
94
|
+
const isJestWorker = !!getEnvironmentVariable('JEST_WORKER_ID')
|
|
95
|
+
const jestSessionState = globalThis[JEST_SESSION_STATE] || (globalThis[JEST_SESSION_STATE] = {})
|
|
68
96
|
|
|
69
97
|
// https://github.com/jestjs/jest/blob/41f842a46bb2691f828c3a5f27fc1d6290495b82/packages/jest-circus/src/types.ts#L9C8-L9C54
|
|
70
98
|
const RETRY_TIMES = Symbol.for('RETRY_TIMES')
|
|
71
99
|
|
|
72
100
|
let skippableSuites = []
|
|
101
|
+
let skippableSuitesCoverage = {}
|
|
102
|
+
let skippedSuitesCoverage = {}
|
|
73
103
|
let knownTests = {}
|
|
74
104
|
let isCodeCoverageEnabled = false
|
|
75
|
-
let
|
|
105
|
+
let isCoverageReportUploadEnabled = false
|
|
106
|
+
let isItrEnabled = false
|
|
76
107
|
let isSuitesSkippingEnabled = false
|
|
77
|
-
let isKeepingCoverageConfiguration = false
|
|
78
108
|
let isUserCodeCoverageEnabled = false
|
|
79
109
|
let isSuitesSkipped = false
|
|
80
110
|
let numSkippedSuites = 0
|
|
@@ -92,10 +122,21 @@ let testManagementTests = {}
|
|
|
92
122
|
let testManagementAttemptToFixRetries = 0
|
|
93
123
|
let isImpactedTestsEnabled = false
|
|
94
124
|
let modifiedFiles = {}
|
|
125
|
+
let repositoryRoot
|
|
126
|
+
let lastCoverageMap
|
|
127
|
+
let lastCoverageMapRootDir
|
|
128
|
+
let coverageBackfillContexts
|
|
129
|
+
let coverageBackfillFiles
|
|
130
|
+
let coverageReporterClass
|
|
131
|
+
let coverageReporterRequire
|
|
132
|
+
let activeTestSuiteAbsolutePath
|
|
133
|
+
let isConsoleErrorWrapped = false
|
|
95
134
|
|
|
96
135
|
const testContexts = new WeakMap()
|
|
97
136
|
const originalTestFns = new WeakMap()
|
|
98
137
|
const originalHookFns = new WeakMap()
|
|
138
|
+
const concurrentHookContextQueues = new WeakMap()
|
|
139
|
+
const concurrentHookFns = new WeakMap()
|
|
99
140
|
const retriedTestsToNumAttempts = new Map()
|
|
100
141
|
const newTestsTestStatuses = new Map()
|
|
101
142
|
const attemptToFixRetriedTestsStatuses = new Map()
|
|
@@ -103,6 +144,7 @@ const wrappedWorkerChannels = new WeakMap()
|
|
|
103
144
|
// New tests whose names contain likely dynamic data (timestamps, UUIDs, etc.)
|
|
104
145
|
// Populated in-process for runInBand, and via worker-report:trace for parallel mode.
|
|
105
146
|
const newTestsWithDynamicNames = new Set()
|
|
147
|
+
const loggedAttemptToFixTests = new Set()
|
|
106
148
|
const testSuiteMockedFiles = new Map()
|
|
107
149
|
const testsToBeRetried = new Set()
|
|
108
150
|
// Per-test: how many EFD retries were determined after the first execution.
|
|
@@ -111,12 +153,83 @@ const efdDeterminedRetries = new Map()
|
|
|
111
153
|
const efdSlowAbortedTests = new Set()
|
|
112
154
|
// Tests added as EFD new-test candidates (not ATF, not impacted).
|
|
113
155
|
const efdNewTestCandidates = new Set()
|
|
114
|
-
|
|
156
|
+
// Tests that are genuinely new (not in known tests list).
|
|
157
|
+
const newTests = new Set()
|
|
115
158
|
const testSuiteJestObjects = new Map()
|
|
159
|
+
const testSuiteDatadogEnvironments = new Map()
|
|
160
|
+
const wrappedJestGlobals = new WeakSet()
|
|
161
|
+
const wrappedJestObjects = new WeakSet()
|
|
162
|
+
const wrappedWorkerInitializers = new WeakSet()
|
|
163
|
+
const publishedRuntimeReferenceErrors = new WeakMap()
|
|
164
|
+
const wrappedCoverageReporters = new WeakSet()
|
|
165
|
+
const coverageReporterRequires = new WeakMap()
|
|
166
|
+
const handledJestEvents = new WeakSet()
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @typedef {object} ConcurrentTestOptions
|
|
170
|
+
* @property {(...args: unknown[]) => unknown} [concurrentTest]
|
|
171
|
+
* @property {unknown} [concurrentTestThisArg]
|
|
172
|
+
* @property {boolean} [isAttemptToFixRetry]
|
|
173
|
+
* @property {boolean} [isEfdRetry]
|
|
174
|
+
* @property {boolean} [isModified]
|
|
175
|
+
* @property {(...args: unknown[]) => unknown} [serialTest]
|
|
176
|
+
* @property {unknown} [serialTestThisArg]
|
|
177
|
+
* @property {(...args: unknown[]) => unknown} [sourceTestFn]
|
|
178
|
+
* @property {string} [testParameters]
|
|
179
|
+
*/
|
|
116
180
|
|
|
117
|
-
const BREAKPOINT_HIT_GRACE_PERIOD_MS = 200
|
|
118
181
|
const ATR_RETRY_SUPPRESSION_FLAG = '_ddDisableAtrRetry'
|
|
182
|
+
const MINIMUM_JEST_VERSION = DD_MAJOR >= 6 ? '>=28.0.0' : '>=24.8.0'
|
|
183
|
+
const MINIMUM_JEST_VERSION_BEFORE_30 = DD_MAJOR >= 6 ? '>=28.0.0 <30.0.0' : '>=24.8.0 <30.0.0'
|
|
184
|
+
const MINIMUM_JEST_WORKER_VERSION_BEFORE_30 = DD_MAJOR >= 6 ? '>=28.0.0 <30.0.0' : '>=24.9.0 <30.0.0'
|
|
185
|
+
const MINIMUM_JEST_CONFIG_ASYNC_VERSION = DD_MAJOR >= 6 ? '>=28.0.0' : '>=25.1.0'
|
|
186
|
+
const MINIMUM_JEST_TEST_SCHEDULER_VERSION = DD_MAJOR >= 6 ? '>=28.0.0' : '>=27.0.0'
|
|
187
|
+
const MINIMUM_JEST_COVERAGE_BACKFILL_VERSION = '>=28.0.0'
|
|
119
188
|
const atrSuppressedErrors = new Map()
|
|
189
|
+
let hasWarnedDeprecatedJestVersion = false
|
|
190
|
+
let isJestCoverageBackfillSupported = false
|
|
191
|
+
let hasFinishedTestSession = false
|
|
192
|
+
let jestEachBind
|
|
193
|
+
|
|
194
|
+
// Track quarantined tests whose errors were suppressed, keyed by "suite › testName"
|
|
195
|
+
const quarantinedFailingTests = new Set()
|
|
196
|
+
|
|
197
|
+
function getJestRepositoryRoot (readConfigsResult) {
|
|
198
|
+
const configuredRepositoryRoot = readConfigsResult.configs
|
|
199
|
+
?.find(config => config.testEnvironmentOptions?._ddRepositoryRoot)
|
|
200
|
+
?.testEnvironmentOptions._ddRepositoryRoot
|
|
201
|
+
|
|
202
|
+
return configuredRepositoryRoot || process.cwd()
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Sends suppressed quarantine test names from a worker process to the main process.
|
|
207
|
+
* Supports both child_process (process.send) and worker_threads (parentPort.postMessage).
|
|
208
|
+
* Returns true if the data was sent (worker mode), false if in main process (runInBand).
|
|
209
|
+
*
|
|
210
|
+
* @param {string[]} testNames
|
|
211
|
+
* @returns {boolean}
|
|
212
|
+
*/
|
|
213
|
+
function sendQuarantineInfoToMainProcess (testNames) {
|
|
214
|
+
const payload = [JEST_WORKER_QUARANTINE_PAYLOAD_CODE, JSON.stringify(testNames)]
|
|
215
|
+
|
|
216
|
+
if (process.send) {
|
|
217
|
+
process.send(payload)
|
|
218
|
+
return true
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
try {
|
|
222
|
+
const { isMainThread, parentPort } = require('node:worker_threads')
|
|
223
|
+
if (!isMainThread && parentPort) {
|
|
224
|
+
parentPort.postMessage(payload)
|
|
225
|
+
return true
|
|
226
|
+
}
|
|
227
|
+
} catch {
|
|
228
|
+
// Not in a worker context
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return false
|
|
232
|
+
}
|
|
120
233
|
|
|
121
234
|
// based on https://github.com/facebook/jest/blob/main/packages/jest-circus/src/formatNodeAssertErrors.ts#L41
|
|
122
235
|
function formatJestError (errors) {
|
|
@@ -135,6 +248,20 @@ function formatJestError (errors) {
|
|
|
135
248
|
return error
|
|
136
249
|
}
|
|
137
250
|
|
|
251
|
+
function warnDeprecatedJestVersion (frameworkVersion) {
|
|
252
|
+
if (DD_MAJOR >= 6 || hasWarnedDeprecatedJestVersion || !frameworkVersion ||
|
|
253
|
+
!satisfies(frameworkVersion, '<28.0.0')) {
|
|
254
|
+
return
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
hasWarnedDeprecatedJestVersion = true
|
|
258
|
+
// eslint-disable-next-line no-console
|
|
259
|
+
console.warn(
|
|
260
|
+
'dd-trace support for Jest<28.0.0 is deprecated and will be removed in dd-trace v6. ' +
|
|
261
|
+
'Please upgrade Jest to >=28.0.0.'
|
|
262
|
+
)
|
|
263
|
+
}
|
|
264
|
+
|
|
138
265
|
function getTestEnvironmentOptions (config) {
|
|
139
266
|
if (config.projectConfig && config.projectConfig.testEnvironmentOptions) { // newer versions
|
|
140
267
|
return config.projectConfig.testEnvironmentOptions
|
|
@@ -155,64 +282,183 @@ function getTestStats (testStatuses) {
|
|
|
155
282
|
}
|
|
156
283
|
|
|
157
284
|
/**
|
|
158
|
-
*
|
|
159
|
-
* @param {string[]} quarantineNames
|
|
160
|
-
* @param {number} totalCount
|
|
161
|
-
*/
|
|
162
|
-
/**
|
|
163
|
-
* Renders a truncated bullet list from an array of items.
|
|
285
|
+
* Formats the ignored-failure section for the Test Optimization summary.
|
|
164
286
|
*
|
|
165
|
-
* @param {
|
|
287
|
+
* @param {{ efdNames: string[], quarantineNames: string[], totalCount: number } | undefined} ignoredFailures
|
|
166
288
|
* @returns {string}
|
|
167
289
|
*/
|
|
168
|
-
function
|
|
290
|
+
function formatIgnoredFailuresSummary (ignoredFailures) {
|
|
291
|
+
if (!ignoredFailures) return ''
|
|
292
|
+
|
|
293
|
+
const items = []
|
|
294
|
+
|
|
295
|
+
for (const n of ignoredFailures.efdNames) {
|
|
296
|
+
items.push({ text: n, suffix: 'Early Flake Detection' })
|
|
297
|
+
}
|
|
298
|
+
for (const n of ignoredFailures.quarantineNames) {
|
|
299
|
+
items.push({ text: n, suffix: 'Quarantine' })
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (items.length === 0 || ignoredFailures.totalCount <= 0) return ''
|
|
303
|
+
|
|
169
304
|
const shown = items.slice(0, MAX_IGNORED_TEST_NAMES)
|
|
170
305
|
const more = items.length - shown.length
|
|
171
306
|
const moreSuffix = more > 0 ? `\n ... and ${more} more` : ''
|
|
172
|
-
|
|
307
|
+
const formattedItems = shown
|
|
308
|
+
.map(({ text, suffix }) => ` • ${text}${suffix ? ` (${suffix})` : ''}`)
|
|
309
|
+
.join('\n') + moreSuffix
|
|
310
|
+
|
|
311
|
+
return `${ignoredFailures.totalCount} test failure(s) were ignored. Exit code set to 0.\n\n${formattedItems}`
|
|
173
312
|
}
|
|
174
313
|
|
|
175
314
|
/**
|
|
176
|
-
* Logs a single "Datadog Test Optimization" summary at session end
|
|
177
|
-
* combining all relevant sections (ignored failures, dynamic names).
|
|
315
|
+
* Logs a single "Datadog Test Optimization" summary at session end.
|
|
178
316
|
*
|
|
179
317
|
* @param {{ efdNames: string[], quarantineNames: string[], totalCount: number } | undefined} ignoredFailures
|
|
180
318
|
*/
|
|
181
|
-
function logSessionSummary (ignoredFailures) {
|
|
182
|
-
|
|
319
|
+
function logSessionSummary (ignoredFailures, attemptToFixExecutions) {
|
|
320
|
+
logTestOptimizationSummary({
|
|
321
|
+
attemptToFixExecutions,
|
|
322
|
+
extraSections: [formatIgnoredFailuresSummary(ignoredFailures)],
|
|
323
|
+
newTestsWithDynamicNames,
|
|
324
|
+
})
|
|
325
|
+
loggedAttemptToFixTests.clear()
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function getTestStatusFromJestResult (status) {
|
|
329
|
+
if (status === 'failed') return 'fail'
|
|
330
|
+
if (status === 'passed') return 'pass'
|
|
331
|
+
}
|
|
183
332
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
333
|
+
function getAttemptToFixExecutionsFromJestResults (result) {
|
|
334
|
+
const executions = new Map()
|
|
335
|
+
const rootDir = result.globalConfig?.rootDir || process.cwd()
|
|
336
|
+
|
|
337
|
+
for (const { testResults, testFilePath } of result.results.testResults) {
|
|
338
|
+
const testSuite = getTestSuitePath(testFilePath, rootDir)
|
|
339
|
+
const testManagementTestsForSuite = testManagementTests
|
|
340
|
+
?.jest
|
|
341
|
+
?.suites
|
|
342
|
+
?.[testSuite]
|
|
343
|
+
?.tests
|
|
344
|
+
if (!testManagementTestsForSuite) continue
|
|
345
|
+
|
|
346
|
+
for (const { fullName, status } of testResults) {
|
|
347
|
+
const testName = removeSeedSuffixFromTestName(fullName)
|
|
348
|
+
const testStatus = getTestStatusFromJestResult(status)
|
|
349
|
+
if (!testStatus) continue
|
|
350
|
+
|
|
351
|
+
const testManagementTest = testManagementTestsForSuite[testName]?.properties
|
|
352
|
+
if (!testManagementTest?.attempt_to_fix) continue
|
|
353
|
+
|
|
354
|
+
recordAttemptToFixExecution(executions, {
|
|
355
|
+
testSuite,
|
|
356
|
+
testName,
|
|
357
|
+
status: testStatus,
|
|
358
|
+
isDisabled: testManagementTest.disabled,
|
|
359
|
+
isQuarantined: testManagementTest.quarantined,
|
|
360
|
+
})
|
|
188
361
|
}
|
|
189
|
-
|
|
190
|
-
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return executions
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function wrapConsoleErrorForJestReferenceErrors () {
|
|
368
|
+
if (isConsoleErrorWrapped) return
|
|
369
|
+
|
|
370
|
+
isConsoleErrorWrapped = true
|
|
371
|
+
// eslint-disable-next-line no-console
|
|
372
|
+
const originalConsoleError = console.error
|
|
373
|
+
// eslint-disable-next-line no-console
|
|
374
|
+
console.error = function () {
|
|
375
|
+
const [message] = arguments
|
|
376
|
+
if (
|
|
377
|
+
typeof message === 'string' &&
|
|
378
|
+
message.includes('Jest environment has been torn down') &&
|
|
379
|
+
activeTestSuiteAbsolutePath
|
|
380
|
+
) {
|
|
381
|
+
publishRuntimeReferenceError({ _testPath: activeTestSuiteAbsolutePath }, message)
|
|
191
382
|
}
|
|
192
|
-
|
|
193
|
-
`${ignoredFailures.totalCount} test failure(s) were ignored. Exit code set to 0.\n\n` +
|
|
194
|
-
formatList(items)
|
|
195
|
-
)
|
|
383
|
+
return originalConsoleError.apply(this, arguments)
|
|
196
384
|
}
|
|
385
|
+
}
|
|
197
386
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
387
|
+
function isDatadogJestEventHandled (event) {
|
|
388
|
+
return event && typeof event === 'object' && handledJestEvents.has(event)
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function markDatadogJestEventHandled (event) {
|
|
392
|
+
if (event && typeof event === 'object') {
|
|
393
|
+
handledJestEvents.add(event)
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Gets the original Jest concurrent registration function behind a Datadog wrapper.
|
|
399
|
+
*
|
|
400
|
+
* @param {(...args: unknown[]) => unknown} concurrentTest
|
|
401
|
+
* @returns {(...args: unknown[]) => unknown}
|
|
402
|
+
*/
|
|
403
|
+
function getOriginalConcurrentTest (concurrentTest) {
|
|
404
|
+
return concurrentTest[DD_JEST_CONCURRENT_TEST_ORIGINAL] || concurrentTest
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Marks a Datadog concurrent registration wrapper with its original Jest function.
|
|
409
|
+
*
|
|
410
|
+
* @param {(...args: unknown[]) => unknown} wrappedConcurrentTest
|
|
411
|
+
* @param {(...args: unknown[]) => unknown} originalConcurrentTest
|
|
412
|
+
* @returns {void}
|
|
413
|
+
*/
|
|
414
|
+
function setOriginalConcurrentTest (wrappedConcurrentTest, originalConcurrentTest) {
|
|
415
|
+
Object.defineProperty(wrappedConcurrentTest, DD_JEST_CONCURRENT_TEST_ORIGINAL, {
|
|
416
|
+
configurable: true,
|
|
417
|
+
value: originalConcurrentTest,
|
|
418
|
+
})
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Wraps a custom Jest environment handler so Datadog still observes events even
|
|
423
|
+
* when the custom environment does not call `super.handleTestEvent`.
|
|
424
|
+
*
|
|
425
|
+
* @param {(event: object, state: object) => Promise<void>|void} handleTestEvent
|
|
426
|
+
* @param {(event: object, state: object) => Promise<void>|void} datadogHandleTestEvent
|
|
427
|
+
* @returns {(event: object, state: object) => Promise<void>|void}
|
|
428
|
+
*/
|
|
429
|
+
function getWrappedCustomHandleTestEvent (handleTestEvent, datadogHandleTestEvent) {
|
|
430
|
+
if (
|
|
431
|
+
!handleTestEvent ||
|
|
432
|
+
handleTestEvent === datadogHandleTestEvent ||
|
|
433
|
+
handleTestEvent[DD_JEST_HANDLE_TEST_EVENT_WRAPPED]
|
|
434
|
+
) {
|
|
435
|
+
return handleTestEvent || datadogHandleTestEvent
|
|
209
436
|
}
|
|
210
437
|
|
|
211
|
-
|
|
438
|
+
const wrappedHandleTestEvent = function (event, state) {
|
|
439
|
+
const result = handleTestEvent.call(this, event, state)
|
|
440
|
+
const runDatadogHandler = value => {
|
|
441
|
+
if (isDatadogJestEventHandled(event)) return value
|
|
442
|
+
|
|
443
|
+
const datadogResult = datadogHandleTestEvent.call(this, event, state)
|
|
444
|
+
if (typeof datadogResult?.then === 'function') {
|
|
445
|
+
return datadogResult.then(() => value)
|
|
446
|
+
}
|
|
447
|
+
return value
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (event.name === 'add_test') {
|
|
451
|
+
runDatadogHandler(result)
|
|
452
|
+
return result
|
|
453
|
+
}
|
|
212
454
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
455
|
+
if (typeof result?.then === 'function') {
|
|
456
|
+
return result.then(runDatadogHandler)
|
|
457
|
+
}
|
|
458
|
+
return runDatadogHandler(result)
|
|
459
|
+
}
|
|
460
|
+
wrappedHandleTestEvent[DD_JEST_HANDLE_TEST_EVENT_WRAPPED] = true
|
|
461
|
+
return wrappedHandleTestEvent
|
|
216
462
|
}
|
|
217
463
|
|
|
218
464
|
function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
@@ -221,16 +467,20 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
221
467
|
super(config, context)
|
|
222
468
|
const rootDir = config.globalConfig ? config.globalConfig.rootDir : config.rootDir
|
|
223
469
|
this.rootDir = rootDir
|
|
224
|
-
this.testSuite = getTestSuitePath(context.testPath, rootDir)
|
|
225
470
|
this.nameToParams = {}
|
|
226
471
|
this.global._ddtrace = global._ddtrace
|
|
227
472
|
this.hasSnapshotTests = undefined
|
|
228
473
|
this.testSuiteAbsolutePath = context.testPath
|
|
474
|
+
activeTestSuiteAbsolutePath = this.testSuiteAbsolutePath
|
|
475
|
+
testSuiteDatadogEnvironments.set(this.testSuiteAbsolutePath, this)
|
|
476
|
+
wrapConsoleErrorForJestReferenceErrors()
|
|
477
|
+
this.globalConfig = config.globalConfig
|
|
229
478
|
|
|
230
479
|
this.displayName = config.projectConfig?.displayName?.name || config.displayName
|
|
231
480
|
this.testEnvironmentOptions = getTestEnvironmentOptions(config)
|
|
232
481
|
|
|
233
482
|
const repositoryRoot = this.testEnvironmentOptions._ddRepositoryRoot
|
|
483
|
+
this.testSuite = getTestSuitePath(context.testPath, rootDir)
|
|
234
484
|
|
|
235
485
|
// TODO: could we grab testPath from `this.getVmContext().expect.getState()` instead?
|
|
236
486
|
// so we don't rely on context being passed (some custom test environment do not pass it)
|
|
@@ -246,6 +496,12 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
246
496
|
this.isKnownTestsEnabled = this.testEnvironmentOptions._ddIsKnownTestsEnabled
|
|
247
497
|
this.isTestManagementTestsEnabled = this.testEnvironmentOptions._ddIsTestManagementTestsEnabled
|
|
248
498
|
this.isImpactedTestsEnabled = this.testEnvironmentOptions._ddIsImpactedTestsEnabled
|
|
499
|
+
this.hasConcurrentTests = false
|
|
500
|
+
this.concurrentTestContexts = new Map()
|
|
501
|
+
this.concurrentTestStates = new WeakMap()
|
|
502
|
+
this.concurrentTestSourceFns = new WeakMap()
|
|
503
|
+
this.wrappedConcurrentTestFunctions = new WeakSet()
|
|
504
|
+
this.jestEachBind = undefined
|
|
249
505
|
|
|
250
506
|
if (this.isKnownTestsEnabled) {
|
|
251
507
|
earlyFlakeDetectionSlowTestRetries = this.testEnvironmentOptions._ddEarlyFlakeDetectionSlowTestRetries ?? {}
|
|
@@ -293,6 +549,390 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
293
549
|
this.isImpactedTestsEnabled = false
|
|
294
550
|
}
|
|
295
551
|
}
|
|
552
|
+
|
|
553
|
+
this[DD_JEST_HANDLE_TEST_EVENT_DATADOG] = DatadogEnvironment.prototype.handleTestEvent
|
|
554
|
+
this.wrapCustomHandleTestEvent(DatadogEnvironment.prototype.handleTestEvent)
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Rechecks custom `handleTestEvent` implementations after subclass instance fields
|
|
559
|
+
* and constructors have run.
|
|
560
|
+
*
|
|
561
|
+
* @returns {Promise<void>|void}
|
|
562
|
+
*/
|
|
563
|
+
setup () {
|
|
564
|
+
this.wrapCustomHandleTestEvent(DatadogEnvironment.prototype.handleTestEvent)
|
|
565
|
+
|
|
566
|
+
if (super.setup) {
|
|
567
|
+
const result = super.setup()
|
|
568
|
+
if (typeof result?.then === 'function') {
|
|
569
|
+
return result.then(() => {
|
|
570
|
+
this.wrapCustomHandleTestEvent(DatadogEnvironment.prototype.handleTestEvent)
|
|
571
|
+
})
|
|
572
|
+
}
|
|
573
|
+
this.wrapCustomHandleTestEvent(DatadogEnvironment.prototype.handleTestEvent)
|
|
574
|
+
return result
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Wraps Jest's concurrent test registration methods so eager concurrent bodies
|
|
580
|
+
* in older Jest versions execute inside their test span context.
|
|
581
|
+
*
|
|
582
|
+
* @param {object} state
|
|
583
|
+
* @returns {void}
|
|
584
|
+
*/
|
|
585
|
+
wrapConcurrentTest (state) {
|
|
586
|
+
this.concurrentTestState = state
|
|
587
|
+
this.wrapConcurrentTestGlobals(this.global.test, state)
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Wraps one Jest `test` function object's concurrent registration methods.
|
|
592
|
+
*
|
|
593
|
+
* @param {Function|undefined} test
|
|
594
|
+
* @param {object} state
|
|
595
|
+
* @returns {void}
|
|
596
|
+
*/
|
|
597
|
+
wrapConcurrentTestGlobals (test, state) {
|
|
598
|
+
if (!state) return
|
|
599
|
+
|
|
600
|
+
const concurrentTest = test?.concurrent
|
|
601
|
+
if (typeof concurrentTest !== 'function') return
|
|
602
|
+
|
|
603
|
+
this.wrapConcurrentTestFunction(test, 'concurrent', state, test, test)
|
|
604
|
+
this.wrapConcurrentTestFunction(test.concurrent, 'only', state, test.only, test)
|
|
605
|
+
this.wrapConcurrentTestFunction(test.concurrent, 'failing', state, test.failing, test)
|
|
606
|
+
this.wrapConcurrentTestFunction(test.concurrent.only, 'failing', state, test.only?.failing, test.only)
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Wraps one concurrent test function variant.
|
|
611
|
+
*
|
|
612
|
+
* @param {object} target
|
|
613
|
+
* @param {string} methodName
|
|
614
|
+
* @param {object} state
|
|
615
|
+
* @param {Function|undefined} serialTest
|
|
616
|
+
* @param {unknown} serialTestThisArg
|
|
617
|
+
* @returns {void}
|
|
618
|
+
*/
|
|
619
|
+
wrapConcurrentTestFunction (target, methodName, state, serialTest, serialTestThisArg) {
|
|
620
|
+
let concurrentTest = target?.[methodName]
|
|
621
|
+
if (typeof concurrentTest !== 'function') return
|
|
622
|
+
if (this.wrappedConcurrentTestFunctions.has(concurrentTest)) return
|
|
623
|
+
|
|
624
|
+
const originalConcurrentTest = getOriginalConcurrentTest(concurrentTest)
|
|
625
|
+
if (originalConcurrentTest !== concurrentTest) {
|
|
626
|
+
target[methodName] = originalConcurrentTest
|
|
627
|
+
concurrentTest = originalConcurrentTest
|
|
628
|
+
}
|
|
629
|
+
if (typeof concurrentTest !== 'function') return
|
|
630
|
+
|
|
631
|
+
const environment = this
|
|
632
|
+
shimmer.wrap(target, methodName, concurrentTest => {
|
|
633
|
+
return function wrappedConcurrentTest (testName, testFn, ...args) {
|
|
634
|
+
if (typeof testFn !== 'function') {
|
|
635
|
+
return concurrentTest.apply(this, arguments)
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
environment.hasConcurrentTests = true
|
|
639
|
+
const asyncError = environment.isImpactedTestsEnabled
|
|
640
|
+
? new Error('Datadog concurrent test registration')
|
|
641
|
+
: undefined
|
|
642
|
+
const wrappedTestFn = environment.createConcurrentTestFn(testName, testFn, asyncError, state, {
|
|
643
|
+
concurrentTest,
|
|
644
|
+
concurrentTestThisArg: this,
|
|
645
|
+
serialTest,
|
|
646
|
+
serialTestThisArg,
|
|
647
|
+
sourceTestFn: environment.concurrentTestSourceFns.get(testFn),
|
|
648
|
+
})
|
|
649
|
+
return concurrentTest.call(this, testName, wrappedTestFn, ...args)
|
|
650
|
+
}
|
|
651
|
+
})
|
|
652
|
+
|
|
653
|
+
const wrappedConcurrentTest = target[methodName]
|
|
654
|
+
setOriginalConcurrentTest(wrappedConcurrentTest, concurrentTest)
|
|
655
|
+
this.wrappedConcurrentTestFunctions.add(wrappedConcurrentTest)
|
|
656
|
+
this.bindConcurrentEach(wrappedConcurrentTest, methodName === 'failing')
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* Rebuilds a concurrent `.each` helper so each generated row calls the wrapped test function.
|
|
661
|
+
*
|
|
662
|
+
* @param {Function} concurrentTest
|
|
663
|
+
* @param {boolean} needsEachError
|
|
664
|
+
* @returns {void}
|
|
665
|
+
*/
|
|
666
|
+
bindConcurrentEach (concurrentTest, needsEachError) {
|
|
667
|
+
if (typeof concurrentTest?.each !== 'function') return
|
|
668
|
+
|
|
669
|
+
const bind = this.getJestEachBind()
|
|
670
|
+
if (typeof bind !== 'function') return
|
|
671
|
+
|
|
672
|
+
const environment = this
|
|
673
|
+
concurrentTest.each = function wrappedConcurrentEach (...eachArgs) {
|
|
674
|
+
const testParameters = getFormattedJestTestParameters(eachArgs)
|
|
675
|
+
return function (...testArgs) {
|
|
676
|
+
let parameterIndex = 0
|
|
677
|
+
const sourceTestFn = testArgs[1]
|
|
678
|
+
const concurrentEachTest = function (testName, testFn, ...callArgs) {
|
|
679
|
+
const parameters = testParameters?.[parameterIndex++]
|
|
680
|
+
if (parameters !== undefined) {
|
|
681
|
+
environment.appendNameToParams(testName, parameters)
|
|
682
|
+
}
|
|
683
|
+
if (typeof testFn === 'function' && typeof sourceTestFn === 'function') {
|
|
684
|
+
environment.concurrentTestSourceFns.set(testFn, sourceTestFn)
|
|
685
|
+
}
|
|
686
|
+
return concurrentTest.call(this, testName, testFn, ...callArgs)
|
|
687
|
+
}
|
|
688
|
+
const eachBind = bind(concurrentEachTest, false, needsEachError).apply(this, eachArgs)
|
|
689
|
+
return eachBind.apply(this, testArgs)
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/**
|
|
695
|
+
* Creates a Jest test function wrapper and stores its concurrent execution state.
|
|
696
|
+
*
|
|
697
|
+
* @param {string} testName
|
|
698
|
+
* @param {(...args: unknown[]) => unknown} testFn
|
|
699
|
+
* @param {Error|undefined} asyncError
|
|
700
|
+
* @param {object} state
|
|
701
|
+
* @param {ConcurrentTestOptions|undefined} options
|
|
702
|
+
* @returns {(...args: unknown[]) => unknown}
|
|
703
|
+
*/
|
|
704
|
+
createConcurrentTestFn (testName, testFn, asyncError, state, options) {
|
|
705
|
+
const concurrentTestState = {
|
|
706
|
+
concurrentTest: options?.concurrentTest,
|
|
707
|
+
concurrentTestThisArg: options?.concurrentTestThisArg,
|
|
708
|
+
ctx: this.createConcurrentTestContext(testName, testFn, asyncError, state, options),
|
|
709
|
+
numExecutions: 0,
|
|
710
|
+
serialTest: options?.serialTest,
|
|
711
|
+
serialTestThisArg: options?.serialTestThisArg,
|
|
712
|
+
state,
|
|
713
|
+
testFn,
|
|
714
|
+
}
|
|
715
|
+
concurrentTestState.ctx.concurrentTestState = concurrentTestState
|
|
716
|
+
const environment = this
|
|
717
|
+
const wrappedTestFn = shimmer.wrapFunction(testFn, testFn => function (...args) {
|
|
718
|
+
return environment.runConcurrentTestFn(concurrentTestState, testFn, this, args)
|
|
719
|
+
})
|
|
720
|
+
this.concurrentTestStates.set(wrappedTestFn, concurrentTestState)
|
|
721
|
+
return wrappedTestFn
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Gets Jest's table-driven test binder from the user's Jest installation.
|
|
726
|
+
*
|
|
727
|
+
* @returns {Function|undefined}
|
|
728
|
+
*/
|
|
729
|
+
getJestEachBind () {
|
|
730
|
+
if (this.jestEachBind !== undefined) return this.jestEachBind
|
|
731
|
+
|
|
732
|
+
if (typeof jestEachBind === 'function') {
|
|
733
|
+
this.jestEachBind = jestEachBind
|
|
734
|
+
return this.jestEachBind
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
let jestEach
|
|
738
|
+
try {
|
|
739
|
+
jestEach = createRequire(path.join(this.rootDir, 'package.json'))('jest-each')
|
|
740
|
+
} catch {
|
|
741
|
+
try {
|
|
742
|
+
jestEach = createRequire(path.join(process.cwd(), 'package.json'))('jest-each')
|
|
743
|
+
} catch {
|
|
744
|
+
jestEach = undefined
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
this.jestEachBind = jestEach?.bind
|
|
748
|
+
return this.jestEachBind
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* Creates the context used to start and finish a concurrent test span.
|
|
753
|
+
*
|
|
754
|
+
* @param {string} testName
|
|
755
|
+
* @param {(...args: unknown[]) => unknown} testFn
|
|
756
|
+
* @param {Error|undefined} asyncError
|
|
757
|
+
* @param {object} state
|
|
758
|
+
* @param {ConcurrentTestOptions|undefined} options
|
|
759
|
+
* @returns {object}
|
|
760
|
+
*/
|
|
761
|
+
createConcurrentTestContext (testName, testFn, asyncError, state, options) {
|
|
762
|
+
const testFullName = this.getTestNameFromAddTestEvent({ testName }, state)
|
|
763
|
+
const isNewTest = this.isKnownTestsEnabled && !this.knownTestsForThisSuite?.includes(testFullName)
|
|
764
|
+
const isAttemptToFix = this.isTestManagementTestsEnabled &&
|
|
765
|
+
this.testManagementTestsForThisSuite?.attemptToFix?.includes(testFullName)
|
|
766
|
+
const sourceTestFn = options?.sourceTestFn || testFn
|
|
767
|
+
const ctx = {
|
|
768
|
+
name: testFullName,
|
|
769
|
+
suite: this.testSuite,
|
|
770
|
+
testSourceFile: this.testSourceFile,
|
|
771
|
+
displayName: this.displayName,
|
|
772
|
+
testParameters: options?.testParameters || getTestParametersString(this.nameToParams, testName),
|
|
773
|
+
frameworkVersion: jestVersion,
|
|
774
|
+
isNew: isNewTest,
|
|
775
|
+
isEfdRetry: options?.isEfdRetry === true,
|
|
776
|
+
isAttemptToFix,
|
|
777
|
+
isAttemptToFixRetry: options?.isAttemptToFixRetry === true,
|
|
778
|
+
isJestRetry: false,
|
|
779
|
+
isDisabled: this.testManagementTestsForThisSuite?.disabled?.includes(testFullName),
|
|
780
|
+
isQuarantined: this.testManagementTestsForThisSuite?.quarantined?.includes(testFullName),
|
|
781
|
+
isModified: options?.isModified ?? this.isTestModified(asyncError, sourceTestFn),
|
|
782
|
+
hasDynamicName: isNewTest && DYNAMIC_NAME_RE.test(testFullName),
|
|
783
|
+
testSuiteAbsolutePath: this.testSuiteAbsolutePath,
|
|
784
|
+
}
|
|
785
|
+
let contexts = this.concurrentTestContexts.get(testFullName)
|
|
786
|
+
if (contexts) {
|
|
787
|
+
contexts.push(ctx)
|
|
788
|
+
} else {
|
|
789
|
+
contexts = [ctx]
|
|
790
|
+
this.concurrentTestContexts.set(testFullName, contexts)
|
|
791
|
+
}
|
|
792
|
+
return ctx
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* Checks if a test overlaps modified lines for impacted-test detection.
|
|
797
|
+
*
|
|
798
|
+
* @param {Error|undefined} asyncError
|
|
799
|
+
* @param {Function|undefined} testFn
|
|
800
|
+
* @returns {boolean}
|
|
801
|
+
*/
|
|
802
|
+
isTestModified (asyncError, testFn) {
|
|
803
|
+
if (!this.isImpactedTestsEnabled || !asyncError || typeof testFn !== 'function') return false
|
|
804
|
+
|
|
805
|
+
const testStartLine = getTestLineStart(asyncError, this.testSuite)
|
|
806
|
+
const testEndLine = getTestEndLine(testFn, testStartLine)
|
|
807
|
+
return isModifiedTest(
|
|
808
|
+
this.testSourceFile,
|
|
809
|
+
testStartLine,
|
|
810
|
+
testEndLine,
|
|
811
|
+
this.modifiedFiles,
|
|
812
|
+
'jest'
|
|
813
|
+
)
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* Gets the next registered concurrent test context for a full Jest test name.
|
|
818
|
+
*
|
|
819
|
+
* @param {string} testName
|
|
820
|
+
* @returns {object|undefined}
|
|
821
|
+
*/
|
|
822
|
+
getNextConcurrentTestContext (testName) {
|
|
823
|
+
const contexts = this.concurrentTestContexts.get(testName)
|
|
824
|
+
if (!contexts?.length) return
|
|
825
|
+
|
|
826
|
+
const ctx = contexts.shift()
|
|
827
|
+
if (contexts.length === 0) {
|
|
828
|
+
this.concurrentTestContexts.delete(testName)
|
|
829
|
+
}
|
|
830
|
+
return ctx
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
/**
|
|
834
|
+
* Removes one registered concurrent test context from the name fallback queue.
|
|
835
|
+
*
|
|
836
|
+
* @param {string} testName
|
|
837
|
+
* @param {object} ctx
|
|
838
|
+
* @returns {void}
|
|
839
|
+
*/
|
|
840
|
+
removeConcurrentTestContext (testName, ctx) {
|
|
841
|
+
const contexts = this.concurrentTestContexts.get(testName)
|
|
842
|
+
if (!contexts?.length) return
|
|
843
|
+
|
|
844
|
+
const contextIndex = contexts.indexOf(ctx)
|
|
845
|
+
if (contextIndex === -1) return
|
|
846
|
+
|
|
847
|
+
contexts.splice(contextIndex, 1)
|
|
848
|
+
if (contexts.length === 0) {
|
|
849
|
+
this.concurrentTestContexts.delete(testName)
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
/**
|
|
854
|
+
* Records formatted parameters for one table-driven Jest test declaration.
|
|
855
|
+
*
|
|
856
|
+
* @param {string} name
|
|
857
|
+
* @param {unknown[]} params
|
|
858
|
+
* @returns {void}
|
|
859
|
+
*/
|
|
860
|
+
setNameToParams (name, params) {
|
|
861
|
+
this.nameToParams[name] = [...params]
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
/**
|
|
865
|
+
* Appends formatted parameters for one table-driven Jest test row.
|
|
866
|
+
*
|
|
867
|
+
* @param {string} name
|
|
868
|
+
* @param {unknown[]|object} params
|
|
869
|
+
* @returns {void}
|
|
870
|
+
*/
|
|
871
|
+
appendNameToParams (name, params) {
|
|
872
|
+
if (this.nameToParams[name]) {
|
|
873
|
+
this.nameToParams[name].push(params)
|
|
874
|
+
} else {
|
|
875
|
+
this.nameToParams[name] = [params]
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* Runs a concurrent test function inside its test span context.
|
|
881
|
+
*
|
|
882
|
+
* @param {{ ctx: object, numExecutions: number }} concurrentTestState
|
|
883
|
+
* @param {(...args: unknown[]) => unknown} testFn
|
|
884
|
+
* @param {object} thisArg
|
|
885
|
+
* @param {unknown[]} args
|
|
886
|
+
* @returns {unknown|void}
|
|
887
|
+
*/
|
|
888
|
+
runConcurrentTestFn (concurrentTestState, testFn, thisArg, args) {
|
|
889
|
+
const ctx = concurrentTestState.ctx
|
|
890
|
+
if (ctx.isDisabled && !ctx.isAttemptToFix) {
|
|
891
|
+
const done = args[0]
|
|
892
|
+
if (typeof done === 'function') {
|
|
893
|
+
done()
|
|
894
|
+
}
|
|
895
|
+
return
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
const runTest = () => testFn.apply(thisArg, args)
|
|
899
|
+
if (!ctx.isAttemptToFixRetry && !ctx.isEfdRetry) {
|
|
900
|
+
ctx.isJestRetry = concurrentTestState.numExecutions > 0
|
|
901
|
+
}
|
|
902
|
+
concurrentTestState.numExecutions++
|
|
903
|
+
|
|
904
|
+
if (ctx.currentStore) {
|
|
905
|
+
return testFnCh.runStores(ctx, runTest)
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
let result
|
|
909
|
+
testStartCh.runStores(ctx, () => {
|
|
910
|
+
result = testFnCh.runStores(ctx, runTest)
|
|
911
|
+
})
|
|
912
|
+
return result
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
* Ensures Datadog handles Jest circus events even when a custom environment overrides
|
|
917
|
+
* `handleTestEvent` without calling `super.handleTestEvent`.
|
|
918
|
+
*
|
|
919
|
+
* @param {(event: object, state: object) => Promise<void>|void} datadogHandleTestEvent
|
|
920
|
+
* @returns {void}
|
|
921
|
+
*/
|
|
922
|
+
wrapCustomHandleTestEvent (datadogHandleTestEvent) {
|
|
923
|
+
const descriptor = Object.getOwnPropertyDescriptor(this, 'handleTestEvent')
|
|
924
|
+
let handleTestEvent = getWrappedCustomHandleTestEvent(this.handleTestEvent, datadogHandleTestEvent)
|
|
925
|
+
|
|
926
|
+
Object.defineProperty(this, 'handleTestEvent', {
|
|
927
|
+
configurable: true,
|
|
928
|
+
enumerable: descriptor?.enumerable ?? false,
|
|
929
|
+
get () {
|
|
930
|
+
return handleTestEvent
|
|
931
|
+
},
|
|
932
|
+
set (value) {
|
|
933
|
+
handleTestEvent = getWrappedCustomHandleTestEvent(value, datadogHandleTestEvent)
|
|
934
|
+
},
|
|
935
|
+
})
|
|
296
936
|
}
|
|
297
937
|
|
|
298
938
|
/**
|
|
@@ -335,6 +975,10 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
335
975
|
*/
|
|
336
976
|
resetMockState () {
|
|
337
977
|
try {
|
|
978
|
+
if (this.moduleMocker?.clearAllMocks) {
|
|
979
|
+
this.moduleMocker.clearAllMocks()
|
|
980
|
+
return
|
|
981
|
+
}
|
|
338
982
|
const jestObject = testSuiteJestObjects.get(this.testSuiteAbsolutePath)
|
|
339
983
|
if (jestObject?.clearAllMocks) {
|
|
340
984
|
jestObject.clearAllMocks()
|
|
@@ -402,12 +1046,47 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
402
1046
|
// Generic function to handle test retries
|
|
403
1047
|
retryTest ({
|
|
404
1048
|
jestEvent,
|
|
1049
|
+
forceSerial,
|
|
405
1050
|
retryCount,
|
|
406
1051
|
retryType,
|
|
407
1052
|
}) {
|
|
408
1053
|
const { testName, fn, timeout } = jestEvent
|
|
1054
|
+
const isAttemptToFixRetry = retryType === 'Test Management (Attempt to Fix)'
|
|
1055
|
+
const isEfdRetry = retryType === 'Impacted tests' || retryType === 'Early flake detection'
|
|
409
1056
|
for (let retryIndex = 0; retryIndex < retryCount; retryIndex++) {
|
|
410
|
-
|
|
1057
|
+
const concurrentTestState = this.concurrentTestStates.get(fn)
|
|
1058
|
+
if (concurrentTestState) {
|
|
1059
|
+
const test = forceSerial
|
|
1060
|
+
? concurrentTestState.serialTest
|
|
1061
|
+
: (
|
|
1062
|
+
concurrentTestState.concurrentTest ||
|
|
1063
|
+
getOriginalConcurrentTest(this.global.test?.concurrent)
|
|
1064
|
+
)
|
|
1065
|
+
if (typeof test !== 'function') {
|
|
1066
|
+
log.error('%s could not retry concurrent test because test is undefined', retryType)
|
|
1067
|
+
continue
|
|
1068
|
+
}
|
|
1069
|
+
const retryFn = this.createConcurrentTestFn(
|
|
1070
|
+
testName,
|
|
1071
|
+
concurrentTestState.testFn,
|
|
1072
|
+
undefined,
|
|
1073
|
+
concurrentTestState.state,
|
|
1074
|
+
{
|
|
1075
|
+
concurrentTest: concurrentTestState.concurrentTest,
|
|
1076
|
+
concurrentTestThisArg: concurrentTestState.concurrentTestThisArg,
|
|
1077
|
+
isAttemptToFixRetry,
|
|
1078
|
+
isEfdRetry,
|
|
1079
|
+
isModified: concurrentTestState.ctx.isModified,
|
|
1080
|
+
serialTest: concurrentTestState.serialTest,
|
|
1081
|
+
serialTestThisArg: concurrentTestState.serialTestThisArg,
|
|
1082
|
+
testParameters: concurrentTestState.ctx.testParameters,
|
|
1083
|
+
}
|
|
1084
|
+
)
|
|
1085
|
+
const thisArg = forceSerial
|
|
1086
|
+
? concurrentTestState.serialTestThisArg
|
|
1087
|
+
: concurrentTestState.concurrentTestThisArg
|
|
1088
|
+
test.call(thisArg, testName, retryFn, timeout)
|
|
1089
|
+
} else if (this.global.test) {
|
|
411
1090
|
this.global.test(testName, fn, timeout)
|
|
412
1091
|
} else {
|
|
413
1092
|
log.error('%s could not retry test because global.test is undefined', retryType)
|
|
@@ -415,36 +1094,45 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
415
1094
|
}
|
|
416
1095
|
}
|
|
417
1096
|
|
|
418
|
-
getShouldStripSeedFromTestName () {
|
|
419
|
-
return testSuiteAbsolutePathsWithFastCheck.has(this.testSuiteAbsolutePath)
|
|
420
|
-
}
|
|
421
|
-
|
|
422
1097
|
// At the `add_test` event we don't have the test object yet, so we can't use it
|
|
423
1098
|
getTestNameFromAddTestEvent (event, state) {
|
|
424
|
-
const describeSuffix =
|
|
425
|
-
|
|
1099
|
+
const describeSuffix = getRawJestTestName(state.currentDescribeBlock)
|
|
1100
|
+
const testName = describeSuffix ? `${describeSuffix} ${event.testName}` : event.testName
|
|
1101
|
+
return removeSeedSuffixFromTestName(testName)
|
|
426
1102
|
}
|
|
427
1103
|
|
|
428
1104
|
async handleTestEvent (event, state) {
|
|
1105
|
+
if (isDatadogJestEventHandled(event)) return
|
|
1106
|
+
markDatadogJestEventHandled(event)
|
|
1107
|
+
|
|
429
1108
|
if (super.handleTestEvent) {
|
|
430
1109
|
await super.handleTestEvent(event, state)
|
|
431
1110
|
}
|
|
432
1111
|
|
|
433
|
-
|
|
434
|
-
|
|
1112
|
+
if (event.name === 'setup') {
|
|
1113
|
+
this.wrapConcurrentTest(state)
|
|
1114
|
+
}
|
|
435
1115
|
if (event.name === 'setup' && this.global.test) {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
1116
|
+
const environment = this
|
|
1117
|
+
shimmer.wrap(this.global.test, 'each', each => function (...args) {
|
|
1118
|
+
const testParameters = getFormattedJestTestParameters(args)
|
|
1119
|
+
const eachBind = each.apply(this, args)
|
|
1120
|
+
return function (...args) {
|
|
1121
|
+
const [testName] = args
|
|
1122
|
+
environment.setNameToParams(testName, testParameters)
|
|
1123
|
+
return eachBind.apply(this, args)
|
|
443
1124
|
}
|
|
444
1125
|
})
|
|
445
1126
|
}
|
|
446
1127
|
if (event.name === 'test_start') {
|
|
447
|
-
const testName = getJestTestName(event.test
|
|
1128
|
+
const testName = getJestTestName(event.test)
|
|
1129
|
+
const concurrentTestState = this.concurrentTestStates.get(event.test.fn)
|
|
1130
|
+
let concurrentCtx = concurrentTestState?.ctx
|
|
1131
|
+
if (concurrentCtx) {
|
|
1132
|
+
this.removeConcurrentTestContext(testName, concurrentCtx)
|
|
1133
|
+
} else {
|
|
1134
|
+
concurrentCtx = this.getNextConcurrentTestContext(testName)
|
|
1135
|
+
}
|
|
448
1136
|
if (testsToBeRetried.has(testName)) {
|
|
449
1137
|
// This is needed because we're retrying tests with the same name
|
|
450
1138
|
this.resetSnapshotState()
|
|
@@ -454,7 +1142,9 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
454
1142
|
let isNewTest = false
|
|
455
1143
|
let numEfdRetry = null
|
|
456
1144
|
let numOfAttemptsToFixRetries = null
|
|
457
|
-
const testParameters =
|
|
1145
|
+
const testParameters = concurrentCtx?.testParameters ||
|
|
1146
|
+
concurrentTestState?.ctx?.testParameters ||
|
|
1147
|
+
getTestParametersString(this.nameToParams, event.test.name)
|
|
458
1148
|
|
|
459
1149
|
let isAttemptToFix = false
|
|
460
1150
|
let isDisabled = false
|
|
@@ -471,21 +1161,13 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
471
1161
|
}
|
|
472
1162
|
}
|
|
473
1163
|
|
|
474
|
-
let isModified =
|
|
475
|
-
if (
|
|
476
|
-
|
|
477
|
-
const testEndLine = getTestEndLine(event.test.fn, testStartLine)
|
|
478
|
-
isModified = isModifiedTest(
|
|
479
|
-
this.testSourceFile,
|
|
480
|
-
testStartLine,
|
|
481
|
-
testEndLine,
|
|
482
|
-
this.modifiedFiles,
|
|
483
|
-
'jest'
|
|
484
|
-
)
|
|
1164
|
+
let isModified = this.isTestModified(event.test.asyncError, event.test.fn)
|
|
1165
|
+
if (concurrentCtx?.isModified || concurrentTestState?.ctx?.isModified) {
|
|
1166
|
+
isModified = true
|
|
485
1167
|
}
|
|
486
1168
|
|
|
487
1169
|
if (this.isKnownTestsEnabled) {
|
|
488
|
-
isNewTest =
|
|
1170
|
+
isNewTest = newTests.has(testName)
|
|
489
1171
|
}
|
|
490
1172
|
|
|
491
1173
|
const willRunEfd = this.isEarlyFlakeDetectionEnabled && (isNewTest || isModified)
|
|
@@ -498,27 +1180,34 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
498
1180
|
|
|
499
1181
|
const isJestRetry = event.test?.invocations > 1
|
|
500
1182
|
const hasDynamicName = isNewTest && DYNAMIC_NAME_RE.test(testName)
|
|
501
|
-
const ctx = {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
1183
|
+
const ctx = concurrentCtx || concurrentTestState?.ctx || {}
|
|
1184
|
+
ctx.name = testName
|
|
1185
|
+
ctx.suite = this.testSuite
|
|
1186
|
+
ctx.testSourceFile = this.testSourceFile
|
|
1187
|
+
ctx.displayName = this.displayName
|
|
1188
|
+
ctx.testParameters = testParameters
|
|
1189
|
+
ctx.frameworkVersion = jestVersion
|
|
1190
|
+
ctx.isNew = isNewTest
|
|
1191
|
+
ctx.isEfdRetry = ctx.isEfdRetry || numEfdRetry > 0
|
|
1192
|
+
ctx.isAttemptToFix = isAttemptToFix
|
|
1193
|
+
ctx.isAttemptToFixRetry = ctx.isAttemptToFixRetry || numOfAttemptsToFixRetries > 0
|
|
1194
|
+
ctx.isJestRetry = isJestRetry
|
|
1195
|
+
ctx.isDisabled = isDisabled
|
|
1196
|
+
ctx.isQuarantined = isQuarantined
|
|
1197
|
+
ctx.isModified = isModified
|
|
1198
|
+
ctx.hasDynamicName = hasDynamicName
|
|
1199
|
+
ctx.testSuiteAbsolutePath = this.testSuiteAbsolutePath
|
|
1200
|
+
if (concurrentTestState) {
|
|
1201
|
+
ctx.concurrentTestState = concurrentTestState
|
|
1202
|
+
concurrentTestState.ctx = ctx
|
|
518
1203
|
}
|
|
519
1204
|
testContexts.set(event.test, ctx)
|
|
520
1205
|
|
|
521
|
-
|
|
1206
|
+
if (isAttemptToFix) {
|
|
1207
|
+
logAttemptToFixTestExecution(this.testSuite, testName, loggedAttemptToFixTests)
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
const wrapTestAndHooks = () => {
|
|
522
1211
|
let p = event.test.parent
|
|
523
1212
|
const hooks = []
|
|
524
1213
|
while (p != null) {
|
|
@@ -532,20 +1221,67 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
532
1221
|
} else {
|
|
533
1222
|
originalHookFns.set(hook, hookFn)
|
|
534
1223
|
}
|
|
535
|
-
const newHookFn = shimmer.wrapFunction(hookFn, hookFn => function () {
|
|
536
|
-
return testFnCh.runStores(ctx, () => hookFn.apply(this,
|
|
1224
|
+
const newHookFn = shimmer.wrapFunction(hookFn, hookFn => function (...args) {
|
|
1225
|
+
return testFnCh.runStores(ctx, () => hookFn.apply(this, args))
|
|
537
1226
|
})
|
|
538
1227
|
hook.fn = newHookFn
|
|
539
1228
|
}
|
|
1229
|
+
|
|
540
1230
|
const originalFn = event.test.fn
|
|
541
1231
|
originalTestFns.set(event.test, originalFn)
|
|
542
1232
|
|
|
543
|
-
const newFn = shimmer.wrapFunction(event.test.fn, testFn => function () {
|
|
544
|
-
return testFnCh.runStores(ctx, () => testFn.apply(this,
|
|
1233
|
+
const newFn = shimmer.wrapFunction(event.test.fn, testFn => function (...args) {
|
|
1234
|
+
return testFnCh.runStores(ctx, () => testFn.apply(this, args))
|
|
545
1235
|
})
|
|
546
1236
|
|
|
547
1237
|
event.test.fn = newFn
|
|
548
|
-
}
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
const isConcurrentTest = event.test.concurrent || ctx.concurrentTestState
|
|
1241
|
+
if (isConcurrentTest) {
|
|
1242
|
+
if (!ctx.currentStore && event.test.errors?.length) {
|
|
1243
|
+
testStartCh.runStores(ctx, () => {})
|
|
1244
|
+
}
|
|
1245
|
+
} else if (ctx.currentStore) {
|
|
1246
|
+
wrapTestAndHooks()
|
|
1247
|
+
} else {
|
|
1248
|
+
testStartCh.runStores(ctx, wrapTestAndHooks)
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
if (event.name === 'hook_start' && (event.hook.type === 'beforeEach' || event.hook.type === 'afterEach')) {
|
|
1253
|
+
const ctx = testContexts.get(event.test) || this.concurrentTestStates.get(event.test?.fn)?.ctx
|
|
1254
|
+
if (ctx?.concurrentTestState && (!ctx.isDisabled || ctx.isAttemptToFix)) {
|
|
1255
|
+
let hookFn = event.hook.fn
|
|
1256
|
+
if (originalHookFns.has(event.hook)) {
|
|
1257
|
+
hookFn = originalHookFns.get(event.hook)
|
|
1258
|
+
} else {
|
|
1259
|
+
originalHookFns.set(event.hook, hookFn)
|
|
1260
|
+
}
|
|
1261
|
+
let hookContexts = concurrentHookContextQueues.get(event.hook)
|
|
1262
|
+
if (!hookContexts) {
|
|
1263
|
+
hookContexts = []
|
|
1264
|
+
concurrentHookContextQueues.set(event.hook, hookContexts)
|
|
1265
|
+
}
|
|
1266
|
+
hookContexts.push(ctx)
|
|
1267
|
+
if (!ctx.currentStore) {
|
|
1268
|
+
testStartCh.runStores(ctx, () => {})
|
|
1269
|
+
}
|
|
1270
|
+
let concurrentHookFn = concurrentHookFns.get(event.hook)
|
|
1271
|
+
if (!concurrentHookFn) {
|
|
1272
|
+
concurrentHookFn = shimmer.wrapFunction(hookFn, hookFn => function (...args) {
|
|
1273
|
+
const hookContexts = concurrentHookContextQueues.get(event.hook)
|
|
1274
|
+
const [hookCtx] = hookContexts || []
|
|
1275
|
+
if (hookCtx) {
|
|
1276
|
+
hookContexts.shift()
|
|
1277
|
+
return testFnCh.runStores(hookCtx, () => hookFn.apply(this, args))
|
|
1278
|
+
}
|
|
1279
|
+
return hookFn.apply(this, args)
|
|
1280
|
+
})
|
|
1281
|
+
concurrentHookFns.set(event.hook, concurrentHookFn)
|
|
1282
|
+
}
|
|
1283
|
+
event.hook.fn = concurrentHookFn
|
|
1284
|
+
}
|
|
549
1285
|
}
|
|
550
1286
|
|
|
551
1287
|
if (event.name === 'hook_start' && (event.hook.type === 'beforeAll' || event.hook.type === 'afterAll')) {
|
|
@@ -556,12 +1292,16 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
556
1292
|
} else {
|
|
557
1293
|
originalHookFns.set(event.hook, hookFn)
|
|
558
1294
|
}
|
|
559
|
-
event.hook.fn = shimmer.wrapFunction(hookFn, hookFn => function () {
|
|
560
|
-
return testSuiteHookFnCh.runStores(ctx, () => hookFn.apply(this,
|
|
1295
|
+
event.hook.fn = shimmer.wrapFunction(hookFn, hookFn => function (...args) {
|
|
1296
|
+
return testSuiteHookFnCh.runStores(ctx, () => hookFn.apply(this, args))
|
|
561
1297
|
})
|
|
562
1298
|
}
|
|
563
1299
|
|
|
564
1300
|
if (event.name === 'add_test') {
|
|
1301
|
+
if (event.concurrent) {
|
|
1302
|
+
this.hasConcurrentTests = true
|
|
1303
|
+
}
|
|
1304
|
+
|
|
565
1305
|
if (event.failing) {
|
|
566
1306
|
return
|
|
567
1307
|
}
|
|
@@ -584,15 +1324,9 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
584
1324
|
})
|
|
585
1325
|
}
|
|
586
1326
|
if (!isAttemptToFix && this.isImpactedTestsEnabled) {
|
|
587
|
-
const
|
|
588
|
-
const
|
|
589
|
-
|
|
590
|
-
this.testSourceFile,
|
|
591
|
-
testStartLine,
|
|
592
|
-
testEndLine,
|
|
593
|
-
this.modifiedFiles,
|
|
594
|
-
'jest'
|
|
595
|
-
)
|
|
1327
|
+
const concurrentTestState = this.concurrentTestStates.get(event.fn)
|
|
1328
|
+
const isModified = concurrentTestState?.ctx?.isModified ||
|
|
1329
|
+
this.isTestModified(event.asyncError, event.fn)
|
|
596
1330
|
if (isModified && !retriedTestsToNumAttempts.has(testFullName) && this.isEarlyFlakeDetectionEnabled) {
|
|
597
1331
|
retriedTestsToNumAttempts.set(testFullName, 0)
|
|
598
1332
|
testsToBeRetried.add(testFullName)
|
|
@@ -605,6 +1339,9 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
605
1339
|
}
|
|
606
1340
|
if (!isAttemptToFix && this.isKnownTestsEnabled) {
|
|
607
1341
|
const isNew = !this.knownTestsForThisSuite.includes(testFullName)
|
|
1342
|
+
if (isNew && !isSkipped) {
|
|
1343
|
+
newTests.add(testFullName)
|
|
1344
|
+
}
|
|
608
1345
|
if (isNew && !isSkipped && !retriedTestsToNumAttempts.has(testFullName)) {
|
|
609
1346
|
if (DYNAMIC_NAME_RE.test(testFullName)) {
|
|
610
1347
|
// Populated directly for runInBand; for parallel workers the main process
|
|
@@ -628,7 +1365,9 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
628
1365
|
status = 'fail'
|
|
629
1366
|
}
|
|
630
1367
|
// restore in case it is retried
|
|
631
|
-
|
|
1368
|
+
if (originalTestFns.has(event.test)) {
|
|
1369
|
+
event.test.fn = originalTestFns.get(event.test)
|
|
1370
|
+
}
|
|
632
1371
|
// If ATR retry is being suppressed for this test (due to EFD or Attempt to Fix taking precedence)
|
|
633
1372
|
// and the test has errors for this attempt, store the errors temporarily and clear them
|
|
634
1373
|
// so Jest won't treat this attempt as failed (the real status will be reported after retries).
|
|
@@ -641,7 +1380,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
641
1380
|
let attemptToFixFailed = false
|
|
642
1381
|
let failedAllTests = false
|
|
643
1382
|
let isAttemptToFix = false
|
|
644
|
-
const testName = getJestTestName(event.test
|
|
1383
|
+
const testName = getJestTestName(event.test)
|
|
645
1384
|
if (this.isTestManagementTestsEnabled) {
|
|
646
1385
|
isAttemptToFix = this.testManagementTestsForThisSuite?.attemptToFix?.includes(testName)
|
|
647
1386
|
if (isAttemptToFix) {
|
|
@@ -697,6 +1436,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
697
1436
|
state.currentDescribeBlock = event.test.parent ?? originalDescribeBlock
|
|
698
1437
|
state.hasStarted = false
|
|
699
1438
|
this.retryTest({
|
|
1439
|
+
forceSerial: true,
|
|
700
1440
|
jestEvent: {
|
|
701
1441
|
testName: event.test.name,
|
|
702
1442
|
fn: event.test.fn,
|
|
@@ -715,7 +1455,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
715
1455
|
let isEfdRetry = false
|
|
716
1456
|
// We'll store the test statuses of the retries
|
|
717
1457
|
if (this.isKnownTestsEnabled) {
|
|
718
|
-
const isNewTest =
|
|
1458
|
+
const isNewTest = newTests.has(testName)
|
|
719
1459
|
if (isNewTest) {
|
|
720
1460
|
if (newTestsTestStatuses.has(testName)) {
|
|
721
1461
|
newTestsTestStatuses.get(testName).push(status)
|
|
@@ -745,14 +1485,31 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
745
1485
|
const promises = {}
|
|
746
1486
|
const numRetries = this.global[RETRY_TIMES]
|
|
747
1487
|
const numTestExecutions = event.test?.invocations
|
|
748
|
-
const
|
|
749
|
-
const
|
|
1488
|
+
const willBeRetriedByAutoTestRetry = numRetries > 0 && numTestExecutions - 1 < numRetries
|
|
1489
|
+
const isFailedTestReplayAllowed = !this.hasConcurrentTests
|
|
1490
|
+
const willBeRetriedByFailedTestReplay = isFailedTestReplayAllowed && willBeRetriedByAutoTestRetry
|
|
1491
|
+
const mightHitBreakpoint = this.isDiEnabled && isFailedTestReplayAllowed && numTestExecutions >= 2
|
|
1492
|
+
|
|
1493
|
+
// For quarantined tests, track failures so the session can be marked as passing later,
|
|
1494
|
+
// and suppress errors so Jest does not mark the test suite as failing.
|
|
1495
|
+
// The actual status ('fail') is already captured above for dd-trace reporting.
|
|
1496
|
+
// Only suppress on the final execution — not when ATR/EFD/ATF will retry the test.
|
|
1497
|
+
if (!event.test?.[ATR_RETRY_SUPPRESSION_FLAG] && !willBeRetriedByAutoTestRetry) {
|
|
1498
|
+
const quarantineCtx = testContexts.get(event.test)
|
|
1499
|
+
if (quarantineCtx?.isQuarantined && !quarantineCtx.isAttemptToFix && event.test.errors?.length) {
|
|
1500
|
+
quarantinedFailingTests.add(`${quarantineCtx.suite} › ${quarantineCtx.name}`)
|
|
1501
|
+
event.test.errors = []
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
750
1504
|
|
|
751
1505
|
const ctx = testContexts.get(event.test)
|
|
752
1506
|
if (!ctx) {
|
|
753
1507
|
log.warn('"ci:jest:test_done": no context found for test "%s"', testName)
|
|
754
1508
|
return
|
|
755
1509
|
}
|
|
1510
|
+
if (ctx.concurrentTestState && !ctx.currentStore && !ctx.isDisabled) {
|
|
1511
|
+
testStartCh.runStores(ctx, () => {})
|
|
1512
|
+
}
|
|
756
1513
|
|
|
757
1514
|
const finalStatus = this.getFinalStatus(testName,
|
|
758
1515
|
status,
|
|
@@ -768,18 +1525,13 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
768
1525
|
...ctx.currentStore,
|
|
769
1526
|
error: formatJestError(originalError),
|
|
770
1527
|
shouldSetProbe,
|
|
1528
|
+
shouldWaitForHitProbe: mightHitBreakpoint,
|
|
771
1529
|
promises,
|
|
772
1530
|
})
|
|
773
1531
|
}
|
|
774
1532
|
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
if (status === 'fail' && mightHitBreakpoint) {
|
|
778
|
-
await new Promise(resolve => {
|
|
779
|
-
setTimeout(() => {
|
|
780
|
-
resolve()
|
|
781
|
-
}, BREAKPOINT_HIT_GRACE_PERIOD_MS)
|
|
782
|
-
})
|
|
1533
|
+
if (promises.hitBreakpointPromise) {
|
|
1534
|
+
await promises.hitBreakpointPromise
|
|
783
1535
|
}
|
|
784
1536
|
|
|
785
1537
|
let isAtrRetry = false
|
|
@@ -797,26 +1549,51 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
797
1549
|
isAtrRetry,
|
|
798
1550
|
finalStatus,
|
|
799
1551
|
earlyFlakeAbortReason: efdSlowAbortedTests.has(testName) ? 'slow' : undefined,
|
|
1552
|
+
promises,
|
|
800
1553
|
})
|
|
801
1554
|
|
|
1555
|
+
if (promises.hitBreakpointPromise) {
|
|
1556
|
+
await promises.hitBreakpointPromise
|
|
1557
|
+
}
|
|
802
1558
|
if (promises.isProbeReady) {
|
|
803
1559
|
await promises.isProbeReady
|
|
804
1560
|
}
|
|
1561
|
+
if (ctx.concurrentTestState) {
|
|
1562
|
+
ctx.currentStore = undefined
|
|
1563
|
+
}
|
|
805
1564
|
}
|
|
806
1565
|
if (event.name === 'run_finish') {
|
|
807
1566
|
for (const [test, errors] of atrSuppressedErrors) {
|
|
808
|
-
|
|
1567
|
+
// Do not restore errors for non-ATF quarantined tests — they should stay suppressed
|
|
1568
|
+
// so Jest doesn't see the failure (prevents --bail from stopping the run).
|
|
1569
|
+
const ctx = testContexts.get(test)
|
|
1570
|
+
if (ctx?.isQuarantined && !ctx.isAttemptToFix) {
|
|
1571
|
+
const testName = getJestTestName(test)
|
|
1572
|
+
quarantinedFailingTests.add(`${ctx.suite} › ${testName}`)
|
|
1573
|
+
} else {
|
|
1574
|
+
test.errors = errors
|
|
1575
|
+
}
|
|
809
1576
|
}
|
|
810
1577
|
atrSuppressedErrors.clear()
|
|
811
|
-
|
|
1578
|
+
|
|
1579
|
+
// In parallel mode, send suppressed quarantine info to the main process
|
|
1580
|
+
// so it can include them in the session summary.
|
|
1581
|
+
// In runInBand mode, keep the set — it will be consumed by the session-level code directly.
|
|
1582
|
+
if (quarantinedFailingTests.size > 0 && sendQuarantineInfoToMainProcess([...quarantinedFailingTests])) {
|
|
1583
|
+
quarantinedFailingTests.clear()
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
efdDeterminedRetries.clear()
|
|
812
1587
|
efdSlowAbortedTests.clear()
|
|
813
1588
|
efdNewTestCandidates.clear()
|
|
1589
|
+
newTests.clear()
|
|
814
1590
|
retriedTestsToNumAttempts.clear()
|
|
815
1591
|
attemptToFixRetriedTestsStatuses.clear()
|
|
816
1592
|
testsToBeRetried.clear()
|
|
1593
|
+
testSuiteDatadogEnvironments.delete(this.testSuiteAbsolutePath)
|
|
817
1594
|
}
|
|
818
1595
|
if (event.name === 'test_skip' || event.name === 'test_todo') {
|
|
819
|
-
const testName = getJestTestName(event.test
|
|
1596
|
+
const testName = getJestTestName(event.test)
|
|
820
1597
|
testSkippedCh.publish({
|
|
821
1598
|
test: {
|
|
822
1599
|
name: testName,
|
|
@@ -914,7 +1691,8 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
914
1691
|
|
|
915
1692
|
// If the test is quarantined, regardless of its actual execution result,
|
|
916
1693
|
// the final status of its last execution should be reported as 'skip'.
|
|
917
|
-
if (
|
|
1694
|
+
if (!attemptToFixResult.isAttemptToFixEnabled &&
|
|
1695
|
+
this.isTestManagementTestsEnabled &&
|
|
918
1696
|
this.testManagementTestsForThisSuite?.quarantined?.includes(testName)) {
|
|
919
1697
|
return 'skip'
|
|
920
1698
|
}
|
|
@@ -930,7 +1708,19 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
930
1708
|
}
|
|
931
1709
|
}
|
|
932
1710
|
}
|
|
933
|
-
|
|
1711
|
+
const clearActiveTestSuite = () => {
|
|
1712
|
+
realSetTimeout(() => {
|
|
1713
|
+
if (activeTestSuiteAbsolutePath === this.testSuiteAbsolutePath) {
|
|
1714
|
+
activeTestSuiteAbsolutePath = undefined
|
|
1715
|
+
}
|
|
1716
|
+
}, 0)
|
|
1717
|
+
}
|
|
1718
|
+
const result = super.teardown()
|
|
1719
|
+
if (result?.then) {
|
|
1720
|
+
return result.finally(clearActiveTestSuite)
|
|
1721
|
+
}
|
|
1722
|
+
clearActiveTestSuite()
|
|
1723
|
+
return result
|
|
934
1724
|
}
|
|
935
1725
|
}
|
|
936
1726
|
}
|
|
@@ -953,29 +1743,378 @@ function getTestEnvironment (pkg, jestVersion) {
|
|
|
953
1743
|
return getWrappedEnvironment(pkg, jestVersion)
|
|
954
1744
|
}
|
|
955
1745
|
|
|
1746
|
+
function getRepositoryRootFromConfig (config, fallbackRootDir) {
|
|
1747
|
+
return config?.testEnvironmentOptions?._ddRepositoryRoot || repositoryRoot || fallbackRootDir || process.cwd()
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
function getRepositoryRootFromContexts (contexts, fallbackRootDir) {
|
|
1751
|
+
const [firstContext] = contexts || []
|
|
1752
|
+
return getRepositoryRootFromConfig(firstContext?.config, fallbackRootDir)
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
function getRepositoryRootFromTest (test, fallbackRootDir) {
|
|
1756
|
+
return getRepositoryRootFromConfig(test?.context?.config, fallbackRootDir)
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
function hasSkippableSuitesCoverage () {
|
|
1760
|
+
return skippableSuitesCoverage &&
|
|
1761
|
+
typeof skippableSuitesCoverage === 'object' &&
|
|
1762
|
+
Object.keys(skippableSuitesCoverage).length > 0
|
|
1763
|
+
}
|
|
1764
|
+
|
|
1765
|
+
function shouldCollectJestCoverageForTia () {
|
|
1766
|
+
return shouldReportJestSuiteCoverageForTia() ||
|
|
1767
|
+
(isJestCoverageBackfillSupported && isItrEnabled && isCoverageReportUploadEnabled)
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
function shouldReportJestSuiteCoverageForTia () {
|
|
1771
|
+
return isItrEnabled && isCodeCoverageEnabled
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1774
|
+
function hasJestCoverageMap () {
|
|
1775
|
+
return isUserCodeCoverageEnabled || shouldCollectJestCoverageForTia()
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1778
|
+
// TIA coverage backfill is part of Datadog Code Coverage, not the per-suite TIA coverage upload.
|
|
1779
|
+
function isTiaCoverageBackfillEnabled () {
|
|
1780
|
+
return isJestCoverageBackfillSupported && isItrEnabled && isCoverageReportUploadEnabled && hasJestCoverageMap()
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
// Non-TIA Jest coverage keeps the legacy metric. TIA only reports it when Datadog Code Coverage is enabled and
|
|
1784
|
+
// either the run is complete locally or the skipped suites can be backfilled.
|
|
1785
|
+
function shouldReportCodeCoverageLinesPct () {
|
|
1786
|
+
if (!hasJestCoverageMap()) return false
|
|
1787
|
+
if (!isItrEnabled) return true
|
|
1788
|
+
if (!isCoverageReportUploadEnabled) return false
|
|
1789
|
+
|
|
1790
|
+
// If no suites were actually skipped, the local Jest coverage map is complete and does not need backfill.
|
|
1791
|
+
return !isSuitesSkipped || isTiaCoverageBackfillEnabled()
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
function getHookRequire (hookMeta) {
|
|
1795
|
+
if (!hookMeta?.moduleBaseDir) return
|
|
1796
|
+
|
|
1797
|
+
return createRequire(path.join(hookMeta.moduleBaseDir, 'package.json'))
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
function getCoverageBackfillRequire (CoverageReporter) {
|
|
1801
|
+
const hookedCoverageReporterRequire = CoverageReporter && coverageReporterRequires.get(CoverageReporter)
|
|
1802
|
+
if (hookedCoverageReporterRequire) return hookedCoverageReporterRequire
|
|
1803
|
+
if (coverageReporterRequire) return coverageReporterRequire
|
|
1804
|
+
|
|
1805
|
+
const coverageReporterFilename = CoverageReporter?.filename || coverageReporterClass?.filename
|
|
1806
|
+
if (coverageReporterFilename) {
|
|
1807
|
+
return createRequire(`${path.join(path.dirname(coverageReporterFilename), 'CoverageWorker')}.js`)
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
return require
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
function addDatadogBailReporter (globalConfig) {
|
|
1814
|
+
if (!globalConfig.bail) return globalConfig
|
|
1815
|
+
|
|
1816
|
+
const reporters = globalConfig.reporters || [['default', {}]]
|
|
1817
|
+
for (const [reporter] of reporters) {
|
|
1818
|
+
if (reporter === JEST_BAIL_REPORTER_PATH) {
|
|
1819
|
+
return globalConfig
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1823
|
+
return {
|
|
1824
|
+
...globalConfig,
|
|
1825
|
+
reporters: [
|
|
1826
|
+
...reporters,
|
|
1827
|
+
[JEST_BAIL_REPORTER_PATH, {}],
|
|
1828
|
+
],
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1832
|
+
function getTestContexts (tests) {
|
|
1833
|
+
if (!tests?.length) return
|
|
1834
|
+
|
|
1835
|
+
const contexts = new Set()
|
|
1836
|
+
for (const test of tests) {
|
|
1837
|
+
if (test.context) {
|
|
1838
|
+
contexts.add(test.context)
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
return contexts.size ? contexts : undefined
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
function getCoverageBackfillContexts (contexts) {
|
|
1845
|
+
return contexts?.size ? contexts : coverageBackfillContexts || contexts
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
function resetSuiteSkippingRunState () {
|
|
1849
|
+
isSuitesSkipped = false
|
|
1850
|
+
numSkippedSuites = 0
|
|
1851
|
+
hasUnskippableSuites = false
|
|
1852
|
+
hasForcedToRunSuites = false
|
|
1853
|
+
hasFilteredSkippableSuites = false
|
|
1854
|
+
skippedSuitesCoverage = {}
|
|
1855
|
+
lastCoverageMap = undefined
|
|
1856
|
+
lastCoverageMapRootDir = undefined
|
|
1857
|
+
coverageBackfillContexts = undefined
|
|
1858
|
+
coverageBackfillFiles = undefined
|
|
1859
|
+
}
|
|
1860
|
+
|
|
956
1861
|
function applySuiteSkipping (originalTests, rootDir, frameworkVersion) {
|
|
957
|
-
|
|
1862
|
+
if (!isItrEnabled || !isSuitesSkippingEnabled) return originalTests
|
|
1863
|
+
|
|
1864
|
+
const repositoryRoot = getRepositoryRootFromTest(originalTests[0], rootDir)
|
|
1865
|
+
const jestSuitesToRun = getJestSuitesToRun(skippableSuites, originalTests, repositoryRoot, rootDir)
|
|
958
1866
|
hasFilteredSkippableSuites = true
|
|
959
|
-
log.debug(
|
|
1867
|
+
log.debug(
|
|
1868
|
+
'Jest discovered %d suites; skipped %d using %d skippable candidates; %d suites will run.',
|
|
1869
|
+
originalTests.length,
|
|
1870
|
+
jestSuitesToRun.skippedSuites.length,
|
|
1871
|
+
skippableSuites.length,
|
|
1872
|
+
jestSuitesToRun.suitesToRun.length
|
|
1873
|
+
)
|
|
960
1874
|
hasUnskippableSuites = jestSuitesToRun.hasUnskippableSuites
|
|
961
1875
|
hasForcedToRunSuites = jestSuitesToRun.hasForcedToRunSuites
|
|
962
1876
|
|
|
963
1877
|
isSuitesSkipped = jestSuitesToRun.suitesToRun.length !== originalTests.length
|
|
964
1878
|
numSkippedSuites = jestSuitesToRun.skippedSuites.length
|
|
1879
|
+
skippedSuitesCoverage = isSuitesSkipped && isTiaCoverageBackfillEnabled() && hasSkippableSuitesCoverage()
|
|
1880
|
+
? skippableSuitesCoverage
|
|
1881
|
+
: {}
|
|
1882
|
+
coverageBackfillContexts = isSuitesSkipped && isTiaCoverageBackfillEnabled()
|
|
1883
|
+
? getTestContexts(originalTests)
|
|
1884
|
+
: undefined
|
|
1885
|
+
coverageBackfillFiles = isSuitesSkipped && isTiaCoverageBackfillEnabled() && hasSkippableSuitesCoverage()
|
|
1886
|
+
? getCoverageBackfillFiles(skippableSuitesCoverage, repositoryRoot, getTestSuitePath)
|
|
1887
|
+
: undefined
|
|
965
1888
|
|
|
966
1889
|
itrSkippedSuitesCh.publish({ skippedSuites: jestSuitesToRun.skippedSuites, frameworkVersion })
|
|
967
1890
|
|
|
968
1891
|
return jestSuitesToRun.suitesToRun
|
|
969
1892
|
}
|
|
970
1893
|
|
|
1894
|
+
function applySkippedCoverageToJestCoverageMap (coverageMap, rootDir) {
|
|
1895
|
+
if (!coverageMap || !isSuitesSkipped || !isTiaCoverageBackfillEnabled()) return
|
|
1896
|
+
applySkippedCoverageToCoverage(
|
|
1897
|
+
coverageMap,
|
|
1898
|
+
skippedSuitesCoverage,
|
|
1899
|
+
rootDir || process.cwd()
|
|
1900
|
+
)
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1903
|
+
function getSessionFinishError (results) {
|
|
1904
|
+
const numFailedTestSuites = results?.numFailedTestSuites || 0
|
|
1905
|
+
const numFailedTests = results?.numFailedTests || 0
|
|
1906
|
+
|
|
1907
|
+
return new Error(`Failed test suites: ${numFailedTestSuites}. Failed tests: ${numFailedTests}`)
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
function getTestSessionCoveragePayload (results, fallbackRootDir) {
|
|
1911
|
+
const payload = {}
|
|
1912
|
+
if (!shouldReportCodeCoverageLinesPct()) return payload
|
|
1913
|
+
|
|
1914
|
+
try {
|
|
1915
|
+
const coverageMap = results?.coverageMap || lastCoverageMap
|
|
1916
|
+
const coverageRootDir = lastCoverageMapRootDir ||
|
|
1917
|
+
repositoryRoot ||
|
|
1918
|
+
fallbackRootDir ||
|
|
1919
|
+
process.cwd()
|
|
1920
|
+
if (isSuitesSkipped) {
|
|
1921
|
+
applySkippedCoverageToJestCoverageMap(coverageMap, coverageRootDir)
|
|
1922
|
+
}
|
|
1923
|
+
payload.testCodeCoverageLinesTotal = getTestCoverageLinesPercentage(
|
|
1924
|
+
coverageMap,
|
|
1925
|
+
undefined,
|
|
1926
|
+
coverageRootDir
|
|
1927
|
+
)
|
|
1928
|
+
if (isTiaCoverageBackfillEnabled()) {
|
|
1929
|
+
payload.testSessionCoverageFiles = getExecutableFilesFromCoverage(coverageMap).map(({ filename, bitmap }) => ({
|
|
1930
|
+
filename: getTestSuitePath(filename, coverageRootDir),
|
|
1931
|
+
bitmap,
|
|
1932
|
+
}))
|
|
1933
|
+
}
|
|
1934
|
+
} catch {
|
|
1935
|
+
// ignore errors
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
return payload
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
function getNumBailFailures (results) {
|
|
1942
|
+
const numFailedTests = results?.numFailedTests || 0
|
|
1943
|
+
const numFailedSuites = results?.numRuntimeErrorTestSuites === undefined
|
|
1944
|
+
? (numFailedTests === 0 ? results?.numFailedTestSuites || 0 : 0)
|
|
1945
|
+
: results.numRuntimeErrorTestSuites
|
|
1946
|
+
|
|
1947
|
+
return numFailedTests + numFailedSuites
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
function shouldFinishBailTestSession (globalConfig, results) {
|
|
1951
|
+
return !!globalConfig?.bail && getNumBailFailures(results) >= globalConfig.bail
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1954
|
+
async function waitForTestSessionFinish (payload) {
|
|
1955
|
+
if (!testSessionFinishCh.hasSubscribers || hasFinishedTestSession) return
|
|
1956
|
+
|
|
1957
|
+
hasFinishedTestSession = true
|
|
1958
|
+
|
|
1959
|
+
let timeoutId
|
|
1960
|
+
|
|
1961
|
+
const flushPromise = new Promise((resolve) => {
|
|
1962
|
+
payload.onDone = () => {
|
|
1963
|
+
clearTimeout(timeoutId)
|
|
1964
|
+
resolve()
|
|
1965
|
+
}
|
|
1966
|
+
})
|
|
1967
|
+
|
|
1968
|
+
const timeoutPromise = new Promise((resolve) => {
|
|
1969
|
+
timeoutId = realSetTimeout(() => {
|
|
1970
|
+
resolve('timeout')
|
|
1971
|
+
}, FLUSH_TIMEOUT)
|
|
1972
|
+
timeoutId.unref?.()
|
|
1973
|
+
})
|
|
1974
|
+
|
|
1975
|
+
testSessionFinishCh.publish(payload)
|
|
1976
|
+
|
|
1977
|
+
const waitingResult = await Promise.race([flushPromise, timeoutPromise])
|
|
1978
|
+
|
|
1979
|
+
if (waitingResult === 'timeout') {
|
|
1980
|
+
log.error('Timeout waiting for the tracer to flush')
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1984
|
+
function getTestSessionFinishPayload (status, error, extra = {}) {
|
|
1985
|
+
return {
|
|
1986
|
+
status,
|
|
1987
|
+
isSuitesSkipped,
|
|
1988
|
+
isSuitesSkippingEnabled,
|
|
1989
|
+
isCodeCoverageEnabled,
|
|
1990
|
+
isCoverageReportUploadEnabled,
|
|
1991
|
+
numSkippedSuites,
|
|
1992
|
+
hasUnskippableSuites,
|
|
1993
|
+
hasForcedToRunSuites,
|
|
1994
|
+
error,
|
|
1995
|
+
isEarlyFlakeDetectionEnabled,
|
|
1996
|
+
isEarlyFlakeDetectionFaulty,
|
|
1997
|
+
isTestManagementTestsEnabled,
|
|
1998
|
+
...extra,
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
async function finishBailTestSession (results, fallbackRootDir) {
|
|
2003
|
+
await waitForTestSessionFinish(getTestSessionFinishPayload(
|
|
2004
|
+
'fail',
|
|
2005
|
+
getSessionFinishError(results),
|
|
2006
|
+
getTestSessionCoveragePayload(results, fallbackRootDir)
|
|
2007
|
+
))
|
|
2008
|
+
}
|
|
2009
|
+
|
|
2010
|
+
jestSessionState.finishBailTestSession = finishBailTestSession
|
|
2011
|
+
|
|
2012
|
+
function reporterDispatcherWrapper (reporterDispatcherPackage) {
|
|
2013
|
+
const ReporterDispatcher = reporterDispatcherPackage.default ?? reporterDispatcherPackage
|
|
2014
|
+
if (ReporterDispatcher?.prototype?.onRunComplete) {
|
|
2015
|
+
shimmer.wrap(ReporterDispatcher.prototype, 'onRunComplete', onRunComplete => function (contexts, results) {
|
|
2016
|
+
if (isSuitesSkipped && isTiaCoverageBackfillEnabled()) {
|
|
2017
|
+
applySkippedCoverageToJestCoverageMap(results?.coverageMap, getRepositoryRootFromContexts(contexts))
|
|
2018
|
+
}
|
|
2019
|
+
return onRunComplete.apply(this, arguments)
|
|
2020
|
+
})
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
return reporterDispatcherPackage
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
function wrapCoverageReporter (CoverageReporter, hookMeta) {
|
|
2027
|
+
if (!CoverageReporter?.prototype?.onRunComplete || wrappedCoverageReporters.has(CoverageReporter)) {
|
|
2028
|
+
return
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2031
|
+
coverageReporterRequire = getHookRequire(hookMeta) || coverageReporterRequire
|
|
2032
|
+
if (coverageReporterRequire) {
|
|
2033
|
+
coverageReporterRequires.set(CoverageReporter, coverageReporterRequire)
|
|
2034
|
+
}
|
|
2035
|
+
coverageReporterClass = CoverageReporter
|
|
2036
|
+
wrappedCoverageReporters.add(CoverageReporter)
|
|
2037
|
+
if (CoverageReporter.prototype._addUntestedFiles) {
|
|
2038
|
+
shimmer.wrap(CoverageReporter.prototype, '_addUntestedFiles', addUntestedFiles => function (...args) {
|
|
2039
|
+
const rootDir = repositoryRoot || this._globalConfig?.rootDir || process.cwd()
|
|
2040
|
+
args[0] = getCoverageBackfillContexts(args[0])
|
|
2041
|
+
const result = addUntestedFiles.apply(this, args)
|
|
2042
|
+
if (!isSuitesSkipped || !isTiaCoverageBackfillEnabled()) return result
|
|
2043
|
+
|
|
2044
|
+
const addBackfillAndApplyCoverage = () => {
|
|
2045
|
+
return addCoverageBackfillUntestedFiles({
|
|
2046
|
+
coverageMap: this._coverageMap,
|
|
2047
|
+
testContexts: args[0],
|
|
2048
|
+
rootDir,
|
|
2049
|
+
CoverageReporter,
|
|
2050
|
+
coverageBackfillFiles,
|
|
2051
|
+
getCoverageBackfillRequire,
|
|
2052
|
+
}).then(() => {
|
|
2053
|
+
applySkippedCoverageToJestCoverageMap(this._coverageMap, rootDir)
|
|
2054
|
+
})
|
|
2055
|
+
}
|
|
2056
|
+
|
|
2057
|
+
return Promise.resolve(result).then(value => {
|
|
2058
|
+
return addBackfillAndApplyCoverage().then(() => value)
|
|
2059
|
+
})
|
|
2060
|
+
})
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
shimmer.wrap(CoverageReporter.prototype, 'onRunComplete', onRunComplete => async function (contexts, results) {
|
|
2064
|
+
const coverageContexts = getCoverageBackfillContexts(contexts)
|
|
2065
|
+
const rootDir = getRepositoryRootFromContexts(coverageContexts, this._globalConfig?.rootDir)
|
|
2066
|
+
const coverageMap = results?.coverageMap || this._coverageMap
|
|
2067
|
+
if (isSuitesSkipped && isTiaCoverageBackfillEnabled()) {
|
|
2068
|
+
await addCoverageBackfillUntestedFiles({
|
|
2069
|
+
coverageMap,
|
|
2070
|
+
testContexts: coverageContexts,
|
|
2071
|
+
rootDir,
|
|
2072
|
+
CoverageReporter,
|
|
2073
|
+
coverageBackfillFiles,
|
|
2074
|
+
getCoverageBackfillRequire,
|
|
2075
|
+
})
|
|
2076
|
+
applySkippedCoverageToJestCoverageMap(coverageMap, rootDir)
|
|
2077
|
+
}
|
|
2078
|
+
lastCoverageMap = coverageMap
|
|
2079
|
+
lastCoverageMapRootDir = rootDir
|
|
2080
|
+
const result = await onRunComplete.call(this, coverageContexts, results)
|
|
2081
|
+
if (shouldFinishBailTestSession(this._globalConfig, results)) {
|
|
2082
|
+
await finishBailTestSession(results, rootDir)
|
|
2083
|
+
}
|
|
2084
|
+
return result
|
|
2085
|
+
})
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
function reportersWrapper (reportersPackage, _version, _isIitm, hookMeta) {
|
|
2089
|
+
wrapCoverageReporter(reportersPackage.CoverageReporter, hookMeta)
|
|
2090
|
+
return reportersPackage
|
|
2091
|
+
}
|
|
2092
|
+
|
|
2093
|
+
function coverageReporterWrapper (coverageReporterPackage, _version, _isIitm, hookMeta) {
|
|
2094
|
+
wrapCoverageReporter(coverageReporterPackage.default ?? coverageReporterPackage, hookMeta)
|
|
2095
|
+
return coverageReporterPackage
|
|
2096
|
+
}
|
|
2097
|
+
|
|
2098
|
+
addHook({
|
|
2099
|
+
name: 'jest-environment-node',
|
|
2100
|
+
versions: [MINIMUM_JEST_VERSION],
|
|
2101
|
+
}, getTestEnvironment)
|
|
2102
|
+
|
|
971
2103
|
addHook({
|
|
972
2104
|
name: 'jest-environment-node',
|
|
973
|
-
|
|
2105
|
+
file: 'build/index.js',
|
|
2106
|
+
versions: [MINIMUM_JEST_VERSION],
|
|
974
2107
|
}, getTestEnvironment)
|
|
975
2108
|
|
|
976
2109
|
addHook({
|
|
977
2110
|
name: 'jest-environment-jsdom',
|
|
978
|
-
versions: [
|
|
2111
|
+
versions: [MINIMUM_JEST_VERSION],
|
|
2112
|
+
}, getTestEnvironment)
|
|
2113
|
+
|
|
2114
|
+
addHook({
|
|
2115
|
+
name: 'jest-environment-jsdom',
|
|
2116
|
+
file: 'build/index.js',
|
|
2117
|
+
versions: [MINIMUM_JEST_VERSION],
|
|
979
2118
|
}, getTestEnvironment)
|
|
980
2119
|
|
|
981
2120
|
addHook({
|
|
@@ -998,6 +2137,12 @@ function getWrappedScheduleTests (scheduleTests, frameworkVersion) {
|
|
|
998
2137
|
}
|
|
999
2138
|
}
|
|
1000
2139
|
|
|
2140
|
+
function getChannelPromise (channelToPublishTo, payload = {}) {
|
|
2141
|
+
return new Promise(resolve => {
|
|
2142
|
+
channelToPublishTo.publish({ ...payload, onDone: resolve })
|
|
2143
|
+
})
|
|
2144
|
+
}
|
|
2145
|
+
|
|
1001
2146
|
function searchSourceWrapper (searchSourcePackage, frameworkVersion) {
|
|
1002
2147
|
const SearchSource = searchSourcePackage.default ?? searchSourcePackage
|
|
1003
2148
|
|
|
@@ -1006,7 +2151,9 @@ function searchSourceWrapper (searchSourcePackage, frameworkVersion) {
|
|
|
1006
2151
|
const [{ rootDir, shard }] = arguments
|
|
1007
2152
|
|
|
1008
2153
|
if (isKnownTestsEnabled) {
|
|
1009
|
-
const projectSuites = testPaths.tests.map(test =>
|
|
2154
|
+
const projectSuites = testPaths.tests.map(test => {
|
|
2155
|
+
return getTestSuitePath(test.path, getRepositoryRootFromTest(test, test.context.config.rootDir))
|
|
2156
|
+
})
|
|
1010
2157
|
|
|
1011
2158
|
// If the `jest` key does not exist in the known tests response, we consider the Early Flake detection faulty.
|
|
1012
2159
|
const isFaulty = !knownTests?.jest ||
|
|
@@ -1026,14 +2173,11 @@ function searchSourceWrapper (searchSourcePackage, frameworkVersion) {
|
|
|
1026
2173
|
}
|
|
1027
2174
|
}
|
|
1028
2175
|
|
|
2176
|
+
// When Jest sharding is enabled, filter after Jest picks this process's shard. Different shards usually run in
|
|
2177
|
+
// different CI jobs, so their skippable requests can happen at different times and receive different responses.
|
|
2178
|
+
// Filtering before Jest shards would make each job shard a different base test list, which can cause duplicate
|
|
2179
|
+
// suite execution across shards.
|
|
1029
2180
|
if (shard?.shardCount > 1 || !isSuitesSkippingEnabled || !skippableSuites.length) {
|
|
1030
|
-
// If the user is using jest sharding, we want to apply the filtering of tests in the shard process.
|
|
1031
|
-
// The reason for this is the following:
|
|
1032
|
-
// The tests for different shards are likely being run in different CI jobs so
|
|
1033
|
-
// the requests to the skippable endpoint might be done at different times and their responses might be different.
|
|
1034
|
-
// If the skippable endpoint is returning different suites and we filter the list of tests here,
|
|
1035
|
-
// the base list of tests that is used for sharding might be different,
|
|
1036
|
-
// causing the shards to potentially run the same suite.
|
|
1037
2181
|
return testPaths
|
|
1038
2182
|
}
|
|
1039
2183
|
const { tests } = testPaths
|
|
@@ -1047,6 +2191,10 @@ function searchSourceWrapper (searchSourcePackage, frameworkVersion) {
|
|
|
1047
2191
|
|
|
1048
2192
|
function getCliWrapper (isNewJestVersion) {
|
|
1049
2193
|
return function cliWrapper (cli, jestVersion) {
|
|
2194
|
+
warnDeprecatedJestVersion(jestVersion)
|
|
2195
|
+
isJestCoverageBackfillSupported = !!jestVersion &&
|
|
2196
|
+
satisfies(jestVersion, MINIMUM_JEST_COVERAGE_BACKFILL_VERSION)
|
|
2197
|
+
|
|
1050
2198
|
if (isNewJestVersion) {
|
|
1051
2199
|
cli = shimmer.wrap(
|
|
1052
2200
|
cli,
|
|
@@ -1056,23 +2204,22 @@ function getCliWrapper (isNewJestVersion) {
|
|
|
1056
2204
|
)
|
|
1057
2205
|
}
|
|
1058
2206
|
return shimmer.wrap(cli, 'runCLI', runCLI => async function () {
|
|
1059
|
-
let onDone
|
|
1060
|
-
const configurationPromise = new Promise((resolve) => {
|
|
1061
|
-
onDone = resolve
|
|
1062
|
-
})
|
|
1063
2207
|
if (!libraryConfigurationCh.hasSubscribers) {
|
|
1064
2208
|
return runCLI.apply(this, arguments)
|
|
1065
2209
|
}
|
|
1066
2210
|
|
|
1067
|
-
|
|
2211
|
+
resetSuiteSkippingRunState()
|
|
2212
|
+
hasFinishedTestSession = false
|
|
1068
2213
|
|
|
1069
2214
|
try {
|
|
1070
|
-
const { err, libraryConfig } = await
|
|
2215
|
+
const { err, libraryConfig } = await getChannelPromise(libraryConfigurationCh, {
|
|
2216
|
+
frameworkVersion: jestVersion,
|
|
2217
|
+
})
|
|
1071
2218
|
if (!err) {
|
|
1072
2219
|
isCodeCoverageEnabled = libraryConfig.isCodeCoverageEnabled
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
2220
|
+
isCoverageReportUploadEnabled = libraryConfig.isCoverageReportUploadEnabled
|
|
2221
|
+
isItrEnabled = libraryConfig.isItrEnabled
|
|
2222
|
+
isSuitesSkippingEnabled = isItrEnabled && libraryConfig.isSuitesSkippingEnabled
|
|
1076
2223
|
isEarlyFlakeDetectionEnabled = libraryConfig.isEarlyFlakeDetectionEnabled
|
|
1077
2224
|
earlyFlakeDetectionNumRetries = libraryConfig.earlyFlakeDetectionNumRetries
|
|
1078
2225
|
earlyFlakeDetectionSlowTestRetries = libraryConfig.earlyFlakeDetectionSlowTestRetries ?? {}
|
|
@@ -1086,15 +2233,22 @@ function getCliWrapper (isNewJestVersion) {
|
|
|
1086
2233
|
log.error('Jest library configuration error', err)
|
|
1087
2234
|
}
|
|
1088
2235
|
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
2236
|
+
const {
|
|
2237
|
+
knownTestsResponse,
|
|
2238
|
+
testManagementTestsResponse,
|
|
2239
|
+
skippableSuitesResponse,
|
|
2240
|
+
} = await getTestOptimizationRequestResults({
|
|
2241
|
+
isKnownTestsEnabled,
|
|
2242
|
+
isTestManagementTestsEnabled,
|
|
2243
|
+
isSuitesSkippingEnabled,
|
|
2244
|
+
getKnownTests: () => getChannelPromise(knownTestsCh),
|
|
2245
|
+
getTestManagementTests: () => getChannelPromise(testManagementTestsCh),
|
|
2246
|
+
getSkippableSuites: () => getChannelPromise(skippableSuitesCh),
|
|
2247
|
+
})
|
|
1095
2248
|
|
|
2249
|
+
if (isKnownTestsEnabled) {
|
|
1096
2250
|
try {
|
|
1097
|
-
const { err, knownTests: receivedKnownTests } = await
|
|
2251
|
+
const { err, knownTests: receivedKnownTests } = knownTestsResponse || await getChannelPromise(knownTestsCh)
|
|
1098
2252
|
if (err) {
|
|
1099
2253
|
// We disable EFD if there has been an error in the known tests request
|
|
1100
2254
|
isEarlyFlakeDetectionEnabled = false
|
|
@@ -1108,16 +2262,19 @@ function getCliWrapper (isNewJestVersion) {
|
|
|
1108
2262
|
}
|
|
1109
2263
|
|
|
1110
2264
|
if (isSuitesSkippingEnabled) {
|
|
1111
|
-
const skippableSuitesPromise = new Promise((resolve) => {
|
|
1112
|
-
onDone = resolve
|
|
1113
|
-
})
|
|
1114
|
-
|
|
1115
|
-
skippableSuitesCh.publish({ onDone })
|
|
1116
|
-
|
|
1117
2265
|
try {
|
|
1118
|
-
const {
|
|
1119
|
-
|
|
2266
|
+
const {
|
|
2267
|
+
err,
|
|
2268
|
+
skippableSuites: receivedSkippableSuites,
|
|
2269
|
+
skippableSuitesCoverage: receivedSkippableSuitesCoverage,
|
|
2270
|
+
} = skippableSuitesResponse || await getChannelPromise(skippableSuitesCh)
|
|
2271
|
+
if (err) {
|
|
2272
|
+
skippableSuitesCoverage = {}
|
|
2273
|
+
skippedSuitesCoverage = {}
|
|
2274
|
+
} else {
|
|
1120
2275
|
skippableSuites = receivedSkippableSuites
|
|
2276
|
+
skippableSuitesCoverage = receivedSkippableSuitesCoverage || {}
|
|
2277
|
+
skippedSuitesCoverage = {}
|
|
1121
2278
|
}
|
|
1122
2279
|
} catch (err) {
|
|
1123
2280
|
log.error('Jest test-suite skippable error', err)
|
|
@@ -1125,14 +2282,9 @@ function getCliWrapper (isNewJestVersion) {
|
|
|
1125
2282
|
}
|
|
1126
2283
|
|
|
1127
2284
|
if (isTestManagementTestsEnabled) {
|
|
1128
|
-
const testManagementTestsPromise = new Promise((resolve) => {
|
|
1129
|
-
onDone = resolve
|
|
1130
|
-
})
|
|
1131
|
-
|
|
1132
|
-
testManagementTestsCh.publish({ onDone })
|
|
1133
|
-
|
|
1134
2285
|
try {
|
|
1135
|
-
const { err, testManagementTests: receivedTestManagementTests } =
|
|
2286
|
+
const { err, testManagementTests: receivedTestManagementTests } =
|
|
2287
|
+
testManagementTestsResponse || await getChannelPromise(testManagementTestsCh)
|
|
1136
2288
|
if (err) {
|
|
1137
2289
|
isTestManagementTestsEnabled = false
|
|
1138
2290
|
testManagementTests = {}
|
|
@@ -1146,14 +2298,8 @@ function getCliWrapper (isNewJestVersion) {
|
|
|
1146
2298
|
}
|
|
1147
2299
|
|
|
1148
2300
|
if (isImpactedTestsEnabled) {
|
|
1149
|
-
const impactedTestsPromise = new Promise((resolve) => {
|
|
1150
|
-
onDone = resolve
|
|
1151
|
-
})
|
|
1152
|
-
|
|
1153
|
-
modifiedFilesCh.publish({ onDone })
|
|
1154
|
-
|
|
1155
2301
|
try {
|
|
1156
|
-
const { err, modifiedFiles: receivedModifiedFiles } = await
|
|
2302
|
+
const { err, modifiedFiles: receivedModifiedFiles } = await getChannelPromise(modifiedFilesCh)
|
|
1157
2303
|
if (!err) {
|
|
1158
2304
|
modifiedFiles = receivedModifiedFiles
|
|
1159
2305
|
}
|
|
@@ -1163,13 +2309,15 @@ function getCliWrapper (isNewJestVersion) {
|
|
|
1163
2309
|
}
|
|
1164
2310
|
|
|
1165
2311
|
const processArgv = process.argv.slice(2).join(' ')
|
|
1166
|
-
testSessionStartCh.publish({
|
|
2312
|
+
testSessionStartCh.publish({
|
|
2313
|
+
command: `jest ${processArgv}`,
|
|
2314
|
+
frameworkVersion: jestVersion,
|
|
2315
|
+
})
|
|
1167
2316
|
|
|
1168
2317
|
const result = await runCLI.apply(this, arguments)
|
|
1169
2318
|
|
|
1170
2319
|
const {
|
|
1171
2320
|
results: {
|
|
1172
|
-
coverageMap,
|
|
1173
2321
|
numFailedTestSuites,
|
|
1174
2322
|
numFailedTests,
|
|
1175
2323
|
numRuntimeErrorTestSuites = 0,
|
|
@@ -1184,17 +2332,6 @@ function getCliWrapper (isNewJestVersion) {
|
|
|
1184
2332
|
const hasRunLevelFailure = runExecError != null || wasInterrupted === true
|
|
1185
2333
|
const mustNotFlipSuccess = hasSuiteLevelFailures || hasRunLevelFailure
|
|
1186
2334
|
|
|
1187
|
-
let testCodeCoverageLinesTotal
|
|
1188
|
-
|
|
1189
|
-
if (isUserCodeCoverageEnabled) {
|
|
1190
|
-
try {
|
|
1191
|
-
const { pct, total } = coverageMap.getCoverageSummary().lines
|
|
1192
|
-
testCodeCoverageLinesTotal = total === 0 ? 0 : pct
|
|
1193
|
-
} catch {
|
|
1194
|
-
// ignore errors
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
|
|
1198
2335
|
/**
|
|
1199
2336
|
* If Early Flake Detection (EFD) is enabled the logic is as follows:
|
|
1200
2337
|
* - If all attempts for a test are failing, the test has failed and we will let the test process fail.
|
|
@@ -1211,9 +2348,7 @@ function getCliWrapper (isNewJestVersion) {
|
|
|
1211
2348
|
for (const { testResults, testFilePath } of result.results.testResults) {
|
|
1212
2349
|
const suite = getTestSuitePath(testFilePath, result.globalConfig.rootDir)
|
|
1213
2350
|
for (const { fullName } of testResults) {
|
|
1214
|
-
const name =
|
|
1215
|
-
? fullName.replace(SEED_SUFFIX_RE, '')
|
|
1216
|
-
: fullName
|
|
2351
|
+
const name = removeSeedSuffixFromTestName(fullName)
|
|
1217
2352
|
fullNameToSuite.set(name, suite)
|
|
1218
2353
|
}
|
|
1219
2354
|
}
|
|
@@ -1245,17 +2380,15 @@ function getCliWrapper (isNewJestVersion) {
|
|
|
1245
2380
|
}
|
|
1246
2381
|
|
|
1247
2382
|
let numFailedQuarantinedTests = 0
|
|
1248
|
-
let
|
|
2383
|
+
let numSuppressedQuarantinedTests = 0
|
|
1249
2384
|
if (isTestManagementTestsEnabled) {
|
|
1250
2385
|
const failedTests = result
|
|
1251
2386
|
.results
|
|
1252
2387
|
.testResults.flatMap(({ testResults, testFilePath: testSuiteAbsolutePath }) => (
|
|
1253
2388
|
testResults.map(({ fullName: testName, status }) => (
|
|
1254
2389
|
{
|
|
1255
|
-
// Strip
|
|
1256
|
-
testName:
|
|
1257
|
-
? testName.replace(SEED_SUFFIX_RE, '')
|
|
1258
|
-
: testName,
|
|
2390
|
+
// Strip seed suffix so the name matches what was reported via TEST_NAME.
|
|
2391
|
+
testName: removeSeedSuffixFromTestName(testName),
|
|
1259
2392
|
testSuiteAbsolutePath,
|
|
1260
2393
|
status,
|
|
1261
2394
|
}
|
|
@@ -1272,55 +2405,73 @@ function getCliWrapper (isNewJestVersion) {
|
|
|
1272
2405
|
?.tests
|
|
1273
2406
|
?.[testName]
|
|
1274
2407
|
?.properties
|
|
1275
|
-
|
|
1276
|
-
if (testManagementTest?.attempt_to_fix && (testManagementTest?.quarantined || testManagementTest?.disabled)) {
|
|
1277
|
-
numFailedQuarantinedOrDisabledAttemptedToFixTests++
|
|
1278
|
-
quarantineIgnoredNames.push(`${testSuite} › ${testName}`)
|
|
1279
|
-
} else if (testManagementTest?.quarantined) {
|
|
2408
|
+
if (testManagementTest?.quarantined && !testManagementTest?.attempt_to_fix) {
|
|
1280
2409
|
numFailedQuarantinedTests++
|
|
1281
2410
|
quarantineIgnoredNames.push(`${testSuite} › ${testName}`)
|
|
1282
2411
|
}
|
|
1283
2412
|
}
|
|
1284
2413
|
|
|
2414
|
+
// Include quarantined tests whose errors were suppressed at test_done time.
|
|
2415
|
+
// These tests don't appear as failed in Jest's results because their errors were cleared
|
|
2416
|
+
// to prevent --bail from stopping the run, but they should still be counted for the summary.
|
|
2417
|
+
for (const name of quarantinedFailingTests) {
|
|
2418
|
+
if (!quarantineIgnoredNames.includes(name)) {
|
|
2419
|
+
numSuppressedQuarantinedTests++
|
|
2420
|
+
quarantineIgnoredNames.push(name)
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
quarantinedFailingTests.clear()
|
|
2424
|
+
|
|
1285
2425
|
// If every test that failed was quarantined, we'll consider the suite passed
|
|
1286
|
-
//
|
|
1287
|
-
// it's considered quarantined both if it's disabled and if it's quarantined
|
|
1288
|
-
// (it'll run but its status is ignored)
|
|
2426
|
+
// Attempt-to-fix tests ignore quarantine/disabled suppression and keep their framework result.
|
|
1289
2427
|
// Skip if EFD block already flipped (to avoid logging twice)
|
|
2428
|
+
// Only use visible failures (from Jest results) for the flip check.
|
|
2429
|
+
// Suppressed quarantine failures are not in numFailedTests.
|
|
2430
|
+
const visibleQuarantineFailures = numFailedQuarantinedTests
|
|
1290
2431
|
if (
|
|
1291
2432
|
!result.results.success &&
|
|
1292
2433
|
!mustNotFlipSuccess &&
|
|
1293
|
-
|
|
1294
|
-
result.results.numFailedTests ===
|
|
1295
|
-
numFailedQuarantinedTests + numFailedQuarantinedOrDisabledAttemptedToFixTests
|
|
2434
|
+
visibleQuarantineFailures !== 0 &&
|
|
2435
|
+
result.results.numFailedTests === visibleQuarantineFailures
|
|
1296
2436
|
) {
|
|
1297
2437
|
result.results.success = true
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
2438
|
+
}
|
|
2439
|
+
|
|
2440
|
+
const totalQuarantineFailures = visibleQuarantineFailures + numSuppressedQuarantinedTests
|
|
2441
|
+
if (totalQuarantineFailures > 0) {
|
|
2442
|
+
if (ignoredFailuresSummary) {
|
|
2443
|
+
ignoredFailuresSummary.quarantineNames = quarantineIgnoredNames
|
|
2444
|
+
ignoredFailuresSummary.totalCount += totalQuarantineFailures
|
|
2445
|
+
} else {
|
|
2446
|
+
ignoredFailuresSummary = {
|
|
2447
|
+
efdNames: [],
|
|
2448
|
+
quarantineNames: quarantineIgnoredNames,
|
|
2449
|
+
totalCount: totalQuarantineFailures,
|
|
2450
|
+
}
|
|
1302
2451
|
}
|
|
1303
2452
|
}
|
|
1304
2453
|
}
|
|
1305
2454
|
|
|
1306
2455
|
// Combined check: if all failed tests are accounted for by EFD (flaky retries) and/or quarantine,
|
|
1307
2456
|
// we should consider the suite passed even when neither check alone covers all failures.
|
|
2457
|
+
// Only visible failures (in Jest results) are compared — suppressed quarantine failures
|
|
2458
|
+
// are already removed from numFailedTests at test_done time.
|
|
1308
2459
|
if (
|
|
1309
2460
|
!result.results.success &&
|
|
1310
2461
|
!mustNotFlipSuccess &&
|
|
1311
2462
|
(isEarlyFlakeDetectionEnabled || isTestManagementTestsEnabled)
|
|
1312
2463
|
) {
|
|
1313
|
-
const
|
|
1314
|
-
numEfdFailedTestsToIgnore + numFailedQuarantinedTests
|
|
2464
|
+
const visibleIgnoredFailures =
|
|
2465
|
+
numEfdFailedTestsToIgnore + numFailedQuarantinedTests
|
|
1315
2466
|
if (
|
|
1316
|
-
|
|
1317
|
-
result.results.numFailedTests ===
|
|
2467
|
+
visibleIgnoredFailures !== 0 &&
|
|
2468
|
+
result.results.numFailedTests === visibleIgnoredFailures
|
|
1318
2469
|
) {
|
|
1319
2470
|
result.results.success = true
|
|
1320
2471
|
ignoredFailuresSummary = {
|
|
1321
2472
|
efdNames: efdIgnoredNames,
|
|
1322
2473
|
quarantineNames: quarantineIgnoredNames,
|
|
1323
|
-
totalCount:
|
|
2474
|
+
totalCount: visibleIgnoredFailures + numSuppressedQuarantinedTests,
|
|
1324
2475
|
}
|
|
1325
2476
|
}
|
|
1326
2477
|
}
|
|
@@ -1334,43 +2485,9 @@ function getCliWrapper (isNewJestVersion) {
|
|
|
1334
2485
|
error = new Error(`Failed test suites: ${numFailedTestSuites}. Failed tests: ${numFailedTests}`)
|
|
1335
2486
|
}
|
|
1336
2487
|
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
const flushPromise = new Promise((resolve) => {
|
|
1341
|
-
onDone = () => {
|
|
1342
|
-
clearTimeout(timeoutId)
|
|
1343
|
-
resolve()
|
|
1344
|
-
}
|
|
1345
|
-
})
|
|
1346
|
-
|
|
1347
|
-
const timeoutPromise = new Promise((resolve) => {
|
|
1348
|
-
timeoutId = setTimeout(() => {
|
|
1349
|
-
resolve('timeout')
|
|
1350
|
-
}, FLUSH_TIMEOUT).unref()
|
|
1351
|
-
})
|
|
1352
|
-
|
|
1353
|
-
testSessionFinishCh.publish({
|
|
1354
|
-
status,
|
|
1355
|
-
isSuitesSkipped,
|
|
1356
|
-
isSuitesSkippingEnabled,
|
|
1357
|
-
isCodeCoverageEnabled,
|
|
1358
|
-
testCodeCoverageLinesTotal,
|
|
1359
|
-
numSkippedSuites,
|
|
1360
|
-
hasUnskippableSuites,
|
|
1361
|
-
hasForcedToRunSuites,
|
|
1362
|
-
error,
|
|
1363
|
-
isEarlyFlakeDetectionEnabled,
|
|
1364
|
-
isEarlyFlakeDetectionFaulty,
|
|
1365
|
-
isTestManagementTestsEnabled,
|
|
1366
|
-
onDone,
|
|
1367
|
-
})
|
|
1368
|
-
|
|
1369
|
-
const waitingResult = await Promise.race([flushPromise, timeoutPromise])
|
|
1370
|
-
|
|
1371
|
-
if (waitingResult === 'timeout') {
|
|
1372
|
-
log.error('Timeout waiting for the tracer to flush')
|
|
1373
|
-
}
|
|
2488
|
+
await waitForTestSessionFinish(getTestSessionFinishPayload(status, error, {
|
|
2489
|
+
...getTestSessionCoveragePayload(result.results, result.globalConfig?.rootDir),
|
|
2490
|
+
}))
|
|
1374
2491
|
|
|
1375
2492
|
if (codeCoverageReportCh.hasSubscribers) {
|
|
1376
2493
|
const rootDir = result.globalConfig?.rootDir || process.cwd()
|
|
@@ -1379,9 +2496,9 @@ function getCliWrapper (isNewJestVersion) {
|
|
|
1379
2496
|
})
|
|
1380
2497
|
}
|
|
1381
2498
|
|
|
1382
|
-
logSessionSummary(ignoredFailuresSummary)
|
|
2499
|
+
logSessionSummary(ignoredFailuresSummary, getAttemptToFixExecutionsFromJestResults(result))
|
|
1383
2500
|
|
|
1384
|
-
|
|
2501
|
+
resetSuiteSkippingRunState()
|
|
1385
2502
|
|
|
1386
2503
|
return result
|
|
1387
2504
|
}, {
|
|
@@ -1390,32 +2507,49 @@ function getCliWrapper (isNewJestVersion) {
|
|
|
1390
2507
|
}
|
|
1391
2508
|
}
|
|
1392
2509
|
|
|
1393
|
-
function
|
|
1394
|
-
|
|
2510
|
+
function shouldWaitForTestSuiteFinish (environment) {
|
|
2511
|
+
return isJestWorker && environment.globalConfig?.workerIdleMemoryLimit !== undefined
|
|
2512
|
+
}
|
|
1395
2513
|
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
2514
|
+
function publishTestSuiteFinish (payload, waitForFinish) {
|
|
2515
|
+
if (!testSuiteFinishCh.hasSubscribers) return
|
|
2516
|
+
|
|
2517
|
+
if (!waitForFinish) {
|
|
2518
|
+
testSuiteFinishCh.publish(payload)
|
|
2519
|
+
return
|
|
2520
|
+
}
|
|
2521
|
+
|
|
2522
|
+
return new Promise(resolve => {
|
|
2523
|
+
testSuiteFinishCh.publish({
|
|
2524
|
+
...payload,
|
|
2525
|
+
waitForFinish,
|
|
2526
|
+
onDone: resolve,
|
|
2527
|
+
})
|
|
1410
2528
|
})
|
|
2529
|
+
}
|
|
1411
2530
|
|
|
1412
|
-
|
|
2531
|
+
function cleanupTestSuiteState (testSuiteAbsolutePath) {
|
|
2532
|
+
testSuiteMockedFiles.delete(testSuiteAbsolutePath)
|
|
2533
|
+
testSuiteJestObjects.delete(testSuiteAbsolutePath)
|
|
2534
|
+
}
|
|
2535
|
+
|
|
2536
|
+
/**
|
|
2537
|
+
* Rechecks custom handlers after Jest has finished constructing the environment.
|
|
2538
|
+
*
|
|
2539
|
+
* @param {object} environment
|
|
2540
|
+
* @returns {void}
|
|
2541
|
+
*/
|
|
2542
|
+
function wrapEnvironmentCustomHandleTestEvent (environment) {
|
|
2543
|
+
const datadogHandleTestEvent = environment[DD_JEST_HANDLE_TEST_EVENT_DATADOG]
|
|
2544
|
+
if (typeof environment.wrapCustomHandleTestEvent === 'function' && datadogHandleTestEvent) {
|
|
2545
|
+
environment.wrapCustomHandleTestEvent(datadogHandleTestEvent)
|
|
2546
|
+
}
|
|
1413
2547
|
}
|
|
1414
2548
|
|
|
1415
2549
|
addHook({
|
|
1416
2550
|
name: '@jest/core',
|
|
1417
2551
|
file: 'build/TestScheduler.js',
|
|
1418
|
-
versions: [
|
|
2552
|
+
versions: [MINIMUM_JEST_TEST_SCHEDULER_VERSION],
|
|
1419
2553
|
}, (testSchedulerPackage, frameworkVersion) => {
|
|
1420
2554
|
const oldCreateTestScheduler = testSchedulerPackage.createTestScheduler
|
|
1421
2555
|
const newCreateTestScheduler = async function () {
|
|
@@ -1431,24 +2565,23 @@ addHook({
|
|
|
1431
2565
|
return testSchedulerPackage
|
|
1432
2566
|
})
|
|
1433
2567
|
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
2568
|
+
if (DD_MAJOR < 6) {
|
|
2569
|
+
addHook({
|
|
2570
|
+
name: '@jest/core',
|
|
2571
|
+
file: 'build/TestScheduler.js',
|
|
2572
|
+
versions: ['>=24.8.0 <27.0.0'],
|
|
2573
|
+
}, (testSchedulerPackage, frameworkVersion) => {
|
|
2574
|
+
shimmer.wrap(
|
|
2575
|
+
testSchedulerPackage.default.prototype,
|
|
2576
|
+
'scheduleTests', scheduleTests => getWrappedScheduleTests(scheduleTests, frameworkVersion)
|
|
2577
|
+
)
|
|
2578
|
+
return testSchedulerPackage
|
|
2579
|
+
})
|
|
2580
|
+
}
|
|
1445
2581
|
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
}, (sequencerPackage, frameworkVersion) => {
|
|
1450
|
-
shimmer.wrap(sequencerPackage.default.prototype, 'shard', shard => function () {
|
|
1451
|
-
const shardedTests = shard.apply(this, arguments)
|
|
2582
|
+
function testSequencerWrapper (sequencerPackage, frameworkVersion) {
|
|
2583
|
+
shimmer.wrap(sequencerPackage.default.prototype, 'shard', shard => function (...args) {
|
|
2584
|
+
const shardedTests = shard.apply(this, args)
|
|
1452
2585
|
|
|
1453
2586
|
if (!shardedTests.length || !isSuitesSkippingEnabled || !skippableSuites.length) {
|
|
1454
2587
|
return shardedTests
|
|
@@ -1459,31 +2592,23 @@ addHook({
|
|
|
1459
2592
|
return applySuiteSkipping(shardedTests, rootDir, frameworkVersion)
|
|
1460
2593
|
})
|
|
1461
2594
|
return sequencerPackage
|
|
1462
|
-
}
|
|
1463
|
-
|
|
1464
|
-
addHook({
|
|
1465
|
-
name: '@jest/reporters',
|
|
1466
|
-
file: 'build/coverage_reporter.js',
|
|
1467
|
-
versions: ['>=24.8.0 <26.6.2'],
|
|
1468
|
-
}, coverageReporterWrapper)
|
|
2595
|
+
}
|
|
1469
2596
|
|
|
1470
2597
|
addHook({
|
|
1471
|
-
name: '@jest/
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
}, coverageReporterWrapper)
|
|
2598
|
+
name: '@jest/test-sequencer',
|
|
2599
|
+
versions: ['>=28'],
|
|
2600
|
+
}, testSequencerWrapper)
|
|
1475
2601
|
|
|
1476
2602
|
addHook({
|
|
1477
|
-
name: '@jest/
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
})
|
|
2603
|
+
name: '@jest/test-sequencer',
|
|
2604
|
+
file: 'build/index.js',
|
|
2605
|
+
versions: ['>=28'],
|
|
2606
|
+
}, testSequencerWrapper)
|
|
1482
2607
|
|
|
1483
2608
|
addHook({
|
|
1484
2609
|
name: '@jest/core',
|
|
1485
2610
|
file: 'build/cli/index.js',
|
|
1486
|
-
versions: [
|
|
2611
|
+
versions: [MINIMUM_JEST_VERSION_BEFORE_30],
|
|
1487
2612
|
}, getCliWrapper(false))
|
|
1488
2613
|
|
|
1489
2614
|
addHook({
|
|
@@ -1491,13 +2616,41 @@ addHook({
|
|
|
1491
2616
|
versions: ['>=30.0.0'],
|
|
1492
2617
|
}, getCliWrapper(true))
|
|
1493
2618
|
|
|
2619
|
+
addHook({
|
|
2620
|
+
name: '@jest/core',
|
|
2621
|
+
file: 'build/ReporterDispatcher.js',
|
|
2622
|
+
versions: [MINIMUM_JEST_VERSION],
|
|
2623
|
+
}, reporterDispatcherWrapper)
|
|
2624
|
+
|
|
2625
|
+
if (DD_MAJOR < 6) {
|
|
2626
|
+
addHook({
|
|
2627
|
+
name: '@jest/reporters',
|
|
2628
|
+
file: 'build/coverage_reporter.js',
|
|
2629
|
+
versions: ['>=24.8.0 <26.6.2'],
|
|
2630
|
+
}, coverageReporterWrapper)
|
|
2631
|
+
}
|
|
2632
|
+
|
|
2633
|
+
addHook({
|
|
2634
|
+
name: '@jest/reporters',
|
|
2635
|
+
versions: ['>=30.0.0'],
|
|
2636
|
+
}, reportersWrapper)
|
|
2637
|
+
|
|
2638
|
+
addHook({
|
|
2639
|
+
name: '@jest/reporters',
|
|
2640
|
+
file: 'build/CoverageReporter.js',
|
|
2641
|
+
versions: [DD_MAJOR >= 6 ? '>=28.0.0' : '>=26.6.2'],
|
|
2642
|
+
}, coverageReporterWrapper)
|
|
2643
|
+
|
|
1494
2644
|
function jestAdapterWrapper (jestAdapter, jestVersion) {
|
|
1495
2645
|
const adapter = jestAdapter.default ?? jestAdapter
|
|
1496
|
-
const newAdapter = shimmer.wrapFunction(adapter, adapter => function () {
|
|
1497
|
-
const environment =
|
|
2646
|
+
const newAdapter = shimmer.wrapFunction(adapter, adapter => function (...args) {
|
|
2647
|
+
const environment = args[2]
|
|
1498
2648
|
if (!environment || !environment.testEnvironmentOptions) {
|
|
1499
|
-
return adapter.apply(this,
|
|
2649
|
+
return adapter.apply(this, args)
|
|
1500
2650
|
}
|
|
2651
|
+
|
|
2652
|
+
wrapEnvironmentCustomHandleTestEvent(environment)
|
|
2653
|
+
|
|
1501
2654
|
testSuiteStartCh.publish({
|
|
1502
2655
|
testSuite: environment.testSuite,
|
|
1503
2656
|
testEnvironmentOptions: environment.testEnvironmentOptions,
|
|
@@ -1506,7 +2659,7 @@ function jestAdapterWrapper (jestAdapter, jestVersion) {
|
|
|
1506
2659
|
frameworkVersion: jestVersion,
|
|
1507
2660
|
testSuiteAbsolutePath: environment.testSuiteAbsolutePath,
|
|
1508
2661
|
})
|
|
1509
|
-
return adapter.apply(this,
|
|
2662
|
+
return adapter.apply(this, args).then(suiteResults => {
|
|
1510
2663
|
const { numFailingTests, skipped, failureMessage: errorMessage } = suiteResults
|
|
1511
2664
|
let status = 'pass'
|
|
1512
2665
|
if (skipped) {
|
|
@@ -1523,10 +2676,13 @@ function jestAdapterWrapper (jestAdapter, jestVersion) {
|
|
|
1523
2676
|
if (environment.testEnvironmentOptions?._ddTestCodeCoverageEnabled) {
|
|
1524
2677
|
const root = environment.repositoryRoot || environment.rootDir
|
|
1525
2678
|
|
|
1526
|
-
const
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
2679
|
+
const coverageFiles = getCoveredFilesFromCoverage(environment.global.__coverage__)
|
|
2680
|
+
.map(file => ({
|
|
2681
|
+
...file,
|
|
2682
|
+
filename: getTestSuitePath(file.filename, root),
|
|
2683
|
+
}))
|
|
2684
|
+
const mockedFiles = getMockedFiles(environment.testSuiteAbsolutePath)
|
|
2685
|
+
.map(file => getTestSuitePath(file, root))
|
|
1530
2686
|
|
|
1531
2687
|
testSuiteCodeCoverageCh.publish({
|
|
1532
2688
|
coverageFiles,
|
|
@@ -1535,19 +2691,51 @@ function jestAdapterWrapper (jestAdapter, jestVersion) {
|
|
|
1535
2691
|
testSuiteAbsolutePath: environment.testSuiteAbsolutePath,
|
|
1536
2692
|
})
|
|
1537
2693
|
}
|
|
1538
|
-
|
|
2694
|
+
const waitForFinish = shouldWaitForTestSuiteFinish(environment)
|
|
2695
|
+
const finishPayload = {
|
|
2696
|
+
status,
|
|
2697
|
+
errorMessage,
|
|
2698
|
+
testSuiteAbsolutePath: environment.testSuiteAbsolutePath,
|
|
2699
|
+
}
|
|
2700
|
+
if (waitForFinish) {
|
|
2701
|
+
const finishPromise = publishTestSuiteFinish(finishPayload, waitForFinish)
|
|
2702
|
+
if (finishPromise) {
|
|
2703
|
+
return finishPromise.then(() => {
|
|
2704
|
+
// Cleanup per-suite state to avoid memory leaks
|
|
2705
|
+
cleanupTestSuiteState(environment.testSuiteAbsolutePath)
|
|
2706
|
+
|
|
2707
|
+
return suiteResults
|
|
2708
|
+
})
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
publishTestSuiteFinish(finishPayload, waitForFinish)
|
|
1539
2712
|
|
|
1540
2713
|
// Cleanup per-suite state to avoid memory leaks
|
|
1541
|
-
|
|
1542
|
-
testSuiteJestObjects.delete(environment.testSuiteAbsolutePath)
|
|
2714
|
+
cleanupTestSuiteState(environment.testSuiteAbsolutePath)
|
|
1543
2715
|
|
|
1544
2716
|
return suiteResults
|
|
1545
2717
|
}).catch(error => {
|
|
1546
|
-
|
|
2718
|
+
const waitForFinish = shouldWaitForTestSuiteFinish(environment)
|
|
2719
|
+
const finishPayload = {
|
|
2720
|
+
status: 'fail',
|
|
2721
|
+
error,
|
|
2722
|
+
testSuiteAbsolutePath: environment.testSuiteAbsolutePath,
|
|
2723
|
+
}
|
|
2724
|
+
if (waitForFinish) {
|
|
2725
|
+
const finishPromise = publishTestSuiteFinish(finishPayload, waitForFinish)
|
|
2726
|
+
if (finishPromise) {
|
|
2727
|
+
return finishPromise.then(() => {
|
|
2728
|
+
// Cleanup per-suite state to avoid memory leaks
|
|
2729
|
+
cleanupTestSuiteState(environment.testSuiteAbsolutePath)
|
|
2730
|
+
|
|
2731
|
+
throw error
|
|
2732
|
+
})
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
publishTestSuiteFinish(finishPayload, waitForFinish)
|
|
1547
2736
|
|
|
1548
2737
|
// Cleanup per-suite state to avoid memory leaks
|
|
1549
|
-
|
|
1550
|
-
testSuiteJestObjects.delete(environment.testSuiteAbsolutePath)
|
|
2738
|
+
cleanupTestSuiteState(environment.testSuiteAbsolutePath)
|
|
1551
2739
|
|
|
1552
2740
|
throw error
|
|
1553
2741
|
})
|
|
@@ -1570,45 +2758,54 @@ addHook({
|
|
|
1570
2758
|
addHook({
|
|
1571
2759
|
name: 'jest-circus',
|
|
1572
2760
|
file: 'build/legacy-code-todo-rewrite/jestAdapter.js',
|
|
1573
|
-
versions: [
|
|
2761
|
+
versions: [MINIMUM_JEST_VERSION],
|
|
1574
2762
|
}, jestAdapterWrapper)
|
|
1575
2763
|
|
|
1576
2764
|
function configureTestEnvironment (readConfigsResult) {
|
|
1577
|
-
|
|
1578
|
-
testSessionConfigurationCh.publish(configs.map(config => config.testEnvironmentOptions))
|
|
1579
|
-
// We can't directly use isCodeCoverageEnabled when reporting coverage in `jestAdapterWrapper`
|
|
1580
|
-
// because `jestAdapterWrapper` runs in a different process. We have to go through `testEnvironmentOptions`
|
|
1581
|
-
for (const config of configs) {
|
|
1582
|
-
config.testEnvironmentOptions._ddTestCodeCoverageEnabled = isCodeCoverageEnabled
|
|
1583
|
-
}
|
|
1584
|
-
|
|
2765
|
+
repositoryRoot = getJestRepositoryRoot(readConfigsResult)
|
|
1585
2766
|
isUserCodeCoverageEnabled = !!readConfigsResult.globalConfig.collectCoverage
|
|
1586
|
-
isCodeCoverageEnabledBecauseOfUs =
|
|
1587
|
-
|
|
1588
|
-
if (readConfigsResult.globalConfig.forceExit) {
|
|
1589
|
-
log.warn("Jest's '--forceExit' flag has been passed. This may cause loss of data.")
|
|
1590
|
-
}
|
|
2767
|
+
const isCodeCoverageEnabledBecauseOfUs = shouldCollectJestCoverageForTia() && !isUserCodeCoverageEnabled
|
|
1591
2768
|
|
|
1592
2769
|
if (isCodeCoverageEnabledBecauseOfUs) {
|
|
1593
|
-
|
|
2770
|
+
readConfigsResult.globalConfig = {
|
|
1594
2771
|
...readConfigsResult.globalConfig,
|
|
1595
2772
|
collectCoverage: true,
|
|
2773
|
+
coverageReporters: ['none'],
|
|
1596
2774
|
}
|
|
1597
|
-
readConfigsResult.
|
|
2775
|
+
readConfigsResult.configs = readConfigsResult.configs.map(config => ({
|
|
2776
|
+
...config,
|
|
2777
|
+
coverageReporters: ['none'],
|
|
2778
|
+
}))
|
|
1598
2779
|
}
|
|
2780
|
+
|
|
2781
|
+
// We can't directly use the parent process flags when reporting suite coverage in `jestAdapterWrapper`
|
|
2782
|
+
// because `jestAdapterWrapper` runs in a different process. We have to go through `testEnvironmentOptions`.
|
|
2783
|
+
const configs = readConfigsResult.configs.map(config => {
|
|
2784
|
+
const testEnvironmentOptions = config.testEnvironmentOptions || {}
|
|
2785
|
+
testEnvironmentOptions._ddRepositoryRoot = repositoryRoot
|
|
2786
|
+
testEnvironmentOptions._ddTestCodeCoverageEnabled = shouldReportJestSuiteCoverageForTia()
|
|
2787
|
+
|
|
2788
|
+
return {
|
|
2789
|
+
...config,
|
|
2790
|
+
testEnvironmentOptions,
|
|
2791
|
+
}
|
|
2792
|
+
})
|
|
2793
|
+
readConfigsResult.configs = configs
|
|
2794
|
+
testSessionConfigurationCh.publish(readConfigsResult.configs.map(config => config.testEnvironmentOptions))
|
|
2795
|
+
repositoryRoot = getJestRepositoryRoot(readConfigsResult)
|
|
2796
|
+
|
|
2797
|
+
if (readConfigsResult.globalConfig.forceExit) {
|
|
2798
|
+
log.warn("Jest's '--forceExit' flag has been passed. This may cause loss of data.")
|
|
2799
|
+
}
|
|
2800
|
+
|
|
2801
|
+
readConfigsResult.globalConfig = addDatadogBailReporter(readConfigsResult.globalConfig)
|
|
2802
|
+
|
|
1599
2803
|
if (isSuitesSkippingEnabled) {
|
|
1600
2804
|
// If suite skipping is enabled, we pass `passWithNoTests` in case every test gets skipped.
|
|
1601
2805
|
const globalConfig = {
|
|
1602
2806
|
...readConfigsResult.globalConfig,
|
|
1603
2807
|
passWithNoTests: true,
|
|
1604
2808
|
}
|
|
1605
|
-
if (isCodeCoverageEnabledBecauseOfUs && !isKeepingCoverageConfiguration) {
|
|
1606
|
-
globalConfig.coverageReporters = ['none']
|
|
1607
|
-
readConfigsResult.configs = configs.map(config => ({
|
|
1608
|
-
...config,
|
|
1609
|
-
coverageReporters: ['none'],
|
|
1610
|
-
}))
|
|
1611
|
-
}
|
|
1612
2809
|
readConfigsResult.globalConfig = globalConfig
|
|
1613
2810
|
}
|
|
1614
2811
|
|
|
@@ -1624,8 +2821,8 @@ function jestConfigAsyncWrapper (jestConfig) {
|
|
|
1624
2821
|
}
|
|
1625
2822
|
|
|
1626
2823
|
function jestConfigSyncWrapper (jestConfig) {
|
|
1627
|
-
return shimmer.wrap(jestConfig, 'readConfigs', readConfigs => function () {
|
|
1628
|
-
const readConfigsResult = readConfigs.apply(this,
|
|
2824
|
+
return shimmer.wrap(jestConfig, 'readConfigs', readConfigs => function (...args) {
|
|
2825
|
+
const readConfigsResult = readConfigs.apply(this, args)
|
|
1629
2826
|
configureTestEnvironment(readConfigsResult)
|
|
1630
2827
|
return readConfigsResult
|
|
1631
2828
|
})
|
|
@@ -1643,8 +2840,10 @@ const DD_TEST_ENVIRONMENT_OPTION_KEYS = [
|
|
|
1643
2840
|
'_ddIsEarlyFlakeDetectionEnabled',
|
|
1644
2841
|
'_ddEarlyFlakeDetectionSlowTestRetries',
|
|
1645
2842
|
'_ddRepositoryRoot',
|
|
2843
|
+
'_ddTestCodeCoverageEnabled',
|
|
1646
2844
|
'_ddIsFlakyTestRetriesEnabled',
|
|
1647
2845
|
'_ddFlakyTestRetriesCount',
|
|
2846
|
+
'_ddItrSkippingEnabledTags',
|
|
1648
2847
|
'_ddIsDiEnabled',
|
|
1649
2848
|
'_ddIsKnownTestsEnabled',
|
|
1650
2849
|
'_ddIsTestManagementTestsEnabled',
|
|
@@ -1707,7 +2906,7 @@ function wrapCreateScriptTransformer (createScriptTransformer) {
|
|
|
1707
2906
|
|
|
1708
2907
|
addHook({
|
|
1709
2908
|
name: '@jest/transform',
|
|
1710
|
-
versions: [
|
|
2909
|
+
versions: [MINIMUM_JEST_VERSION_BEFORE_30],
|
|
1711
2910
|
file: 'build/ScriptTransformer.js',
|
|
1712
2911
|
}, transformPackage => {
|
|
1713
2912
|
transformPackage.createScriptTransformer = wrapCreateScriptTransformer(transformPackage.createScriptTransformer)
|
|
@@ -1727,20 +2926,30 @@ addHook({
|
|
|
1727
2926
|
*/
|
|
1728
2927
|
addHook({
|
|
1729
2928
|
name: '@jest/core',
|
|
1730
|
-
versions: [
|
|
2929
|
+
versions: [MINIMUM_JEST_VERSION_BEFORE_30],
|
|
1731
2930
|
file: 'build/SearchSource.js',
|
|
1732
2931
|
}, searchSourceWrapper)
|
|
1733
2932
|
|
|
2933
|
+
addHook({
|
|
2934
|
+
name: 'jest-each',
|
|
2935
|
+
versions: [MINIMUM_JEST_VERSION],
|
|
2936
|
+
}, jestEach => {
|
|
2937
|
+
cacheJestEachBind(jestEach)
|
|
2938
|
+
return jestEach
|
|
2939
|
+
})
|
|
2940
|
+
|
|
1734
2941
|
// from 25.1.0 on, readConfigs becomes async
|
|
1735
2942
|
addHook({
|
|
1736
2943
|
name: 'jest-config',
|
|
1737
|
-
versions: [
|
|
2944
|
+
versions: [MINIMUM_JEST_CONFIG_ASYNC_VERSION],
|
|
1738
2945
|
}, jestConfigAsyncWrapper)
|
|
1739
2946
|
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
2947
|
+
if (DD_MAJOR < 6) {
|
|
2948
|
+
addHook({
|
|
2949
|
+
name: 'jest-config',
|
|
2950
|
+
versions: ['24.8.0 - 24.9.0'],
|
|
2951
|
+
}, jestConfigSyncWrapper)
|
|
2952
|
+
}
|
|
1744
2953
|
|
|
1745
2954
|
const LIBRARIES_BYPASSING_JEST_REQUIRE_ENGINE = new Set([
|
|
1746
2955
|
'selenium-webdriver',
|
|
@@ -1753,39 +2962,180 @@ const LIBRARIES_BYPASSING_JEST_REQUIRE_ENGINE = new Set([
|
|
|
1753
2962
|
'winston',
|
|
1754
2963
|
])
|
|
1755
2964
|
|
|
2965
|
+
function recordMockedFile (suiteFilePath, moduleName) {
|
|
2966
|
+
if (!suiteFilePath || typeof moduleName !== 'string') return
|
|
2967
|
+
|
|
2968
|
+
const existingMockedFiles = testSuiteMockedFiles.get(suiteFilePath) || []
|
|
2969
|
+
const suiteDir = path.dirname(suiteFilePath)
|
|
2970
|
+
const mockPath = path.resolve(suiteDir, moduleName)
|
|
2971
|
+
existingMockedFiles.push(mockPath)
|
|
2972
|
+
testSuiteMockedFiles.set(suiteFilePath, existingMockedFiles)
|
|
2973
|
+
}
|
|
2974
|
+
|
|
2975
|
+
const JEST_STATIC_MOCK_CALL_RE = /\bjest\.(?:mock|doMock|unstable_mockModule)\(\s*(['"`])([^'"`]+)\1/g
|
|
2976
|
+
|
|
2977
|
+
function getStaticMockedFiles (suiteFilePath) {
|
|
2978
|
+
if (!suiteFilePath) return []
|
|
2979
|
+
|
|
2980
|
+
const mockedFiles = []
|
|
2981
|
+
try {
|
|
2982
|
+
const source = readFileSync(suiteFilePath, 'utf8')
|
|
2983
|
+
let match
|
|
2984
|
+
JEST_STATIC_MOCK_CALL_RE.lastIndex = 0
|
|
2985
|
+
while ((match = JEST_STATIC_MOCK_CALL_RE.exec(source)) !== null) {
|
|
2986
|
+
mockedFiles.push(path.resolve(path.dirname(suiteFilePath), match[2]))
|
|
2987
|
+
}
|
|
2988
|
+
} catch {
|
|
2989
|
+
// ignore errors
|
|
2990
|
+
}
|
|
2991
|
+
|
|
2992
|
+
return mockedFiles
|
|
2993
|
+
}
|
|
2994
|
+
|
|
2995
|
+
function getMockedFiles (suiteFilePath) {
|
|
2996
|
+
const mockedFiles = testSuiteMockedFiles.get(suiteFilePath)
|
|
2997
|
+
const staticMockedFiles = getStaticMockedFiles(suiteFilePath)
|
|
2998
|
+
|
|
2999
|
+
if (mockedFiles?.length) {
|
|
3000
|
+
return [...new Set([...mockedFiles, ...staticMockedFiles])]
|
|
3001
|
+
}
|
|
3002
|
+
return staticMockedFiles
|
|
3003
|
+
}
|
|
3004
|
+
|
|
3005
|
+
function wrapJestObject (jestObject, suiteFilePath) {
|
|
3006
|
+
if (!jestObject || !suiteFilePath || wrappedJestObjects.has(jestObject)) return
|
|
3007
|
+
|
|
3008
|
+
testSuiteJestObjects.set(suiteFilePath, jestObject)
|
|
3009
|
+
wrappedJestObjects.add(jestObject)
|
|
3010
|
+
|
|
3011
|
+
shimmer.wrap(jestObject, 'mock', mock => function (moduleName) {
|
|
3012
|
+
// If the library is mocked with `jest.mock`, we don't want to bypass jest's own require engine
|
|
3013
|
+
if (LIBRARIES_BYPASSING_JEST_REQUIRE_ENGINE.has(moduleName)) {
|
|
3014
|
+
LIBRARIES_BYPASSING_JEST_REQUIRE_ENGINE.delete(moduleName)
|
|
3015
|
+
}
|
|
3016
|
+
recordMockedFile(suiteFilePath, moduleName)
|
|
3017
|
+
return mock.apply(this, arguments)
|
|
3018
|
+
})
|
|
3019
|
+
}
|
|
3020
|
+
|
|
3021
|
+
function wrapJestGlobalsForRuntime (runtime) {
|
|
3022
|
+
const jestGlobals = runtime?.jestGlobals
|
|
3023
|
+
if (!jestGlobals || wrappedJestGlobals.has(jestGlobals) || typeof jestGlobals.jestObjectFor !== 'function') {
|
|
3024
|
+
return
|
|
3025
|
+
}
|
|
3026
|
+
|
|
3027
|
+
wrappedJestGlobals.add(jestGlobals)
|
|
3028
|
+
shimmer.wrap(jestGlobals, 'jestObjectFor', jestObjectFor => function (from) {
|
|
3029
|
+
const jestObject = jestObjectFor.apply(this, arguments)
|
|
3030
|
+
wrapJestObject(jestObject, from)
|
|
3031
|
+
return jestObject
|
|
3032
|
+
})
|
|
3033
|
+
}
|
|
3034
|
+
|
|
3035
|
+
function wrapConcurrentJestGlobalsForRuntime (runtime, jestGlobals) {
|
|
3036
|
+
const environment = testSuiteDatadogEnvironments.get(runtime?._testPath)
|
|
3037
|
+
environment?.wrapConcurrentTestGlobals(jestGlobals?.test, environment.concurrentTestState)
|
|
3038
|
+
}
|
|
3039
|
+
|
|
3040
|
+
function cacheJestEachBind (jestEach) {
|
|
3041
|
+
if (typeof jestEach?.bind === 'function') {
|
|
3042
|
+
jestEachBind = jestEach.bind
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
3045
|
+
|
|
3046
|
+
function getLastLoggedReferenceError (runtime) {
|
|
3047
|
+
const loggedReferenceErrors = runtime?.loggedReferenceErrors
|
|
3048
|
+
if (!loggedReferenceErrors?.size) return
|
|
3049
|
+
return [...loggedReferenceErrors].pop()
|
|
3050
|
+
}
|
|
3051
|
+
|
|
3052
|
+
function publishRuntimeReferenceError (runtime, errorMessage) {
|
|
3053
|
+
if (!errorMessage || !runtime?._testPath) return
|
|
3054
|
+
|
|
3055
|
+
let publishedErrors = publishedRuntimeReferenceErrors.get(runtime)
|
|
3056
|
+
if (!publishedErrors) {
|
|
3057
|
+
publishedErrors = new Set()
|
|
3058
|
+
publishedRuntimeReferenceErrors.set(runtime, publishedErrors)
|
|
3059
|
+
}
|
|
3060
|
+
if (publishedErrors.has(errorMessage)) return
|
|
3061
|
+
|
|
3062
|
+
publishedErrors.add(errorMessage)
|
|
3063
|
+
testSuiteErrorCh.publish({
|
|
3064
|
+
errorMessage,
|
|
3065
|
+
testSuiteAbsolutePath: runtime._testPath,
|
|
3066
|
+
})
|
|
3067
|
+
}
|
|
3068
|
+
|
|
3069
|
+
function isBetweenTestsReferenceError (error) {
|
|
3070
|
+
return error?.name === 'ReferenceError' &&
|
|
3071
|
+
typeof error.message === 'string' &&
|
|
3072
|
+
error.message.includes('outside of the scope of the test code')
|
|
3073
|
+
}
|
|
3074
|
+
|
|
3075
|
+
function reportBetweenTestsReferenceError (runtime, moduleName, originalErrorMessage) {
|
|
3076
|
+
if (typeof moduleName !== 'string') return false
|
|
3077
|
+
|
|
3078
|
+
const fallbackErrorMessage = moduleName.startsWith('node:') || builtinModules.includes(moduleName)
|
|
3079
|
+
? 'You are trying to access a Node.js module outside of the scope of the test code.'
|
|
3080
|
+
: 'You are trying to `require` a file after the Jest environment has been torn down.'
|
|
3081
|
+
const errorMessage = originalErrorMessage || fallbackErrorMessage
|
|
3082
|
+
|
|
3083
|
+
if (typeof runtime._logFormattedReferenceError === 'function') {
|
|
3084
|
+
runtime._logFormattedReferenceError(errorMessage)
|
|
3085
|
+
}
|
|
3086
|
+
publishRuntimeReferenceError(runtime, getLastLoggedReferenceError(runtime) || errorMessage)
|
|
3087
|
+
process.exitCode = 1
|
|
3088
|
+
return true
|
|
3089
|
+
}
|
|
3090
|
+
|
|
3091
|
+
function requireOutsideJestRequireEngine (runtime, moduleName) {
|
|
3092
|
+
if (typeof runtime._requireCoreModule === 'function') {
|
|
3093
|
+
return runtime._requireCoreModule(moduleName)
|
|
3094
|
+
}
|
|
3095
|
+
return require(moduleName)
|
|
3096
|
+
}
|
|
3097
|
+
|
|
3098
|
+
function formatDefaultStackTrace (error, structuredStackTrace) {
|
|
3099
|
+
const errorString = Error.prototype.toString.call(error)
|
|
3100
|
+
if (structuredStackTrace.length === 0) return errorString
|
|
3101
|
+
|
|
3102
|
+
return `${errorString}\n at ${structuredStackTrace.join('\n at ')}`
|
|
3103
|
+
}
|
|
3104
|
+
|
|
1756
3105
|
addHook({
|
|
1757
3106
|
name: 'jest-runtime',
|
|
1758
|
-
versions: [
|
|
3107
|
+
versions: [MINIMUM_JEST_VERSION],
|
|
1759
3108
|
}, (runtimePackage) => {
|
|
1760
3109
|
const Runtime = runtimePackage.default ?? runtimePackage
|
|
1761
3110
|
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
3111
|
+
if (typeof Runtime.prototype._createJestObjectFor === 'function') {
|
|
3112
|
+
shimmer.wrap(Runtime.prototype, '_createJestObjectFor', _createJestObjectFor => function (from) {
|
|
3113
|
+
const result = _createJestObjectFor.apply(this, arguments)
|
|
3114
|
+
const suiteFilePath = this._testPath || from
|
|
1765
3115
|
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
3116
|
+
wrapJestObject(result, suiteFilePath)
|
|
3117
|
+
return result
|
|
3118
|
+
})
|
|
3119
|
+
}
|
|
1770
3120
|
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
3121
|
+
shimmer.wrap(Runtime.prototype, 'requireModule', requireModule => function (from, moduleName) {
|
|
3122
|
+
wrapJestGlobalsForRuntime(this)
|
|
3123
|
+
try {
|
|
3124
|
+
const returnedValue = requireModule.apply(this, arguments)
|
|
3125
|
+
if (moduleName === '@jest/globals') {
|
|
3126
|
+
wrapConcurrentJestGlobalsForRuntime(this, returnedValue)
|
|
1775
3127
|
}
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
existingMockedFiles.push(mockPath)
|
|
1781
|
-
testSuiteMockedFiles.set(suiteFilePath, existingMockedFiles)
|
|
3128
|
+
return returnedValue
|
|
3129
|
+
} catch (error) {
|
|
3130
|
+
if (isBetweenTestsReferenceError(error)) {
|
|
3131
|
+
reportBetweenTestsReferenceError(this, moduleName, error.message)
|
|
1782
3132
|
}
|
|
1783
|
-
|
|
1784
|
-
}
|
|
1785
|
-
return result
|
|
3133
|
+
throw error
|
|
3134
|
+
}
|
|
1786
3135
|
})
|
|
1787
3136
|
|
|
1788
3137
|
shimmer.wrap(Runtime.prototype, 'requireModuleOrMock', requireModuleOrMock => function (from, moduleName) {
|
|
3138
|
+
wrapJestGlobalsForRuntime(this)
|
|
1789
3139
|
// `requireModuleOrMock` may log errors to the console. If we don't remove ourselves
|
|
1790
3140
|
// from the stack trace, the user might see a useless stack trace rather than the error
|
|
1791
3141
|
// that `jest` tries to show.
|
|
@@ -1794,32 +3144,34 @@ addHook({
|
|
|
1794
3144
|
const filteredStackTrace = structuredStackTrace
|
|
1795
3145
|
.filter(callSite => !callSite.getFileName()?.includes('datadog-instrumentations/src/jest.js'))
|
|
1796
3146
|
|
|
1797
|
-
|
|
3147
|
+
if (typeof originalPrepareStackTrace === 'function') {
|
|
3148
|
+
return originalPrepareStackTrace(error, filteredStackTrace)
|
|
3149
|
+
}
|
|
3150
|
+
return formatDefaultStackTrace(error, filteredStackTrace)
|
|
1798
3151
|
}
|
|
1799
3152
|
try {
|
|
1800
3153
|
// TODO: do this for every library that we instrument
|
|
1801
3154
|
if (LIBRARIES_BYPASSING_JEST_REQUIRE_ENGINE.has(moduleName)) {
|
|
1802
3155
|
// To bypass jest's own require engine
|
|
1803
|
-
return this
|
|
3156
|
+
return requireOutsideJestRequireEngine(this, moduleName)
|
|
1804
3157
|
}
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
3158
|
+
let returnedValue
|
|
3159
|
+
try {
|
|
3160
|
+
returnedValue = requireModuleOrMock.apply(this, arguments)
|
|
3161
|
+
if (moduleName === '@jest/globals') {
|
|
3162
|
+
wrapConcurrentJestGlobalsForRuntime(this, returnedValue)
|
|
3163
|
+
}
|
|
3164
|
+
} catch (error) {
|
|
3165
|
+
if (isBetweenTestsReferenceError(error)) {
|
|
3166
|
+
reportBetweenTestsReferenceError(this, moduleName, error.message)
|
|
3167
|
+
}
|
|
3168
|
+
throw error
|
|
1808
3169
|
}
|
|
1809
|
-
const returnedValue = requireModuleOrMock.apply(this, arguments)
|
|
1810
3170
|
if (process.exitCode === 1) {
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
testSuiteAbsolutePath: this._testPath,
|
|
1816
|
-
})
|
|
1817
|
-
} else {
|
|
1818
|
-
testSuiteErrorCh.publish({
|
|
1819
|
-
errorMessage: 'An error occurred while importing a module',
|
|
1820
|
-
testSuiteAbsolutePath: this._testPath,
|
|
1821
|
-
})
|
|
1822
|
-
}
|
|
3171
|
+
publishRuntimeReferenceError(
|
|
3172
|
+
this,
|
|
3173
|
+
getLastLoggedReferenceError(this) || 'An error occurred while importing a module'
|
|
3174
|
+
)
|
|
1823
3175
|
}
|
|
1824
3176
|
return returnedValue
|
|
1825
3177
|
} finally {
|
|
@@ -1828,14 +3180,35 @@ addHook({
|
|
|
1828
3180
|
}
|
|
1829
3181
|
})
|
|
1830
3182
|
|
|
3183
|
+
if (Runtime.prototype._logFormattedReferenceError) {
|
|
3184
|
+
shimmer.wrap(Runtime.prototype, '_logFormattedReferenceError', logFormattedReferenceError => function () {
|
|
3185
|
+
// eslint-disable-next-line no-console
|
|
3186
|
+
const originalConsoleError = console.error
|
|
3187
|
+
let loggedReferenceError
|
|
3188
|
+
// eslint-disable-next-line no-console
|
|
3189
|
+
console.error = function () {
|
|
3190
|
+
loggedReferenceError = arguments[0]
|
|
3191
|
+
return originalConsoleError.apply(this, arguments)
|
|
3192
|
+
}
|
|
3193
|
+
try {
|
|
3194
|
+
const result = logFormattedReferenceError.apply(this, arguments)
|
|
3195
|
+
publishRuntimeReferenceError(this, getLastLoggedReferenceError(this) || loggedReferenceError)
|
|
3196
|
+
return result
|
|
3197
|
+
} finally {
|
|
3198
|
+
// eslint-disable-next-line no-console
|
|
3199
|
+
console.error = originalConsoleError
|
|
3200
|
+
}
|
|
3201
|
+
})
|
|
3202
|
+
}
|
|
3203
|
+
|
|
1831
3204
|
return runtimePackage
|
|
1832
3205
|
})
|
|
1833
3206
|
|
|
1834
3207
|
function onMessageWrapper (onMessage) {
|
|
1835
|
-
return function () {
|
|
1836
|
-
const response =
|
|
3208
|
+
return function (...args) {
|
|
3209
|
+
const response = args[0]
|
|
1837
3210
|
if (!Array.isArray(response)) {
|
|
1838
|
-
return onMessage.apply(this,
|
|
3211
|
+
return onMessage.apply(this, args)
|
|
1839
3212
|
}
|
|
1840
3213
|
|
|
1841
3214
|
const [code, data] = response
|
|
@@ -1856,7 +3229,13 @@ function onMessageWrapper (onMessage) {
|
|
|
1856
3229
|
workerReportTelemetryCh.publish(data)
|
|
1857
3230
|
return
|
|
1858
3231
|
}
|
|
1859
|
-
|
|
3232
|
+
if (code === JEST_WORKER_QUARANTINE_PAYLOAD_CODE) { // quarantined test failures suppressed in worker
|
|
3233
|
+
for (const name of JSON.parse(data)) {
|
|
3234
|
+
quarantinedFailingTests.add(name)
|
|
3235
|
+
}
|
|
3236
|
+
return
|
|
3237
|
+
}
|
|
3238
|
+
return onMessage.apply(this, args)
|
|
1860
3239
|
}
|
|
1861
3240
|
}
|
|
1862
3241
|
|
|
@@ -1908,11 +3287,23 @@ function wrapWorkerChannel (worker) {
|
|
|
1908
3287
|
shimmer.wrap(workerChannel, worker._child ? 'send' : 'postMessage', sendWrapper)
|
|
1909
3288
|
}
|
|
1910
3289
|
|
|
3290
|
+
function wrapWorkerInitializer (worker) {
|
|
3291
|
+
if (wrappedWorkerInitializers.has(worker) || typeof worker.initialize !== 'function') return
|
|
3292
|
+
|
|
3293
|
+
wrappedWorkerInitializers.add(worker)
|
|
3294
|
+
shimmer.wrap(worker, 'initialize', initialize => function () {
|
|
3295
|
+
const result = initialize.apply(this, arguments)
|
|
3296
|
+
wrapWorkerChannel(this)
|
|
3297
|
+
return result
|
|
3298
|
+
})
|
|
3299
|
+
}
|
|
3300
|
+
|
|
1911
3301
|
function wrapWorker (worker) {
|
|
1912
3302
|
// ChildProcessWorker uses _child (child_process), ExperimentalWorker uses _worker (worker_threads)
|
|
1913
3303
|
const workerChannel = worker._child || worker._worker
|
|
1914
3304
|
if (!workerChannel) return
|
|
1915
3305
|
|
|
3306
|
+
wrapWorkerInitializer(worker)
|
|
1916
3307
|
wrapWorkerChannel(worker)
|
|
1917
3308
|
shimmer.wrap(worker, '_onMessage', onMessageWrapper)
|
|
1918
3309
|
workerChannel.removeAllListeners('message')
|
|
@@ -1920,8 +3311,8 @@ function wrapWorker (worker) {
|
|
|
1920
3311
|
}
|
|
1921
3312
|
|
|
1922
3313
|
function enqueueWrapper (enqueue) {
|
|
1923
|
-
return function () {
|
|
1924
|
-
shimmer.wrap(
|
|
3314
|
+
return function (...args) {
|
|
3315
|
+
shimmer.wrap(args[0], 'onStart', onStart => function (worker) {
|
|
1925
3316
|
if (worker) {
|
|
1926
3317
|
const currentChannel = worker._child || worker._worker
|
|
1927
3318
|
const previousChannel = wrappedWorkerChannels.get(worker)
|
|
@@ -1938,7 +3329,7 @@ function enqueueWrapper (enqueue) {
|
|
|
1938
3329
|
}
|
|
1939
3330
|
return onStart.apply(this, arguments)
|
|
1940
3331
|
})
|
|
1941
|
-
return enqueue.apply(this,
|
|
3332
|
+
return enqueue.apply(this, args)
|
|
1942
3333
|
}
|
|
1943
3334
|
}
|
|
1944
3335
|
|
|
@@ -1950,7 +3341,7 @@ function enqueueWrapper (enqueue) {
|
|
|
1950
3341
|
*/
|
|
1951
3342
|
addHook({
|
|
1952
3343
|
name: 'jest-worker',
|
|
1953
|
-
versions: [
|
|
3344
|
+
versions: [MINIMUM_JEST_WORKER_VERSION_BEFORE_30],
|
|
1954
3345
|
file: 'build/workers/ChildProcessWorker.js',
|
|
1955
3346
|
}, (childProcessWorker) => {
|
|
1956
3347
|
const ChildProcessWorker = childProcessWorker.default
|
|
@@ -1965,7 +3356,7 @@ addHook({
|
|
|
1965
3356
|
|
|
1966
3357
|
addHook({
|
|
1967
3358
|
name: 'jest-worker',
|
|
1968
|
-
versions: [
|
|
3359
|
+
versions: [MINIMUM_JEST_WORKER_VERSION_BEFORE_30],
|
|
1969
3360
|
file: 'build/workers/NodeThreadsWorker.js',
|
|
1970
3361
|
}, (nodeThreadsWorker) => {
|
|
1971
3362
|
const ExperimentalWorker = nodeThreadsWorker.default
|