Skip to content

Commit 84c04a6

Browse files
test: add tests
1 parent 59f0c8c commit 84c04a6

31 files changed

Lines changed: 3449 additions & 214 deletions

.github/workflows/ci-tests.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
name: CI Tests
3+
permissions: {}
4+
5+
on:
6+
pull_request:
7+
push:
8+
branches:
9+
- master
10+
workflow_dispatch:
11+
12+
concurrency:
13+
group: "${{ github.workflow }}-${{ github.ref }}"
14+
cancel-in-progress: true
15+
16+
jobs:
17+
tests:
18+
permissions:
19+
contents: write # write is required for release_setup
20+
runs-on: ${{ matrix.runner }}
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
27+
with:
28+
python-version: '3.12'
29+
30+
- name: Set up Node
31+
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
32+
with:
33+
node-version: latest
34+
35+
- name: Install Python Dependencies
36+
shell: bash
37+
run: |
38+
python -m pip install --upgrade pip setuptools wheel
39+
python -m pip install -e .[dev]
40+
41+
- name: Install Node Dependencies
42+
shell: bash
43+
run: npm install --ignore-scripts
44+
45+
- name: Test with pytest
46+
id: pytest
47+
shell: bash
48+
run: python -m pytest
49+
50+
- name: Test with Jest
51+
id: jest
52+
if: always()
53+
env:
54+
FORCE_COLOR: true
55+
shell: bash
56+
run: npm test
57+
58+
- name: Upload coverage
59+
# any except canceled or skipped
60+
if: >-
61+
always() &&
62+
(
63+
steps.pytest.outcome == 'success' ||
64+
steps.pytest.outcome == 'failure' ||
65+
steps.jest.outcome == 'success' ||
66+
steps.jest.outcome == 'failure'
67+
) &&
68+
startsWith(github.repository, 'LizardByte/')
69+
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
70+
with:
71+
fail_ci_if_error: true
72+
files: ./coverage/python-coverage.xml,./coverage/coverage-final.json
73+
flags: ${{ runner.os }}
74+
report_type: coverage
75+
token: ${{ secrets.CODECOV_TOKEN }}
76+
verbose: true
77+
78+
- name: Upload test results
79+
# any except canceled or skipped
80+
if: >-
81+
always() &&
82+
(
83+
steps.pytest.outcome == 'success' ||
84+
steps.pytest.outcome == 'failure' ||
85+
steps.jest.outcome == 'success' ||
86+
steps.jest.outcome == 'failure'
87+
) &&
88+
startsWith(github.repository, 'LizardByte/')
89+
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
90+
with:
91+
fail_ci_if_error: true
92+
files: ./junit-python.xml,./junit.xml
93+
flags: ${{ runner.os }}
94+
report_type: test_results
95+
token: ${{ secrets.CODECOV_TOKEN }}
96+
verbose: true

.github/workflows/update-db.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ jobs:
3939
- name: Install Python dependencies
4040
run: |
4141
python -m pip install --upgrade pip
42-
python -m pip install -r requirements.txt
42+
python -m pip install -e .
4343
4444
- name: Update
4545
env:
4646
TWITCH_CLIENT_ID: ${{ secrets.TWITCH_CLIENT_ID }}
4747
TWITCH_CLIENT_SECRET: ${{ secrets.TWITCH_CLIENT_SECRET }}
4848
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }}
49-
run: python -u src/update_db.py ${{ github.event_name == 'pull_request' && '-t' || '' }}
49+
run: python -u update-db ${{ github.event_name == 'pull_request' && '-t' || '' }}
5050

5151
- name: Prepare Artifacts # uploading artifacts will fail if not zipped due to very large quantity of files
5252
shell: bash

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ cython_debug/
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
.idea/
161161

162+
# Node.js
163+
node_modules/
164+
npm-debug.log*
165+
yarn-debug.log*
166+
yarn-error.log*
167+
package-lock.json
168+
169+
# Jest
170+
.jest-cache/
171+
coverage/
172+
junit*.xml
173+
162174
# Project specific
163175
gh-pages/
164176
cache/

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,3 @@
55
This repository clones IGDB to gh-pages to be consumed by LizardByte projects, such as LizardByte/Sunshine.
66

77
Information from YouTube API is also added to the database for videos.
8-
9-
## Plans
10-
11-
- [x] Build with Jekyll
12-
- [ ] Revamp index page
13-
- [x] Provide an item page for each API item
14-
- [ ] Add unit tests
15-
- [ ] Add code coverage

babel.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// this allows jest to use ES6 module imports
2+
module.exports = {presets: ['@babel/preset-env']}

codecov.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
codecov:
3+
branch: master
4+
5+
coverage:
6+
status:
7+
project:
8+
default:
9+
target: auto
10+
threshold: 10%
11+
12+
comment:
13+
layout: "header, reach, diff, flags, files, footer"
14+
behavior: default
15+
require_changes: false

eslint.config.mjs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import globals from "globals";
2+
import pluginJs from "@eslint/js";
3+
4+
export default [
5+
pluginJs.configs.recommended,
6+
{
7+
ignores: [
8+
"coverage/**",
9+
"node_modules/**",
10+
"gh-pages/**",
11+
],
12+
},
13+
{
14+
languageOptions: {
15+
globals: {
16+
...globals.browser,
17+
...globals.node,
18+
...globals.jquery,
19+
// cross-file globals injected by item_detail.js into the browser scope
20+
"base_url": "readonly",
21+
"base_path": "readonly",
22+
"igdbImageUrl": "readonly",
23+
"makeBadge": "readonly",
24+
"addDlRow": "readonly",
25+
"loadItemDetail": "readonly",
26+
"renderGameList": "readonly",
27+
"splitString": "readonly",
28+
"require": "readonly",
29+
},
30+
},
31+
},
32+
];

gh-pages-template/assets/js/character_detail.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,10 @@ function renderCharacter(data) {
4444
document.addEventListener("DOMContentLoaded", () => {
4545
loadItemDetail("characters", renderCharacter);
4646
});
47+
48+
/* istanbul ignore next */
49+
if (typeof module !== "undefined") {
50+
module.exports = {
51+
renderCharacter,
52+
};
53+
}

gh-pages-template/assets/js/collection_detail.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ function renderCollection(data) {
2626
document.addEventListener("DOMContentLoaded", () => {
2727
loadItemDetail("collections", renderCollection);
2828
});
29+
30+
/* istanbul ignore next */
31+
if (typeof module !== "undefined") {
32+
module.exports = {
33+
renderCollection,
34+
};
35+
}

gh-pages-template/assets/js/franchise_detail.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ function renderFranchise(data) {
2626
document.addEventListener("DOMContentLoaded", () => {
2727
loadItemDetail("franchises", renderFranchise);
2828
});
29+
30+
/* istanbul ignore next */
31+
if (typeof module !== "undefined") {
32+
module.exports = {
33+
renderFranchise,
34+
};
35+
}

0 commit comments

Comments
 (0)