diff --git a/packages/core/database/src/__tests__/collection-importer.test.ts b/packages/core/database/src/__tests__/collection-importer.test.ts index 0a9bcf8c8..e9d3c6399 100644 --- a/packages/core/database/src/__tests__/collection-importer.test.ts +++ b/packages/core/database/src/__tests__/collection-importer.test.ts @@ -7,7 +7,19 @@ describe('collection importer', () => { const reader = new ImporterReader(path.resolve(__dirname, './fixtures/collections')); const modules = await reader.read(); - expect(modules).toBeDefined(); + + const posts = modules.find((m) => m.name === 'posts'); + + expect(posts).toMatchObject({ + name: 'posts', + fields: [{ type: 'string', name: 'title' }], + }); + + posts.schema = 'test'; + + const modules2 = await reader.read(); + const posts2 = modules2.find((m) => m.name === 'posts'); + expect(posts2.schema).toBeFalsy(); }); test('extend', async () => { diff --git a/packages/core/database/src/collection-importer.ts b/packages/core/database/src/collection-importer.ts index 2dcae4e45..1d1a78a29 100644 --- a/packages/core/database/src/collection-importer.ts +++ b/packages/core/database/src/collection-importer.ts @@ -1,6 +1,6 @@ import path from 'path'; import { readdir } from 'fs/promises'; -import { isPlainObject } from 'lodash'; +import { cloneDeep, isPlainObject } from 'lodash'; import { requireModule } from '@nocobase/utils'; export type ImportFileExtension = 'js' | 'ts' | 'json'; @@ -36,6 +36,6 @@ export class ImporterReader { return typeof mod === 'function' ? mod() : mod; }); - return (await Promise.all(modules)).filter((module) => isPlainObject(module)); + return (await Promise.all(modules)).filter((module) => isPlainObject(module)).map((module) => cloneDeep(module)); } }