Skip to content

Commit 8511250

Browse files
author
Wakidur Rahaman
committed
fix(queue-28): test env sutap
1 parent 870eb44 commit 8511250

File tree

8 files changed

+249
-9
lines changed

8 files changed

+249
-9
lines changed

.babelrc

Whitespace-only changes.

babel.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
presets: [
3+
["@babel/preset-env", { targets: { node: "current" } }],
4+
"@babel/preset-typescript",
5+
],
6+
};

data-structure/linked-list/linked-list-original.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import LinkedListNode from "./linked-list-node-original";
2-
import Comparator from "../../utils/comparator-original";
1+
import LinkedListNode from "./linked-list-node-original.js";
2+
import Comparator from "../../utils/comparator-original.js";
33

44
export default class LinkedList {
55
/**

data-structure/queue/queue-original.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import LinkedList from "../linked-list/linked-list-original";
1+
import LinkedList from "../linked-list/linked-list-original.js";
22

33
export default class Queue {
44
constructor() {
@@ -59,3 +59,10 @@ export default class Queue {
5959
return this.linkedList.toString(callback);
6060
}
6161
}
62+
63+
const queue = new Queue();
64+
65+
queue.enqueue(1);
66+
queue.enqueue(2);
67+
68+
console.log(queue);

jest.config.ts

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

package.json

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,42 @@
11
{
2-
"name": "npm",
3-
"version": "1.0.0",
4-
"description": "JavaScript based examples of many algorithms and data structures. Note that this repository is meant to be used for learning and researching purposes only.",
2+
"name": "javascript-algorithms-and-data-structures",
3+
"version": "0.0.1",
4+
"description": "JavaScript based data-structures and Algorithms",
55
"main": "index.js",
66
"scripts": {
7-
"test": ""
7+
"test": "jest",
8+
"coverage": "npm run test -- --coverage"
89
},
910
"repository": {
1011
"type": "git",
1112
"url": "git+https://github.com/wakidurrahman/JavaScript-Algorithms-And-Data-Structures.git"
1213
},
1314
"keywords": [
14-
"prictice"
15+
"algorithms",
16+
"data-structures",
17+
"javascript",
18+
"algorithm",
19+
"javascript-algorithms"
1520
],
16-
"author": "wakidurrahman",
21+
"author": "Wakidur Rahman",
1722
"license": "ISC",
1823
"bugs": {
1924
"url": "https://github.com/wakidurrahman/JavaScript-Algorithms-And-Data-Structures/issues"
2025
},
2126
"homepage": "https://github.com/wakidurrahman/JavaScript-Algorithms-And-Data-Structures#readme",
2227
"devDependencies": {
28+
"@babel/core": "^7.19.1",
29+
"@babel/preset-env": "^7.19.1",
30+
"@babel/preset-typescript": "^7.18.6",
31+
"@types/jest": "^29.0.3",
32+
"babel-jest": "^29.0.3",
33+
"jest": "^29.0.3",
34+
"ts-jest": "^29.0.2",
35+
"ts-node": "^10.9.1",
2336
"typescript": "^4.8.3"
37+
},
38+
"engines": {
39+
"node": ">=16.13.2",
40+
"npm": ">=8.1.2"
2441
}
2542
}

sum.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { describe, expect, test } from "@jest/globals";
2+
import { sum } from "./sum";
3+
4+
describe("sum module", () => {
5+
test("adds 1 + 2 to equal 3", () => {
6+
expect(sum(1, 2)).toBe(3);
7+
});
8+
});

sum.ts

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

0 commit comments

Comments
 (0)