Skip to content

Commit 793de3e

Browse files
Add Jest imports everywhere, remove global availability (#6911)
In ESM mode, the `jest` globals are technically no longer available. For some reason, we're still getting away with it, but this issue surfaces in the v29 upgrade PR so I'm going to address it separately. https://jestjs.io/docs/ecmascript-modules#differences-between-esm-and-commonjs Ref: #6850 (comment) <!-- First, 🌠 thank you 🌠 for taking the time to consider a contribution to Apollo! Here are some important details to follow: * ⏰ Your time is important To save your precious time, if the contribution you are making will take more than an hour, please make sure it has been discussed in an issue first. This is especially true for feature requests! * 💡 Features Feature requests can be created and discussed within a GitHub Issue. Be sure to search for existing feature requests (and related issues!) prior to opening a new request. If an existing issue covers the need, please upvote that issue by using the 👍 emote, rather than opening a new issue. * 🔌 Integrations Apollo Server has many web-framework integrations including Express, Koa, Hapi and more. When adding a new feature, or fixing a bug, please take a peak and see if other integrations are also affected. In most cases, the fix can be applied to the other frameworks as well. Please note that, since new web-frameworks have a high maintenance cost, pull-requests for new web-frameworks should be discussed with a project maintainer first. * 🕷 Bug fixes These can be created and discussed in this repository. When fixing a bug, please _try_ to add a test which verifies the fix. If you cannot, you should still submit the PR but we may still ask you (and help you!) to create a test. * 📖 Contribution guidelines Follow https://github.com/apollographql/apollo-server/blob/main/CONTRIBUTING.md when submitting a pull request. Make sure existing tests still pass, and add tests for all new behavior. * ✏️ Explain your pull request Describe the big picture of your changes here to communicate to what your pull request is meant to accomplish. Provide 🔗 links 🔗 to associated issues! We hope you will find this to be a positive experience! Open source contribution can be intimidating and we hope to alleviate that pain as much as possible. Without following these guidelines, you may be missing context that can help you succeed with your contribution, which is why we encourage discussion first. Ultimately, there is no guarantee that we will be able to merge your pull-request, but by following these guidelines we can try to avoid disappointment. -->
1 parent 6541f92 commit 793de3e

32 files changed

Lines changed: 57 additions & 30 deletions

.changeset/eleven-drinks-mix.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/plugin-response-cache/src/__tests__/ApolloServerPluginResponseCache.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import plugin from '../ApolloServerPluginResponseCache';
2+
import { describe, it, expect } from '@jest/globals';
23

34
describe('Response cache plugin', () => {
45
it('will instantiate when not called with options', () => {

packages/plugin-response-cache/src/__tests__/integration.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import { startStandaloneServer } from '@apollo/server/standalone';
77
import ApolloServerPluginResponseCache from '../index.js';
88
import request, { type Response } from 'supertest';
9+
import { jest, describe, it, expect, beforeAll, afterAll } from '@jest/globals';
910

1011
describe('Response caching', () => {
1112
beforeAll(() => {

packages/plugin-response-cache/src/__tests__/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"include": ["**/*"],
44
"references": [
55
{ "path": "../../" },
6+
{ "path": "../../../server" }
67
]
78
}

packages/server/src/__tests__/ApolloServer.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { HeaderMap } from '../runHttpQuery.js';
99
import { mockLogger } from './mockLogger.js';
1010
import gql from 'graphql-tag';
1111
import type { GatewayInterface } from '@apollo/server-gateway-interface';
12+
import { jest, describe, it, expect } from '@jest/globals';
1213

1314
const typeDefs = gql`
1415
type Query {
@@ -132,7 +133,7 @@ const failToStartPlugin: ApolloServerPlugin<BaseContext> = {
132133

133134
describe('ApolloServer start', () => {
134135
it('start throws on startup error and startupDidFail hook is called with error', async () => {
135-
const startupDidFail = jest.fn();
136+
const startupDidFail = jest.fn(async () => {});
136137
const server = new ApolloServer({
137138
typeDefs,
138139
resolvers,

packages/server/src/__tests__/cachePolicy.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { CachePolicy } from '@apollo/cache-control-types';
22
import { newCachePolicy } from '../cachePolicy.js';
3+
import { describe, it, expect, beforeEach } from '@jest/globals';
34

45
describe('newCachePolicy', () => {
56
let cachePolicy: CachePolicy;

packages/server/src/__tests__/documentStore.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { DocumentNode } from 'graphql';
33
import gql from 'graphql-tag';
44
import { InMemoryLRUCache } from '@apollo/utils.keyvaluecache';
55
import { ApolloServer } from '..';
6+
import { jest, describe, it, expect } from '@jest/globals';
67

78
const typeDefs = gql`
89
type Query {

packages/server/src/__tests__/errors.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { GraphQLError, GraphQLFormattedError } from 'graphql';
22
import { unwrapResolverError } from '@apollo/server/errors';
33

44
import { normalizeAndFormatErrors } from '../errorNormalize.js';
5+
import { jest, describe, it, expect } from '@jest/globals';
56

67
describe('Errors', () => {
78
describe('normalizeAndFormatErrors', () => {
@@ -55,7 +56,7 @@ describe('Errors', () => {
5556
const error = new GraphQLError(message, {
5657
extensions: { code, key },
5758
});
58-
const formatError = jest.fn();
59+
const formatError = jest.fn((fErr, _err) => fErr);
5960
normalizeAndFormatErrors([error], {
6061
formatError,
6162
includeStacktraceInErrorResponses: true,

packages/server/src/__tests__/express/expressSpecific.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import express from 'express';
22
import request from 'supertest';
33
import { ApolloServer } from '../../index.js';
44
import { expressMiddleware } from '../../express4/index.js';
5+
import { it, expect } from '@jest/globals';
56

67
it('gives helpful error if body-parser middleware is not installed', async () => {
78
const server = new ApolloServer({ typeDefs: 'type Query {f: ID}' });

packages/server/src/__tests__/gatewayCompatibility0.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ApolloServer } from '..';
33
import { ApolloGateway as AG0OldestSupported } from 'apollo-gateway-0-oldest-supported';
44
import { ApolloGateway as AG0BeforeASGI } from 'apollo-gateway-0-before-asgi';
55
import { ApolloGateway as AG0Latest } from 'apollo-gateway-0-latest';
6+
import { it } from '@jest/globals';
67

78
// This is the oldest version which prints no peer dep warnings when installed
89
// with graphql-js@16; it's possible that some older versions could work as

0 commit comments

Comments
 (0)