Skip to content

Commit e431a56

Browse files
committed
fix(tests): make tests pass
1 parent b683fcd commit e431a56

15 files changed

+72
-54
lines changed

package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"prebuild": "npm run clean",
3636
"precommit": "lint-staged",
3737
"test": "jest",
38-
"test:watch": "jest --watchAll --onlyChanged",
38+
"test:watch": "jest --watchAll",
3939
"coverage": "jest --coverage",
4040
"watch": "tsc -w -p .",
4141
"publish:git": "git push && git push --tags",
@@ -56,22 +56,23 @@
5656
},
5757
"jest": {
5858
"moduleFileExtensions": [
59-
"ts",
6059
"js",
61-
"json"
60+
"json",
61+
"ts"
6262
],
6363
"transform": {
64-
"\\.ts$": "ts-jest"
64+
"\\.ts$": [
65+
"ts-jest",
66+
{
67+
"babelConfig": true
68+
}
69+
]
6570
},
6671
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|js)$",
67-
"globals": {
68-
"ts-jest": {
69-
"useBabelrc": true
70-
}
71-
},
7272
"transformIgnorePatterns": [
7373
"node_modules/(?!apollo-cache-hermes)"
74-
]
74+
],
75+
"preset": "ts-jest"
7576
},
7677
"dependencies": {},
7778
"peerDependencies": {

src/Cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default class Cache<T> {
55
cache: ApolloCache<T>;
66
serialize: boolean;
77

8-
constructor(options: ApolloPersistOptions<T>) {
8+
constructor(options: Pick<ApolloPersistOptions<T>, 'cache' | 'serialize'>) {
99
const { cache, serialize = true } = options;
1010

1111
this.cache = cache;

src/CachePersistor.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ export default class CachePersistor<T> {
1717
if (!options.cache) {
1818
throw new Error(
1919
'In order to persist your Apollo Cache, you need to pass in a cache. ' +
20-
'Please see https://www.apollographql.com/docs/react/basics/caching.html for our default InMemoryCache.'
20+
'Please see https://www.apollographql.com/docs/react/basics/caching.html for our default InMemoryCache.',
2121
);
2222
}
2323

2424
if (!options.storage) {
2525
throw new Error(
2626
'In order to persist your Apollo Cache, you need to pass in an underlying storage provider. ' +
27-
'Please see https://github.com/apollographql/apollo-cache-persist#storage-providers'
27+
'Please see https://github.com/apollographql/apollo-cache-persist#storage-providers',
2828
);
2929
}
3030

@@ -36,9 +36,10 @@ export default class CachePersistor<T> {
3636

3737
this.log = log;
3838
this.cache = cache;
39-
this.storage = storage;
40-
this.persistor = persistor;
41-
this.trigger = trigger;
39+
// TODO: remove type assertion
40+
this.storage = storage as Storage<T>;
41+
this.persistor = persistor as Persistor<T>;
42+
this.trigger = trigger as Trigger<T>;
4243
}
4344

4445
/**

src/Log.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default class Log<T> {
77
static buffer = 30;
88
static prefix = '[apollo-cache-persist]';
99

10-
constructor(options: ApolloPersistOptions<T>) {
10+
constructor(options: Pick<ApolloPersistOptions<T>, 'debug'>) {
1111
const { debug = false } = options;
1212

1313
this.debug = debug;

src/Persistor.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ export default class Persistor<T> {
2020

2121
constructor(
2222
{ log, cache, storage }: PersistorConfig<T>,
23-
options: ApolloPersistOptions<T>,
23+
options: Pick<ApolloPersistOptions<T>, 'maxSize' | 'persistenceMapper'>,
2424
) {
25-
const {
26-
maxSize = 1024 * 1024,
27-
persistenceMapper,
28-
} = options;
25+
const { maxSize = 1024 * 1024, persistenceMapper } = options;
2926

3027
this.log = log;
3128
this.cache = cache;

src/Storage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default class Storage<T> {
88
storage: PersistentStorage<PersistedData<T>>;
99
key: string;
1010

11-
constructor(options: ApolloPersistOptions<T>) {
11+
constructor(options: Pick<ApolloPersistOptions<T>, 'storage' | 'key'>) {
1212
const { storage, key = 'apollo-cache-persist' } = options;
1313

1414
this.storage = storage;

src/Trigger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default class Trigger<T> {
2121

2222
constructor(
2323
{ log, persistor }: TriggerConfig<T>,
24-
options: ApolloPersistOptions<T>
24+
options: Pick<ApolloPersistOptions<T>, 'cache' | 'debounce' | 'trigger'>,
2525
) {
2626
const { defaultDebounce } = Trigger;
2727
const { cache, debounce, trigger = 'write' } = options;

src/__mocks__/MockCache.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import Cache from '../Cache';
22
import { ApolloPersistOptions, PersistedData } from '../types';
33

4-
export default class MockCache<T> implements Cache<T> {
4+
export default class MockCache<T, U extends boolean = true>
5+
implements Cache<T>
6+
{
57
cache: null;
68
serialize: boolean;
79
data: PersistedData<T>;
810

9-
constructor(options: ApolloPersistOptions<T>) {
11+
constructor(options: Pick<ApolloPersistOptions<T, U>, 'serialize'>) {
1012
const { serialize = true } = options;
1113
this.serialize = serialize;
1214
}

src/__mocks__/MockStorage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { PersistentStorage } from '../types';
22

3-
export default class MockStorage implements PersistentStorage {
3+
export default class MockStorage implements PersistentStorage<any> {
44
storage: Map<string, string>;
55

66
constructor() {
77
this.storage = new Map();
88
}
99

10-
setItem(key: string, data: string): Promise<any> {
10+
setItem(key: string, data: string): Promise<void> {
1111
return new Promise(resolve => {
1212
this.storage.set(key, data);
1313
resolve();
1414
});
1515
}
1616

17-
removeItem(key: string): Promise<any> {
17+
removeItem(key: string): Promise<void> {
1818
return new Promise((resolve, reject) => {
1919
this.storage.delete(key);
2020
resolve();

src/__mocks__/MockStorageSync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { PersistentStorage } from '../types';
22

3-
export default class MockStorageSync implements PersistentStorage {
3+
export default class MockStorageSync implements PersistentStorage<any> {
44
storage: Map<string, string>;
55

66
constructor() {

0 commit comments

Comments
 (0)