Skip to content

Commit

Permalink
Silence logger by default (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
Siegrift authored Oct 1, 2023
1 parent a8e65d7 commit 284a447
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
7 changes: 5 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
const { join } = require('path');

/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/
module.exports = {
restoreMocks: true,
collectCoverage: true,
coverageDirectory: 'coverage',
coverageProvider: 'v8',
modulePathIgnorePatterns: ['<rootDir>/.build', '<rootDir>/dist/', '<rootDir>/build/'],
preset: 'ts-jest',
restoreMocks: true,
setupFiles: [join(__dirname, './jest.setup.js')],
testEnvironment: 'jest-environment-node',
modulePathIgnorePatterns: ['<rootDir>/.build', '<rootDir>/dist/', '<rootDir>/build/'],
};
20 changes: 20 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Sometimes Jest can have issues when trying to spy on an internal module. Import
// and use this function as a workaround at the top of your test.
//
// Credit: https://github.com/facebook/jest/issues/6914#issuecomment-654710111
const { defineProperty } = Object;

Object.defineProperty = function (object, name, meta) {
if (meta.get && !meta.configurable) {
// it might be an ES6 exports object
return defineProperty(object, name, {
...meta,
configurable: true, // prevent freezing
});
}

return defineProperty(object, name, meta);
};

// Disable logger if it is not explicitly set to true.
process.env.LOGGER_ENABLED = process.env.LOGGER_ENABLED || 'false';
12 changes: 12 additions & 0 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ the data in memory and provides endpoints to push and retrieve beacon data.
2. `cp .env.example .env` - To copy the example environment variables. Optionally change the defaults.
3. `pnpm run dev` - To start the API server. The port number can be configured in the configuration file.

### Testing

To run the tests:

```sh
pnpm run test
# or to run test only from a specific files (path substring search)
pnpm run test schema
# or to enable logger (by default the logger is disabled by jest.setup.js).
LOGGER_ENABLED=true pnpm run test
```

## Configuration

The API is configured via combination of [environment variables](#environment-variables) and
Expand Down
12 changes: 12 additions & 0 deletions packages/pusher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ To start the the pusher in dev mode run the following:
5. `pnpm run dev` - To run the pusher. This step assumes already running signed API as specified in the `pusher.json`
configuration.

### Testing

To run the tests:

```sh
pnpm run test
# or to run test only from a specific files (path substring search)
pnpm run test schema
# or to enable logger (by default the logger is disabled by jest.setup.js).
LOGGER_ENABLED=true pnpm run test
```

## Configuration

Pusher can be configured via a combination of [environment variables](#environment-variables) and
Expand Down

0 comments on commit 284a447

Please sign in to comment.