@encore.dev/sdk 0.0.0 → 2.0.0-beta.11
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 +362 -0
- package/README.md +245 -2
- package/app_meta.test.ts +154 -0
- package/app_meta.ts +226 -0
- package/config/config.test.ts +384 -0
- package/config/config.ts +236 -0
- package/config/mod.ts +15 -0
- package/config/secrets.ts +173 -0
- package/config/value.ts +239 -0
- package/cron/mod.test.ts +52 -0
- package/cron/mod.ts +62 -0
- package/dist/app_meta.d.ts +126 -0
- package/dist/app_meta.d.ts.map +1 -0
- package/dist/app_meta.js +67 -0
- package/dist/app_meta.js.map +1 -0
- package/dist/config/config.d.ts +135 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +115 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/mod.d.ts +5 -0
- package/dist/config/mod.d.ts.map +1 -0
- package/dist/config/mod.js +3 -0
- package/dist/config/mod.js.map +1 -0
- package/dist/config/secrets.d.ts +124 -0
- package/dist/config/secrets.d.ts.map +1 -0
- package/dist/config/secrets.js +73 -0
- package/dist/config/secrets.js.map +1 -0
- package/dist/config/value.d.ts +54 -0
- package/dist/config/value.d.ts.map +1 -0
- package/dist/config/value.js +181 -0
- package/dist/config/value.js.map +1 -0
- package/dist/cron/mod.d.ts +57 -0
- package/dist/cron/mod.d.ts.map +1 -0
- package/dist/cron/mod.js +39 -0
- package/dist/cron/mod.js.map +1 -0
- package/dist/frontends/mod.d.ts +39 -0
- package/dist/frontends/mod.d.ts.map +1 -0
- package/dist/frontends/mod.js +47 -0
- package/dist/frontends/mod.js.map +1 -0
- package/dist/gateway/errors.d.ts +101 -0
- package/dist/gateway/errors.d.ts.map +1 -0
- package/dist/gateway/errors.js +146 -0
- package/dist/gateway/errors.js.map +1 -0
- package/dist/gateway/match.d.ts +127 -0
- package/dist/gateway/match.d.ts.map +1 -0
- package/dist/gateway/match.js +206 -0
- package/dist/gateway/match.js.map +1 -0
- package/dist/gateway/middleware.d.ts +108 -0
- package/dist/gateway/middleware.d.ts.map +1 -0
- package/dist/gateway/middleware.js +9 -0
- package/dist/gateway/middleware.js.map +1 -0
- package/dist/gateway/mod.d.ts +130 -0
- package/dist/gateway/mod.d.ts.map +1 -0
- package/dist/gateway/mod.js +188 -0
- package/dist/gateway/mod.js.map +1 -0
- package/dist/gateway/request.d.ts +304 -0
- package/dist/gateway/request.d.ts.map +1 -0
- package/dist/gateway/request.js +403 -0
- package/dist/gateway/request.js.map +1 -0
- package/dist/gateway/serve.d.ts +114 -0
- package/dist/gateway/serve.d.ts.map +1 -0
- package/dist/gateway/serve.js +510 -0
- package/dist/gateway/serve.js.map +1 -0
- package/dist/gateways/mod.d.ts +42 -0
- package/dist/gateways/mod.d.ts.map +1 -0
- package/dist/gateways/mod.js +55 -0
- package/dist/gateways/mod.js.map +1 -0
- package/dist/internal/clients/call.d.ts +171 -0
- package/dist/internal/clients/call.d.ts.map +1 -0
- package/dist/internal/clients/call.js +284 -0
- package/dist/internal/clients/call.js.map +1 -0
- package/dist/internal/clients/grpc.d.ts +108 -0
- package/dist/internal/clients/grpc.d.ts.map +1 -0
- package/dist/internal/clients/grpc.js +349 -0
- package/dist/internal/clients/grpc.js.map +1 -0
- package/dist/internal/clients/mod.d.ts +81 -0
- package/dist/internal/clients/mod.d.ts.map +1 -0
- package/dist/internal/clients/mod.js +237 -0
- package/dist/internal/clients/mod.js.map +1 -0
- package/dist/internal/fetch.d.ts +67 -0
- package/dist/internal/fetch.d.ts.map +1 -0
- package/dist/internal/fetch.js +271 -0
- package/dist/internal/fetch.js.map +1 -0
- package/dist/internal/otel/backend.d.ts +52 -0
- package/dist/internal/otel/backend.d.ts.map +1 -0
- package/dist/internal/otel/backend.js +2 -0
- package/dist/internal/otel/backend.js.map +1 -0
- package/dist/internal/otel/context.d.ts +11 -0
- package/dist/internal/otel/context.d.ts.map +1 -0
- package/dist/internal/otel/context.js +34 -0
- package/dist/internal/otel/context.js.map +1 -0
- package/dist/internal/otel/context_manager.d.ts +23 -0
- package/dist/internal/otel/context_manager.d.ts.map +1 -0
- package/dist/internal/otel/context_manager.js +120 -0
- package/dist/internal/otel/context_manager.js.map +1 -0
- package/dist/internal/otel/encode.d.ts +114 -0
- package/dist/internal/otel/encode.d.ts.map +1 -0
- package/dist/internal/otel/encode.js +290 -0
- package/dist/internal/otel/encode.js.map +1 -0
- package/dist/internal/otel/http.d.ts +11 -0
- package/dist/internal/otel/http.d.ts.map +1 -0
- package/dist/internal/otel/http.js +65 -0
- package/dist/internal/otel/http.js.map +1 -0
- package/dist/internal/otel/index.d.ts +9 -0
- package/dist/internal/otel/index.d.ts.map +1 -0
- package/dist/internal/otel/index.js +8 -0
- package/dist/internal/otel/index.js.map +1 -0
- package/dist/internal/otel/meter.d.ts +74 -0
- package/dist/internal/otel/meter.d.ts.map +1 -0
- package/dist/internal/otel/meter.js +265 -0
- package/dist/internal/otel/meter.js.map +1 -0
- package/dist/internal/otel/propagator.d.ts +15 -0
- package/dist/internal/otel/propagator.d.ts.map +1 -0
- package/dist/internal/otel/propagator.js +61 -0
- package/dist/internal/otel/propagator.js.map +1 -0
- package/dist/internal/otel/provider.d.ts +13 -0
- package/dist/internal/otel/provider.d.ts.map +1 -0
- package/dist/internal/otel/provider.js +22 -0
- package/dist/internal/otel/provider.js.map +1 -0
- package/dist/internal/otel/span.d.ts +75 -0
- package/dist/internal/otel/span.d.ts.map +1 -0
- package/dist/internal/otel/span.js +234 -0
- package/dist/internal/otel/span.js.map +1 -0
- package/dist/internal/otel/tracer.d.ts +16 -0
- package/dist/internal/otel/tracer.d.ts.map +1 -0
- package/dist/internal/otel/tracer.js +71 -0
- package/dist/internal/otel/tracer.js.map +1 -0
- package/dist/internal/reqfields.d.ts +170 -0
- package/dist/internal/reqfields.d.ts.map +1 -0
- package/dist/internal/reqfields.js +349 -0
- package/dist/internal/reqfields.js.map +1 -0
- package/dist/internal/runtime/meter.d.ts +12 -0
- package/dist/internal/runtime/meter.d.ts.map +1 -0
- package/dist/internal/runtime/meter.js +22 -0
- package/dist/internal/runtime/meter.js.map +1 -0
- package/dist/internal/runtime/mod.d.ts +18 -0
- package/dist/internal/runtime/mod.d.ts.map +1 -0
- package/dist/internal/runtime/mod.js +59 -0
- package/dist/internal/runtime/mod.js.map +1 -0
- package/dist/internal/runtime/napi/napi.cjs +308 -0
- package/dist/internal/runtime/napi/napi.d.cts +1249 -0
- package/dist/internal/runtime/shutdown.d.ts +91 -0
- package/dist/internal/runtime/shutdown.d.ts.map +1 -0
- package/dist/internal/runtime/shutdown.js +299 -0
- package/dist/internal/runtime/shutdown.js.map +1 -0
- package/dist/internal/testing/carry.d.ts +49 -0
- package/dist/internal/testing/carry.d.ts.map +1 -0
- package/dist/internal/testing/carry.js +77 -0
- package/dist/internal/testing/carry.js.map +1 -0
- package/dist/internal/testing/runner.d.ts +2 -0
- package/dist/internal/testing/runner.d.ts.map +1 -0
- package/dist/internal/testing/runner.js +10 -0
- package/dist/internal/testing/runner.js.map +1 -0
- package/dist/internal/testing/scope.d.ts +112 -0
- package/dist/internal/testing/scope.d.ts.map +1 -0
- package/dist/internal/testing/scope.js +346 -0
- package/dist/internal/testing/scope.js.map +1 -0
- package/dist/internal/testing/steps.d.ts +55 -0
- package/dist/internal/testing/steps.d.ts.map +1 -0
- package/dist/internal/testing/steps.js +295 -0
- package/dist/internal/testing/steps.js.map +1 -0
- package/dist/internal/testing/telemetry.d.ts +305 -0
- package/dist/internal/testing/telemetry.d.ts.map +1 -0
- package/dist/internal/testing/telemetry.js +188 -0
- package/dist/internal/testing/telemetry.js.map +1 -0
- package/dist/internal/utils/constraints.d.ts +10 -0
- package/dist/internal/utils/constraints.d.ts.map +1 -0
- package/dist/internal/utils/constraints.js +2 -0
- package/dist/internal/utils/constraints.js.map +1 -0
- package/dist/log/index.d.ts +40 -0
- package/dist/log/index.d.ts.map +1 -0
- package/dist/log/index.js +44 -0
- package/dist/log/index.js.map +1 -0
- package/dist/log/logger.d.ts +125 -0
- package/dist/log/logger.d.ts.map +1 -0
- package/dist/log/logger.js +203 -0
- package/dist/log/logger.js.map +1 -0
- package/dist/log/runtime.d.ts +21 -0
- package/dist/log/runtime.d.ts.map +1 -0
- package/dist/log/runtime.js +22 -0
- package/dist/log/runtime.js.map +1 -0
- package/dist/log/stderr.d.ts +10 -0
- package/dist/log/stderr.d.ts.map +1 -0
- package/dist/log/stderr.js +25 -0
- package/dist/log/stderr.js.map +1 -0
- package/dist/metrics/mod.d.ts +242 -0
- package/dist/metrics/mod.d.ts.map +1 -0
- package/dist/metrics/mod.js +353 -0
- package/dist/metrics/mod.js.map +1 -0
- package/dist/mod.d.ts +5 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +3 -0
- package/dist/mod.js.map +1 -0
- package/dist/otel.d.ts +10 -0
- package/dist/otel.d.ts.map +1 -0
- package/dist/otel.js +13 -0
- package/dist/otel.js.map +1 -0
- package/dist/pubsub/encoding.d.ts +8 -0
- package/dist/pubsub/encoding.d.ts.map +1 -0
- package/dist/pubsub/encoding.js +18 -0
- package/dist/pubsub/encoding.js.map +1 -0
- package/dist/pubsub/mod.d.ts +7 -0
- package/dist/pubsub/mod.d.ts.map +1 -0
- package/dist/pubsub/mod.js +3 -0
- package/dist/pubsub/mod.js.map +1 -0
- package/dist/pubsub/refs.d.ts +20 -0
- package/dist/pubsub/refs.d.ts.map +1 -0
- package/dist/pubsub/refs.js +11 -0
- package/dist/pubsub/refs.js.map +1 -0
- package/dist/pubsub/subscription.d.ts +223 -0
- package/dist/pubsub/subscription.d.ts.map +1 -0
- package/dist/pubsub/subscription.js +121 -0
- package/dist/pubsub/subscription.js.map +1 -0
- package/dist/pubsub/topic.d.ts +218 -0
- package/dist/pubsub/topic.d.ts.map +1 -0
- package/dist/pubsub/topic.js +281 -0
- package/dist/pubsub/topic.js.map +1 -0
- package/dist/reqctx/mod.d.ts +174 -0
- package/dist/reqctx/mod.d.ts.map +1 -0
- package/dist/reqctx/mod.js +144 -0
- package/dist/reqctx/mod.js.map +1 -0
- package/dist/services/index.d.ts +171 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +187 -0
- package/dist/services/index.js.map +1 -0
- package/dist/shutdown/mod.d.ts +60 -0
- package/dist/shutdown/mod.d.ts.map +1 -0
- package/dist/shutdown/mod.js +59 -0
- package/dist/shutdown/mod.js.map +1 -0
- package/dist/storage/clickhouse/database.d.ts +262 -0
- package/dist/storage/clickhouse/database.d.ts.map +1 -0
- package/dist/storage/clickhouse/database.js +362 -0
- package/dist/storage/clickhouse/database.js.map +1 -0
- package/dist/storage/clickhouse/errors.d.ts +67 -0
- package/dist/storage/clickhouse/errors.d.ts.map +1 -0
- package/dist/storage/clickhouse/errors.js +91 -0
- package/dist/storage/clickhouse/errors.js.map +1 -0
- package/dist/storage/clickhouse/mod.d.ts +31 -0
- package/dist/storage/clickhouse/mod.d.ts.map +1 -0
- package/dist/storage/clickhouse/mod.js +29 -0
- package/dist/storage/clickhouse/mod.js.map +1 -0
- package/dist/storage/objects/bucket.d.ts +522 -0
- package/dist/storage/objects/bucket.d.ts.map +1 -0
- package/dist/storage/objects/bucket.js +414 -0
- package/dist/storage/objects/bucket.js.map +1 -0
- package/dist/storage/objects/error.d.ts +24 -0
- package/dist/storage/objects/error.d.ts.map +1 -0
- package/dist/storage/objects/error.js +105 -0
- package/dist/storage/objects/error.js.map +1 -0
- package/dist/storage/objects/mod.d.ts +5 -0
- package/dist/storage/objects/mod.d.ts.map +1 -0
- package/dist/storage/objects/mod.js +3 -0
- package/dist/storage/objects/mod.js.map +1 -0
- package/dist/storage/objects/refs.d.ts +47 -0
- package/dist/storage/objects/refs.d.ts.map +1 -0
- package/dist/storage/objects/refs.js +26 -0
- package/dist/storage/objects/refs.js.map +1 -0
- package/dist/storage/postgres/database.d.ts +365 -0
- package/dist/storage/postgres/database.d.ts.map +1 -0
- package/dist/storage/postgres/database.js +480 -0
- package/dist/storage/postgres/database.js.map +1 -0
- package/dist/storage/postgres/errors.d.ts +120 -0
- package/dist/storage/postgres/errors.d.ts.map +1 -0
- package/dist/storage/postgres/errors.js +162 -0
- package/dist/storage/postgres/errors.js.map +1 -0
- package/dist/storage/postgres/interval.d.ts +44 -0
- package/dist/storage/postgres/interval.d.ts.map +1 -0
- package/dist/storage/postgres/interval.js +153 -0
- package/dist/storage/postgres/interval.js.map +1 -0
- package/dist/storage/postgres/mod.d.ts +5 -0
- package/dist/storage/postgres/mod.d.ts.map +1 -0
- package/dist/storage/postgres/mod.js +4 -0
- package/dist/storage/postgres/mod.js.map +1 -0
- package/dist/storage/redis/bitfield.d.ts +67 -0
- package/dist/storage/redis/bitfield.d.ts.map +1 -0
- package/dist/storage/redis/bitfield.js +114 -0
- package/dist/storage/redis/bitfield.js.map +1 -0
- package/dist/storage/redis/command.d.ts +45 -0
- package/dist/storage/redis/command.d.ts.map +1 -0
- package/dist/storage/redis/command.js +78 -0
- package/dist/storage/redis/command.js.map +1 -0
- package/dist/storage/redis/commands.d.ts +657 -0
- package/dist/storage/redis/commands.d.ts.map +1 -0
- package/dist/storage/redis/commands.js +759 -0
- package/dist/storage/redis/commands.js.map +1 -0
- package/dist/storage/redis/database.d.ts +336 -0
- package/dist/storage/redis/database.d.ts.map +1 -0
- package/dist/storage/redis/database.js +398 -0
- package/dist/storage/redis/database.js.map +1 -0
- package/dist/storage/redis/mod.d.ts +115 -0
- package/dist/storage/redis/mod.d.ts.map +1 -0
- package/dist/storage/redis/mod.js +109 -0
- package/dist/storage/redis/mod.js.map +1 -0
- package/dist/storage/redis/native.d.ts +16 -0
- package/dist/storage/redis/native.d.ts.map +1 -0
- package/dist/storage/redis/native.js +21 -0
- package/dist/storage/redis/native.js.map +1 -0
- package/dist/storage/redis/options.d.ts +90 -0
- package/dist/storage/redis/options.d.ts.map +1 -0
- package/dist/storage/redis/options.js +53 -0
- package/dist/storage/redis/options.js.map +1 -0
- package/dist/storage/redis/pubsub.d.ts +55 -0
- package/dist/storage/redis/pubsub.d.ts.map +1 -0
- package/dist/storage/redis/pubsub.js +88 -0
- package/dist/storage/redis/pubsub.js.map +1 -0
- package/dist/storage/redis/reply.d.ts +290 -0
- package/dist/storage/redis/reply.d.ts.map +1 -0
- package/dist/storage/redis/reply.js +611 -0
- package/dist/storage/redis/reply.js.map +1 -0
- package/dist/storage/redis/scan.d.ts +12 -0
- package/dist/storage/redis/scan.d.ts.map +1 -0
- package/dist/storage/redis/scan.js +76 -0
- package/dist/storage/redis/scan.js.map +1 -0
- package/dist/storage/redis/script.d.ts +92 -0
- package/dist/storage/redis/script.d.ts.map +1 -0
- package/dist/storage/redis/script.js +143 -0
- package/dist/storage/redis/script.js.map +1 -0
- package/dist/storage/redis/target.d.ts +49 -0
- package/dist/storage/redis/target.d.ts.map +1 -0
- package/dist/storage/redis/target.js +93 -0
- package/dist/storage/redis/target.js.map +1 -0
- package/dist/storage/redis/wire.d.ts +102 -0
- package/dist/storage/redis/wire.d.ts.map +1 -0
- package/dist/storage/redis/wire.js +309 -0
- package/dist/storage/redis/wire.js.map +1 -0
- package/dist/testing/bun.d.ts +8 -0
- package/dist/testing/bun.d.ts.map +1 -0
- package/dist/testing/bun.js +13 -0
- package/dist/testing/bun.js.map +1 -0
- package/dist/testing/jest.d.ts +8 -0
- package/dist/testing/jest.d.ts.map +1 -0
- package/dist/testing/jest.js +11 -0
- package/dist/testing/jest.js.map +1 -0
- package/dist/testing/mod.d.ts +183 -0
- package/dist/testing/mod.d.ts.map +1 -0
- package/dist/testing/mod.js +271 -0
- package/dist/testing/mod.js.map +1 -0
- package/dist/testing/node.d.ts +9 -0
- package/dist/testing/node.d.ts.map +1 -0
- package/dist/testing/node.js +12 -0
- package/dist/testing/node.js.map +1 -0
- package/dist/testing/playwright.d.ts +93 -0
- package/dist/testing/playwright.d.ts.map +1 -0
- package/dist/testing/playwright.js +164 -0
- package/dist/testing/playwright.js.map +1 -0
- package/dist/testing/puppeteer.d.ts +36 -0
- package/dist/testing/puppeteer.d.ts.map +1 -0
- package/dist/testing/puppeteer.js +70 -0
- package/dist/testing/puppeteer.js.map +1 -0
- package/dist/testing/system.d.ts +181 -0
- package/dist/testing/system.d.ts.map +1 -0
- package/dist/testing/system.js +255 -0
- package/dist/testing/system.js.map +1 -0
- package/dist/testing/vitest.d.ts +8 -0
- package/dist/testing/vitest.d.ts.map +1 -0
- package/dist/testing/vitest.js +13 -0
- package/dist/testing/vitest.js.map +1 -0
- package/dist/tracing/http.d.ts +11 -0
- package/dist/tracing/http.d.ts.map +1 -0
- package/dist/tracing/http.js +34 -0
- package/dist/tracing/http.js.map +1 -0
- package/dist/tracing/mod.d.ts +20 -0
- package/dist/tracing/mod.d.ts.map +1 -0
- package/dist/tracing/mod.js +47 -0
- package/dist/tracing/mod.js.map +1 -0
- package/dist/tracing/node.d.ts +10 -0
- package/dist/tracing/node.d.ts.map +1 -0
- package/dist/tracing/node.js +142 -0
- package/dist/tracing/node.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/mod.d.ts +43 -0
- package/dist/types/mod.d.ts.map +1 -0
- package/dist/types/mod.js +65 -0
- package/dist/types/mod.js.map +1 -0
- package/frontends/mod.test.ts +51 -0
- package/frontends/mod.ts +50 -0
- package/gateway/errors.ts +172 -0
- package/gateway/gateway.e2e.test.ts +297 -0
- package/gateway/gateway.test.ts +891 -0
- package/gateway/match.ts +239 -0
- package/gateway/middleware.ts +134 -0
- package/gateway/mod.ts +211 -0
- package/gateway/request.ts +578 -0
- package/gateway/serve.ts +738 -0
- package/gateways/mod.ts +60 -0
- package/internal/clients/call.ts +418 -0
- package/internal/clients/grpc.test.ts +664 -0
- package/internal/clients/grpc.ts +485 -0
- package/internal/clients/mod.test.ts +481 -0
- package/internal/clients/mod.ts +337 -0
- package/internal/fetch.ts +320 -0
- package/internal/otel/backend.ts +60 -0
- package/internal/otel/context.test.ts +70 -0
- package/internal/otel/context.ts +48 -0
- package/internal/otel/context_manager.test.ts +154 -0
- package/internal/otel/context_manager.ts +141 -0
- package/internal/otel/encode.test.ts +266 -0
- package/internal/otel/encode.ts +408 -0
- package/internal/otel/http.ts +92 -0
- package/internal/otel/index.ts +14 -0
- package/internal/otel/meter.test.ts +231 -0
- package/internal/otel/meter.ts +332 -0
- package/internal/otel/propagator.test.ts +105 -0
- package/internal/otel/propagator.ts +68 -0
- package/internal/otel/provider.ts +26 -0
- package/internal/otel/span.ts +281 -0
- package/internal/otel/tracer.test.ts +380 -0
- package/internal/otel/tracer.ts +111 -0
- package/internal/reqfields.ts +423 -0
- package/internal/runtime/meter.ts +26 -0
- package/internal/runtime/mod.ts +81 -0
- package/internal/runtime/napi/napi.cjs +308 -0
- package/internal/runtime/napi/napi.d.cts +1249 -0
- package/internal/runtime/shutdown.test.ts +464 -0
- package/internal/runtime/shutdown.ts +350 -0
- package/internal/testing/carry.test.ts +242 -0
- package/internal/testing/carry.ts +101 -0
- package/internal/testing/runner.ts +10 -0
- package/internal/testing/scope.ts +384 -0
- package/internal/testing/steps.test.ts +152 -0
- package/internal/testing/steps.ts +342 -0
- package/internal/testing/telemetry.test.ts +210 -0
- package/internal/testing/telemetry.ts +466 -0
- package/internal/utils/constraints.ts +12 -0
- package/log/index.ts +107 -0
- package/log/logger.test.ts +194 -0
- package/log/logger.ts +308 -0
- package/log/runtime.test.ts +65 -0
- package/log/runtime.ts +40 -0
- package/log/stderr.test.ts +23 -0
- package/log/stderr.ts +24 -0
- package/metrics/export.test.ts +341 -0
- package/metrics/mod.test.ts +177 -0
- package/metrics/mod.ts +450 -0
- package/mod.ts +15 -0
- package/otel.test.ts +98 -0
- package/otel.ts +17 -0
- package/package.json +208 -5
- package/pubsub/encoding.ts +18 -0
- package/pubsub/mod.ts +26 -0
- package/pubsub/pubsub.test.ts +405 -0
- package/pubsub/refs.ts +38 -0
- package/pubsub/subscription.ts +359 -0
- package/pubsub/topic.test.ts +147 -0
- package/pubsub/topic.ts +431 -0
- package/reqctx/mod.ts +267 -0
- package/reqctx/reqctx.test.ts +216 -0
- package/scripts/postprocess-docs.test.ts +58 -0
- package/services/index.test.ts +393 -0
- package/services/index.ts +215 -0
- package/shutdown/mod.ts +78 -0
- package/storage/clickhouse/database.integration.test.ts +337 -0
- package/storage/clickhouse/database.test.ts +279 -0
- package/storage/clickhouse/database.ts +586 -0
- package/storage/clickhouse/errors.ts +130 -0
- package/storage/clickhouse/mod.ts +37 -0
- package/storage/objects/bucket.test.ts +573 -0
- package/storage/objects/bucket.ts +968 -0
- package/storage/objects/error.ts +121 -0
- package/storage/objects/mod.ts +50 -0
- package/storage/objects/refs.ts +117 -0
- package/storage/postgres/database.integration.test.ts +450 -0
- package/storage/postgres/database.test.ts +428 -0
- package/storage/postgres/database.ts +658 -0
- package/storage/postgres/errors.ts +186 -0
- package/storage/postgres/interval.test.ts +72 -0
- package/storage/postgres/interval.ts +170 -0
- package/storage/postgres/mod.ts +19 -0
- package/storage/redis/bitfield.ts +162 -0
- package/storage/redis/command.ts +84 -0
- package/storage/redis/commands.ts +1471 -0
- package/storage/redis/database.ts +520 -0
- package/storage/redis/mod.ts +171 -0
- package/storage/redis/native.ts +22 -0
- package/storage/redis/options.ts +119 -0
- package/storage/redis/pubsub.ts +92 -0
- package/storage/redis/redis.test.ts +866 -0
- package/storage/redis/reply.ts +780 -0
- package/storage/redis/runtime.test.ts +248 -0
- package/storage/redis/scan.ts +125 -0
- package/storage/redis/script.ts +162 -0
- package/storage/redis/target.ts +134 -0
- package/storage/redis/wire.ts +345 -0
- package/testing/bun.ts +13 -0
- package/testing/jest.ts +11 -0
- package/testing/mod.ts +393 -0
- package/testing/node.ts +12 -0
- package/testing/playwright.ts +247 -0
- package/testing/puppeteer.ts +101 -0
- package/testing/system.test.ts +108 -0
- package/testing/system.ts +373 -0
- package/testing/vitest.ts +13 -0
- package/tracing/http.ts +49 -0
- package/tracing/mod.ts +83 -0
- package/tracing/native.test.ts +276 -0
- package/tracing/node.ts +176 -0
- package/tracing/tracing.test.ts +953 -0
- package/types/mod.ts +92 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A system test's browser, driven with Puppeteer.
|
|
3
|
+
*
|
|
4
|
+
* {@link connect} connects Puppeteer to the browser Encore runs for the
|
|
5
|
+
* current test (see `system.browser` in `@encore.dev/sdk/testing`): a page
|
|
6
|
+
* reaches the app where `encore run` has it, in the test session; its
|
|
7
|
+
* requests are the test's; and what it shows is recorded.
|
|
8
|
+
*
|
|
9
|
+
* Each call the test makes on a page is reported as it is written, with
|
|
10
|
+
* where it is, so that the recording and the test's telemetry say which
|
|
11
|
+
* statement had the browser do what, and which requests came of it:
|
|
12
|
+
*
|
|
13
|
+
* page.locator("#pay").click() checkout.test.ts:14
|
|
14
|
+
* click button "Pay"
|
|
15
|
+
* POST http://localhost:4000/orders 500
|
|
16
|
+
* POST orders /orders 500
|
|
17
|
+
*
|
|
18
|
+
* Puppeteer is the test's own, passed in: `puppeteer` or `puppeteer-core`.
|
|
19
|
+
* Neither downloads a browser for this, as Encore runs its own.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* import puppeteer from "puppeteer-core";
|
|
23
|
+
* import {system} from "@encore.dev/sdk/testing";
|
|
24
|
+
* import {connect, url} from "@encore.dev/sdk/testing/puppeteer";
|
|
25
|
+
*
|
|
26
|
+
* test("pays from the browser", async () => {
|
|
27
|
+
* const browser = await connect(puppeteer);
|
|
28
|
+
* const page = await browser.newPage();
|
|
29
|
+
* await page.goto(await url("web"));
|
|
30
|
+
* await page.locator("button#pay").click();
|
|
31
|
+
* await page.waitForSelector("#thanks");
|
|
32
|
+
* await system.settled();
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* @module
|
|
36
|
+
*/
|
|
37
|
+
import {Steps, wrap} from '../internal/testing/steps';
|
|
38
|
+
import {browser as testBrowser, type BrowserOptions} from './system';
|
|
39
|
+
|
|
40
|
+
/** Puppeteer, as much of it as {@link connect} uses. */
|
|
41
|
+
export interface Puppeteer<B> {
|
|
42
|
+
connect(options: {
|
|
43
|
+
browserWSEndpoint: string;
|
|
44
|
+
defaultViewport?: {width: number; height: number} | null;
|
|
45
|
+
[option: string]: unknown;
|
|
46
|
+
}): Promise<B>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The options of {@link connect}. */
|
|
50
|
+
export interface ConnectOptions extends BrowserOptions {
|
|
51
|
+
/**
|
|
52
|
+
* More of Puppeteer's own options for `connect`, such as `slowMo` and
|
|
53
|
+
* `protocolTimeout`.
|
|
54
|
+
*/
|
|
55
|
+
connect?: Record<string, unknown>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** What {@link connect} uses of a Puppeteer browser. */
|
|
59
|
+
interface Connected {
|
|
60
|
+
target(): {
|
|
61
|
+
createCDPSession(): Promise<{
|
|
62
|
+
send(method: string, params?: Record<string, unknown>): Promise<unknown>;
|
|
63
|
+
}>;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Connects `puppeteer` to the current test's browser, starting it if the
|
|
69
|
+
* test has none yet, and returns Puppeteer's `Browser`. The browser ends
|
|
70
|
+
* with the test: there is nothing to close.
|
|
71
|
+
*
|
|
72
|
+
* Its pages' viewport is the browser's window (`options.window`), unless
|
|
73
|
+
* `options.connect.defaultViewport` says otherwise.
|
|
74
|
+
*/
|
|
75
|
+
export async function connect<B>(
|
|
76
|
+
puppeteer: Puppeteer<B>,
|
|
77
|
+
options?: ConnectOptions,
|
|
78
|
+
): Promise<B> {
|
|
79
|
+
const info = await testBrowser(options);
|
|
80
|
+
const browser = await puppeteer.connect({
|
|
81
|
+
defaultViewport: options?.window ?? {width: 1280, height: 800},
|
|
82
|
+
...options?.connect,
|
|
83
|
+
browserWSEndpoint: info.wsEndpoint,
|
|
84
|
+
});
|
|
85
|
+
// The commands that say which statement is running go over the
|
|
86
|
+
// connection Puppeteer's own do, so they arrive in order with them.
|
|
87
|
+
const session = await (browser as unknown as Connected)
|
|
88
|
+
.target()
|
|
89
|
+
.createCDPSession();
|
|
90
|
+
const steps = new Steps((method, params) => session.send(method, params));
|
|
91
|
+
return wrap(browser as object, 'browser', steps) as B;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The URL a page of the current test's browser reaches the gateway or
|
|
96
|
+
* frontend `name` at: the one `encore run` has it at, which the frontend is
|
|
97
|
+
* written against.
|
|
98
|
+
*/
|
|
99
|
+
export async function url(name: string): Promise<string> {
|
|
100
|
+
return (await testBrowser()).url(name);
|
|
101
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {describe, expect, test} from 'bun:test';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What the `system` helpers say in a process that is no system test's. The
|
|
5
|
+
* native runtime reads its config from the environment when it is first
|
|
6
|
+
* imported, so this runs in a child process, as `app_meta.test.ts` does: a
|
|
7
|
+
* service's, which runs no tests at all.
|
|
8
|
+
*/
|
|
9
|
+
const outcomes = (() => {
|
|
10
|
+
const probe = `
|
|
11
|
+
import { deliver, published, system } from ${JSON.stringify(`${import.meta.dir}/mod`)};
|
|
12
|
+
const said = (fn) => {
|
|
13
|
+
try {
|
|
14
|
+
return Promise.resolve(fn()).then(() => "returned", (e) => String(e.message ?? e));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
return String(e.message ?? e);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
console.log(JSON.stringify({
|
|
20
|
+
settled: await said(() => system.settled()),
|
|
21
|
+
url: await said(() => system.url("api")),
|
|
22
|
+
headers: await said(() => system.headers()),
|
|
23
|
+
telemetry: await said(() => system.telemetry({ settle: false })),
|
|
24
|
+
// Its other helpers are a service test's, as before.
|
|
25
|
+
published: await said(() => published({ name: "events" })),
|
|
26
|
+
deliver: await said(() => deliver({})),
|
|
27
|
+
}));
|
|
28
|
+
`;
|
|
29
|
+
const proc = Bun.spawnSync({
|
|
30
|
+
cmd: [process.execPath, '-e', probe],
|
|
31
|
+
cwd: import.meta.dir,
|
|
32
|
+
env: {...process.env, ENCORE_RUNTIME_CONFIG: runtimeConfig()},
|
|
33
|
+
});
|
|
34
|
+
const stdout = proc.stdout.toString();
|
|
35
|
+
if (proc.exitCode !== 0) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`system probe failed (exit ${proc.exitCode}):\n${stdout}\n${proc.stderr.toString()}`,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
// The core logs to stdout as it initializes; the probe's JSON is the last line.
|
|
41
|
+
const lines = stdout.trim().split('\n');
|
|
42
|
+
return JSON.parse(lines[lines.length - 1]!);
|
|
43
|
+
})();
|
|
44
|
+
|
|
45
|
+
describe('outside a system test', () => {
|
|
46
|
+
const NOT_A_SYSTEM_TEST =
|
|
47
|
+
'this is not a system test: only the tests of a system test suite, a directory ' +
|
|
48
|
+
'with an `encore.systest.json`, run against the app';
|
|
49
|
+
|
|
50
|
+
test('each helper says it is for a system test', () => {
|
|
51
|
+
expect(outcomes.settled).toBe(NOT_A_SYSTEM_TEST);
|
|
52
|
+
expect(outcomes.url).toBe(NOT_A_SYSTEM_TEST);
|
|
53
|
+
expect(outcomes.headers).toBe(NOT_A_SYSTEM_TEST);
|
|
54
|
+
expect(outcomes.telemetry).toBe(NOT_A_SYSTEM_TEST);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('published and deliver are a service test’s', () => {
|
|
58
|
+
expect(outcomes.published).toContain('not running as a test');
|
|
59
|
+
expect(outcomes.deliver).toContain('not running as a test');
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* A serialized `encore.runtime.v1.RuntimeConfig` of a process that hosts a
|
|
65
|
+
* service, base64-encoded as the runtime expects it. Hand-encoded, as in
|
|
66
|
+
* `app_meta.test.ts`.
|
|
67
|
+
*/
|
|
68
|
+
function runtimeConfig(): string {
|
|
69
|
+
const varint = (n: number): number[] => {
|
|
70
|
+
const out: number[] = [];
|
|
71
|
+
for (;;) {
|
|
72
|
+
const b = n & 0x7f;
|
|
73
|
+
n >>>= 7;
|
|
74
|
+
out.push(n ? b | 0x80 : b);
|
|
75
|
+
if (!n) return out;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const tag = (field: number, wire: number) => varint((field << 3) | wire);
|
|
79
|
+
const str = (field: number, value: string): number[] => {
|
|
80
|
+
const raw = [...new TextEncoder().encode(value)];
|
|
81
|
+
return [...tag(field, 2), ...varint(raw.length), ...raw];
|
|
82
|
+
};
|
|
83
|
+
const msg = (field: number, body: number[]): number[] => [
|
|
84
|
+
...tag(field, 2),
|
|
85
|
+
...varint(body.length),
|
|
86
|
+
...body,
|
|
87
|
+
];
|
|
88
|
+
const varintField = (field: number, value: number): number[] => [
|
|
89
|
+
...tag(field, 0),
|
|
90
|
+
...varint(value),
|
|
91
|
+
];
|
|
92
|
+
|
|
93
|
+
// Environment{app_id=1, app_slug=2, env_id=3, env_name=4, env_type=5, cloud=6}
|
|
94
|
+
const environment = [
|
|
95
|
+
...str(1, 'app-id'),
|
|
96
|
+
...str(2, 'my-app'),
|
|
97
|
+
...str(3, 'env-1'),
|
|
98
|
+
...str(4, 'local'),
|
|
99
|
+
...varintField(5, 1), // TYPE_DEVELOPMENT
|
|
100
|
+
...varintField(6, 1), // CLOUD_LOCAL
|
|
101
|
+
];
|
|
102
|
+
// Deployment{deploy_id=1, hosted_services=5}
|
|
103
|
+
const deployment = [...str(1, 'deploy-1'), ...msg(5, str(1, 'svc'))];
|
|
104
|
+
|
|
105
|
+
// RuntimeConfig{environment=1, deployment=3}
|
|
106
|
+
const cfg = [...msg(1, environment), ...msg(3, deployment)];
|
|
107
|
+
return Buffer.from(Uint8Array.from(cfg)).toString('base64');
|
|
108
|
+
}
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System tests: tests of the whole app, which run as no service.
|
|
3
|
+
*
|
|
4
|
+
* A test in a service runs as that service, alone: a call to another service
|
|
5
|
+
* is not answered, and what it publishes nothing handles. A test in a system
|
|
6
|
+
* test suite — a directory with an `encore.systest.json` — runs against the
|
|
7
|
+
* app instead, in its test session: each service starts when something first
|
|
8
|
+
* reaches it, as under `encore run`, with the secrets and configs configured
|
|
9
|
+
* for tests and data that is the session's own.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import {client} from "@encore.dev/sdk/services";
|
|
13
|
+
* import {Database} from "@encore.dev/sdk/storage/postgres";
|
|
14
|
+
* import {system} from "@encore.dev/sdk/testing";
|
|
15
|
+
*
|
|
16
|
+
* const orders = client("orders");
|
|
17
|
+
* const billing = Database.named("billing");
|
|
18
|
+
*
|
|
19
|
+
* test("placing an order charges the card", async () => {
|
|
20
|
+
* const res = await orders.fetch("/orders", {
|
|
21
|
+
* method: "POST",
|
|
22
|
+
* body: JSON.stringify({sku: "tee", qty: 2}),
|
|
23
|
+
* });
|
|
24
|
+
* const order = await res.json();
|
|
25
|
+
* // The order's event has been handled by billing's subscription.
|
|
26
|
+
* await system.settled();
|
|
27
|
+
*
|
|
28
|
+
* const row = await billing.queryRow`
|
|
29
|
+
* SELECT amount FROM charges WHERE order_id = ${order.id}`;
|
|
30
|
+
* expect(row?.amount).toBe(4000);
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* A system test may use any resource the app declares, bound with `named` or
|
|
35
|
+
* through a service's own declaration, and call any service.
|
|
36
|
+
*
|
|
37
|
+
* Each test has data of its own: an instance of every database, Redis
|
|
38
|
+
* database and bucket, which starts as a service's test's does, the
|
|
39
|
+
* databases migrated and the rest empty. What the services do for the test
|
|
40
|
+
* they do on that data, whichever of them it is, so a test reads what they
|
|
41
|
+
* wrote for it and nothing of another test's, and tests run side by side.
|
|
42
|
+
*
|
|
43
|
+
* A test can start from a `fixture` instead, as a service's test can. Its
|
|
44
|
+
* setup calls the app, and what the services made of that, in every
|
|
45
|
+
* database, bucket and Redis database, once what the setup set in motion
|
|
46
|
+
* has finished, is what each test that loads the fixture gets a copy of.
|
|
47
|
+
*
|
|
48
|
+
* What the app does for no request, as a Worker's loop or a job that finds
|
|
49
|
+
* its work in a table, is done on the data the services share, which a test
|
|
50
|
+
* does not see. A suite that tests such work says `"data": "shared"` in its
|
|
51
|
+
* `encore.systest.json`: its tests then share that data too, and each
|
|
52
|
+
* other's.
|
|
53
|
+
*
|
|
54
|
+
* What a test publishes is sent, and each subscription handles it in the
|
|
55
|
+
* service that declares it. {@link settled} waits for that: there is nothing
|
|
56
|
+
* to `deliver`.
|
|
57
|
+
*
|
|
58
|
+
* Each test has an id, which travels with every call and message it makes,
|
|
59
|
+
* and with what those cause in turn, so that what the app did for the test
|
|
60
|
+
* can be told from the rest. A test that fails prints what it caused in the
|
|
61
|
+
* app under its failure, where its runner says how it ended: under vitest
|
|
62
|
+
* and `node --test`, and in any runner for a test wrapped in `scoped`.
|
|
63
|
+
*
|
|
64
|
+
* The suite needs the runner adapter for its test runner, as a service's
|
|
65
|
+
* tests do (such as `@encore.dev/sdk/testing/vitest`). Run the tests with
|
|
66
|
+
* `encore test`, or with the runner itself in the suite's directory.
|
|
67
|
+
*
|
|
68
|
+
* @module
|
|
69
|
+
*/
|
|
70
|
+
import {requireScope, systemTest, type Scope} from '../internal/testing/scope';
|
|
71
|
+
import {caller, Steps} from '../internal/testing/steps';
|
|
72
|
+
import {Telemetry} from '../internal/testing/telemetry';
|
|
73
|
+
|
|
74
|
+
export {Telemetry} from '../internal/testing/telemetry';
|
|
75
|
+
export type {LostContext} from '../internal/testing/telemetry';
|
|
76
|
+
export type {
|
|
77
|
+
DeliveryWhat,
|
|
78
|
+
Filter,
|
|
79
|
+
HopWhat,
|
|
80
|
+
Log,
|
|
81
|
+
OtherWhat,
|
|
82
|
+
PublishWhat,
|
|
83
|
+
QueryWhat,
|
|
84
|
+
RequestWhat,
|
|
85
|
+
Span,
|
|
86
|
+
SpanEvent,
|
|
87
|
+
SpanKind,
|
|
88
|
+
SpanLink,
|
|
89
|
+
SpanStatus,
|
|
90
|
+
TestWhat,
|
|
91
|
+
What,
|
|
92
|
+
} from '../internal/testing/telemetry';
|
|
93
|
+
|
|
94
|
+
/** The test session the process's tests run against. */
|
|
95
|
+
function session(): NonNullable<typeof systemTest> {
|
|
96
|
+
if (systemTest === null) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
'this is not a system test: only the tests of a system test suite, a directory ' +
|
|
99
|
+
'with an `encore.systest.json`, run against the app',
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
return systemTest;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The current test, of a system test's process. */
|
|
106
|
+
function current(): Scope {
|
|
107
|
+
session();
|
|
108
|
+
return requireScope();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The options of {@link settled}. */
|
|
112
|
+
export interface SettledOptions {
|
|
113
|
+
/** How long to wait at most, in milliseconds: 30 seconds when not given. */
|
|
114
|
+
timeout?: number;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Waits until nothing the test set in motion is still running or queued: no
|
|
119
|
+
* request in flight to a service or through a gateway, and no message
|
|
120
|
+
* waiting, being handled or due a retry on a subscription. For at most 30
|
|
121
|
+
* seconds, or `options.timeout`: it rejects when the app has not settled by
|
|
122
|
+
* then, with an error saying what was still under way.
|
|
123
|
+
*
|
|
124
|
+
* It is the current test's work that is waited for, which is told by the
|
|
125
|
+
* test's id travelling with it, and nothing else: not what another test set
|
|
126
|
+
* in motion, so tests running side by side do not wait for each other, and
|
|
127
|
+
* not what the app does for no test. The work of a service that did not
|
|
128
|
+
* pass its request's context on has lost the test's id: it is not waited
|
|
129
|
+
* for, and is done on data the test does not see. The test's telemetry says
|
|
130
|
+
* which call lost it.
|
|
131
|
+
*
|
|
132
|
+
* In a suite whose tests share the session's data (`"data": "shared"`),
|
|
133
|
+
* everything the app has under way is waited for instead.
|
|
134
|
+
*
|
|
135
|
+
* What a service does that is neither — work that goes on after its request
|
|
136
|
+
* was answered — is not waited for.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* await orders.fetch("/orders", {method: "POST", body}); // publishes `order-placed`
|
|
140
|
+
* await system.settled(); // billing has handled it
|
|
141
|
+
*/
|
|
142
|
+
export async function settled(options?: SettledOptions): Promise<void> {
|
|
143
|
+
await current().native.settled(options?.timeout ?? null);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The URL of the gateway or frontend `name` in the test session, for a
|
|
148
|
+
* client of the test's own, such as a WebSocket client. A frontend starts
|
|
149
|
+
* when something first connects to it.
|
|
150
|
+
*
|
|
151
|
+
* A request made with the SDK's clients, or the suite's generated ones,
|
|
152
|
+
* carries the test already: a generated Gateway Client made with no options
|
|
153
|
+
* calls the gateway here, for the test making the request. One made with
|
|
154
|
+
* another client carries the test with {@link headers}.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* import {Client} from "./encore_gen/gateway/api";
|
|
158
|
+
* const api = new Client();
|
|
159
|
+
*/
|
|
160
|
+
export function url(name: string): string {
|
|
161
|
+
const system = session();
|
|
162
|
+
const found = system.url(name);
|
|
163
|
+
if (found === null) {
|
|
164
|
+
const known = system.gateways();
|
|
165
|
+
throw new Error(
|
|
166
|
+
`the app has no gateway or frontend ${JSON.stringify(name)} ` +
|
|
167
|
+
`(its gateways: ${known.length === 0 ? 'none' : known.join(', ')})`,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
return found;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The headers that make a request part of the current test, for a client of
|
|
175
|
+
* the test's own: the test's id, as the Request Context field Encore carries
|
|
176
|
+
* it in, and the test's span for the request to continue. By lowercase name.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* const res = await fetch(`${system.url("api")}/health`, {
|
|
180
|
+
* headers: system.headers(),
|
|
181
|
+
* });
|
|
182
|
+
*/
|
|
183
|
+
export function headers(): Record<string, string> {
|
|
184
|
+
return {...current().carried?.headers};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** The options of {@link telemetry}. */
|
|
188
|
+
export interface TelemetryOptions {
|
|
189
|
+
/**
|
|
190
|
+
* Whether to wait for the app to settle first, as {@link settled} does,
|
|
191
|
+
* which is when all of what the test caused is recorded. `false` reads
|
|
192
|
+
* what has been recorded by now. Defaults to `true`.
|
|
193
|
+
*/
|
|
194
|
+
settle?: boolean;
|
|
195
|
+
/** How long to wait for the app to settle at most, in milliseconds: 30
|
|
196
|
+
* seconds when not given. */
|
|
197
|
+
timeout?: number;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* What the app recorded for the current test, once it has {@link settled}:
|
|
202
|
+
* every span of what the test caused — in the services it reached, in the
|
|
203
|
+
* requests between them, in the deliveries of what was published for it —
|
|
204
|
+
* and the lines logged in them.
|
|
205
|
+
*
|
|
206
|
+
* Each span says what it is of ({@link Span.what}): a request a service was
|
|
207
|
+
* handed, a query, a message published or delivered, for a test to assert
|
|
208
|
+
* on. As a string it is the tree of it a failed test prints, and
|
|
209
|
+
* {@link Telemetry.shape} the same without what differs between runs, to
|
|
210
|
+
* keep as a snapshot of which services a flow touches.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* const recorded = await system.telemetry();
|
|
214
|
+
* expect(recorded.requests({service: "catalog"})).toHaveLength(1);
|
|
215
|
+
* expect(recorded.deliveries().every(d => d.what.handled)).toBe(true);
|
|
216
|
+
* expect(recorded.errors()).toEqual([]);
|
|
217
|
+
*/
|
|
218
|
+
export async function telemetry(
|
|
219
|
+
options?: TelemetryOptions,
|
|
220
|
+
): Promise<Telemetry> {
|
|
221
|
+
const json = await current().native.telemetry(
|
|
222
|
+
options?.settle ?? true,
|
|
223
|
+
options?.timeout ?? null,
|
|
224
|
+
);
|
|
225
|
+
return Telemetry.parse(json);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** The options of {@link browser}. */
|
|
229
|
+
export interface BrowserOptions {
|
|
230
|
+
/**
|
|
231
|
+
* When what the browser recorded is kept: for a test that `'failed'`, or
|
|
232
|
+
* whose runner does not say how it ended; for `'all'` tests; or `'off'`.
|
|
233
|
+
* Defaults to what `ENCORE_TEST_RECORD` says, else `'failed'`.
|
|
234
|
+
*/
|
|
235
|
+
record?: 'failed' | 'all' | 'off';
|
|
236
|
+
/** More command-line arguments for the browser. */
|
|
237
|
+
args?: string[];
|
|
238
|
+
/** The size of the browser's window, in CSS pixels: 1280×800 by default. */
|
|
239
|
+
window?: {width: number; height: number};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** The current test's browser: see {@link browser}. */
|
|
243
|
+
export interface Browser {
|
|
244
|
+
/**
|
|
245
|
+
* What a DevTools Protocol client connects to: the address of a WebSocket,
|
|
246
|
+
* as a browser gives for itself. Puppeteer's `connect`, Playwright's
|
|
247
|
+
* `connectOverCDP`.
|
|
248
|
+
*/
|
|
249
|
+
readonly wsEndpoint: string;
|
|
250
|
+
/**
|
|
251
|
+
* The file the recording is written to when the test ends, if it is kept:
|
|
252
|
+
* one HTML file that plays the pages back beside what the test and the app
|
|
253
|
+
* did. `null` when nothing is recorded.
|
|
254
|
+
*/
|
|
255
|
+
readonly recording: string | null;
|
|
256
|
+
/**
|
|
257
|
+
* The URL a page reaches the gateway or frontend `name` at: the one
|
|
258
|
+
* `encore run` has it at, which the frontend is written against. The
|
|
259
|
+
* browser's requests there go to the test session.
|
|
260
|
+
*/
|
|
261
|
+
url(name: string): string;
|
|
262
|
+
/**
|
|
263
|
+
* Runs `fn` as one statement of the test, called `name`: what `fn` has the
|
|
264
|
+
* browser do, and the requests that come of it, are recorded under it, in
|
|
265
|
+
* the test's telemetry and in its recording, with where `step` was called.
|
|
266
|
+
* It resolves to what `fn` returns, and a `fn` that throws fails the step.
|
|
267
|
+
*
|
|
268
|
+
* An adapter reports each call a test makes on its tool by itself: this is
|
|
269
|
+
* for a tool that has none, and for naming several calls as one.
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* await browser.step("pay with a saved card", async () => {
|
|
273
|
+
* await page.click("#saved-card");
|
|
274
|
+
* await page.click("#pay");
|
|
275
|
+
* });
|
|
276
|
+
*/
|
|
277
|
+
step<R>(name: string, fn: () => R | Promise<R>): Promise<R>;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* The current test's browser: a headless Chromium Encore runs for the test,
|
|
282
|
+
* for a tool of the test's own to drive. It is started the first time the
|
|
283
|
+
* test asks, and ends with the test.
|
|
284
|
+
*
|
|
285
|
+
* It is the test's in every way a call the test makes is:
|
|
286
|
+
*
|
|
287
|
+
* - It reaches the app where `encore run` has it. A frontend says itself
|
|
288
|
+
* where its API is, as `http://localhost:4000`: a page's requests there,
|
|
289
|
+
* and to the frontends' own addresses, go to the test session.
|
|
290
|
+
* - Each request a page makes to the app carries the test, so what the app
|
|
291
|
+
* does for a click is done on the test's data, and {@link settled} waits
|
|
292
|
+
* for it.
|
|
293
|
+
* - What the test has the browser do, and each request a page makes, is in
|
|
294
|
+
* the test's {@link telemetry}, with what the app did for a request
|
|
295
|
+
* under it. So is what a page says went wrong: an error on its console,
|
|
296
|
+
* an exception nothing caught, a request that failed.
|
|
297
|
+
* - Its pages are recorded. A test that fails is left a file that plays
|
|
298
|
+
* them back beside all of that ({@link Browser.recording}).
|
|
299
|
+
*
|
|
300
|
+
* The adapters connect a tool to it and say which statement of the test
|
|
301
|
+
* is running: `@encore.dev/sdk/testing/puppeteer`,
|
|
302
|
+
* `@encore.dev/sdk/testing/playwright`. This is for any other tool that
|
|
303
|
+
* speaks the DevTools Protocol.
|
|
304
|
+
*
|
|
305
|
+
* The browser is the `browser/chromium` component, which Encore downloads
|
|
306
|
+
* the first time a test asks for one.
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* const {wsEndpoint, url} = await system.browser();
|
|
310
|
+
* const browser = await puppeteer.connect({browserWSEndpoint: wsEndpoint});
|
|
311
|
+
* const page = await browser.newPage();
|
|
312
|
+
* await page.goto(url("web"));
|
|
313
|
+
*/
|
|
314
|
+
export async function browser(options?: BrowserOptions): Promise<Browser> {
|
|
315
|
+
const json = await current().native.browser(
|
|
316
|
+
options?.record ?? null,
|
|
317
|
+
options?.args ?? null,
|
|
318
|
+
options?.window?.width ?? null,
|
|
319
|
+
options?.window?.height ?? null,
|
|
320
|
+
);
|
|
321
|
+
const info = JSON.parse(json) as {
|
|
322
|
+
wsEndpoint: string;
|
|
323
|
+
urls: Record<string, string>;
|
|
324
|
+
recording: string;
|
|
325
|
+
stepsUrl: string;
|
|
326
|
+
};
|
|
327
|
+
// Said to the session over HTTP, on the listener the browser's DevTools
|
|
328
|
+
// endpoint is on: a test with a tool of its own has no hold on the tool's
|
|
329
|
+
// connection. Each word is answered before the next thing is done.
|
|
330
|
+
const steps = new Steps(async (method, params) => {
|
|
331
|
+
if (info.stepsUrl === '') throw new Error('the session takes no steps');
|
|
332
|
+
const response = await fetch(
|
|
333
|
+
`${info.stepsUrl}/${method.replace('Encore.', '')}`,
|
|
334
|
+
{
|
|
335
|
+
method: 'POST',
|
|
336
|
+
headers: {'content-type': 'application/json'},
|
|
337
|
+
body: JSON.stringify(params),
|
|
338
|
+
},
|
|
339
|
+
);
|
|
340
|
+
if (!response.ok)
|
|
341
|
+
throw new Error(`the session answered ${response.status}`);
|
|
342
|
+
return response.json();
|
|
343
|
+
});
|
|
344
|
+
return {
|
|
345
|
+
async step<R>(name: string, fn: () => R | Promise<R>): Promise<R> {
|
|
346
|
+
const at = caller();
|
|
347
|
+
const step = steps.begin(name, at);
|
|
348
|
+
// The session has heard the step began before `fn` does anything.
|
|
349
|
+
await step;
|
|
350
|
+
try {
|
|
351
|
+
const result = await fn();
|
|
352
|
+
await steps.end(step);
|
|
353
|
+
return result;
|
|
354
|
+
} catch (err) {
|
|
355
|
+
await steps.end(step, err instanceof Error ? err.message : String(err));
|
|
356
|
+
throw err;
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
wsEndpoint: info.wsEndpoint,
|
|
360
|
+
recording: info.recording === '' ? null : info.recording,
|
|
361
|
+
url(name: string): string {
|
|
362
|
+
const found = info.urls[name];
|
|
363
|
+
if (found === undefined) {
|
|
364
|
+
const known = Object.keys(info.urls).filter(n => n !== 'proxy');
|
|
365
|
+
throw new Error(
|
|
366
|
+
`the app has no gateway or frontend ${JSON.stringify(name)} ` +
|
|
367
|
+
`(it has: ${known.length === 0 ? 'none' : known.sort().join(', ')})`,
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
return found;
|
|
371
|
+
},
|
|
372
|
+
};
|
|
373
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-test infrastructure under vitest: `test.setupFiles:
|
|
3
|
+
* ["@encore.dev/sdk/testing/vitest"]` in the vitest config.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import '../internal/testing/runner';
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- an error in the build, which has no vitest
|
|
9
|
+
// @ts-ignore: vitest's own module, there when vitest runs this.
|
|
10
|
+
import {afterAll, afterEach, beforeEach} from 'vitest';
|
|
11
|
+
import {setup} from './mod';
|
|
12
|
+
|
|
13
|
+
setup({beforeEach, afterEach, afterAll});
|
package/tracing/http.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type {TextMapGetter} from '@opentelemetry/api';
|
|
2
|
+
import {withContext} from '../internal/otel/context';
|
|
3
|
+
import {
|
|
4
|
+
recordHTTPError,
|
|
5
|
+
recordHTTPStatus,
|
|
6
|
+
startHTTPSpan,
|
|
7
|
+
} from '../internal/otel/http';
|
|
8
|
+
|
|
9
|
+
const headersGetter: TextMapGetter<Headers> = {
|
|
10
|
+
keys: headers => Array.from(headers.keys()),
|
|
11
|
+
get: (headers, key) => headers.get(key) ?? undefined,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Wraps a Request handler with an active SERVER span and incoming trace and
|
|
16
|
+
* Request Context fields. Preserves the receiver, extra arguments and Response.
|
|
17
|
+
* No OpenTelemetry globals are registered.
|
|
18
|
+
*
|
|
19
|
+
* The span ends when the handler produces a Response, not when its streaming
|
|
20
|
+
* body completes. Framework-specific code can add route-based span naming.
|
|
21
|
+
*/
|
|
22
|
+
export function instrumentHTTP<This, Args extends unknown[]>(
|
|
23
|
+
handler: (
|
|
24
|
+
this: This,
|
|
25
|
+
request: Request,
|
|
26
|
+
...args: Args
|
|
27
|
+
) => Response | PromiseLike<Response>,
|
|
28
|
+
): (this: This, request: Request, ...args: Args) => Promise<Response> {
|
|
29
|
+
return async function (this: This, request: Request, ...args: Args) {
|
|
30
|
+
const {span, context} = startHTTPSpan(
|
|
31
|
+
request.headers,
|
|
32
|
+
headersGetter,
|
|
33
|
+
request.method,
|
|
34
|
+
new URL(request.url),
|
|
35
|
+
);
|
|
36
|
+
return withContext(context, async () => {
|
|
37
|
+
try {
|
|
38
|
+
const response = await handler.call(this, request, ...args);
|
|
39
|
+
recordHTTPStatus(span, response.status);
|
|
40
|
+
return response;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
recordHTTPError(span, error);
|
|
43
|
+
throw error;
|
|
44
|
+
} finally {
|
|
45
|
+
span.end();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
}
|