Skip to content

Commit 4441e0f

Browse files
committed
✨ Add tests
1 parent c899bd0 commit 4441e0f

File tree

5 files changed

+215
-2
lines changed

5 files changed

+215
-2
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build
2+
/*.js

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"env": {
33
"es2021": true,
4-
"node": true
4+
"node": true,
5+
"jest": true
56
},
67
"settings": {
78
"import/resolver": {

jest.config.js

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
/* eslint-disable */
2+
// For a detailed explanation regarding each configuration property, visit:
3+
// https://jestjs.io/docs/en/configuration.html
4+
5+
module.exports = {
6+
// All imported modules in your tests should be mocked automatically
7+
// automock: false,
8+
9+
// Stop running tests after `n` failures
10+
// bail: 0,
11+
12+
// The directory where Jest should store its cached dependency information
13+
// cacheDirectory: "C:\\Users\\higor\\AppData\\Local\\Temp\\jest",
14+
15+
// Automatically clear mock calls and instances between every test
16+
clearMocks: true,
17+
18+
// Indicates whether the coverage information should be collected while executing the test
19+
// collectCoverage: false,
20+
21+
// An array of glob patterns indicating a set of files for which coverage information should be collected
22+
// collectCoverageFrom: undefined,
23+
24+
// The directory where Jest should output its coverage files
25+
// coverageDirectory: undefined,
26+
27+
// An array of regexp pattern strings used to skip coverage collection
28+
// coveragePathIgnorePatterns: [
29+
// "\\\\node_modules\\\\"
30+
// ],
31+
32+
// Indicates which provider should be used to instrument code for coverage
33+
coverageProvider: 'v8',
34+
35+
// A list of reporter names that Jest uses when writing coverage reports
36+
// coverageReporters: [
37+
// "json",
38+
// "text",
39+
// "lcov",
40+
// "clover"
41+
// ],
42+
43+
// An object that configures minimum threshold enforcement for coverage results
44+
// coverageThreshold: undefined,
45+
46+
// A path to a custom dependency extractor
47+
// dependencyExtractor: undefined,
48+
49+
// Make calling deprecated APIs throw helpful error messages
50+
// errorOnDeprecated: false,
51+
52+
// Force coverage collection from ignored files using an array of glob patterns
53+
// forceCoverageMatch: [],
54+
55+
// A path to a module which exports an async function that is triggered once before all test suites
56+
// globalSetup: undefined,
57+
58+
// A path to a module which exports an async function that is triggered once after all test suites
59+
// globalTeardown: undefined,
60+
61+
// A set of global variables that need to be available in all test environments
62+
// globals: {},
63+
64+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
65+
// maxWorkers: "50%",
66+
67+
// An array of directory names to be searched recursively up from the requiring module's location
68+
// moduleDirectories: [
69+
// "node_modules"
70+
// ],
71+
72+
// An array of file extensions your modules use
73+
// moduleFileExtensions: [
74+
// "js",
75+
// "json",
76+
// "jsx",
77+
// "ts",
78+
// "tsx",
79+
// "node"
80+
// ],
81+
82+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
83+
// moduleNameMapper: {},
84+
85+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
86+
// modulePathIgnorePatterns: [],
87+
88+
// Activates notifications for test results
89+
// notify: false,
90+
91+
// An enum that specifies notification mode. Requires { notify: true }
92+
// notifyMode: "failure-change",
93+
94+
// A preset that is used as a base for Jest's configuration
95+
preset: 'ts-jest',
96+
97+
// Run tests from one or more projects
98+
// projects: undefined,
99+
100+
// Use this configuration option to add custom reporters to Jest
101+
// reporters: undefined,
102+
103+
// Automatically reset mock state between every test
104+
// resetMocks: false,
105+
106+
// Reset the module registry before running each individual test
107+
// resetModules: false,
108+
109+
// A path to a custom resolver
110+
// resolver: undefined,
111+
112+
// Automatically restore mock state between every test
113+
// restoreMocks: false,
114+
115+
// The root directory that Jest should scan for tests and modules within
116+
// rootDir: undefined,
117+
118+
// A list of paths to directories that Jest should use to search for files in
119+
// roots: [
120+
// "<rootDir>"
121+
// ],
122+
123+
// Allows you to use a custom runner instead of Jest's default test runner
124+
// runner: "jest-runner",
125+
126+
// The paths to modules that run some code to configure or set up the testing environment before each test
127+
// setupFiles: [],
128+
129+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
130+
// setupFilesAfterEnv: [],
131+
132+
// The number of seconds after which a test is considered as slow and reported as such in the results.
133+
// slowTestThreshold: 5,
134+
135+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
136+
// snapshotSerializers: [],
137+
138+
// The test environment that will be used for testing
139+
testEnvironment: 'node',
140+
141+
// Options that will be passed to the testEnvironment
142+
// testEnvironmentOptions: {},
143+
144+
// Adds a location field to test results
145+
// testLocationInResults: false,
146+
147+
// The glob patterns Jest uses to detect test files
148+
// testMatch: [
149+
// "**/__tests__/**/*.[jt]s?(x)",
150+
// "**/?(*.)+(spec|test).[tj]s?(x)"
151+
// ],
152+
153+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
154+
// testPathIgnorePatterns: [
155+
// "\\\\node_modules\\\\"
156+
// ],
157+
158+
// The regexp pattern or array of patterns that Jest uses to detect test files
159+
// testRegex: [],
160+
161+
// This option allows the use of a custom results processor
162+
// testResultsProcessor: undefined,
163+
164+
// This option allows use of a custom test runner
165+
// testRunner: "jasmine2",
166+
167+
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
168+
// testURL: "http://localhost",
169+
170+
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
171+
// timers: "real",
172+
173+
// A map from regular expressions to paths to transformers
174+
// transform: undefined,
175+
176+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
177+
// transformIgnorePatterns: [
178+
// "\\\\node_modules\\\\",
179+
// "\\.pnp\\.[^\\\\]+$"
180+
// ],
181+
182+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
183+
// unmockedModulePathPatterns: undefined,
184+
185+
// Indicates whether each individual test should be reported during the run
186+
// verbose: undefined,
187+
188+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
189+
// watchPathIgnorePatterns: [],
190+
191+
// Whether to use watchman for file crawling
192+
// watchman: true,
193+
};

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
"scripts": {
77
"dev": "nodemon --watch \"src/\" --exec \"ts-node src/index.ts\" -e ts",
88
"build": "rimraf ./build && tsc",
9-
"start": "node build/index.js"
9+
"start": "node build/index.js",
10+
"test": "jest"
1011
},
1112
"dependencies": {
13+
"@types/jest": "^26.0.13",
1214
"cors": "^2.8.5",
1315
"dotenv": "^8.2.0",
1416
"express": "^4.17.1",
@@ -22,8 +24,10 @@
2224
"eslint": "^7.9.0",
2325
"eslint-config-airbnb-base": "^14.2.0",
2426
"eslint-plugin-import": "2.21.2",
27+
"jest": "^26.4.2",
2528
"nodemon": "^2.0.4",
2629
"rimraf": "^3.0.2",
30+
"ts-jest": "^26.3.0",
2731
"ts-node": "^9.0.0",
2832
"typescript": "^4.0.2"
2933
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import calcFactorial from '../../utils/calcFactorial';
2+
3+
describe('it should be able to calculate the factorial', () => {
4+
test('factorial of 4', () => {
5+
expect(calcFactorial(4)).toBe(BigInt(24));
6+
});
7+
test('factorial of 12', () => {
8+
expect(calcFactorial(12)).toBe(BigInt(479001600));
9+
});
10+
test('factorial of 5', () => {
11+
expect(calcFactorial(5)).toBe(BigInt(120));
12+
});
13+
});

0 commit comments

Comments
 (0)