Skip to content

Commit b255996

Browse files
committed
add tests
1 parent 01d1391 commit b255996

17 files changed

+2573
-56
lines changed

.github/bug.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
name: Bug
3+
about: Report a bug or unexpected behavior.
4+
---
5+
6+
<!--
7+
Thank you for filing a bug! Please feel free to answer as much or as little of this template as you can.
8+
-->
9+
10+
**Describe the bug**
11+
12+
<!-- Please be as detailed as possible! -->
13+
14+
**How to reproduce**
15+
16+
**Expected behavior**
17+
18+
<!-- What should have happened? -->

.github/package_request.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
name: Package request
3+
about: Suggest a new package
4+
---
5+
6+
**Package information**
7+
8+
<!-- name, url -->

.github/workflows/tests.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
jobs:
8+
test_frontend:
9+
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
matrix:
14+
node-version: [16.x]
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Use Node.js ${{ matrix.node-version }}
19+
uses: actions/setup-node@v1
20+
with:
21+
node-version: ${{ matrix.node-version }}
22+
- run: |
23+
cd frontend
24+
yarn install
25+
yarn build
26+
yarn lint
27+
28+
test_backend:
29+
30+
runs-on: ubuntu-latest
31+
32+
strategy:
33+
matrix:
34+
node-version: [16.x]
35+
36+
steps:
37+
- uses: actions/checkout@v3
38+
- name: Use Node.js ${{ matrix.node-version }}
39+
uses: actions/setup-node@v1
40+
with:
41+
node-version: ${{ matrix.node-version }}
42+
43+
- run: |
44+
cd backend
45+
touch .env
46+
echo API_KEY=${{ secrets.API_KEY }} > .env
47+
yarn install
48+
yarn test
49+
yarn lint
50+

.vscode/launch.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "node",
6+
"request": "launch",
7+
"name": "Backend: Jest single run all tests",
8+
"cwd": "${workspaceFolder}/backend",
9+
"program": "${workspaceRoot}/backend/node_modules/jest-cli/bin/jest.js",
10+
"args": ["--verbose", "-i", "--no-cache"],
11+
"console": "integratedTerminal",
12+
"internalConsoleOptions": "neverOpen"
13+
},
14+
{
15+
"type": "node",
16+
"request": "launch",
17+
"name": "Backend: Jest watch all tests",
18+
"cwd": "${workspaceFolder}/backend",
19+
"program": "${workspaceRoot}/backend/node_modules/jest-cli/bin/jest.js",
20+
"args": ["--verbose", "-i", "--no-cache", "--watchAll"],
21+
"console": "integratedTerminal",
22+
"internalConsoleOptions": "neverOpen"
23+
},
24+
{
25+
"type": "node",
26+
"request": "launch",
27+
"name": "Backend: Jest watch current file",
28+
"cwd": "${workspaceFolder}/backend",
29+
"program": "${workspaceFolder}/backend/node_modules/jest-cli/bin/jest",
30+
"args": [
31+
"${fileBasename}",
32+
"--verbose",
33+
"-i",
34+
"--no-cache",
35+
"--watchAll"
36+
],
37+
"console": "integratedTerminal",
38+
"internalConsoleOptions": "neverOpen"
39+
}
40+
]
41+
}

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
See README files in respective folders.
1+
The frontend is in `frontend/` and the backend is in `backend/`.

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# Python Packaging Tools
2+
13
An interactive web app to explore, and hopefully better understand, Python packaging tools.
24

3-
https://chadsmith.dev/python-packaging
5+
**https://chadsmith.dev/python-packaging**
6+
7+
<p align="center">
8+
<a href="https://github.com/cs01/python-packaging-tools/actions">
9+
<img src="https://github.com/cs01/python-packaging-tools/workflows/tests/badge.svg?branch=main" alt="image" /></a>
10+
11+
<p align="center">
12+
<a href="https://chadsmith.dev/python-packaging"><img src="https://github.com/cs01/python-packaging-tools/raw/main/screenshot.png"></a>
13+
</p>
14+
15+
</p>

