-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(__tests__ dir): added vitest and coverage reporting GitHub Actions workflow #8
Changes from 5 commits
74f3516
9bfc05c
dea26e8
a020e58
c476214
e3264f8
d21b62b
ca5420f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,39 @@ | ||||||
# ./.github/workflows/node-ci.yml | ||||||
# | ||||||
# Auto CI/CD for Node.js projects using GitHub Actions. | ||||||
name: Node CI | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
|
||||||
# Enable the workflow for auto push, pull_request | ||||||
# and manual workflow_dispatch events. | ||||||
on: | ||||||
push: | ||||||
pull_request: | ||||||
workflow_dispatch: | ||||||
|
||||||
jobs: | ||||||
yarn-vitest: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
name: Yarn Vitest | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
|
||||||
permissions: | ||||||
contents: read | ||||||
pull-requests: write | ||||||
|
||||||
runs-on: ubuntu-latest | ||||||
|
||||||
steps: | ||||||
- uses: actions/checkout@v4 | ||||||
|
||||||
- name: Set Node.js 18.x | ||||||
uses: actions/setup-node@v4 | ||||||
with: | ||||||
node-version: 18.x | ||||||
|
||||||
- name: Install dependencies | ||||||
run: yarn install | ||||||
|
||||||
- name: Run tests | ||||||
run: yarn test | ||||||
|
||||||
- name: Run coverage | ||||||
if: always() | ||||||
uses: davelosert/vitest-coverage-report-action@v2 |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,45 @@ | ||||||
// ./__tests__/Fuzzy.test.ts | ||||||
// | ||||||
// Unittests for the Fuzzy class. | ||||||
|
||||||
// Local Fuzzy class import. | ||||||
import Fuzzy from '../src/Fuzzy'; | ||||||
|
||||||
// Fuzzy class test suite. | ||||||
describe('Fuzzy', () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Let's add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
const list = ['apple', 'banana', 'grape', 'orange', 'pineapple']; | ||||||
const fuzzy = new Fuzzy(list); | ||||||
|
||||||
it('should return correct results for a query', () => { | ||||||
const query = 'apple'; | ||||||
const results = fuzzy.search(query); | ||||||
expect(results).toMatchSnapshot(); | ||||||
}); | ||||||
|
||||||
// Branch coverage: cache hit. | ||||||
it('should NOT update cache for repeated same query', () => { | ||||||
const query = 'apple'; | ||||||
const results = fuzzy.search(query); | ||||||
expect(results).toMatchSnapshot(); | ||||||
}); | ||||||
|
||||||
it('should return empty array for no matches', () => { | ||||||
const query = 'xyz'; | ||||||
const results = fuzzy.search(query); | ||||||
expect(results).toMatchSnapshot(); | ||||||
}); | ||||||
|
||||||
// Branch coverage: includeMatches option is true. | ||||||
it('should include matches if includeMatches option is true', () => { | ||||||
const fuzzyWithMatches = new Fuzzy(list, { includeMatches: true }); | ||||||
const query = 'apple'; | ||||||
const results = fuzzyWithMatches.search(query); | ||||||
expect(results).toMatchSnapshot(); | ||||||
}); | ||||||
|
||||||
// Edge case: list is undefined. | ||||||
it('should set this.list to an empty array if list is undefined', () => { | ||||||
const badFuzzy = new Fuzzy(undefined as any); // Simulate absence of list | ||||||
expect(badFuzzy).toMatchSnapshot(); | ||||||
}); | ||||||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`Fuzzy > should NOT update cache for repeated same query 1`] = ` | ||
[ | ||
{ | ||
"distance": 0, | ||
"text": "apple", | ||
}, | ||
{ | ||
"distance": 4, | ||
"text": "pineapple", | ||
}, | ||
{ | ||
"distance": 5, | ||
"text": "orange", | ||
}, | ||
{ | ||
"distance": 5, | ||
"text": "banana", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`Fuzzy > should include matches if includeMatches option is true 1`] = ` | ||
[ | ||
{ | ||
"distance": 0, | ||
"matches": [ | ||
[ | ||
0, | ||
0, | ||
], | ||
[ | ||
1, | ||
1, | ||
], | ||
[ | ||
2, | ||
2, | ||
], | ||
[ | ||
3, | ||
3, | ||
], | ||
[ | ||
4, | ||
4, | ||
], | ||
], | ||
"text": "apple", | ||
}, | ||
{ | ||
"distance": 4, | ||
"matches": [ | ||
[ | ||
0, | ||
4, | ||
], | ||
[ | ||
1, | ||
5, | ||
], | ||
[ | ||
2, | ||
6, | ||
], | ||
[ | ||
3, | ||
7, | ||
], | ||
[ | ||
4, | ||
8, | ||
], | ||
], | ||
"text": "pineapple", | ||
}, | ||
{ | ||
"distance": 5, | ||
"matches": [ | ||
[ | ||
0, | ||
2, | ||
], | ||
[ | ||
4, | ||
5, | ||
], | ||
], | ||
"text": "orange", | ||
}, | ||
{ | ||
"distance": 5, | ||
"matches": [ | ||
[ | ||
0, | ||
1, | ||
], | ||
], | ||
"text": "banana", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`Fuzzy > should return correct results for a query 1`] = ` | ||
[ | ||
{ | ||
"distance": 0, | ||
"text": "apple", | ||
}, | ||
{ | ||
"distance": 4, | ||
"text": "pineapple", | ||
}, | ||
{ | ||
"distance": 5, | ||
"text": "orange", | ||
}, | ||
{ | ||
"distance": 5, | ||
"text": "banana", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`Fuzzy > should return empty array for no matches 1`] = `[]`; | ||
|
||
exports[`Fuzzy > should set this.list to an empty array if list is undefined 1`] = ` | ||
Fuzzy { | ||
"cache": {}, | ||
"list": [], | ||
"options": { | ||
"includeMatches": false, | ||
}, | ||
"search": [Function], | ||
} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`getMatchingIndices > should return the correct matching indices 1`] = ` | ||
[ | ||
[ | ||
3, | ||
3, | ||
], | ||
] | ||
`; | ||
|
||
exports[`levenshteinFullMatrixSearch > should return a matrix of the correct dimensions 1`] = ` | ||
[ | ||
[ | ||
0, | ||
1, | ||
2, | ||
3, | ||
4, | ||
5, | ||
], | ||
[ | ||
1, | ||
1, | ||
2, | ||
3, | ||
4, | ||
5, | ||
], | ||
[ | ||
2, | ||
2, | ||
2, | ||
3, | ||
4, | ||
5, | ||
], | ||
[ | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
4, | ||
], | ||
[ | ||
4, | ||
4, | ||
4, | ||
4, | ||
3, | ||
4, | ||
], | ||
[ | ||
5, | ||
5, | ||
4, | ||
5, | ||
4, | ||
4, | ||
], | ||
] | ||
`; | ||
|
||
exports[`levenshteinFullMatrixSearch > should return a matrix with the correct values 1`] = ` | ||
[ | ||
[ | ||
0, | ||
1, | ||
2, | ||
3, | ||
4, | ||
5, | ||
], | ||
[ | ||
1, | ||
1, | ||
2, | ||
3, | ||
4, | ||
5, | ||
], | ||
[ | ||
2, | ||
2, | ||
2, | ||
3, | ||
4, | ||
5, | ||
], | ||
[ | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
4, | ||
], | ||
[ | ||
4, | ||
4, | ||
4, | ||
4, | ||
3, | ||
4, | ||
], | ||
[ | ||
5, | ||
5, | ||
4, | ||
5, | ||
4, | ||
4, | ||
], | ||
] | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// ./__tests__/index.test.ts | ||
// | ||
// Integration test for the package entrypoint. | ||
|
||
import Fuzzy from "../src/Fuzzy"; | ||
import * as IndexExport from "../src/index"; | ||
|
||
describe("Package entrypoint", () => { | ||
it("should correctly export the Fuzzy class", () => { | ||
expect(IndexExport.default).toBe(Fuzzy); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's rename this file to
test-coverage-pr.yml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.