Skip to content

Commit cae4b4d

Browse files
committed
feat: add Jest configuration and mock for catalog model; update entity ref tests for improved error messages
1 parent f5b50b9 commit cae4b4d

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ dist
22
.yarn
33
node_modules
44
coverage
5+
__mocks__
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const CompoundEntityRef = {
2+
parse: (ref) => {
3+
// Simple mock implementation
4+
const parts = ref.split(':');
5+
if (parts.length === 2) {
6+
const [kind, rest] = parts;
7+
const [namespace, name] = rest.split('/');
8+
return { kind, namespace, name };
9+
}
10+
return null;
11+
},
12+
};
13+
14+
export const DEFAULT_NAMESPACE = 'default';

jest.config.js renamed to jest.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ export default {
55
extensionsToTreatAsEsm: ['.ts'],
66
moduleNameMapper: {
77
'^(\\.{1,2}/.*)\\.js$': '$1',
8+
'^@backstage/catalog-model$': '<rootDir>/__mocks__/@backstage/catalog-model.js',
89
},
910
transform: {
1011
'^.+\\.tsx?$': ['ts-jest', { useESM: true, tsconfig: 'tsconfig.spec.json' }],
1112
},
13+
transformIgnorePatterns: ['node_modules/(?!(@modelcontextprotocol)/)'],
1214
testPathIgnorePatterns: ['<rootDir>/dist/'],
1315
collectCoverageFrom: ['src/**/*.{ts,js}', '!src/**/*.spec.ts', '!src/**/*.test.ts', '!src/**/__fixtures__/**/*'],
16+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
1417
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"lint": "eslint 'src/**/*.ts' --ext .ts",
4444
"lint:fix": "prettier . --write && eslint 'src/**/*.ts' --ext .ts --fix",
4545
"start": "node dist/bundle.cjs",
46-
"test": "jest --coverage"
46+
"test": "NODE_OPTIONS=\"--experimental-vm-modules\" jest --coverage"
4747
},
4848
"types": "dist/index.d.ts",
4949
"version": "1.0.0"

src/utils/formatting/entity-ref.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('EntityRef', () => {
5555
});
5656

5757
it('should throw for invalid kind', () => {
58-
expect(() => EntityRef.parse('invalid:default/name')).toThrow('Invalid kind');
58+
expect(() => EntityRef.parse('invalid:default/name')).toThrow('Unknown entity kind');
5959
});
6060

6161
it('should throw for empty namespace in full format', () => {
@@ -87,7 +87,7 @@ describe('EntityRef', () => {
8787

8888
it('should throw for ref with invalid kind', () => {
8989
const ref = { kind: 'invalid', namespace: 'default', name: 'name' };
90-
expect(() => EntityRef.toString(ref)).toThrow('Invalid kind');
90+
expect(() => EntityRef.toString(ref)).toThrow('Unknown entity kind');
9191
});
9292

9393
it('should throw for ref with empty namespace', () => {

0 commit comments

Comments
 (0)