Skip to content

Commit

Permalink
feat(test): add jest (#84)
Browse files Browse the repository at this point in the history
louisgrasset authored Oct 22, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent a33a5ff commit 3c8e730
Showing 7 changed files with 5,182 additions and 2,028 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -28,6 +28,26 @@ jobs:
- name: Build documentations
run: npm run build

tests:
name: "Tests Validation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
cache: 'npm'

- name: Install dependencies (with dev)
run: npm ci --include=dev

- name: Run tests
run: npm run test

commitlint:
name: "Commitlint Validation"
runs-on: ubuntu-latest
@@ -73,6 +93,7 @@ jobs:
build:
name: "Build from source"
needs:
- tests
- commitlint
- eslint
runs-on: ubuntu-latest
17 changes: 17 additions & 0 deletions meta/testing/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
collectCoverageFrom: ['src/**/*.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
modulePaths: ['<rootDir>/src/'],
rootDir: '../../',
setupFilesAfterEnv: ['<rootDir>/meta/testing/jest.setup.cjs'],
testRegex: '(/__tests__/.*\\.spec)\\.ts?$',
testTimeout: 10000,
transform: {
"^.+\\.ts?$": ["ts-jest", {
useESM: true,
}]
},
verbose: false,
};
1 change: 1 addition & 0 deletions meta/testing/jest.setup.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jest.retryTimes(3);
7,149 changes: 5,122 additions & 2,027 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
"scripts": {
"lint": "eslint src/ --ext .ts",
"lint:fix": "eslint src/ --ext .ts --fix",
"test": "jest --config ./meta/testing/jest.config.cjs",
"build": "tsc",
"predeploy": "npm ci && npm run build",
"deploy": "bash ./deployment/deploy.sh",
@@ -38,6 +39,7 @@
"@commitlint/cli": "^18.0.0",
"@commitlint/config-conventional": "^18.0.0",
"@types/html-escaper": "^3.0.1",
"@types/jest": "^29.5.6",
"@types/mime": "^3.0.3",
"@types/tough-cookie": "^4.0.4",
"@typescript-eslint/eslint-plugin": "^6.8.0",
@@ -46,6 +48,8 @@
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"husky": "^8.0.3",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
}
}
14 changes: 14 additions & 0 deletions src/helpers/tweet/__tests__/format-tweet-text.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Tweet } from '@the-convocation/twitter-scraper';

import { formatTweetText } from '../format-tweet-text.js';

describe('formatTweetText', () => {
it('should keep untouched a tweet without links', () => {
const tweet: Tweet = {
text:'This is a tweet without links.',
urls: []
} as unknown as Tweet;
const result = formatTweetText(tweet);
expect(result).toStrictEqual('This is a tweet without links.');
});
});
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"include": ["src/**/*"],
"exclude": ["src/**/__tests_"],
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */

@@ -112,7 +114,7 @@

/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true
"skipLibCheck": true,
/* Skip type checking all .d.ts files. */
}
}

0 comments on commit 3c8e730

Please sign in to comment.