@firestore-emulator/jest
Version:
This package contains a [`Jest`](https://jestjs.io/) environment for setup `@firestore-emulator/server`.
41 lines • 1.18 kB
JavaScript
// src/environment/node.ts
import { FirestoreServer } from "@firestore-emulator/server";
import { findFreePorts } from "find-free-ports";
import { TestEnvironment } from "jest-environment-node";
var FirestoreEmulatorEnvironment = class extends TestEnvironment {
server;
constructor(config, context) {
super(config, context);
this.server = new FirestoreServer();
}
async setup() {
await super.setup();
let tryCount = 0;
while (tryCount < 50) {
const [port] = await findFreePorts(1);
if (!port) throw new Error("Could not find a free port");
try {
await this.server.start(port);
this.global.emulator = {
host: `0.0.0.0:${port}`,
port,
state: this.server.state
};
return;
} catch (err) {
if (!(err instanceof Error)) throw err;
if (!err.message.startsWith("No address added out of total")) throw err;
}
tryCount++;
}
throw new Error("Could not find a free port");
}
async teardown() {
this.server.stop();
await super.teardown();
}
};
export {
FirestoreEmulatorEnvironment as default
};
//# sourceMappingURL=node.mjs.map