Skip to content

Commit

Permalink
Fix data masking tests that depended on the old profiler utils (#12113)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller authored Nov 8, 2024
1 parent ba70b62 commit 7a0e1b1
Show file tree
Hide file tree
Showing 9 changed files with 481 additions and 494 deletions.
2 changes: 1 addition & 1 deletion .size-limits.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"dist/apollo-client.min.cjs": 41445,
"dist/apollo-client.min.cjs": 41459,
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 34213
}
96 changes: 50 additions & 46 deletions src/react/hooks/__tests__/useBackgroundQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4141,9 +4141,9 @@ it("masks queries when dataMasking is `true`", async () => {
link: new MockLink(mocks),
});

const Profiler = createDefaultProfiler<Masked<Query>>();
const renderStream = createDefaultProfiler<Masked<Query>>();
const { SuspenseFallback, ReadQueryHook } =
createDefaultTrackedComponents(Profiler);
createDefaultTrackedComponents(renderStream);

function App() {
useTrackRenders();
Expand All @@ -4156,13 +4156,15 @@ it("masks queries when dataMasking is `true`", async () => {
);
}

renderWithClient(<App />, { client, wrapper: Profiler });
renderStream.render(<App />, {
wrapper: createClientWrapper(client),
});

// loading
await Profiler.takeRender();
await renderStream.takeRender();

{
const { snapshot } = await Profiler.takeRender();
const { snapshot } = await renderStream.takeRender();

expect(snapshot.result).toEqual({
data: {
Expand Down Expand Up @@ -4227,9 +4229,9 @@ it("does not mask query when dataMasking is `false`", async () => {
link: new MockLink(mocks),
});

const Profiler = createDefaultProfiler<Query>();
const renderStream = createDefaultProfiler<Query>();
const { SuspenseFallback, ReadQueryHook } =
createDefaultTrackedComponents(Profiler);
createDefaultTrackedComponents(renderStream);

function App() {
useTrackRenders();
Expand All @@ -4242,12 +4244,12 @@ it("does not mask query when dataMasking is `false`", async () => {
);
}

renderWithClient(<App />, { client, wrapper: Profiler });
renderStream.render(<App />, { wrapper: createClientWrapper(client) });

// loading
await Profiler.takeRender();
await renderStream.takeRender();

const { snapshot } = await Profiler.takeRender();
const { snapshot } = await renderStream.takeRender();

expect(snapshot.result).toEqual({
data: {
Expand Down Expand Up @@ -4311,9 +4313,9 @@ it("does not mask query by default", async () => {
link: new MockLink(mocks),
});

const Profiler = createDefaultProfiler<Query>();
const renderStream = createDefaultProfiler<Query>();
const { SuspenseFallback, ReadQueryHook } =
createDefaultTrackedComponents(Profiler);
createDefaultTrackedComponents(renderStream);

function App() {
useTrackRenders();
Expand All @@ -4326,12 +4328,12 @@ it("does not mask query by default", async () => {
);
}

renderWithClient(<App />, { client, wrapper: Profiler });
renderStream.render(<App />, { wrapper: createClientWrapper(client) });

// loading
await Profiler.takeRender();
await renderStream.takeRender();

const { snapshot } = await Profiler.takeRender();
const { snapshot } = await renderStream.takeRender();

expect(snapshot.result).toEqual({
data: {
Expand Down Expand Up @@ -4396,9 +4398,9 @@ it("masks queries updated by the cache", async () => {
link: new MockLink(mocks),
});

const Profiler = createDefaultProfiler<Masked<Query>>();
const renderStream = createDefaultProfiler<Masked<Query>>();
const { SuspenseFallback, ReadQueryHook } =
createDefaultTrackedComponents(Profiler);
createDefaultTrackedComponents(renderStream);

function App() {
useTrackRenders();
Expand All @@ -4411,13 +4413,13 @@ it("masks queries updated by the cache", async () => {
);
}

renderWithClient(<App />, { client, wrapper: Profiler });
renderStream.render(<App />, { wrapper: createClientWrapper(client) });

// loading
await Profiler.takeRender();
await renderStream.takeRender();

{
const { snapshot } = await Profiler.takeRender();
const { snapshot } = await renderStream.takeRender();

expect(snapshot.result).toEqual({
data: {
Expand Down Expand Up @@ -4447,7 +4449,7 @@ it("masks queries updated by the cache", async () => {
});

{
const { snapshot } = await Profiler.takeRender();
const { snapshot } = await renderStream.takeRender();

expect(snapshot.result).toEqual({
data: {
Expand Down Expand Up @@ -4512,9 +4514,9 @@ it("does not rerender when updating field in named fragment", async () => {
link: new MockLink(mocks),
});

const Profiler = createDefaultProfiler<Masked<Query>>();
const renderStream = createDefaultProfiler<Masked<Query>>();
const { SuspenseFallback, ReadQueryHook } =
createDefaultTrackedComponents(Profiler);
createDefaultTrackedComponents(renderStream);

function App() {
useTrackRenders();
Expand All @@ -4527,13 +4529,15 @@ it("does not rerender when updating field in named fragment", async () => {
);
}

renderWithClient(<App />, { client, wrapper: Profiler });
renderStream.render(<App />, {
wrapper: createClientWrapper(client),
});

// loading
await Profiler.takeRender();
await renderStream.takeRender();

{
const { snapshot } = await Profiler.takeRender();
const { snapshot } = await renderStream.takeRender();

expect(snapshot.result).toEqual({
data: {
Expand Down Expand Up @@ -4562,7 +4566,7 @@ it("does not rerender when updating field in named fragment", async () => {
},
});

await expect(Profiler).not.toRerender();
await expect(renderStream).not.toRerender();

expect(client.readQuery({ query })).toEqual({
currentUser: {
Expand Down Expand Up @@ -4635,9 +4639,9 @@ it("masks result from cache when using with cache-first fetch policy", async ()
},
});

const Profiler = createDefaultProfiler<Masked<Query>>();
const renderStream = createDefaultProfiler<Masked<Query>>();
const { SuspenseFallback, ReadQueryHook } =
createDefaultTrackedComponents(Profiler);
createDefaultTrackedComponents(renderStream);

function App() {
useTrackRenders();
Expand All @@ -4652,9 +4656,9 @@ it("masks result from cache when using with cache-first fetch policy", async ()
);
}

renderWithClient(<App />, { client, wrapper: Profiler });
renderStream.render(<App />, { wrapper: createClientWrapper(client) });

const { snapshot } = await Profiler.takeRender();
const { snapshot } = await renderStream.takeRender();

expect(snapshot.result).toEqual({
data: {
Expand Down Expand Up @@ -4731,9 +4735,9 @@ it("masks cache and network result when using cache-and-network fetch policy", a
},
});

const Profiler = createDefaultProfiler<Masked<Query>>();
const renderStream = createDefaultProfiler<Masked<Query>>();
const { SuspenseFallback, ReadQueryHook } =
createDefaultTrackedComponents(Profiler);
createDefaultTrackedComponents(renderStream);

function App() {
useTrackRenders();
Expand All @@ -4748,10 +4752,10 @@ it("masks cache and network result when using cache-and-network fetch policy", a
);
}

renderWithClient(<App />, { client, wrapper: Profiler });
renderStream.render(<App />, { wrapper: createClientWrapper(client) });

{
const { snapshot } = await Profiler.takeRender();
const { snapshot } = await renderStream.takeRender();

expect(snapshot.result).toEqual({
data: {
Expand All @@ -4767,7 +4771,7 @@ it("masks cache and network result when using cache-and-network fetch policy", a
}

{
const { snapshot } = await Profiler.takeRender();
const { snapshot } = await renderStream.takeRender();

expect(snapshot.result).toEqual({
data: {
Expand Down Expand Up @@ -4848,9 +4852,9 @@ it("masks partial cache data when returnPartialData is `true`", async () => {
});
}

const Profiler = createDefaultProfiler<DeepPartial<Masked<Query>>>();
const renderStream = createDefaultProfiler<DeepPartial<Masked<Query>>>();
const { SuspenseFallback, ReadQueryHook } =
createDefaultTrackedComponents(Profiler);
createDefaultTrackedComponents(renderStream);

function App() {
useTrackRenders();
Expand All @@ -4863,10 +4867,10 @@ it("masks partial cache data when returnPartialData is `true`", async () => {
);
}

renderWithClient(<App />, { client, wrapper: Profiler });
renderStream.render(<App />, { wrapper: createClientWrapper(client) });

{
const { snapshot } = await Profiler.takeRender();
const { snapshot } = await renderStream.takeRender();

expect(snapshot.result).toEqual({
data: {
Expand All @@ -4881,7 +4885,7 @@ it("masks partial cache data when returnPartialData is `true`", async () => {
}

{
const { snapshot } = await Profiler.takeRender();
const { snapshot } = await renderStream.takeRender();

expect(snapshot.result).toEqual({
data: {
Expand Down Expand Up @@ -4948,9 +4952,9 @@ it("masks partial data returned from data on errors with errorPolicy `all`", asy
link: new MockLink(mocks),
});

const Profiler = createDefaultProfiler<Masked<Query> | undefined>();
const renderStream = createDefaultProfiler<Masked<Query> | undefined>();
const { SuspenseFallback, ReadQueryHook } =
createDefaultTrackedComponents(Profiler);
createDefaultTrackedComponents(renderStream);

function App() {
useTrackRenders();
Expand All @@ -4963,13 +4967,13 @@ it("masks partial data returned from data on errors with errorPolicy `all`", asy
);
}

renderWithClient(<App />, { client, wrapper: Profiler });
renderStream.render(<App />, { wrapper: createClientWrapper(client) });

// loading
await Profiler.takeRender();
await renderStream.takeRender();

{
const { snapshot } = await Profiler.takeRender();
const { snapshot } = await renderStream.takeRender();

expect(snapshot.result).toEqual({
data: {
Expand Down
Loading

0 comments on commit 7a0e1b1

Please sign in to comment.