Skip to content

Add unit tests for lib modules with Contentful mocking - #82

Draft
tharders with Copilot wants to merge 10 commits into
mainfrom
copilot/add-unit-tests-for-lib-modules
Draft

Add unit tests for lib modules with Contentful mocking#82
tharders with Copilot wants to merge 10 commits into
mainfrom
copilot/add-unit-tests-for-lib-modules

Conversation

Copilot AI commented Jan 23, 2026

Copy link
Copy Markdown

Added unit tests for 8 modules lacking coverage in the lib folder. All Contentful SDK calls are mocked to enable isolated testing.

Modules Tested

  • backend.js - Migration storage (tag/content), version tracking
  • config.js - Configuration loading, confirmation prompts
  • contentful.js - API utilities (ID extraction, content naming)
  • diff.js - Content comparison across all field types
  • environment.js - Environment CRUD operations
  • helpers/locale.js - Locale detection and defaults
  • tree.js - Content tree building with circular reference handling
  • version.js - Version add/delete operations

Test Coverage

  • 129 tests across 10 suites
  • Error paths extensively covered per requirements
  • Console output mocked using jest.spyOn for proper test isolation

Modules Not Tested

Three modules use dynamic imports incompatible with Jest without --experimental-vm-modules:

  • doc.js - imports markdown-table dynamically
  • migration.js - imports contentful-migration and executes external CLI
  • content.js - complex integration with inquirer and contentful-import

These would require either refactoring for testability or integration test approach.

Example Test Pattern

// Mock Contentful SDK
jest.mock('./contentful');

describe('storeMigration', () => {
  beforeEach(() => {
    mockClient.getTag.mockResolvedValue({ name: '100', update: jest.fn() });
  });

  it('should create new tag when tag does not exist', async () => {
    mockClient.getTag.mockRejectedValue(new Error('Not found'));
    await storeMigration({ version: 123, state: STATE_SUCCESS }, mockConfig);
    expect(mockClient.createTag).toHaveBeenCalledWith('migration', '123');
  });
});
Original prompt

This section details on the original issue you should resolve

<issue_title>Add unit tests</issue_title>
<issue_description>Currently the project has a unit test setup, but only very few functions are actually tested.

We need to add unit tests for most of the modules in the lib folder.
The unit tests should mock the calls to all imported packages that are Contentful related.
Loggin does not need to be tested.
But especially the error cases need to be covered by the unit tests.

</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 6 commits January 23, 2026 10:03
Co-authored-by: tharders <6458408+tharders@users.noreply.github.com>
Co-authored-by: tharders <6458408+tharders@users.noreply.github.com>
Co-authored-by: tharders <6458408+tharders@users.noreply.github.com>
Co-authored-by: tharders <6458408+tharders@users.noreply.github.com>
Co-authored-by: tharders <6458408+tharders@users.noreply.github.com>
Co-authored-by: tharders <6458408+tharders@users.noreply.github.com>
Copilot AI changed the title [WIP] Add unit tests for lib folder modules Add unit tests for lib modules with Contentful mocking Jan 23, 2026
Copilot AI requested a review from tharders January 23, 2026 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests

2 participants