Skip to content

Commit

Permalink
feat!: 删除 engines.localStorage 和 engines.sessionStorage 两个属性
Browse files Browse the repository at this point in the history
  • Loading branch information
geekact committed Feb 26, 2024
1 parent 3cce1ab commit 298ea1d
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 88 deletions.
26 changes: 0 additions & 26 deletions src/engines/index.ts

This file was deleted.

16 changes: 0 additions & 16 deletions src/engines/local.ts

This file was deleted.

16 changes: 0 additions & 16 deletions src/engines/session.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export { connect } from './redux/connect';
export { compose } from 'redux';
export { modelStore as store } from './store/model-store';
export { FocaProvider } from './redux/foca-provider';
export { engines } from './engines';
export { memoryStorage } from './engines/memory';

// 可能用到的TS类型
Expand Down
35 changes: 6 additions & 29 deletions test/engine.test.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,34 @@
import 'fake-indexeddb/auto';
import localforage from 'localforage';
import ReactNativeStorage from '@react-native-async-storage/async-storage';
import { engines } from '../src';
import { toPromise } from '../src/utils/to-promise';
import { memoryStorage } from '../src';

const storages = [
[engines.localStorage, localStorage, 'local'],
[engines.sessionStorage, sessionStorage, 'session'],
[engines.memoryStorage, undefined, 'memory'],
[localStorage, 'local'],
[sessionStorage, 'session'],
[memoryStorage, 'memory'],
[
localforage.createInstance({ driver: localforage.LOCALSTORAGE }),
undefined,
'localforage local',
],
[
localforage.createInstance({ driver: localforage.INDEXEDDB }),
undefined,
'localforage indexedDb',
],
[ReactNativeStorage, undefined, 'react-native'],
[ReactNativeStorage, 'react-native'],
] as const;

describe.each(storages)('storage io', (storage, syncOrigin, name) => {
describe.each(storages)('storage io', (storage, name) => {
beforeEach(() => storage.clear());
afterEach(() => storage.clear());

test(`[${name}] Get and set data`, async () => {
if (syncOrigin) {
expect(syncOrigin.getItem('test1')).toBeNull();
}

await expect(toPromise(() => storage.getItem('test1'))).resolves.toBeNull();
await storage.setItem('test1', 'yes');
await expect(toPromise(() => storage.getItem('test1'))).resolves.toBe(
'yes',
);

if (syncOrigin) {
expect(syncOrigin.getItem('test1')).toBe('yes');
}
});

test(`[${name}] Update data`, async () => {
Expand All @@ -48,10 +38,6 @@ describe.each(storages)('storage io', (storage, syncOrigin, name) => {
);
await storage.setItem('test2', 'no');
await expect(toPromise(() => storage.getItem('test2'))).resolves.toBe('no');

if (syncOrigin) {
expect(syncOrigin.getItem('test2')).toBe('no');
}
});

test(`[${name}] Delete data`, async () => {
Expand All @@ -61,10 +47,6 @@ describe.each(storages)('storage io', (storage, syncOrigin, name) => {
);
await storage.removeItem('test3');
await expect(toPromise(() => storage.getItem('test3'))).resolves.toBeNull();

if (syncOrigin) {
expect(syncOrigin.getItem('test3')).toBeNull();
}
});

test(`[${name}] Clear all data`, async () => {
Expand All @@ -75,10 +57,5 @@ describe.each(storages)('storage io', (storage, syncOrigin, name) => {

await expect(toPromise(() => storage.getItem('test4'))).resolves.toBeNull();
await expect(toPromise(() => storage.getItem('test5'))).resolves.toBeNull();

if (syncOrigin) {
expect(syncOrigin.getItem('test4')).toBeNull();
expect(syncOrigin.getItem('test5')).toBeNull();
}
});
});

0 comments on commit 298ea1d

Please sign in to comment.