Repository: puppeteer/puppeteer
File: test/src/cookies.spec.ts (TypeScript)

Code before:
        value: 'GRID',
        path: '/grid.html',
      });
      await expectCookieEquals(await page.cookies(), [
        {
          name: 'gridcookie',
          value: 'GRID',
          domain: 'localhost',
          path: '/grid.html',
          sameParty: false,
          expires: -1,
          size: 14,
          httpOnly: false,
          secure: false,
          session: true,
          sourceScheme: 'NonSecure',
        },
      ]);
      expect(await page.evaluate('document.cookie')).toBe('gridcookie=GRID');
      await page.goto(server.EMPTY_PAGE);
      await expectCookieEquals(await page.cookies(), []);
      expect(await page.evaluate('document.cookie')).toBe('');
      await page.goto(server.PREFIX + '/grid.html');
      expect(await page.evaluate('document.cookie')).toBe('gridcookie=GRID');
    });
    it('should set a cookie with a partitionKey', async () => {
      const {page, server} = await getTestState();

      await page.goto(server.EMPTY_PAGE);
      const url = 'https://example.com';
      await page.setCookie({
        url,
        name: 'partitionCookie',
        value: 'partition',
        partitionKey: 'http://localhost',
      });
      await expectCookieEquals(await page.cookies(url), [
        {
          name: 'partitionCookie',
          value: 'partition',
          domain: 'example.com',
          path: '/',
          expires: -1,
          size: 24,
          httpOnly: false,
          secure: true,
          session: true,
          sameParty: false,
          sourceScheme: 'Secure',
          partitionKey: 'http://localhost',
        },

Review comment (suggestion):
so this test has to be something like this:

```
    it('should set a cookie with a partitionKey', async () => {
      const {page, server, isChrome} = await getTestState();

      await page.goto(server.EMPTY_PAGE);
      const url = new URL(page.url());
      await page.setCookie({
        url: url.toString(),
        name: 'partitionCookie',
        value: 'partition',
        secure: true,
        partitionKey: url.origin,
      });
      await expectCookieEquals(await page.cookies(), [
        {
          name: 'partitionCookie',
          value: 'partition',
          domain: url.hostname,
          path: '/',
          expires: -1,
          size: 24,
          httpOnly: false,
          secure: true,
          session: true,
          sameParty: false,
          sourceScheme: 'Secure',
          partitionKey: isChrome ? url.origin.replace(`:${url.port}`, '') : url.origin,
        },
      ]);
    });
```

unfortunately, there are some differences in partitioning across browsers.

Code after:
        value: 'GRID',
        path: '/grid.html',
      });
      await expectCookieEquals(await page.cookies(), [
        {
          name: 'gridcookie',
          value: 'GRID',
          domain: 'localhost',
          path: '/grid.html',
          sameParty: false,
          expires: -1,
          size: 14,
          httpOnly: false,
          secure: false,
          session: true,
          sourceScheme: 'NonSecure',
        },
      ]);
      expect(await page.evaluate('document.cookie')).toBe('gridcookie=GRID');
      await page.goto(server.EMPTY_PAGE);
      await expectCookieEquals(await page.cookies(), []);
      expect(await page.evaluate('document.cookie')).toBe('');
      await page.goto(server.PREFIX + '/grid.html');
      expect(await page.evaluate('document.cookie')).toBe('gridcookie=GRID');
    });
    it('should set a cookie with a partitionKey', async () => {
      const {page, server, isChrome} = await getTestState();

      await page.goto(server.EMPTY_PAGE);
      const url = new URL(page.url());
      await page.setCookie({
        url: url.toString(),
        name: 'partitionCookie',
        value: 'partition',
        secure: true,
        partitionKey: url.origin,
      });
      await expectCookieEquals(await page.cookies(), [
        {
          name: 'partitionCookie',
          value: 'partition',
          domain: url.hostname,
          path: '/',
          expires: -1,
          size: 24,
          httpOnly: false,
          secure: true,
          session: true,
          sameParty: false,
          sourceScheme: 'Secure',
          partitionKey: isChrome