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

Code before:
      });

      // Expect the cookie for the COOKIE_DESTINATION from URL_2 is deleted.
      expect(await page.cookies(COOKIE_DESTINATION_URL)).toHaveLength(0);

      // Navigate back to the URL_1.
      await page.goto(server.EMPTY_PAGE);
      // Expect the cookie for the COOKIE_DESTINATION from URL_1 is deleted.
      expect(await page.cookies(COOKIE_DESTINATION_URL)).toHaveLength(0);
    });
    it('should only delete cookie without partition key if partitionkey is not specified', async () => {
      const {page, server} = await getTestState();
      const url = 'https://example.com';

      await page.goto(server.EMPTY_PAGE);
      await page.setCookie({
        url,
        name: 'partitionCookie',
        value: 'partition',
        partitionKey: 'http://localhost',
      });

      await page.setCookie({
        url,
        name: 'partitionCookie',
        value: 'partition',
      });

      await page.deleteCookie({
        url,
        name: 'partitionCookie',
      });

      expect(await page.cookies(url)).toHaveLength(1);
      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):
this test would not work since by default the partition key from the page is computed in setCookie and deleteCookie and it's all the same http://localhost used in tests. I think we should try changing the parition key to something else in the first setCookie

Code after:
      await page.deleteCookie({
        name: COOKIE_NAME,
        url: COOKIE_DESTINATION_URL,
      });

      // Expect the cookie for the COOKIE_DESTINATION from URL_2 is deleted.
      expect(await page.cookies(COOKIE_DESTINATION_URL)).toHaveLength(0);

      // Navigate back to the URL_1.
      await page.goto(server.EMPTY_PAGE);
      // Expect the cookie for the COOKIE_DESTINATION from URL_1 is deleted.
      expect(await page.cookies(COOKIE_DESTINATION_URL)).toHaveLength(0);
    });
    it('should only delete cookie from the default partition if partitionkey is not specified', async () => {
      const {page, server} = await getTestState();
      const url = new URL(server.EMPTY_PAGE);
      await page.goto(url.toString());
      await page.setCookie({
        url: url.toString(),
        name: 'partitionCookie',
        value: 'partition',
        secure: true,
        partitionKey: url.origin,
      });
      expect(await page.cookies()).toHaveLength(1);
      await page.deleteCookie({
        url: url.toString(),
        name: 'partitionCookie',
      });
      expect(await page.cookies()).toHaveLength(0);
    });
    it('should delete cookie with partition key if partition key is specified', async () => {
      const {page, server, isChrome} = await getTestState();
      const url = new URL(server.EMPTY_PAGE);
      await page.goto(url.toString());
      const origin = isChrome
        ? url.origin.replace(`:${url.port}`, '')
        : url.origin;
      await page.setCookie({
        url: url.toString(),
        name: 'partitionCookie',
        value: 'partition',
        secure: true,
        partitionKey: origin,
      });
      expect(await page.cookies()).toHaveLength(1);
      await page.deleteCookie({
        url: url.toString(),
        name: 'partitionCookie',
        partitionKey: origin,
      });