'TypeError (yield* ... is not iterable) while running Pact provider tests on Node.js with Express
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
