tapjs icon indicating copy to clipboard operation
tapjs copied to clipboard

[BUG] Context is not propagated if set after async call

Open edsondewes opened this issue 2 years ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Have you read the CONTRIBUTING guide on posting bugs, and CODE_OF_CONDUCT?

  • [X] yes I read the things

This issue exists in the latest tap version

  • [X] I am using the latest tap

Description

Context propagation behavior changed after we updated the lib to v18.

We have the following scenario:

  • Start a database in "before" and set the connection address in the context
  • We use context data when running tests

We noticed that setting the context after initializing the database caused the field in the context to have the value "undefined" in the tests.

Another change compared to v16 is:

  • The "context" object has the value "undefined" if called in a "before" in the test root
  • The "context" object has the value "{}" if called in a "before" within a test

It would be nice if the context had the same behavior as in v16:

  • "context" object is initialized both in the "before" of the root and in the "before" within a test
  • Setting the context value after an async call will cause the value to be propagated to the tests

Reproduction

https://github.com/edsondewes/tap-context-propagation

Environment

which tap
tap not found

npm ls tap
[email protected] /Users/edson.dewes/tap-test
└── [email protected]

tap versions
tap: 18.6.1
"@tapjs/config": 2.4.14
"@tapjs/core": 1.4.6
"@tapjs/run": 1.4.16
"@tapjs/stack": 1.2.7
"@tapjs/test": 1.3.17
tap-parser: 15.3.1
tap-yaml: 2.2.1
tcompare: 6.4.5
plugins:
  "@tapjs/after": 1.1.17
  "@tapjs/after-each": 1.1.17
  "@tapjs/asserts": 1.1.17
  "@tapjs/before": 1.1.17
  "@tapjs/before-each": 1.1.17
  "@tapjs/filter": 1.2.17
  "@tapjs/fixture": 1.2.17
  "@tapjs/intercept": 1.2.17
  "@tapjs/mock": 1.2.15
  "@tapjs/node-serialize": 1.2.6
  "@tapjs/snapshot": 1.2.17
  "@tapjs/spawn": 1.1.17
  "@tapjs/stdin": 1.1.17
  "@tapjs/typescript": 1.3.6
  "@tapjs/worker": 1.1.17

tap config list
# vim: set filetype=yaml :
color: true
coverage-report:
  - text
exclude:
  - "**/@(fixture*(s)|dist)/**"
include:
  - "**/@(test?(s)|__test?(s)__)/**/*.@(js|cjs|mjs|tap|cts|jsx|mts|ts|tsx)"
  - "**/*.@(test?(s)|spec).@(js|cjs|mjs|tap|cts|jsx|mts|ts|tsx)"
  - "**/test?(s).@(js|cjs|mjs|tap|cts|jsx|mts|ts|tsx)"
jobs: 8
reporter: base
snapshot-clean-cwd: true
timeout: 30

tap plugin list
@tapjs/after
@tapjs/after-each
@tapjs/asserts
@tapjs/before
@tapjs/before-each
@tapjs/filter
@tapjs/fixture
@tapjs/intercept
@tapjs/mock
@tapjs/node-serialize
@tapjs/snapshot
@tapjs/spawn
@tapjs/stdin
@tapjs/typescript
@tapjs/worker

uname -a
Darwin N0145775.local 23.1.0 Darwin Kernel Version 23.1.0: Mon Oct  9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000 arm64

edsondewes avatar Dec 12 '23 15:12 edsondewes