feat: add Jest configuration and basic framework tests
This commit is contained in:
parent
f58fa0caf7
commit
071723f673
18
jest.config.cjs
Normal file
18
jest.config.cjs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
module.exports = {
|
||||||
|
preset: 'ts-jest',
|
||||||
|
testEnvironment: 'node',
|
||||||
|
roots: ['<rootDir>/tests'],
|
||||||
|
testMatch: ['**/__tests__/**/*.ts', '**/?(*.)+(spec|test).ts'],
|
||||||
|
transform: {
|
||||||
|
'^.+\\.ts$': [
|
||||||
|
'ts-jest',
|
||||||
|
{
|
||||||
|
isolatedModules: true
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
collectCoverageFrom: ['src/**/*.ts', '!src/**/*.d.ts', '!src/**/index.ts', '!src/examples/**'],
|
||||||
|
coverageDirectory: 'coverage',
|
||||||
|
coverageReporters: ['text', 'lcov', 'html'],
|
||||||
|
testTimeout: 30000,
|
||||||
|
};
|
@ -1,34 +0,0 @@
|
|||||||
export default {
|
|
||||||
preset: 'ts-jest/presets/default-esm',
|
|
||||||
extensionsToTreatAsEsm: ['.ts'],
|
|
||||||
testEnvironment: 'node',
|
|
||||||
roots: ['<rootDir>/src', '<rootDir>/tests'],
|
|
||||||
testMatch: [
|
|
||||||
'**/__tests__/**/*.ts',
|
|
||||||
'**/?(*.)+(spec|test).ts'
|
|
||||||
],
|
|
||||||
transform: {
|
|
||||||
'^.+\\.ts$': ['ts-jest', {
|
|
||||||
useESM: true
|
|
||||||
}],
|
|
||||||
},
|
|
||||||
collectCoverageFrom: [
|
|
||||||
'src/**/*.ts',
|
|
||||||
'!src/**/*.d.ts',
|
|
||||||
'!src/**/index.ts',
|
|
||||||
'!src/examples/**',
|
|
||||||
],
|
|
||||||
coverageDirectory: 'coverage',
|
|
||||||
coverageReporters: [
|
|
||||||
'text',
|
|
||||||
'lcov',
|
|
||||||
'html'
|
|
||||||
],
|
|
||||||
setupFilesAfterEnv: ['<rootDir>/tests/setup.ts'],
|
|
||||||
testTimeout: 30000,
|
|
||||||
moduleNameMapping: {
|
|
||||||
'^@/(.*)$': '<rootDir>/src/$1',
|
|
||||||
'^@orbitdb/core$': '<rootDir>/tests/mocks/orbitdb.ts',
|
|
||||||
'^@helia/helia$': '<rootDir>/tests/mocks/ipfs.ts',
|
|
||||||
},
|
|
||||||
};
|
|
@ -87,14 +87,5 @@
|
|||||||
"tsc-esm-fix": "^3.1.2",
|
"tsc-esm-fix": "^3.1.2",
|
||||||
"typescript": "^5.8.2",
|
"typescript": "^5.8.2",
|
||||||
"typescript-eslint": "^8.29.0"
|
"typescript-eslint": "^8.29.0"
|
||||||
},
|
|
||||||
"compilerOptions": {
|
|
||||||
"typeRoots": [
|
|
||||||
"./node_modules/@types",
|
|
||||||
"./node_modules/@constl/orbit-db-types"
|
|
||||||
],
|
|
||||||
"types": [
|
|
||||||
"@constl/orbit-db-types"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
22
tests/basic.test.ts
Normal file
22
tests/basic.test.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { describe, it, expect } from '@jest/globals';
|
||||||
|
|
||||||
|
describe('Basic Framework Test', () => {
|
||||||
|
it('should be able to run tests', () => {
|
||||||
|
expect(1 + 1).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate test infrastructure', () => {
|
||||||
|
const mockFunction = jest.fn();
|
||||||
|
mockFunction('test');
|
||||||
|
expect(mockFunction).toHaveBeenCalledWith('test');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle async operations', async () => {
|
||||||
|
const asyncFunction = async () => {
|
||||||
|
return Promise.resolve('success');
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = await asyncFunction();
|
||||||
|
expect(result).toBe('success');
|
||||||
|
});
|
||||||
|
});
|
Reference in New Issue
Block a user