typeerror(屈服* ...是不可能的)
我一直在尝试在 React-Node/Express 项目中实现 Pact。在提供程序测试中,我遇到了一个奇怪的错误,我无法在网上找到解释。我的提供者交互全部通过,但在输出结束时我收到以下错误,这使得测试套件以失败结束,尽管所有测试都通过了
TypeError: yield* (intermediate value)(intermediate value)(intermediate value)(intermediate value) is not iterable
at loadOneConfig (node_modules/@babel/core/lib/config/files/configuration.js:146:37)
at loadOneConfig.next (<anonymous>)
at buildRootChain (node_modules/@babel/core/lib/config/config-chain.js:82:51)
at buildRootChain.next (<anonymous>)
at loadPrivatePartialConfig (node_modules/@babel/core/lib/config/partial.js:103:62)
at loadPrivatePartialConfig.next (<anonymous>)
at loadFullConfig (node_modules/@babel/core/lib/config/full.js:57:46)
at loadFullConfig.next (<anonymous>)
at Function.<anonymous> (node_modules/@babel/core/lib/config/index.js:35:43)
at evaluateSync (node_modules/gensync/index.js:251:28)
at Function.sync (node_modules/gensync/index.js:89:14)
at node_modules/@babel/core/lib/config/index.js:47:61
at OptionManager.init (node_modules/@babel/core/lib/index.js:257:36)
at Object.<anonymous>.exports.transformSync (node_modules/@babel/register/lib/worker/transform.js:80:44)
at Function.handleMessage (node_modules/@babel/register/lib/worker/handle-message.js:23:16)
at LocalClient.<anonymous> (node_modules/@babel/register/lib/worker-client.js:134:86)
at LocalClient.transform (node_modules/@babel/register/lib/worker-client.js:64:47)
at compile (node_modules/@babel/register/lib/hook.js:58:25)
at compileBabel7 (node_modules/@babel/register/lib/hook.js:49:14)
at Module._compile (node_modules/pirates/lib/index.js:130:29)
这是提供者测试文件,我在 Docker 中运行,以便我可以针对 Postgres 测试数据库运行测试
import app from "../../server/server";
import { Verifier } from "@pact-foundation/pact";
import path from "path";
import { cleanupDatabase } from "../../server/testHelpers/requestTestHelpers";
import models from "../../server/policeDataManager/models";
import Case from "../../sharedTestHelpers/case";
import Officer from "../../sharedTestHelpers/officer";
import CaseOfficer from "../../sharedTestHelpers/caseOfficer";
import { CASE_STATUS, COMPLAINANT } from "../../sharedUtilities/constants";
import IntakeSource from "../../server/testHelpers/intakeSource";
import ReferralLetter from "../../server/testHelpers/ReferralLetter";
import { updateCaseStatus } from "../../server/handlers/data/queries/queryHelperFunctions";
import { random } from "lodash";
jest.mock(
"../../server/handlers/cases/referralLetters/sharedLetterUtilities/uploadLetterToS3",
() => jest.fn()
);
const setupCase = async () => {
try {
models.cases.destroy({ where: {}, truncate: true, auditUser: "user" });
const intakeSource = await models.intake_source.create(
new IntakeSource.Builder().defaultIntakeSource().withId(random(5, 99999)),
{ auditUser: "user" }
);
const c = await models.cases.create(
new Case.Builder()
.defaultCase()
.withId(1)
.withComplaintType("Civilian Within NOPD Initiated")
.withIntakeSourceId(intakeSource.id),
{
auditUser: "user"
}
);
const officer = await models.officer.create(
new Officer.Builder().defaultOfficer(),
{ auditUser: "user" }
);
const case_officer = await models.case_officer.create(
new CaseOfficer.Builder()
.defaultCaseOfficer()
.withOfficerId(officer.id)
.withCaseId(c.id)
.withRoleOnCase(COMPLAINANT),
{ auditUser: "user" }
);
return c;
} catch (e) {
console.log(e);
}
};
const setupLetter = async letterCase => {
try {
await updateCaseStatus(letterCase, CASE_STATUS.READY_FOR_REVIEW);
const letter = await models.referral_letter.create(
new ReferralLetter.Builder()
.defaultReferralLetter()
.withCaseId(letterCase.id)
.withRecipient("King of all police")
.withRecipientAddress("100 Main Street, North Pole")
.withSender("The aggrieved party"),
{ auditUser: "user" }
);
} catch (e) {
console.log(e);
}
};
describe("Pact Verification", () => {
let server;
beforeAll(() => {
server = app.listen(8989);
});
afterAll(async () => {
await cleanupDatabase();
await models.sequelize.close();
await server.close();
});
test("validates the expectations of get case details", async () => {
const opts = {
logLevel: "INFO",
providerBaseUrl: "http://localhost:8989",
provider: "police-data-manager.server",
providerVersion: "1.0.0",
pactUrls: [
path.resolve(
__dirname,
"../../../pact/pacts/police-data-manager.client-police-data-manager.server.json"
)
],
stateHandlers: {
"Case exists": async () => {
await cleanupDatabase();
await setupCase();
},
"letter is ready for review": async () => {
await cleanupDatabase();
const letterCase = await setupCase();
await setupLetter(letterCase);
},
"edit letter": async () => {
const letterCase = await setupCase();
await setupLetter(letterCase);
}
}
};
const output = await new Verifier(opts).verifyProvider();
console.log(output);
});
});
我尝试将代码的各个部分包装在 try/catch 块中以定位问题,但没有成功。我还调整了我的node_modules中的代码,以便更好地查看
@babel/core/lib/config/files/configuration.js中的loadOneConfig
function* loadOneConfig(names, dirname, envName, caller, previousConfig = null) {
const configs = yield* _gensync().all(names.map(filename => readConfig(_path().join(dirname, filename), envName, caller)));
const config = configs.reduce((previousConfig, config) => {
if (config && previousConfig) {
throw new Error(`Multiple configuration files found. Please remove one:\n` + ` - ${_path().basename(previousConfig.filepath)}\n` + ` - ${config.filepath}\n` + `from ${dirname}`);
}
return config || previousConfig;
}, previousConfig);
if (config) {
debug("Found configuration %o from %o.", config.filepath, dirname);
}
return config;
}
问题当我将代码移动到console.log时,我收到了新的错误_gensync().all
不是一个函数,并且 console.logging _gensync()
返回一个空对象。
我尝试将我的babel升级到最新版本,但似乎没有任何效果。
I've been trying to implement Pact in a React-Node/Express project. In the provider tests, I'm running into a strange error that I couldn't find explained online. My provider interactions are all passing, but at the end of the output I get the below error, which makes the test suite end with a failure despite all the tests passing
TypeError: yield* (intermediate value)(intermediate value)(intermediate value)(intermediate value) is not iterable
at loadOneConfig (node_modules/@babel/core/lib/config/files/configuration.js:146:37)
at loadOneConfig.next (<anonymous>)
at buildRootChain (node_modules/@babel/core/lib/config/config-chain.js:82:51)
at buildRootChain.next (<anonymous>)
at loadPrivatePartialConfig (node_modules/@babel/core/lib/config/partial.js:103:62)
at loadPrivatePartialConfig.next (<anonymous>)
at loadFullConfig (node_modules/@babel/core/lib/config/full.js:57:46)
at loadFullConfig.next (<anonymous>)
at Function.<anonymous> (node_modules/@babel/core/lib/config/index.js:35:43)
at evaluateSync (node_modules/gensync/index.js:251:28)
at Function.sync (node_modules/gensync/index.js:89:14)
at node_modules/@babel/core/lib/config/index.js:47:61
at OptionManager.init (node_modules/@babel/core/lib/index.js:257:36)
at Object.<anonymous>.exports.transformSync (node_modules/@babel/register/lib/worker/transform.js:80:44)
at Function.handleMessage (node_modules/@babel/register/lib/worker/handle-message.js:23:16)
at LocalClient.<anonymous> (node_modules/@babel/register/lib/worker-client.js:134:86)
at LocalClient.transform (node_modules/@babel/register/lib/worker-client.js:64:47)
at compile (node_modules/@babel/register/lib/hook.js:58:25)
at compileBabel7 (node_modules/@babel/register/lib/hook.js:49:14)
at Module._compile (node_modules/pirates/lib/index.js:130:29)
Here's the provider test file, which I'm running in Docker so that I can run the tests against a Postgres test database
import app from "../../server/server";
import { Verifier } from "@pact-foundation/pact";
import path from "path";
import { cleanupDatabase } from "../../server/testHelpers/requestTestHelpers";
import models from "../../server/policeDataManager/models";
import Case from "../../sharedTestHelpers/case";
import Officer from "../../sharedTestHelpers/officer";
import CaseOfficer from "../../sharedTestHelpers/caseOfficer";
import { CASE_STATUS, COMPLAINANT } from "../../sharedUtilities/constants";
import IntakeSource from "../../server/testHelpers/intakeSource";
import ReferralLetter from "../../server/testHelpers/ReferralLetter";
import { updateCaseStatus } from "../../server/handlers/data/queries/queryHelperFunctions";
import { random } from "lodash";
jest.mock(
"../../server/handlers/cases/referralLetters/sharedLetterUtilities/uploadLetterToS3",
() => jest.fn()
);
const setupCase = async () => {
try {
models.cases.destroy({ where: {}, truncate: true, auditUser: "user" });
const intakeSource = await models.intake_source.create(
new IntakeSource.Builder().defaultIntakeSource().withId(random(5, 99999)),
{ auditUser: "user" }
);
const c = await models.cases.create(
new Case.Builder()
.defaultCase()
.withId(1)
.withComplaintType("Civilian Within NOPD Initiated")
.withIntakeSourceId(intakeSource.id),
{
auditUser: "user"
}
);
const officer = await models.officer.create(
new Officer.Builder().defaultOfficer(),
{ auditUser: "user" }
);
const case_officer = await models.case_officer.create(
new CaseOfficer.Builder()
.defaultCaseOfficer()
.withOfficerId(officer.id)
.withCaseId(c.id)
.withRoleOnCase(COMPLAINANT),
{ auditUser: "user" }
);
return c;
} catch (e) {
console.log(e);
}
};
const setupLetter = async letterCase => {
try {
await updateCaseStatus(letterCase, CASE_STATUS.READY_FOR_REVIEW);
const letter = await models.referral_letter.create(
new ReferralLetter.Builder()
.defaultReferralLetter()
.withCaseId(letterCase.id)
.withRecipient("King of all police")
.withRecipientAddress("100 Main Street, North Pole")
.withSender("The aggrieved party"),
{ auditUser: "user" }
);
} catch (e) {
console.log(e);
}
};
describe("Pact Verification", () => {
let server;
beforeAll(() => {
server = app.listen(8989);
});
afterAll(async () => {
await cleanupDatabase();
await models.sequelize.close();
await server.close();
});
test("validates the expectations of get case details", async () => {
const opts = {
logLevel: "INFO",
providerBaseUrl: "http://localhost:8989",
provider: "police-data-manager.server",
providerVersion: "1.0.0",
pactUrls: [
path.resolve(
__dirname,
"../../../pact/pacts/police-data-manager.client-police-data-manager.server.json"
)
],
stateHandlers: {
"Case exists": async () => {
await cleanupDatabase();
await setupCase();
},
"letter is ready for review": async () => {
await cleanupDatabase();
const letterCase = await setupCase();
await setupLetter(letterCase);
},
"edit letter": async () => {
const letterCase = await setupCase();
await setupLetter(letterCase);
}
}
};
const output = await new Verifier(opts).verifyProvider();
console.log(output);
});
});
I've tried wrapping various parts of the code in try/catch blocks to localize the problem, but with no luck. I've also tweaked the code in my node_modules to get a better look at the problem
loadOneConfig in @babel/core/lib/config/files/configuration.js
function* loadOneConfig(names, dirname, envName, caller, previousConfig = null) {
const configs = yield* _gensync().all(names.map(filename => readConfig(_path().join(dirname, filename), envName, caller)));
const config = configs.reduce((previousConfig, config) => {
if (config && previousConfig) {
throw new Error(`Multiple configuration files found. Please remove one:\n` + ` - ${_path().basename(previousConfig.filepath)}\n` + ` - ${config.filepath}\n` + `from ${dirname}`);
}
return config || previousConfig;
}, previousConfig);
if (config) {
debug("Found configuration %o from %o.", config.filepath, dirname);
}
return config;
}
When I moved code around to console.log it, I get the new error that _gensync().all
is not a function and console.logging _gensync()
returns an empty object.
I tried upgrading my babel to the latest version, but it did not seem to have any effect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论