Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 31, 2025

The extension had no proper test coverage. This PR adds 20 unit tests covering the testable pure functions and data structures.

Tests Added

Utils (8 tests)

  • stripAnsi() - ANSI escape code removal
  • isLibPathWriteable() - directory permission checking
  • waitForFile() - async file existence with timeout

Sidebar (7 tests)

  • SidebarProvider - package storage, filtering, max length calculations
  • RPackageItem - tree item creation for System/User/renv package types
  • Fuzzy search and placeholder display logic

Events (1 test)

  • Code pattern detection for library(), require(), p_load(), detach()

Example

test('stripAnsi removes ANSI escape codes', () => {
  const textWithAnsi = '\x1b[31mError:\x1b[0m Something went wrong';
  const cleanText = stripAnsi(textWithAnsi);
  assert.strictEqual(cleanText, 'Error: Something went wrong');
});

test('RPackageItem creates proper tree item for renv package', () => {
  const pkg: RPackageInfo = {
    name: 'ggplot2',
    version: '3.4.0',
    libpath: '/project/renv/library',
    locationtype: 'renv',
    title: 'Grammar of Graphics',
    loaded: false
  };

  const item = new RPackageItem(pkg, 0, 0);
  assert.strictEqual(item.label, 'ggplot2');
  assert.ok(typeof item.description === 'string' && item.description.includes('renv'));
});

Tests focus on pure functions without R runtime or VS Code extension host dependencies for fast, reliable execution.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add tests</issue_title>
<issue_description>At the moment, we don't have any proper tests. Let's ask copilot to see if we can come up with any useful 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.

@kv9898 kv9898 marked this pull request as ready for review October 31, 2025 15:02
Copilot AI changed the title [WIP] Add unit tests for existing functionality Add unit tests for core extension functionality Oct 31, 2025
Copilot AI requested a review from kv9898 October 31, 2025 15:17
Copilot finished work on behalf of kv9898 October 31, 2025 15:17
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 tests

2 participants