Update configuration based on team requirements
Custom reporter to have a sense of test exec progress
Do not use Jest console
Move jest config files in test folder
Adapted all npm endpoints due to above modifications
MODIFY
.vscode/launch.json
.vscode/launch.json
"args": [
"--i",
"--runInBand",
+ "--config='./test/jest.config.ts'",
+ "--reporters='default'",
+ "--reporters='./JestEvseReporter'",
"--watchAll=false",
],
"cwd": "${workspaceFolder}",

MODIFY
package.json
package.json
"npm-check": "npm-check",
"check:i18n": "cross-env TS_NODE_FILES=true ts-node-dev --files test/I18nChecker.ts",
"import-sort": "npx import-sort-cli --write 'src/**/*.ts{,x}' 'test/**/*.ts{,x}' 'types/**/*.ts{,x}'",
- "test": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent --forceExit --testPathIgnorePatterns='.*Runner.ts$'",
- "test:createContext": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent --forceExit -- ContextBuilderRunner.ts",
- "test:asset": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent -- test/**/AssetTest.ts",
- "test:authentication": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent -- test/**/AuthenticationTest.ts",
- "test:billing": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent -- test/**/BillingTest.ts",
- "test:car": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent -- test/**/CarTest.ts",
- "test:company": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent -- test/**/Company*Test.ts",
- "test:componentActivation": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent -- test/**/ComponentActivation*Test.ts",
- "test:crypto": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent -- test/**/EncryptionSettingTest.ts",
- "test:filter": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent -- test/**/FilterTest.ts",
- "test:firmwareUpdateStatus": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent --forceExit -- test/**/FirmwareUpdateStatusTest.ts",
- "test:locking": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent --forceExit -- test/**/LockingTest.ts",
- "test:ocpi": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent -- test/**/OCPIServerTest.ts",
- "test:ocpp": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent --forceExit -- test/**/OCPP*Test.ts",
- "test:oicp": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent -- test/**/OICP*Test.ts",
- "test:registrationToken": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent -- test/**/RegistrationTokenTest.ts",
- "test:security": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent --forceExit -- test/**/SecurityTest.ts",
- "test:setting": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent -- test/**/*SettingTest.ts",
- "test:site": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent test/**/Site*Test.ts",
- "test:smartCharging": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent --forceExit -- test/**/SmartChargingTest.ts",
- "test:stat": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent -- test/**/StatisticsTest.ts",
- "test:tag": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent --forceExit -- test/**/TagTest.ts",
- "test:tenant": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent -- test/**/*TenantTest.ts",
- "test:transaction": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent --forceExit -- test/**/TransactionTest.ts",
- "test:template": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent -- test/**/UnitTestTemplate.ts",
- "test:user": "npm version && cross-env TS_NODE_FILES=true jest --runInBand --logHeapUsage --verbose --colors --silent -- test/**/UserTest.ts"
+ "test": "npm version && cross-env TS_NODE_FILES=true jest --config='test/jest.config.ts' --reporters='default' --reporters='./JestEvseReporter.js' --runInBand --logHeapUsage --verbose --colors --silent --forceExit --testPathIgnorePatterns='.*Runner.ts$'",
+ "test:createContext": "npm version && cross-env TS_NODE_FILES=true jest --config='test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent --forceExit -- test/**/**/ContextBuilderRunner.ts",
+ "test:asset": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent -- test/**/AssetTest.ts",
+ "test:authentication": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent -- test/**/AuthenticationTest.ts",
+ "test:billing": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent -- test/**/BillingTest.ts",
+ "test:car": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent -- test/**/CarTest.ts",
+ "test:company": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent -- test/**/Company*Test.ts",
+ "test:componentActivation": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent -- test/**/ComponentActivation*Test.ts",
+ "test:crypto": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent -- test/**/EncryptionSettingTest.ts",
+ "test:filter": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent -- test/**/FilterTest.ts",
+ "test:firmwareUpdateStatus": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent --forceExit -- test/**/FirmwareUpdateStatusTest.ts",
+ "test:locking": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent --forceExit -- test/**/LockingTest.ts",
+ "test:ocpi": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent -- test/**/OCPIServerTest.ts",
+ "test:ocpp": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent --forceExit -- test/**/OCPP*Test.ts",
+ "test:oicp": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent -- test/**/OICP*Test.ts",
+ "test:registrationToken": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent -- test/**/RegistrationTokenTest.ts",
+ "test:security": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent --forceExit -- test/**/SecurityTest.ts",
+ "test:setting": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent -- test/**/*SettingTest.ts",
+ "test:site": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent test/**/Site*Test.ts",
+ "test:smartCharging": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent --forceExit -- test/**/SmartChargingTest.ts",
+ "test:stat": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent -- test/**/StatisticsTest.ts",
+ "test:tag": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent --forceExit -- test/**/TagTest.ts",
+ "test:tenant": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent -- test/**/*TenantTest.ts",
+ "test:transaction": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent --forceExit -- test/**/TransactionTest.ts",
+ "test:template": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent -- test/**/UnitTestTemplate.ts",
+ "test:user": "npm version && cross-env TS_NODE_FILES=true jest --config='./test/jest.config.ts' --runInBand --logHeapUsage --verbose --colors --silent -- test/**/UserTest.ts"
},
"dependencies": {
"ajv": "^8.6.3",

ADD
test/JestEvseReporter.js
+/**
+ * Class used by Jest runner, to display usefull information when test cases are performed
+ * Currently Jest is not able to nativly handle a custom reporter written in TS, please migrate when it does !
+ */
+class JestEvseReporter {
+ testInError = [];
+ testInSuccess = [];
+ testInUnknown = [];
+
+ /**
+ *
+ * Note there are other hoocks that we could override, please check base reporter implementation:
+ * https://github.com/facebook/jest/blob/fb10f7a95161f3d93ec54be3b3f69359913b5691/packages/jest-cli/src/reporters/base_reporter.js
+ *
+ */
+
+ /**
+ * Jest hoock
+ * @override
+ */
+ onTestStart(test) {
+ this.log(`\nRunning: ${test.path}`);
+ }
+
+ /**
+ * Jest hoock
+ * @override
+ */
+ onTestCaseResult(test, testCaseResult) {
+ const testPrintmessage = testCaseResult.title;
+ if (testCaseResult.status === 'passed') {
+ this.testInSuccess.push(testCaseResult);
+ this.log('\u2713 ' + testPrintmessage + this.getReportMessage());
+ } else if (testCaseResult.status === 'failed') {
+ this.log('');
+ this.testInError.push(testCaseResult);
+ this.log(testCaseResult.fullName);
+ this.log(testCaseResult.failureMessages);
+ this.log('\u2717 ' + testPrintmessage + this.getReportMessage());
+ this.log('');
+ this.log('#### Stack associated to this error is above ! ####');
+ this.log('\n');
+ } else {
+ this.testInUnknown.push(testCaseResult);
+ this.log('\u25E6 ' + testPrintmessage + this.getReportMessage());
+ }
+ }
+
+ /**
+ * Report message helper
+ * @returns string message
+ */
+ getReportMessage() {
+ if (this.testInError.length > 0) {
+ return ' #### Errors detected [' + this.testInSuccess.length + ' OK, ' + this.testInError.length + ' ERR, ' + this.testInUnknown.length + ' UNK' + ']';
+ }
+ return '';
+ }
+
+ /**
+ * Log helper
+ */
+ log(message) {
+ process.stderr.write(message + '\n');
+ }
+
+}
+module.exports = JestEvseReporter;

ADD
test/jest-setup.ts
+// Use plain old console insteqd of the jest one
+global.console = require('console');

RENAME
jest.config.ts
test/jest.config.ts
@@ -31,7 +31,7 @@ export default {
// ],
// Indicates which provider should be used to instrument code for coverage
- coverageProvider: "v8",
+ coverageProvider: 'v8',
// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
@@ -99,7 +99,7 @@ export default {
// projects: undefined,
// Use this configuration option to add custom reporters to Jest
- // reporters: undefined,
+ reporters: ['default', './JestEvseReporter.js'],
// Automatically reset mock state before every test
// resetMocks: false,
@@ -128,7 +128,7 @@ export default {
// setupFiles: [],
// A list of paths to modules that run some code to configure or set up the testing framework before each test
- // setupFilesAfterEnv: [],
+ setupFilesAfterEnv: ['./jest-setup.ts'],
// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,
@@ -137,7 +137,7 @@ export default {
// snapshotSerializers: [],
// The test environment that will be used for testing
- testEnvironment: "node",
+ testEnvironment: 'node',
// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},
@@ -147,7 +147,7 @@ export default {
// The glob patterns Jest uses to detect test files
testMatch: [
- "**/test/**/*Test.ts","**/test/**/*Runner.ts"
+ '**/test/**/*Test.ts', '**/test/**/*Runner.ts'
],
// testMatch: [
@@ -188,7 +188,7 @@ export default {
// unmockedModulePathPatterns: undefined,
// Indicates whether each individual test should be reported during the run
- verbose: true,
+ // verbose: true,
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],

Update configuration based on team requirements
- Custom reporter to have a sense of test exec progress
- Do not use Jest console
- Move jest config files in test folder
- Adapted all npm endpoints due to above modifications