60

I am new to vue and jest testing, and I keep getting this error when running a specific test. I understand this is a general error, but I am unsure how to drill down and figure out what is wrong.

Here is the error:

 Test suite failed to run

    Jest worker encountered 4 child process exceptions, exceeding retry limit

      at ChildProcessWorker.initialize (node_modules/jest-worker/build/workers/ChildProcessWorker.js:185:21)

Here is the failing test:

test("signupAsUser logs results if email is provided", async () => {
  const consoleSpy = jest.spyOn(console, "log");
  const email = ref("[email protected]");
  const { signupAsUser } = useSignup(email);

  await signupAsUser();

  expect(consoleSpy).toHaveBeenCalledWith("USER:", mockSignup);
});

And here are the files that are being tested. The vue file:

<!--
  View for user signup operations.
-->
<template lang="pug">
.Signup
    .Signup__focus
        .Signup__title Sign Up
            .Signup__form
                .Signup__field
                    va-input.Signup__emailInput(
                       type="email",
                      name="email",
                      placeholder="Email",
                      v-model="email",
                      @keyup.enter="signupAsUser()"
                    )
                        template(v-slot:prependInner="")
                            va-icon(name="email")
                    .Login__buttonRow
                        va-button.Login__submitButton(@click="signupAsUser") Sign Up
</template>

<script lang="ts">
import { ref, defineComponent } from "vue";
import useSignup from "@/views/Signup/useSignup";

/**
 * Assemble the Signup component
 *
 *  @returns Data for the component to use.
 * - email: of the user to sign up with
 * - signupAsUser: function to call to carry out the login operation.
 */
function setup() {
  const email = ref("");
  const { signupAsUser } = useSignup(email);

  return {
    email,
    signupAsUser,
  };
}

export default defineComponent({
  name: "Signup",
  setup,
});
</script>

<style lang="scss">
//basic scss style taken from Login.vue until button and verification code is added
.Signup {
  position: fixed;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;

  &__focus {
    width: 360px;
    max-width: 95vw;
  }

  &__field {
    padding-bottom: 0.5em;
  }

  &__title {
    font-size: 1.2em;
    padding-bottom: 0.5em;
    text-align: center;
  }
}
</style>

and the typescript file:

import { Ref } from "vue";
import { useApolloClient } from "@vue/apollo-composable";
import { ValidatedUser } from "@/models";
import { gql } from "graphql-tag";
import router from "@/router";

const query = gql`
  query Signup($input: Signup) {
    signup(input: $input) {
      __typename
      token
      user {
        emailAddress
        id
      }
    }
  }
`;

/**
 * Retrive apollo client and provide useSignup
 * function to validate input and execute Signup process.
 *
 * @param emailAddress - reactively wrapped emailAddress address of the user signing up.
 * @returns useSignup composition functionality.
 */
export default function useSignup(emailAddress: Ref<string>): {
  signupAsUser: () => Promise<void>;
} {
  const { resolveClient } = useApolloClient();
  /**
   * Execute the Signup process for the specified user values.
   */
  /**
   *
   */
  async function signupAsUser(): Promise<void> {
    console.log("emailAddress " + emailAddress.value);
    if (emailAddress.value.length < 5) {
      console.log("here");
      return;
    } else {
      const client = resolveClient();

      const variables = {
        input: { username: emailAddress.value },
      };
      // const response = await client.query({query, variables});
      console.log("here");
      // const validatedUser: ValidatedUser = response.data.signup;
      // console.log("USER:", validatedUser);
      console.log("emailAddress: ", variables);
    }
    router.push({ path: "/signup/verify" });
  }

  return { signupAsUser };
}

Can I get a pointer in the right direction on where I am timing out? Or where the error might be coming from?

1
  • As discussed below, this usually masks a different error. In my case, I hadn't excluded my "dist" folder from Jest, so it was running tests twice. Also, when I fixed my tests, they would still fail because I hadn't recompiled my source. Exclude to fix :) Commented Jul 26, 2023 at 9:24

10 Answers 10

35

This error hides the real problem in your test or code. You can run the test serially to reveal the actual error in your test jest --runInBand

1
  • 1
    Hey Do you by any chance know why I still see "Jest worker encountered 4 child process exceptions, exceeding retry limit" even though I add --runInBand command?
    – Sean Liu
    Commented Jan 8 at 7:30
31

I had experienced this as well, and this issue thread led me in the right direction. Two things to try:

  1. You could try adding the --maxWorkers 2 to your jest test command.

  2. This error seems to be a mix of a few problems, but uncaught promise rejections are a player. You could also try using waitFor and see if this helps.

    import { waitFor } from 'test/test-utils'
    
    test("signupAsUser logs results if email is provided", async() => {
      const consoleSpy = jest.spyOn(console, "log");
      const email = ref("[email protected]");
      const {
        signupAsUser
      } = useSignup(email);
    
      await waitFor(() => signupAsUser());
    
      expect(consoleSpy).toHaveBeenCalledWith("USER:", mockSignup);
    });
    
  3. This answer shed more light.

    Digging deeper, this is because findBy tests return a promise so the await is needed. https://testing-library.com/docs/guide-disappearance/#1-using-findby-queries It would have been nice for the library to throw a better error however.

19

Test suite failed to run. Jest worker encountered 4 child process exceptions, exceeding retry limit

I had exact same error message on CI tests. It affected all my test cases. This message hides real problem. You have to change maxWorkers to 1 to see what is the problem on single thread. Then you will see cause of error which helps you to resolve issue.

1
  • 3
    after setting maxWorkers to 1 i was able to see the actual error message which helped me fix the failing test. it was just a missing import in the end
    – Fiehra
    Commented Sep 29, 2022 at 19:42
2

For me, the issue was not adding an await to the code under test.

// caused the error to be thrown after the test finished
const data = getData()

// the fix was to ensure we wait for the promise to resolve
const data = await getData()

Hopefully this helps someone else who finds this question.

0

In my case the index file was importing the service from the wrong path. That caused this error when collect coverage ran.

0

You can try to move your test into a try catch block to see the real error. Then, you can proceed to run your tests again and do your fixes. The try catch block can be deleted after all tests pass.

Here is an example of what I did with Typescript:

describe('my-test', () => {
  it('my test description', async () => {
    try {
      // --> your test code goes here <--
    } catch (e: any) {
      console.log('EXCEPTION', e.message);
    }
  });
});

To see the complete error log you can just output e like this instead:

console.log('EXCEPTION', e);
0

I had the same issue. In my case I was passing an async cb to jest's act.

Removing the async from the cb and using waitFor instead of act resolved the issue for me.

Updated code:

 waitFor(() => {
     
    expect(result.current.tutorials[0].completed).toEqual(false);
           
    result.current.setTutorialCompleted(result.current.tutorials[0], true);
    expect(result.current.tutorials[0].completed).toEqual(true);
});
0

In my case it was caused by a couple of units test where I forgot to "return" the promise. Once I added the return keyword then it showed me the real error, which is specific to my code.

0

I solved it by changing NEXT_PUBLIC_REST_API_ENDPOINT=http://localhost:8000/ to NEXT_PUBLIC_REST_API_ENDPOINT=http://127.0.0.1:8000/

0

I face the same issue with my application in ReactJs with vite bundling and Jest test framework. The following solution worked for me.

I updated my jest.config.cjs/js file with following

 modulePathIgnorePatterns: [
    '/secapi/', // Excludes all modules in a specific directory
  ],

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.