Skip to content

Commit 48b3830

Browse files
author
Wakidur Rahaman
committed
add test sample
1 parent 8511250 commit 48b3830

32 files changed

+58
-49
lines changed

.babelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["@babel/preset-env"]
3+
}
4+

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16.13.2

jest.config.ts

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* For a detailed explanation regarding each configuration property and type check, visit:
33
* https://jestjs.io/docs/configuration
44
*/
5-
5+
const { resolve } = require("path");
66
export default {
77
// All imported modules in your tests should be mocked automatically
88
// automock: false,
@@ -70,7 +70,10 @@ export default {
7070
// globalTeardown: undefined,
7171

7272
// A set of global variables that need to be available in all test environments
73-
// globals: {},
73+
globals: {
74+
URL: "http://localhost:8080",
75+
window: {},
76+
},
7477

7578
// 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.
7679
// maxWorkers: "50%",
@@ -81,16 +84,7 @@ export default {
8184
// ],
8285

8386
// An array of file extensions your modules use
84-
// moduleFileExtensions: [
85-
// "js",
86-
// "mjs",
87-
// "cjs",
88-
// "jsx",
89-
// "ts",
90-
// "tsx",
91-
// "json",
92-
// "node"
93-
// ],
87+
moduleFileExtensions: ["js", "ts"],
9488

9589
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
9690
// moduleNameMapper: {},
@@ -105,7 +99,7 @@ export default {
10599
// notifyMode: "failure-change",
106100

107101
// A preset that is used as a base for Jest's configuration
108-
// preset: undefined,
102+
preset: "ts-jest",
109103

110104
// Run tests from one or more projects
111105
// projects: undefined,
@@ -126,12 +120,11 @@ export default {
126120
// restoreMocks: false,
127121

128122
// The root directory that Jest should scan for tests and modules within
129-
// rootDir: undefined,
123+
124+
rootDir: resolve(__dirname, "."),
130125

131126
// A list of paths to directories that Jest should use to search for files in
132-
// roots: [
133-
// "<rootDir>"
134-
// ],
127+
roots: ["<rootDir>/src"],
135128

136129
// Allows you to use a custom runner instead of Jest's default test runner
137130
// runner: "jest-runner",
@@ -149,7 +142,7 @@ export default {
149142
// snapshotSerializers: [],
150143

151144
// The test environment that will be used for testing
152-
// testEnvironment: "jest-environment-node",
145+
testEnvironment: "jest-environment-node",
153146

154147
// Options that will be passed to the testEnvironment
155148
// testEnvironmentOptions: {},
@@ -158,16 +151,13 @@ export default {
158151
// testLocationInResults: false,
159152

160153
// The glob patterns Jest uses to detect test files
161-
// testMatch: [
162-
// "**/__tests__/**/*.[jt]s?(x)",
163-
// "**/?(*.)+(spec|test).[tj]s?(x)"
164-
// ],
154+
testMatch: ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[tj]s?(x)"],
165155

166156
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
167157
testPathIgnorePatterns: ["<rootDir>/node_modules/", "<rootDir>/assets/"],
168158

169159
// The regexp pattern or array of patterns that Jest uses to detect test files
170-
testRegex: ["(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$"],
160+
// testRegex: "\\.test.(js|jsx|ts|tsx)$",
171161

172162
// This option allows the use of a custom results processor
173163
// testResultsProcessor: undefined,
@@ -176,13 +166,20 @@ export default {
176166
// testRunner: "jest-circus/runner",
177167

178168
// A map from regular expressions to paths to transformers
179-
// transform: undefined,
169+
transform: {
170+
"^.+\\.(ts|tsx)?$": "ts-jest",
171+
"^.+\\.[tj]sx?$": "babel-jest",
172+
transform_regex: [
173+
"ts-jest",
174+
{
175+
tsconfig: "tsconfig.json",
176+
babelrc: true,
177+
},
178+
],
179+
},
180180

181181
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
182-
// transformIgnorePatterns: [
183-
// "/node_modules/",
184-
// "\\.pnp\\.[^\\/]+$"
185-
// ],
182+
transformIgnorePatterns: ["/node_modules/", "\\.pnp\\.[^\\/]+$"],
186183

187184
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
188185
// unmockedModulePathPatterns: undefined,
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/sum.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export function sum(a, b) {
2+
return a + b;
3+
}
4+
// module.exports = sum;
File renamed without changes.
File renamed without changes.
File renamed without changes.

sum.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

tsconfig.json

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1212

1313
/* Language and Environment */
14-
"target": "es6", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15-
"lib": ["es2016.Array.Include", "es2016", "es6"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
14+
"target": "es5", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15+
"lib": ["es2016.Array.Include", "es2016", "es6", "esnext"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
// "jsx": "preserve", /* Specify what JSX code is generated. */
1717
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
1818
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
@@ -25,36 +25,36 @@
2525
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
2626

2727
/* Modules */
28-
"module": "commonjs", /* Specify what module code is generated. */
29-
// "rootDir": "./", /* Specify the root folder within your source files. */
30-
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
31-
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
28+
"module": "esnext", /* Specify what module code is generated. */
29+
"rootDir": "./", /* Specify the root folder within your source files. */
30+
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
31+
"baseUrl": "src", /* Specify the base directory to resolve non-relative module names. */
3232
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
3333
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
3434
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
3535
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
3636
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
3737
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
38-
// "resolveJsonModule": true, /* Enable importing .json files. */
38+
"resolveJsonModule": true, /* Enable importing .json files. */
3939
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
4040

4141
/* JavaScript Support */
42-
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
42+
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
4343
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
4444
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
4545

4646
/* Emit */
4747
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
4848
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
4949
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
50-
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
50+
"sourceMap": true, /* Create source map files for emitted JavaScript files. */
5151
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
5252
// "outDir": "./", /* Specify an output folder for all emitted files. */
53-
// "removeComments": true, /* Disable emitting comments. */
54-
// "noEmit": true, /* Disable emitting files from a compilation. */
53+
"removeComments": true, /* Disable emitting comments. */
54+
"noEmit": true, /* Disable emitting files from a compilation. */
5555
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
5656
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
57-
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
57+
"downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
5858
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
5959
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
6060
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
@@ -69,15 +69,15 @@
6969
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
7070

7171
/* Interop Constraints */
72-
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
73-
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
72+
"isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
73+
"allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
7474
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
7575
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
7676
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
7777

7878
/* Type Checking */
7979
"strict": true, /* Enable all strict type-checking options. */
80-
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
80+
"noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
8181
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
8282
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
8383
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
@@ -89,15 +89,22 @@
8989
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
9090
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
9191
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
92-
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
92+
"noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
9393
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
9494
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
9595
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
9696
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
9797
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
9898

9999
/* Completeness */
100-
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
100+
"skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
101101
"skipLibCheck": true /* Skip type checking all .d.ts files. */
102+
},
103+
"include": ["src"],
104+
"exclude": ["node_modules", "assets",],
105+
"ts-node": {
106+
"compilerOptions": {
107+
"module": "CommonJS"
108+
}
102109
}
103110
}

0 commit comments

Comments
 (0)