@inngest/test
Version:
Tooling for testing Inngest functions.
55 lines • 1.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isDeeplyEqual = exports.createMockEvent = exports.mockCtx = void 0;
const inngest_1 = require("inngest");
const ulid_1 = require("ulid");
const spy_js_1 = require("./spy.js");
/**
* The default context transformation function that mocks all step tools. Use
* this in addition to your custom transformation function if you'd like to keep
* this functionality.
*/
const mockCtx = (ctx) => {
return Object.assign(Object.assign({}, ctx), { step: (0, spy_js_1.mockAny)(ctx.step) });
};
exports.mockCtx = mockCtx;
/**
* Creates a tiny mock invocation event used to replace or complement given
* event data.
*/
const createMockEvent = () => {
return {
id: (0, ulid_1.ulid)(),
name: `${inngest_1.internalEvents.FunctionInvoked}`,
data: {},
ts: Date.now(),
};
};
exports.createMockEvent = createMockEvent;
/**
* Ensures that all keys in the subset are present in the actual object and that
* the values match.
*/
const isDeeplyEqual = (subset, actual) => {
return Object.keys(subset).every((key) => {
const subsetValue = subset[key];
const actualValue = actual[key];
// an array? find all of the values
if (Array.isArray(subsetValue) && Array.isArray(actualValue)) {
return subsetValue.every((subValue, i) => {
return (0, exports.isDeeplyEqual)(subValue, actualValue[i]);
});
}
// a non-array object?
if (typeof subsetValue === "object" &&
subsetValue !== null &&
typeof actualValue === "object" &&
actualValue !== null) {
return (0, exports.isDeeplyEqual)(subsetValue, actualValue);
}
// anything else
return subsetValue === actualValue;
});
};
exports.isDeeplyEqual = isDeeplyEqual;
//# sourceMappingURL=util.js.map