Skip to content

Commit

Permalink
Merge pull request #1806 from apollographql/testing-improvements
Browse files Browse the repository at this point in the history
Testing improvements
  • Loading branch information
martijnwalraven authored Oct 12, 2018
2 parents 94fc935 + 9a69ad3 commit 78808cd
Show file tree
Hide file tree
Showing 74 changed files with 1,399 additions and 1,251 deletions.
27 changes: 27 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "TypeScript watch",
"type": "shell",
"command": "./node_modules/.bin/tsc",
"args": [
"--build",
"tsconfig.build.json",
"--watch"
],
"isBackground": true,
"problemMatcher": [
"$tsc-watch"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "never",
"panel": "dedicated"
}
}
]
}
16 changes: 8 additions & 8 deletions __mocks__/apollo-server-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
} from '../packages/apollo-server-env';

interface FetchMock extends jest.Mock<typeof fetch> {
mockResponseOnce(data?: any, headers?: HeadersInit, status?: number);
mockJSONResponseOnce(data?: object, headers?: HeadersInit);
mockResponseOnce(data?: any, headers?: HeadersInit, status?: number): void;
mockJSONResponseOnce(data?: object, headers?: HeadersInit): void;
}

const mockFetch = jest.fn<typeof fetch>(fetch) as FetchMock;
Expand Down Expand Up @@ -46,16 +46,16 @@ mockFetch.mockJSONResponseOnce = (
);
};

export {
mockFetch as fetch,
const env = {
fetch: mockFetch,
Request,
RequestInit,
Response,
Body,
BodyInit,
Headers,
HeadersInit,
URL,
URLSearchParams,
URLSearchParamsInit,
};

jest.doMock('apollo-server-env', () => env);

export = env;
33 changes: 33 additions & 0 deletions jest.config.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const { defaults } = require("jest-config");

module.exports = {
testEnvironment: "node",
setupFiles: [
"<rootDir>/../apollo-server-env/dist/index.js"
],
preset: "ts-jest",
testMatch: null,
testRegex: "/__tests__/.*\\.test\\.(js|ts)$",
testPathIgnorePatterns: [
"/node_modules/",
"/dist/"
],
moduleFileExtensions: [...defaults.moduleFileExtensions, "ts", "tsx"],
moduleNameMapper: {
'^__mocks__/(.*)$': '<rootDir>/../../__mocks__/$1',
// This regex should match the packages that we want compiled from source
// through `ts-jest`, as opposed to loaded from their output files in
// `dist`.
// We don't want to match `apollo-server-env` and
// `apollo-engine-reporting-protobuf`, because these don't depend on
// compilation but need to be initialized from as parto of `prepare`.
'^(?!apollo-server-env|apollo-engine-reporting-protobuf)(apollo-(?:server|datasource|cache-control|tracing|engine)[^/]*|graphql-extensions)(?:/dist)?((?:/.*)|$)': '<rootDir>/../../packages/$1/src$2'
},
clearMocks: true,
globals: {
"ts-jest": {
tsConfig: "<rootDir>/src/__tests__/tsconfig.json",
diagnostics: false
}
}
};
31 changes: 0 additions & 31 deletions jest.config.js

This file was deleted.

Loading

0 comments on commit 78808cd

Please sign in to comment.