mirror of
https://github.com/Inside4ndroid/TMDB-Embed-API.git
synced 2026-10-22 17:45:11 +00:00
added test scripts and github worklow for tests.
This commit is contained in:
@@ -1,2 +0,0 @@
|
|||||||
TMDB_API_KEY="YOUR_TMDB_API_KEY_HERE"
|
|
||||||
PORT=3000
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export default {
|
||||||
|
presets: [
|
||||||
|
['@babel/preset-env', { targets: { node: 'current' } }]
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -177,6 +177,8 @@ app.get('*', (req, res) => {
|
|||||||
res.status(404).json({ error: 'Not found', hint: 'Go to /' });
|
res.status(404).json({ error: 'Not found', hint: 'Go to /' });
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
export const server = app.listen(PORT, () => {
|
||||||
console.log(`Server is running on port http://localhost:${PORT}`);
|
console.log(`Server is running on port http://localhost:${PORT}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export default app;
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
export default {
|
||||||
|
testEnvironment: 'node',
|
||||||
|
transform: {},
|
||||||
|
transformIgnorePatterns: [],
|
||||||
|
moduleNameMapper: {
|
||||||
|
'^(\\.{1,2}/.*)\\.js$': '$1'
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+5328
-16
File diff suppressed because it is too large
Load Diff
+26
-2
@@ -7,14 +7,38 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node --watch index.js"
|
"test:ci": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --forceExit --ci --testTimeout=30000 --reporters=default --reporters=jest-junit",
|
||||||
|
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles",
|
||||||
|
"test:watch": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --watch",
|
||||||
|
"test:debug": "cross-env NODE_OPTIONS='--experimental-vm-modules --inspect-brk' jest --runInBand",
|
||||||
|
"dev": "node --watch index.js",
|
||||||
|
"start": "node index.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cheerio": "^1.0.0",
|
"cheerio": "^1.0.0",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"fetch": "^1.1.0",
|
|
||||||
"node-fetch": "^3.3.2"
|
"node-fetch": "^3.3.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.26.10",
|
||||||
|
"@babel/preset-env": "^7.26.9",
|
||||||
|
"cross-env": "^7.0.3",
|
||||||
|
"jest-junit": "^15.0.0",
|
||||||
|
"jest": "^29.7.0",
|
||||||
|
"supertest": "^7.1.0",
|
||||||
|
"jest-extended": "^3.2.4"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"testEnvironment": "node",
|
||||||
|
"setupFilesAfterEnv": ["jest-extended/all"],
|
||||||
|
"reporters": [
|
||||||
|
"default",
|
||||||
|
["jest-junit", {
|
||||||
|
"outputDirectory": "test-results",
|
||||||
|
"outputName": "junit.xml"
|
||||||
|
}]
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
import request from 'supertest';
|
||||||
|
import { server } from '../index.js';
|
||||||
|
import app from '../index.js';
|
||||||
|
|
||||||
|
const movieProviders = ['2embed', 'autoembed', 'embedsu', 'vidsrcsu'];
|
||||||
|
|
||||||
|
describe('API Routes', () => {
|
||||||
|
describe('GET /', () => {
|
||||||
|
it('should return welcome message', async () => {
|
||||||
|
const res = await request(app).get('/');
|
||||||
|
expect(res.statusCode).toEqual(200);
|
||||||
|
expect(res.body).toHaveProperty('INTRO');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Movie Routes', () => {
|
||||||
|
movieProviders.forEach(provider => {
|
||||||
|
it(`should work with ${provider} provider`, async () => {
|
||||||
|
const testId = 533535;
|
||||||
|
const res = await request(app).get(`/movie/${provider}/${testId}`);
|
||||||
|
expect([200, 404]).toContain(res.statusCode);
|
||||||
|
if (res.statusCode === 200) {
|
||||||
|
res.body.forEach(sourceItem => {
|
||||||
|
expect(sourceItem).toHaveProperty('source');
|
||||||
|
expect(sourceItem.source).toHaveProperty('files');
|
||||||
|
expect(sourceItem.source.files).toBeInstanceOf(Array);
|
||||||
|
expect(sourceItem.source.files.length).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('TV Show Routes', () => {
|
||||||
|
movieProviders.forEach(provider => {
|
||||||
|
it(`should work with ${provider} provider`, async () => {
|
||||||
|
const testId = 93405;
|
||||||
|
const res = await request(app)
|
||||||
|
.get(`/tv/${provider}/${testId}`)
|
||||||
|
.query({ s: 1, e: 1 });
|
||||||
|
expect([200, 404]).toContain(res.statusCode);
|
||||||
|
if (res.statusCode === 200) {
|
||||||
|
res.body.forEach(sourceItem => {
|
||||||
|
expect(sourceItem).toHaveProperty('source');
|
||||||
|
expect(sourceItem.source).toHaveProperty('files');
|
||||||
|
expect(sourceItem.source.files).toBeInstanceOf(Array);
|
||||||
|
expect(sourceItem.source.files.length).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Error Handling', () => {
|
||||||
|
it('GET /nonexistent - should return 404', async () => {
|
||||||
|
const res = await request(app).get('/nonexistent');
|
||||||
|
expect(res.statusCode).toEqual(404);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('GET /movie/ - should return 405', async () => {
|
||||||
|
const res = await request(app).get('/movie/');
|
||||||
|
expect(res.statusCode).toEqual(405);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('GET /tv/ - should return 405', async () => {
|
||||||
|
const res = await request(app).get('/tv/');
|
||||||
|
expect(res.statusCode).toEqual(405);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await new Promise(resolve => server.close(resolve));
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
name: Node.js CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
node-version: [16.x, 18.x]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
cache: 'npm'
|
||||||
|
|
||||||
|
- run: npm ci
|
||||||
|
|
||||||
|
- name: Run Tests
|
||||||
|
run: npm run test:ci
|
||||||
|
|
||||||
|
- name: Upload test results
|
||||||
|
if: always()
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: jest-test-results-${{ matrix.node-version }}
|
||||||
|
path: test-results/junit.xml
|
||||||
Reference in New Issue
Block a user