Skip to content

Commit 5697247

Browse files
committed
Add github actions CI
1 parent e2f7652 commit 5697247

File tree

5 files changed

+84
-1
lines changed

5 files changed

+84
-1
lines changed

.github/workflows/test.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Testing CI
2+
on: pull_request
3+
jobs:
4+
build:
5+
runs-on: ${{ matrix.os }}
6+
strategy:
7+
matrix:
8+
node:
9+
- 24
10+
os:
11+
- ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Use Node.js ${{ matrix.node }}
15+
uses: actions/setup-node@v4
16+
with:
17+
node-version: ${{ matrix.node }}
18+
- uses: actions/cache@v4
19+
with:
20+
path: ~/.npm
21+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
22+
restore-keys: |
23+
${{ runner.os }}-node-
24+
- run: npm ci
25+
- run: npm test

Server/test/database.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import test from 'node:test';
2+
import assert from 'node:assert/strict';
3+
import 'fake-indexeddb/auto';
4+
import { Database } from '../static/storage.js';
5+
6+
test('Database connects and exposes repository', async () => {
7+
const entities = [
8+
{ name: 'user', options: { keyPath: 'id', autoIncrement: true } }
9+
];
10+
const db = await new Database('TestDatabase', 1, entities);
11+
const repo = db.getRepo('user');
12+
assert.ok(repo);
13+
});

Server/test/repository.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import test from 'node:test';
2+
import assert from 'node:assert/strict';
3+
import 'fake-indexeddb/auto';
4+
import { Database } from '../static/storage.js';
5+
6+
test('Repository performs basic CRUD', async () => {
7+
const entities = [
8+
{ name: 'user', options: { keyPath: 'id', autoIncrement: true } }
9+
];
10+
const db = await new Database('TestDatabase', 1, entities);
11+
12+
const repo = db.getRepo('user');
13+
14+
await repo.insert({ name: 'Alice', age: 30 });
15+
await repo.insert({ name: 'Bob', age: 20 });
16+
17+
const users = await repo.select();
18+
assert.equal(users.length, 2);
19+
20+
const user = await repo.get({ id: 1 });
21+
assert.equal(user.name, 'Alice');
22+
23+
user.age++;
24+
await repo.update(user);
25+
26+
const updated = await repo.get({ id: 1 });
27+
assert.equal(updated.age, 31);
28+
29+
await repo.delete({ id: 2 });
30+
const remaining = await repo.select();
31+
assert.equal(remaining.length, 1);
32+
});

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
"version": "1.0.0",
44
"scripts": {
55
"lint": "eslint . && prettier -c \"**/*.js\"",
6-
"fix": "eslint . --fix || prettier --write \"**/*.js\""
6+
"fix": "eslint . --fix || prettier --write \"**/*.js\"",
7+
"test": "node --test"
78
},
89
"author": "Timur Shemsedinov",
910
"private": true,
11+
"type": "module",
1012
"dependencies": {
1113
"eslint": "^9.12.0",
1214
"eslint-config-metarhia": "^9.1.2",
15+
"fake-indexeddb": "^6.0.1",
1316
"prettier": "^3.3.3"
1417
}
1518
}

0 commit comments

Comments
 (0)