testcafe

Tests failing with "Tests took too long to compile"


Periodically our team tests fail to run on CI/CD (GitLab) and one of the hints given is excessive imports. Is there a recommendation on how to possibly cut down on imports to avoid this issue or any other recommendations to stop this from happening intermittently?

Also, why would possibly excessive importing affect browser connectivity?

Here is the error:

ERROR Cannot establish one or more browser connections.
8 of 8 browser connections have not been established:
 - chrome:headless --no-sandbox --disable-dev-shm-usage
 - chrome:headless --no-sandbox --disable-dev-shm-usage
 - chrome:headless --no-sandbox --disable-dev-shm-usage
 - chrome:headless --no-sandbox --disable-dev-shm-usage
 - chrome:headless --no-sandbox --disable-dev-shm-usage
 - chrome:headless --no-sandbox --disable-dev-shm-usage
 - chrome:headless --no-sandbox --disable-dev-shm-usage
 - chrome:headless --no-sandbox --disable-dev-shm-usage
Hints:
 - Tests took too long to compile (2.03 min). Ensure the test code has no excessive imports.
 - The host machine may not be powerful enough to handle the specified concurrency factor (8). Decrease the concurrency factor or allocate more computing resources to the host machine.
 - Increase the Browser Initialization Timeout if its value is too low (currently: 2 minutes for local browsers and 6 minutes for remote browsers). The timeout determines how long TestCafe waits for browsers to be ready.
 - The error can also be caused by network issues or remote device failure. Make sure that your network connection is stable and you can reach the remote device.

Here are the imports in the test file:

import {
  ANSWER_OBFUSCATION_TEST_ID,
  SOQnaTestIdsAnswerPreview,
} from 'chegg-web-app/libs/qna-so/constants/soqnaTestIds';
import {
  questionBody,
  selectByClassName,
  selectById,
  selectByTestId,
  thumbsUp,
} from '../helpers/locators';
import {
  answerTitleToolTip,
  bestAnswer,
  breadcrumbParentSubjectLink,
  breadcrumbQuestionLink,
  breadcrumbSubjectLink,
  breadcrumbSubjectQnALink,
  closeResubscribeModal,
  ctaBody,
  ctaButton,
  ctaHeader,
  ctaModal,
  expertAnswer,
  nextLink,
  nextLinkText,
  positiveRatingText,
  postAQuestionCard,
  previousLink,
  previousLinkText,
  soCtaButton,
  structuredAnswer,
  structuredAnswerPreview,
  transcribedImageText,
  transcriptionSkipLink,
  uaeAnswerPreviewHeader,
  uaeCloseCheckout,
  uaeFinalAnswerHeader,
} from '../helpers/locators/soqnaLocators';
import { AuthPage } from '../helpers/pages';
import soqna, { SOQNAPage } from '../helpers/pages/soqna';
import {
  LanguageRequestHook,
  a11y,
  getPagePath,
  getPageUrl,
  goBack,
  reloadPage,
  rioLogger,
  setStyleAttribute,
  userLogInWithCredentials,
  verifyRioEventv2,
} from '../helpers/shared';
import {
  accessSearchReturnedResult,
  answeredBy,
  expertVerified,
  getTheSolutionLink,
  getTotalCountSearchResults,
  greatMatchQuestionRenderer,
  navigateToSOQna,
  nonSubsAutomatedCTA,
  nonSubsCTA,
  verifyQuestionPreviewSERP,
} from '../helpers/soqnaHelpers';

const sharedHelpers = require('../helpers/shared');

import config from '../config';
import {
  askExpertClickEvent,
  bestAnswerTooltipEvent,
  mathSolverEvent,
  nextQuestionEvent,
  previousQuestionEvent,
  questionNavbarEvent,
  questionStatusEvent,
  questionViewEvent,
  seeAnswerClickEvent,
  showTranscribedClickEvent,
  sqnaStepsViewEvent,
  viewFullAnswerClickEvent,
  viewFullSolutionViewEvent,
} from '../helpers/soqnaRioEvents';

const { userVariables, ClientFunction } = require('testcafe');

import { CountryCode } from '@chegg/testcafe-for-chegg-com/helper/graphql/cartService/types';
import { SubscriptionType } from '@chegg/testcafe-for-chegg-com/helper/graphql/cdpService/types';
import {
  NonSubScriptionType,
  SubscriptionChange,
} from '@chegg/testcafe-for-chegg-com/helper/identity/types';
import { createUser } from '@chegg/testcafe-for-chegg-com/helper/identity/user';
import { createUserForCheckout2 } from '../helpers/commerce';
import {
  enterTextAndSubmit,
  enterTextAndSubmitFromChat,
} from '../helpers/qaauidEditorHelpers';

Thanks in advance for any advice.


Solution

  • That error is pointing to both the Browser Initialization timeout (2 minutes) and the concurrency factor (8 browsers at once). Try increasing the timeout and decreasing the concurrency factor until it succeeds regularly. If it fails differently look through other common issues from the official docs for other things you can try to optimize along with hints on how to do so.

    Imports require time to load and parse, JavaScript also needs to be JIT (just in time, "right before running the file") compiled. Bad code may need to be recompiled multiple times because it wants to "try again" to optimize it. There are too many potential issues from endless loops to a high-latency external API that could then occur when running code to initialize the imports or when running them. Best bet is to use debugging to attempt to find the bottlenecks.