backend/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Backend
22

3-
Add .env file with secret key:
3+
You will need your own GitHub api key to access the GitHub's api via [Octokit](https://github.com/octokit).
4+
5+
Save the API key to the .env file:
46

57
```
68
> cat .env
79
API_KEY=abcd1234
810
```
911

10-
This key is used to access github's [Octokit](https://github.com/octokit).
11-
1212
## Getting Started
1313

1414
Install dependencies:

backend/jest.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
watchPathIgnorePatterns: [
6+
"<rootDir>/data.json" // this file is written to
7+
]
8+
9+
};

backend/package.json

+13-5
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,28 @@
22
"name": "backend",
33
"version": "1.0.0",
44
"scripts": {
5-
"start": "rm ./data.json; ts-node server.ts"
5+
"start": "rm ./data.json; ts-node server.ts",
6+
"test": "yarn jest",
7+
"format": "prettier --write *.ts",
8+
"lint": "prettier --check *.ts"
69
},
710
"main": "index.js",
811
"license": "MIT",
912
"dependencies": {
1013
"@octokit/core": "^3.1.2",
11-
"@types/dotenv": "^8.2.0",
1214
"dotenv": "^8.2.0",
1315
"express": "^4.17.1",
14-
"ts-node": "^9.0.0",
15-
"typescript": "^4.0.2"
16+
"ts-jest": "^28.0.7",
17+
"ts-node": "^9.0.0"
1618
},
1719
"devDependencies": {
1820
"@types/express": "^4.17.8",
19-
"@types/node": "^14.6.4"
21+
"@types/jest": "^28.1.6",
22+
"@types/node": "^14.6.4",
23+
"@types/supertest": "^2.0.12",
24+
"jest": "^28.1.3",
25+
"prettier": "^2.7.1",
26+
"supertest": "^6.2.4",
27+
"typescript": "^4.7.4"
2028
}
2129
}

backend/server.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as express from "express";
22
import { fetchGithubData } from "./githubData";
33
import * as path from "path";
4-
const app = express();
4+
export const app = express();
55
const port = process.env.PORT ?? 3001;
66

77
const secPerMin = 60;
@@ -37,6 +37,8 @@ app.get("/package_data", async (req, res) => {
3737

3838
app.use("/", express.static(path.join(__dirname, "..", "frontend", "build")));
3939

40-
app.listen(port, () => {
41-
console.log(`Example app listening at http://localhost:${port}`);
42-
});
40+
if (process.env.NODE_ENV !== "test") {
41+
app.listen(port, () => {
42+
console.log(`Example app listening at http://localhost:${port}`);
43+
});
44+
}

backend/tests/server.test.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { app } from "../server";
2+
import * as request from "supertest";
3+
import { test, expect } from "@jest/globals";
4+
5+
test("can fetch github data", async () => {
6+
const response = await request(app).get("/package_data");
7+
expect(response.headers["content-type"]).toMatch(/json/);
8+
expect(response.status).toEqual(200);
9+
10+
expect(Array.isArray(response.body)).toBe(true);
11+
12+
const actualRepoNames = response.body.map((githubRepo) => githubRepo.name);
13+
14+
// make sure some common repos are present
15+
const expectedRepos = [
16+
"pip",
17+
"pip",
18+
"cython",
19+
"flit",
20+
"pdm",
21+
"build",
22+
"poetry",
23+
"pipx",
24+
];
25+
expectedRepos.map((repo) => {
26+
expect(actualRepoNames.includes(repo)).toBe(true);
27+
});
28+
29+
const actualFields = Object.keys(response.body[0]);
30+
const expectedFields = [
31+
"stargazers",
32+
"licenseInfo",
33+
"primaryLanguage",
34+
"url",
35+
"owner",
36+
];
37+
38+
expectedFields.map((expectedField) => {
39+
expect(actualFields.includes(expectedField)).toBe(true);
40+
});
41+
});

0 commit comments

Comments
 (0)