mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-24 18:26:20 +01:00
Added jest testing.
This commit is contained in:
parent
2363b03d1c
commit
2a8437cac9
7
jest.config.ts
Normal file
7
jest.config.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export default {
|
||||
roots: ['./src'],
|
||||
testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],
|
||||
transform: {
|
||||
'^.+\\.(ts|tsx)$': 'ts-jest',
|
||||
},
|
||||
};
|
@ -43,6 +43,7 @@
|
||||
"lint": "next lint --quiet",
|
||||
"prepare": "node -e \"if (process.env.NODE_ENV !== 'production'){process.exit(1)} \" || husky install",
|
||||
"postbuild": "node scripts/postbuild.js",
|
||||
"test": "jest",
|
||||
"cypress-open": "cypress open cypress run",
|
||||
"cypress-run": "cypress run cypress run"
|
||||
},
|
||||
@ -129,6 +130,7 @@
|
||||
"@rollup/plugin-replace": "^5.0.2",
|
||||
"@svgr/rollup": "^8.1.0",
|
||||
"@svgr/webpack": "^8.1.0",
|
||||
"@types/jest": "^29.5.12",
|
||||
"@types/node": "^20.9.0",
|
||||
"@types/react": "^18.2.41",
|
||||
"@types/react-dom": "^18.2.17",
|
||||
@ -148,6 +150,7 @@
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"extract-react-intl-messages": "^4.1.1",
|
||||
"husky": "^8.0.3",
|
||||
"jest": "^29.7.0",
|
||||
"lint-staged": "^14.0.1",
|
||||
"postcss": "^8.4.31",
|
||||
"postcss-flexbugs-fixes": "^5.0.2",
|
||||
@ -169,6 +172,7 @@
|
||||
"stylelint-config-prettier": "^9.0.3",
|
||||
"stylelint-config-recommended": "^14.0.0",
|
||||
"tar": "^6.1.2",
|
||||
"ts-jest": "^29.1.2",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.1.6"
|
||||
}
|
||||
|
38
src/lib/__tests__/format.test.ts
Normal file
38
src/lib/__tests__/format.test.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import * as format from '../format';
|
||||
|
||||
test('parseTime', () => {
|
||||
expect(format.parseTime(86400 + 3600 + 60 + 1)).toEqual({
|
||||
days: 1,
|
||||
hours: 1,
|
||||
minutes: 1,
|
||||
seconds: 1,
|
||||
ms: 0,
|
||||
});
|
||||
});
|
||||
|
||||
test('formatTime', () => {
|
||||
expect(format.formatTime(3600 + 60 + 1)).toBe('1:01:01');
|
||||
});
|
||||
|
||||
test('formatShortTime', () => {
|
||||
expect(format.formatShortTime(3600 + 60 + 1)).toBe('1m1s');
|
||||
|
||||
expect(format.formatShortTime(3600 + 60 + 1, ['h', 'm', 's'])).toBe('1h1m1s');
|
||||
});
|
||||
|
||||
test('formatNumber', () => {
|
||||
expect(format.formatNumber('10.2')).toBe('10');
|
||||
expect(format.formatNumber('10.5')).toBe('11');
|
||||
});
|
||||
|
||||
test('formatLongNumber', () => {
|
||||
expect(format.formatLongNumber(1200000)).toBe('1.2m');
|
||||
expect(format.formatLongNumber(575000)).toBe('575k');
|
||||
expect(format.formatLongNumber(10500)).toBe('10.5k');
|
||||
expect(format.formatLongNumber(1200)).toBe('1.20k');
|
||||
});
|
||||
|
||||
test('stringToColor', () => {
|
||||
expect(format.stringToColor('hello')).toBe('#d218e9');
|
||||
expect(format.stringToColor('goodbye')).toBe('#11e956');
|
||||
});
|
@ -39,5 +39,5 @@
|
||||
]
|
||||
},
|
||||
"include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "next-env.d.ts", ".next/types/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
"exclude": ["node_modules", "./cypress.config.ts", "cypress"]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user