Skip to content

Commit

Permalink
test(core): add missing state clear() to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mirabilio committed Jun 9, 2020
1 parent d3456ad commit f9746e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const isUndefined = require("lodash.isundefined");

const _stateCache = new Map(); // internal storage for production env

const clearStateCache = () => {
const clear = () => {
_stateCache.clear();
};
exports.clearStateCache = clearStateCache;
exports.clear = clear;

// if local state is empty, check cache if non-dev env
const getState = ({ cache, reporter }) => {
Expand Down
11 changes: 10 additions & 1 deletion src/core.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const isEmpty = require("lodash.isempty");
const { resolverReducerAndStore, constructResolvers } = require("./core");
const { getState } = require("./cache");
const { getState, clear } = require("./cache");
const { createContentDigest } = require("gatsby-core-utils");
const { onCreateNode, createResolvers, onPreInit } = require("./gatsby-node");

Expand All @@ -27,6 +27,7 @@ let cache;

beforeEach(() => {
cache = new Map();
clear();
});

describe("create leaves recursively from two json files", () => {
Expand Down Expand Up @@ -183,6 +184,7 @@ describe("create leaves recursively from two json files", () => {
createNodeId,
createParentChildLink: {},
createContentDigest,
createResolvers: jest.fn(),
getNodesByType,
actions,
reporter,
Expand All @@ -195,6 +197,7 @@ describe("create leaves recursively from two json files", () => {
createNodeId,
createParentChildLink: {},
createContentDigest,
createResolvers: jest.fn(),
getNodesByType,
actions,
reporter,
Expand Down Expand Up @@ -257,11 +260,17 @@ describe("create leaves recursively from two json files", () => {
});

test("reject node if node isn't owned by transformer-json ", async () => {
console.log(
`state!!: ${JSON.stringify(getState({ cache, reporter }), null, " ")}`
);
nodeApiArgsNode1.node.internal.owner = "not transformer-json";
await onCreateNode(nodeApiArgsNode1, {
fieldNameBlacklist,
paths: ["/dir"],
});
console.log(
`state: ${JSON.stringify(getState({ cache, reporter }), null, " ")}`
);
expect(isEmpty(getState({ cache, reporter }))).toBe(true);
});

Expand Down

0 comments on commit f9746e9

Please sign in to comment.