Move shared mocks to top-level and enforce noImplicitAny

This commit is contained in:
Martijn Walraven 2018-06-20 12:21:52 +02:00
parent d38e289821
commit 655ead3b1b
11 changed files with 18 additions and 42 deletions

View file

@ -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);

View file

@ -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];
}
},
};

View file

@ -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>;

View file

@ -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', () => {

View file

@ -5,6 +5,7 @@
"outDir": "./dist",
"removeComments": true,
"strict": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUnusedParameters": true,

View file

@ -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();

View file

@ -1,4 +1,2 @@
export { KeyValueCache } from './KeyValueCache';
export { testKeyValueCache } from './tests';
export { InMemoryLRUCache } from './InMemoryLRUCache';

View file

@ -5,6 +5,7 @@
"outDir": "./dist",
"removeComments": true,
"strict": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUnusedParameters": true,

View file

@ -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'));

View file

@ -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' }));