Skip to content

Commit cac3a95

Browse files
authored
Adding jest tests (#617)
* Adding jest tests * adding more jest * more tests * fixing dependencies
1 parent 58ab103 commit cac3a95

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+6919
-2453
lines changed

.github/workflows/publish-to-vscode.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# This is a basic workflow to help you get started with Actions
22
name: 📦 Publish To Vscode
33

4+
env:
5+
FORCE_COLOR: true
6+
47
on:
58
workflow_dispatch:
69
push:

.github/workflows/pull-request.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
33
name: PR
44

5+
env:
6+
FORCE_COLOR: true
7+
58
on:
69
pull_request: {}
710
workflow_dispatch: {}

.github/workflows/unit-test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# This is a basic workflow to help you get started with Actions
22
name: 📋 Unit Test
33

4+
env:
5+
FORCE_COLOR: true
6+
47
on:
58
workflow_dispatch: {}
69
workflow_call: {}
@@ -35,4 +38,3 @@ jobs:
3538
run: |
3639
npx vsce package
3740
echo "Size of package: $(du -h *.vsix | cut -f1)" >> $GITHUB_STEP_SUMMARY
38-

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dist/
88
log.txt
99
out
1010
node_modules
11+
coverage
1112
client/server
1213
.vscode-test
1314
/documentation/cheat-sheet/*.html

.mocharc.json

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

.vscodeignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ CONTRIBUTING.md
3131
contributing.mdp
3232
Debugging.md
3333
documentation/**
34+
server/coverage/**
35+
client/coverage/**
3436
log.txt
3537
minecraft colours.json
3638
NOTE.md
@@ -53,6 +55,7 @@ webpack.config.js
5355
**/webpack.config.js
5456
**/package-lock.json
5557

58+
5659
!documentation/cheat-sheet
5760
!documentation/cheat-sheet/*html
5861
!media/**/*

client/.mocharc.json

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

client/jest.config.ts

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

client/package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"scripts": {
1717
"compile": "tsc -b ./tsconfig.json",
1818
"pretest": "npm run compile",
19-
"test": "mocha -r ts-node/register '**/*.test.ts'",
19+
"test": "jest",
2020
"update": "npm update && npm audit fix"
2121
},
2222
"engines": {
@@ -30,13 +30,11 @@
3030
"vscode-languageclient": "^9.0.1"
3131
},
3232
"devDependencies": {
33-
"@types/chai": "^4.3.9",
34-
"@types/mocha": "^10.0.3",
35-
"@types/node": "^20.14.2",
33+
"@types/jest": "^29.5.12",
34+
"@types/node": "^20.14.11",
3635
"@types/vscode": "^1.90.0",
37-
"chai": "^4.3.10",
3836
"json-loader": "^0.5.7",
39-
"mocha": "^10.1.0",
37+
"ts-jest": "^29.2.2",
4038
"ts-loader": "^9.4.4",
4139
"ts-node": "^10.9.2",
4240
"typescript": "^5.5.3",

client/src/constants.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { expect } from "chai";
21
import { Languages, ToolIdentification } from "@blockception/shared";
32

43
describe("Constants", () => {
54
it("values", () => {
6-
expect(Languages.McFunctionIdentifier).to.equal(Languages.McFunctionIdentifier.toLowerCase());
5+
expect(Languages.McFunctionIdentifier).toEqual(Languages.McFunctionIdentifier.toLowerCase());
76
});
87

98
it("Tool Identification", () => {
10-
expect(ToolIdentification.length).to.be.lessThanOrEqual(32);
9+
expect(ToolIdentification.length).toBeLessThanOrEqual(32);
1110
});
1211
});

client/tsconfig.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"compilerOptions": {
33
"alwaysStrict": true,
4-
"baseUrl": ".",
54
"esModuleInterop": true,
5+
"forceConsistentCasingInFileNames": true,
6+
"baseUrl": ".",
67
"lib": ["ES2019"],
78
"module": "commonjs",
89
"moduleResolution": "node",
@@ -20,10 +21,9 @@
2021
"strictNullChecks": true,
2122
"strictPropertyInitialization": true,
2223
"target": "es2019",
23-
"types": ["node", "mocha"],
24-
"forceConsistentCasingInFileNames": true
24+
"types": ["node", "jest"]
2525
},
26-
"exclude": ["node_modules", ".vscode-test", "*.test.ts"],
26+
"exclude": ["node_modules", ".vscode-test", "*.test.ts", "__tests__"],
2727
"include": ["./src"],
2828
"references": [
2929
{ "path": "../shared" }

0 commit comments

Comments
 (0)