mirror of
https://github.com/vale981/apollo-server
synced 2025-03-04 17:21:42 -05:00
Move shared mocks to top-level and enforce noImplicitAny
This commit is contained in:
parent
d38e289821
commit
655ead3b1b
11 changed files with 18 additions and 42 deletions
|
@ -14,7 +14,7 @@ export function advanceTimeBy(ms: number) {
|
|||
now += ms;
|
||||
}
|
||||
|
||||
const handler = {
|
||||
const handler: ProxyHandler<any> = {
|
||||
construct(target, args) {
|
||||
if (args.length === 0) {
|
||||
return new Date(now);
|
|
@ -1,32 +0,0 @@
|
|||
const RealDate = global.Date;
|
||||
|
||||
export function mockDate() {
|
||||
global.Date = new Proxy(RealDate, handler);
|
||||
}
|
||||
|
||||
export function unmockDate() {
|
||||
global.Date = RealDate;
|
||||
}
|
||||
|
||||
let now = Date.now();
|
||||
|
||||
export function advanceTimeBy(ms: number) {
|
||||
now += ms;
|
||||
}
|
||||
|
||||
const handler = {
|
||||
construct(target, args) {
|
||||
if (args.length === 0) {
|
||||
return new Date(now);
|
||||
} else {
|
||||
return new target(...args);
|
||||
}
|
||||
},
|
||||
get(target, propKey, receiver) {
|
||||
if (propKey === 'now') {
|
||||
return () => now;
|
||||
} else {
|
||||
return target[propKey];
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,8 +1,12 @@
|
|||
import 'apollo-server-env';
|
||||
import { HTTPCache } from '../HTTPCache';
|
||||
|
||||
import fetch, { mockFetch, unmockFetch } from '../__mocks__/fetch';
|
||||
import { mockDate, unmockDate, advanceTimeBy } from '../__mocks__/date';
|
||||
import fetch, { mockFetch, unmockFetch } from '../../../../__mocks__/fetch';
|
||||
import {
|
||||
mockDate,
|
||||
unmockDate,
|
||||
advanceTimeBy,
|
||||
} from '../../../../__mocks__/date';
|
||||
|
||||
describe('HTTPCache', () => {
|
||||
let store: Map<string, string>;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import 'apollo-server-env';
|
||||
import { RESTDataSource } from '../RESTDataSource';
|
||||
|
||||
import fetch, { mockFetch, unmockFetch } from '../__mocks__/fetch';
|
||||
import fetch, { mockFetch, unmockFetch } from '../../../../__mocks__/fetch';
|
||||
import { HTTPCache } from '../HTTPCache';
|
||||
|
||||
describe('RESTDataSource', () => {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
"outDir": "./dist",
|
||||
"removeComments": true,
|
||||
"strict": true,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUnusedParameters": true,
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
import { advanceTimeBy, mockDate, unmockDate } from './__mocks__/date';
|
||||
import {
|
||||
advanceTimeBy,
|
||||
mockDate,
|
||||
unmockDate,
|
||||
} from '../../../../__mocks__/date';
|
||||
|
||||
export function testKeyValueCache(keyValueCache) {
|
||||
export function testKeyValueCache(keyValueCache: any) {
|
||||
describe('KeyValueCache Test Suite', () => {
|
||||
beforeAll(() => {
|
||||
mockDate();
|
|
@ -1,4 +1,2 @@
|
|||
export { KeyValueCache } from './KeyValueCache';
|
||||
export { testKeyValueCache } from './tests';
|
||||
|
||||
export { InMemoryLRUCache } from './InMemoryLRUCache';
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
"outDir": "./dist",
|
||||
"removeComments": true,
|
||||
"strict": true,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUnusedParameters": true,
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
jest.mock('memcached', () => require('memcached-mock'));
|
||||
|
||||
import { MemcachedCache } from '../src/index';
|
||||
import { testKeyValueCache } from 'apollo-server-caching';
|
||||
import { testKeyValueCache } from '../../apollo-server-caching/src/__tests__/testsuite';
|
||||
|
||||
testKeyValueCache(new MemcachedCache('localhost'));
|
||||
|
|
|
@ -3,6 +3,6 @@ jest.mock('redis', () => require('redis-mock'));
|
|||
jest.useFakeTimers(); // mocks out setTimeout that is used in redis-mock
|
||||
|
||||
import { RedisCache } from '../src/index';
|
||||
import { testKeyValueCache } from 'apollo-server-caching';
|
||||
import { testKeyValueCache } from '../../apollo-server-caching/src/__tests__/testsuite';
|
||||
|
||||
testKeyValueCache(new RedisCache({ host: 'localhost' }));
|
||||
|
|
Loading…
Add table
Reference in a new issue