Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions mocha/setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import * as chai from "chai";
import * as chaiAsPromised from "chai-as-promised";
import * as nock from "nock";
import * as chaiAsPromisedModule from "chai-as-promised";
import * as nockModule from "nock";

// Normalize CommonJS exports so ts-node (Node.js 20) and Node.js 22's strip-only loader
// both receive callable modules without relying on esModuleInterop.
type ChaiPlugin = Parameters<typeof chai.use>[0];
type NockModule = typeof nockModule;

const chaiAsPromisedExport = chaiAsPromisedModule as ChaiPlugin & { default?: ChaiPlugin };
const chaiAsPromised = chaiAsPromisedExport.default ?? chaiAsPromisedExport;
const nockExport = nockModule as NockModule & { default?: NockModule };
const nock = nockExport.default ?? nockExport;

chai.use(chaiAsPromised);

Expand Down
15 changes: 14 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@
"eslint-plugin-prettier": "^4.0.0",
"firebase-admin": "^13.0.0",
"genkit": "^1.0.0-rc.4",
"js-yaml": "^3.13.1",
"jsdom": "^16.2.1",
"jsonwebtoken": "^9.0.0",
"jwk-to-pem": "^2.0.5",
Expand All @@ -317,6 +316,7 @@
"sinon": "^9.2.4",
"ts-node": "^10.4.0",
"typescript": "^4.3.5",
"yaml": "^2.8.1",
"yargs": "^15.3.1"
},
"peerDependencies": {
Expand Down
9 changes: 8 additions & 1 deletion scripts/bin-test/mocha-setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import * as chai from "chai";
import * as chaiAsPromised from "chai-as-promised";
import * as chaiAsPromisedModule from "chai-as-promised";

// Match the runtime shim in mocha/setup.ts so bin tests work on Node.js 20 ts-node
// and Node.js 22's strip-only TypeScript loader without enabling esModuleInterop.
type ChaiPlugin = Parameters<typeof chai.use>[0];

const chaiAsPromisedExport = chaiAsPromisedModule as ChaiPlugin & { default?: ChaiPlugin };
const chaiAsPromised = chaiAsPromisedExport.default ?? chaiAsPromisedExport;

chai.use(chaiAsPromised);
4 changes: 2 additions & 2 deletions scripts/bin-test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as fs from "fs/promises";
import * as os from "os";

import { expect } from "chai";
import * as yaml from "js-yaml";
import { parse as parseYaml } from "yaml";
import fetch from "node-fetch";
import * as portfinder from "portfinder";

Expand Down Expand Up @@ -177,7 +177,7 @@ async function runHttpDiscovery(modulePath: string): Promise<DiscoveryResult> {
const body = await res.text();

if (res.status === 200) {
const manifest = yaml.load(body) as Record<string, unknown>;
const manifest = parseYaml(body) as Record<string, unknown>;
return { success: true, manifest };
} else {
return { success: false, error: body };
Expand Down
12 changes: 6 additions & 6 deletions spec/common/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@
import { expect } from "chai";
import * as fs from "fs";
import * as process from "process";
import Sinon = require("sinon");
import * as sinon from "sinon";

import { firebaseConfig, resetCache } from "../../src/common/config";

describe("firebaseConfig()", () => {
let readFileSync: Sinon.SinonStub;
let cwdStub: Sinon.SinonStub;
let readFileSync: sinon.SinonStub;
let cwdStub: sinon.SinonStub;

before(() => {
readFileSync = Sinon.stub(fs, "readFileSync");
readFileSync = sinon.stub(fs, "readFileSync");
readFileSync.throws("Unexpected call");
cwdStub = Sinon.stub(process, "cwd");
cwdStub = sinon.stub(process, "cwd");
cwdStub.returns("/srv");
});

after(() => {
Sinon.verifyAndRestore();
sinon.verifyAndRestore();
});

afterEach(() => {
Expand Down
12 changes: 6 additions & 6 deletions spec/v1/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@
import { expect } from "chai";
import * as fs from "fs";
import * as process from "process";
import Sinon = require("sinon");
import * as sinon from "sinon";

import { config, resetCache } from "../../src/v1/config";

describe("config()", () => {
let readFileSync: Sinon.SinonStub;
let cwdStub: Sinon.SinonStub;
let readFileSync: sinon.SinonStub;
let cwdStub: sinon.SinonStub;

before(() => {
readFileSync = Sinon.stub(fs, "readFileSync");
readFileSync = sinon.stub(fs, "readFileSync");
readFileSync.throws("Unexpected call");
cwdStub = Sinon.stub(process, "cwd");
cwdStub = sinon.stub(process, "cwd");
cwdStub.returns("/srv");
});

after(() => {
Sinon.verifyAndRestore();
sinon.verifyAndRestore();
});

afterEach(() => {
Expand Down
Loading