Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot destructure property 'HTTP2_HEADER_CONTENT_ENCODING' of 'http2.constants' as it is undefined. #109

Open
dsaintpierre opened this issue Nov 3, 2022 · 1 comment

Comments

@dsaintpierre
Copy link

dsaintpierre commented Nov 3, 2022

I see that this issue was filed before, but that was with a different implementation where they were able to circumvent the issue by commenting out the require line.

> Cannot destructure property 'HTTP2_HEADER_CONTENT_ENCODING' of 'http2.constants' as it is undefined.

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

Cypress could not associate this error to any specific test.

We dynamically generated a new test to display this failure.
at Object.eval ([webpack:///./node_modules/gmail-tester/node_modules/googleapis-common/build/src/http2.js:25:7](http://localhost:53696/__/#))
    at ./node_modules/gmail-tester/node_modules/googleapis-common/build/src/http2.js (http://localhost:53696/__cypress/tests?p=cypress/e2e/1-getting-started/login.cy.ts:60765:30)
    at __webpack_require__ ([webpack:///webpack/bootstrap:19](http://localhost:53696/__/#))
    at Object.eval ([webpack:///./node_modules/gmail-tester/node_modules/googleapis-common/build/src/apirequest.js:23:11](http://localhost:53696/__/#))
    at ./node_modules/gmail-tester/node_modules/googleapis-common/build/src/apirequest.js (http://localhost:53696/__cypress/tests?p=cypress/e2e/1-getting-started/login.cy.ts:60159:30)
    at __webpack_require__ ([webpack:///webpack/bootstrap:19](http://localhost:53696/__/#))
    at ./node_modules/gmail-tester/node_modules/googleapis-common/build/src/index.js ([webpack:///./node_modules/gmail-tester/node_modules/googleapis-common/build/src/index.js:31:19](http://localhost:53696/__/#))
    at __webpack_require__ ([webpack:///webpack/bootstrap:19](http://localhost:53696/__/#))
    at ./node_modules/gmail-tester/node_modules/googleapis/build/src/apis/abusiveexperiencereport/index.js ([webpack:///./node_modules/gmail-tester/node_modules/googleapis/build/src/apis/abusiveexperiencereport/index.js:17:28](http://localhost:53696/__/#))
    at __webpack_require__ ([webpack:///webpack/bootstrap:19](http://localhost:53696/__/#))
From previous event:
    at evalScripts (http://localhost:53696/__cypress/runner/cypress_runner.js:165456:58)
    at <unknown> (http://localhost:53696/__cypress/runner/cypress_runner.js:165468:152)
From previous event:
    at runScriptsFromUrls (http://localhost:53696/__cypress/runner/cypress_runner.js:165468:136)
    at Object.runScripts (http://localhost:53696/__cypress/runner/cypress_runner.js:165483:12)
    at $Cypress.onSpecWindow (http://localhost:53696/__cypress/runner/cypress_runner.js:153515:75)

My implementation is in a helper file:

const gmail = require("gmail-tester");

...

  const email = await gmail.check_inbox(
    path.resolve(__dirname, "credentials.json"),
    path.resolve(__dirname, "token.json"),
   ...
@johnmccollum
Copy link

johnmccollum commented Dec 15, 2022

I had this problem, and it was caused by not setting up the task properly - requiring "gmail-tester" in the wrong place will cause that issue.

You need to make sure that it runs as a cy.task, since this code should run on the Node side.

For my implementation (Cypress 11), I had to do the following in cypress.config.ts:

import { defineConfig } from 'cypress';
import * as path from 'path';
import * as gmail from 'gmail-tester';

export default defineConfig({
  e2e: {
    setupNodeEvents: (on) =>
      on('task', {
        'gmail:check': async (args) => {
          const { from, to, subject } = args;
          const email = await gmail.check_inbox(
            path.resolve(__dirname, './path/to/credentials.json'),
            path.resolve(__dirname, './path/to/token.json'),
            {
              subject: subject,
              from: from,
              to: to,
              include_body: true,
              wait_time_sec: 10,
              max_wait_time_sec: 30,
            }
          );
          return email;
        },
      }),
  },
});

You can then call the task in a test by doing:

cy.task('gmail:check', {
  from: '[email protected]',
  subject: 'Whatever',
}).then((email) => {
  assert.isNotNull(email, `Email was found`);
});

Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants