Skip to content

Commit d9f6d69

Browse files
committed
feat: Added tests and gh actions
1 parent 94558af commit d9f6d69

File tree

6 files changed

+155
-1
lines changed

6 files changed

+155
-1
lines changed

.github/workflows/ci.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Continuous Integration
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
push:
8+
branches:
9+
- master
10+
11+
jobs:
12+
linter:
13+
# We only require one OS in linter
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- name: Install Deno
19+
uses: denolib/setup-deno@master
20+
21+
- name: Lint code
22+
run: deno lint --unstable src/
23+
24+
formatter:
25+
# We only require one OS in formatter
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v2
29+
30+
- name: Install Deno
31+
uses: denolib/setup-deno@master
32+
33+
- name: Lint code
34+
run: deno fmt --check src/
35+
tests:
36+
strategy:
37+
fail-fast: true
38+
matrix:
39+
os: [ubuntu-latest, windows-latest, macos-latest]
40+
runs-on: ${{ matrix.os }}
41+
steps:
42+
- uses: actions/checkout@v2
43+
44+
- name: Install Deno
45+
uses: denolib/setup-deno@master
46+
47+
- name: Unit Test
48+
run: deno test tests/

.github/workflows/release.yaml

Whitespace-only changes.

deps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";

mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { Moogle } from "./src/Moogle.ts";

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
2-
"name": "Moogle",
2+
"name": "@drashland/Moogle",
33
"version": "1.0.0",
4+
"description": "The Moogle service to save your items and search for them, using terms and keep it fast!",
45
"main": "./lib/Moogle.js",
56
"types": "./lib/Moogle.d.ts",
67
"repository": "[email protected]:drashland/Moogle.git",

tests/unit.test.ts

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { Moogle } from "../mod.ts";
2+
import { assertEquals } from "../deps.ts";
3+
4+
Deno.test({
5+
name: "adds an item to the index and lookup table",
6+
fn: function () {
7+
const moogle = new Moogle();
8+
moogle.addItem(["ok"], "ok value");
9+
moogle.addItem(["hello1"], "hello value 1-1");
10+
moogle.addItem(["hello1"], "hello value 1-2");
11+
moogle.addItem(["hello2"], "hello value 2");
12+
moogle.addItem(["world"], "world value");
13+
moogle.addItem(["skrrrt"], "skrrrt steak value");
14+
moogle.addItem(["test"], "test value");
15+
16+
assertEquals(
17+
moogle.search("tes"),
18+
new Map<number, unknown>([
19+
[
20+
6,
21+
{
22+
id: 6,
23+
item: "test value",
24+
searchTerm: "test",
25+
searchInput: "tes",
26+
},
27+
],
28+
]),
29+
);
30+
},
31+
});
32+
33+
Deno.test({
34+
name: "returns the index",
35+
fn: function () {
36+
const moogle = new Moogle();
37+
moogle.addItem(["ok"], "ok value");
38+
moogle.addItem(["hello1"], "hello value 1-1");
39+
moogle.addItem(["hello1"], "hello value 1-2");
40+
moogle.addItem(["hello2"], "hello value 2");
41+
moogle.addItem(["world"], "world value");
42+
moogle.addItem(["skrrrt"], "skrrrt steak value");
43+
moogle.addItem(["test"], "test value");
44+
45+
assertEquals(
46+
moogle.getIndex(),
47+
new Map<string, number[]>([
48+
["ok", [0]],
49+
["hello1", [1, 2]],
50+
["hello2", [3]],
51+
["world", [4]],
52+
["skrrrt", [5]],
53+
["test", [6]],
54+
]),
55+
);
56+
},
57+
});
58+
59+
Deno.test({
60+
name: "returns search results",
61+
fn: function () {
62+
const moogle = new Moogle();
63+
moogle.addItem(["ok"], "ok value");
64+
moogle.addItem(["hello1"], "hello value 1-1");
65+
moogle.addItem(["hello1"], "hello value 1-2");
66+
moogle.addItem(["hello2"], "hello value 2");
67+
moogle.addItem(["world"], "world value");
68+
moogle.addItem(["skrrrt"], "skrrrt steak value");
69+
70+
assertEquals(
71+
moogle.search("hello"),
72+
new Map<number, unknown>([
73+
[
74+
1,
75+
{
76+
id: 1,
77+
item: "hello value 1-1",
78+
searchInput: "hello",
79+
searchTerm: "hello1",
80+
},
81+
],
82+
[
83+
2,
84+
{
85+
id: 2,
86+
item: "hello value 1-2",
87+
searchInput: "hello",
88+
searchTerm: "hello1",
89+
},
90+
],
91+
[
92+
3,
93+
{
94+
id: 3,
95+
item: "hello value 2",
96+
searchInput: "hello",
97+
searchTerm: "hello2",
98+
},
99+
],
100+
]),
101+
);
102+
},
103+
});

0 commit comments

Comments
 (0)