test: init jest test

This commit is contained in:
DIYgod
2024-01-29 22:41:04 +08:00
parent 00a74bcb09
commit 6333562fe5
5 changed files with 1144 additions and 23 deletions
+6
View File
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-typescript',
],
};
+5 -1
View File
@@ -64,7 +64,7 @@
},
"testEnvironment": "node",
"testMatch": [
"**/test/**/*.js"
"**/test/**/*.ts"
],
"testPathIgnorePatterns": [
"/node_modules/",
@@ -150,6 +150,9 @@
"xxhash-wasm": "1.0.2"
},
"devDependencies": {
"@babel/preset-env": "7.23.9",
"@babel/preset-typescript": "7.23.3",
"@jest/globals": "29.7.0",
"@microsoft/eslint-formatter-sarif": "3.0.0",
"@stylistic/eslint-plugin-js": "1.5.4",
"@types/aes-js": "3.1.4",
@@ -211,6 +214,7 @@
"supertest": "6.3.4",
"to-vfile": "8.0.0",
"tosource": "2.0.0-alpha.3",
"ts-jest": "29.1.2",
"tsx": "4.7.0",
"unified": "9.2.2",
"unist-util-visit": "4.1.2",
+1122 -6
View File
File diff suppressed because it is too large Load Diff
-16
View File
@@ -1,16 +0,0 @@
const supertest = require('supertest');
const server = require('../lib/index');
const request = supertest(server);
afterAll(() => {
server.close();
});
describe('index', () => {
it('serve logo', async () => {
const response = await request.get('/logo.png');
expect(response.status).toBe(200);
expect(response.headers['content-type']).toBe('image/png');
expect(response.headers['content-length']).toBe('89034');
});
});
+11
View File
@@ -0,0 +1,11 @@
import { describe, expect, it } from '@jest/globals';
import app from '../lib/app';
describe('index', () => {
it('serve index', async () => {
const res = await app.request('/')
expect(res.status).toBe(200)
expect(await res.text()).toContain('Welcome to RSSHub!')
});
});