ampproject / ampproject/amphtml

unit tests in separate `describes.realWin()` blocks share cookies

Open
#36,242 3 comments 0 reactions 0 assignees View on GitHub
Stale Type: Bug
Dominant language
JavaScript
Stars
14.9k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

### Description

There seems to be shared cookies between the following tests:
* `should resolve element dependent vars and macros` test in `test-linker-manager.js`
* `should expand globally allowed macros` test in `test-real-time-config.js`

Both tests use cookies (the latter directly; the former through use of the`UrlReplacement` service's CLIENT_ID macro). Previously, both used a cookie with the name `foo` and running the tests in the order listed above caused the latter to fail consistently because they would access the same actual cookie even though they should be getting different window objects. Currently, these tests pass because I changed the latter test to use a cookie called `bar` instead of `foo` (see comment [here](https://github.com/ampproject/amphtml/blob/main/test/unit/test-real-time-config.js#L793)).

(This issue has been revealed by parallelization efforts because tests are sharded differently and potentially run in new orders when files are added/removed)

### Reproduction Steps

```sh
npx amp unit --headless --files=extensions/amp-analytics/0.1/test/test-linker-manager.js,test/unit/test-real-time-config.js
```
Note:

* Must run below 2 tests only, using `it.only(` in both tests, to properly replicate
* `should resolve element dependent vars and macros` test in `test-linker-manager.js`
* `should expand globally allowed macros` test in `test-real-time-config.js`
* Must change `foo` to `bar` in the latter test to cause it to fail

### Relevant Logs

_No response_

### Browser(s) Affected

_No response_

### OS(s) Affected

_No response_

### Device(s) Affected

_No response_

### AMP Version Affected

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the two named tests in extensions/amp-analytics/0.1/test/test-linker-manager.js and test/unit/test-real-time-config.js, then run the provided npx amp unit command with only those tests enabled. Investigate why separate describes.realWin() blocks can access the same cookie, using the foo/bar reproduction. Done means the tests remain isolated and pass without relying on different cookie names or test order.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.