Skip to content

Commit 2e1cffc

Browse files
committed
添加队列单元测试
1 parent 9f793bc commit 2e1cffc

File tree

9 files changed

+4657
-3
lines changed

9 files changed

+4657
-3
lines changed

babel.config.js

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

jest.config.ts

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

main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
import './队列/queue'

package.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"type": "module",
32
"name": "algorithm",
43
"version": "1.0.0",
54
"description": "数据结构算法(javascript描述)",
65
"main": ".js",
76
"scripts": {
8-
"dev": "nodemon ./main.js --watch"
7+
"dev": "nodemon -w ./ --exec babel-node main.js",
8+
"test": "jest"
99
},
1010
"repository": {
1111
"type": "git",
@@ -19,6 +19,18 @@
1919
},
2020
"homepage": "https://github.com/wangjieCode/algorithm#readme",
2121
"devDependencies": {
22+
"@babel/core": "^7.14.3",
23+
"@babel/preset-env": "^7.14.4",
24+
"babel-jest": "^27.0.2",
25+
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
26+
"jest": "^27.0.3",
2227
"nodemon": "^2.0.7"
28+
},
29+
"dependencies": {
30+
"@babel/node": "^7.14.2",
31+
"@types/jest": "^26.0.23",
32+
"babel-node": "^0.0.1-security",
33+
"ts-node": "^10.0.0",
34+
"typescript": "^4.3.2"
2335
}
2436
}

test/queue.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Queue } from "../队列/queue"
2+
3+
4+
describe("测试队列class", () => {
5+
const queue = new Queue()
6+
test('基本入队出队', () => {
7+
// console.log( queue.enQueue({name: 1}))
8+
expect( queue.enQueue({name: 1}) ).toBe(1)
9+
expect( queue.size() ).toBe( 1 )
10+
queue.deQueue()
11+
expect( queue.size() ).toBe( 0 )
12+
})
13+
})

0 commit comments

Comments
 (0)