我是vue和jest测试的新手,在运行特定测试时不断得到这个错误。我知道这是一个一般错误,但我不确定如何深入研究并找出错误所在。
错误如下:
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)
下面是失败的测试:
test("signupAsUser logs results if email is provided", async () => {
const consoleSpy = jest.spyOn(console, "log");
const email = ref("testuser@scoutapm.com");
const { signupAsUser } = useSignup(email);
await signupAsUser();
expect(consoleSpy).toHaveBeenCalledWith("USER:", mockSignup);
});
下面是正在测试的文件。vue文件:
<!--
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>
和类型脚本文件:
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 };
}
我可以得到一个指针,指向正确的方向,指示我在哪里超时?或者错误可能来自哪里?
3条答案
按热度按时间5sxhfpxr1#
我也有过这样的经历,这个问题的线索把我引向了正确的方向。有两件事可以尝试:
1.您可以尝试将
--maxWorkers 2
添加到jest测试命令中。1.这个错误似乎是一些问题的混合,但是未捕获的承诺拒绝是一个玩家。你也可以尝试使用
waitFor
,看看这是否有帮助。深入研究一下,这是因为findBy测试返回一个承诺,所以需要等待。https://testing-library.com/docs/guide-disappearance/#1-using-findby-queries然而,如果库抛出一个更好的错误,那就太好了。
exdqitrt2#
测试套件未能运行。Jest工作线程遇到4个子进程异常,超出了重试限制
我在CI测试中收到了完全相同的错误消息。它影响了我所有的测试用例。此消息隐藏了真实的的问题。您必须将maxWorkers更改为1,以查看单线程上的问题。然后您将看到错误原因,这有助于您解决问题。
ryevplcw3#
此错误隐藏了测试或代码中的真实的问题。您可以串行运行测试以显示测试
jest --runInBand
中的实际错误