Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
chore(jest): setup jest and add test for lmdbkvstore
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Mar 22, 2024
1 parent 90a88a4 commit ceca751
Show file tree
Hide file tree
Showing 4 changed files with 1,679 additions and 18 deletions.
17 changes: 17 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"preset": "ts-jest",
"testEnvironment": "node",
"extensionsToTreatAsEsm": [".ts"],
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1"
},
"transform": {
"^.+\\.m?[tj]sx?$": [
"ts-jest",
{
"useESM": true
}
]
},
"moduleFileExtensions": ["ts", "js", "json", "node"]
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@types/cors": "^2.8.16",
"@types/express": "^4.17.17",
"@types/express-prometheus-middleware": "^1.2.1",
"@types/jest": "^29.5.12",
"@types/node": "^16.11.7",
"@types/swagger-ui-express": "^4.1.3",
"@typescript-eslint/eslint-plugin": "^5.26.0",
Expand All @@ -41,9 +42,11 @@
"eslint-plugin-mocha": "^10.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-unicorn": "^45.0.2",
"jest": "^29.7.0",
"nodemon": "^3.1.0",
"prettier": "^2.6.2",
"rimraf": "^3.0.2",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typescript": "^5.3.0"
},
Expand Down
38 changes: 38 additions & 0 deletions src/cache/lmdb-kv-store.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* AR.IO ArNS Resolver
* Copyright (C) 2023 Permanent Data Solutions, Inc. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { LmdbKVStore } from './lmdb-kv-store.js';

describe('LmdbKVStore', () => {
const cache = new LmdbKVStore({
dbPath: './data/test',
ttlSeconds: 1,
});

it('should set and get value', async () => {
await cache.set('test', Buffer.from('hello'));
const value = await cache.get('test');
expect(value).toEqual(Buffer.from('hello'));
});

it('should remove a value once ttl has expired', async () => {
await cache.set('expire', Buffer.from('hello'));
await new Promise((resolve) => setTimeout(resolve, 1000));
const value = await cache.get('expire');
expect(value).toBeUndefined();
});
});
Loading

0 comments on commit ceca751

Please sign in to comment.