Added jest testing.

This commit is contained in:
Mike Cao 2024-03-01 13:25:32 -08:00
parent 2363b03d1c
commit 2a8437cac9
5 changed files with 1338 additions and 23 deletions

7
jest.config.ts Normal file
View File

@ -0,0 +1,7 @@
export default {
roots: ['./src'],
testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
};

View File

@ -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"
}

View 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');
});

View File

@ -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"]
}

1310
yarn.lock

File diff suppressed because it is too large Load Diff