Skip to content

Implement OpenTracing-like tracer #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This library provides a JavaScript/TypeScript logger inspired by Python's logger

* Simple logging with default handlers supporting `console.log`, `console.error`, and `process.stderr`.
* Fast, logging level checks or log filters are applied **before** log records are created
* Complex log records properties ssupport lazy evaluation, so they evaluated only when they need to be rendered
* Complex log records properties support lazy evaluation, so they evaluated only when they need to be rendered
* Flexible composition of loggers, handlers and formatters
* Custom formatting using template literals
* Supports structured logging through a JSON formatter
Expand Down
73 changes: 34 additions & 39 deletions jest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
import path from 'node:path';
import url from 'node:url';
import tsconfigJSON from './tsconfig.json' assert { type: "json" };
import tsconfigJSON from './tsconfig.json' assert { type: 'json' };

const projectPath = path.dirname(url.fileURLToPath(import.meta.url));

// Global variables that are shared across the jest worker pool
// These variables must be static and serializable
const globals = {
// Absolute directory to the project root
projectDir: projectPath,
// Absolute directory to the test root
testDir: path.join(projectPath, 'tests'),
// Default asynchronous test timeout
defaultTimeout: 20000,
// Timeouts rely on setTimeout which takes 32 bit numbers
maxTimeout: Math.pow(2, 31) - 1,
};

// The `globalSetup` and `globalTeardown` cannot access the `globals`
// They run in their own process context
// They can however receive the process environment
// Use `process.env` to set variables

const config = {
testEnvironment: 'node',
verbose: true,
Expand All @@ -30,55 +19,61 @@ const config = {
coverageDirectory: '<rootDir>/tmp/coverage',
roots: ['<rootDir>/tests'],
testMatch: ['**/?(*.)+(spec|test|unit.test).+(ts|tsx|js|jsx)'],

// Use SWC to transpile TS/JS/TSX
transform: {
"^.+\\.(t|j)sx?$": [
"@swc/jest",
'^.+\\.(t|j)sx?$': [
'@swc/jest',
{
jsc: {
parser: {
syntax: "typescript",
syntax: 'typescript',
tsx: true,
decorators: tsconfigJSON.compilerOptions.experimentalDecorators,
dynamicImport: true,
},
target: tsconfigJSON.compilerOptions.target.toLowerCase(),
keepClassNames: true,
},
}
module: {
type: 'es6', // Crucial for ESM-style imports
},
},
],
},

// Required to treat TS/TSX as ESM in Jest
extensionsToTreatAsEsm: ['.ts', '.tsx', '.mts'],

moduleNameMapper: {
// Remove `.js` extension from relative imports in source like `./foo.js` → `./foo`
'^(\\.{1,2}/.*)\\.js$': '$1',
},

reporters: [
'default',
['jest-junit', {
outputDirectory: '<rootDir>/tmp/junit',
classNameTemplate: '{classname}',
ancestorSeparator: ' > ',
titleTemplate: '{title}',
addFileAttribute: 'true',
reportTestSuiteErrors: 'true',
}],
[
'jest-junit',
{
outputDirectory: '<rootDir>/tmp/junit',
classNameTemplate: '{classname}',
ancestorSeparator: ' > ',
titleTemplate: '{title}',
addFileAttribute: 'true',
reportTestSuiteErrors: 'true',
},
],
],

collectCoverageFrom: ['src/**/*.{ts,tsx,js,jsx}', '!src/**/*.d.ts'],
coverageReporters: ['text', 'cobertura'],

globals,
// Global setup script executed once before all test files

globalSetup: '<rootDir>/tests/globalSetup.ts',
// Global teardown script executed once after all test files
globalTeardown: '<rootDir>/tests/globalTeardown.ts',
// Setup files are executed before each test file
// Can access globals
setupFiles: ['<rootDir>/tests/setup.ts'],
// Setup files after env are executed before each test file
// after the jest test environment is installed
// Can access globals
setupFilesAfterEnv: [
'jest-extended/all',
'<rootDir>/tests/setupAfterEnv.ts'
],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
extensionsToTreatAsEsm: ['.ts', '.tsx', '.mts'],
setupFilesAfterEnv: ['jest-extended/all', '<rootDir>/tests/setupAfterEnv.ts'],
};

export default config;
Loading