Skip to content

Add Jest test suite for MapTyper class#7

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/add-tests
Draft

Add Jest test suite for MapTyper class#7
Copilot wants to merge 3 commits intomainfrom
copilot/add-tests

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 13, 2026

No test coverage existed for the MapTyper class. Added comprehensive unit tests.

Changes

  • Test suite: 19 tests covering MapTyper functionality (91% statement coverage)

    • Constructor validation and parameter handling
    • Async font initialization with callbacks
    • Text-to-GeoJSON conversion pipeline
    • SVG generation and parsing
    • Bounds calculation
  • Test infrastructure: Jest with Babel transpilation for ES modules

    • Mocks for external dependencies (text-to-svg, svg-to-geojson, @turf/buffer)
    • Coverage reporting configured
  • Scripts: npm test, npm run test:watch, npm run test:coverage

Example

// Constructor validation
expect(() => new MapTyper()).toThrow('Font required');
expect(() => new MapTyper(null)).toThrow('Font required');

// Async initialization with callback
const typer = new MapTyper('/fonts/font.ttf', 72, (loaded) => {
  const geojson = loaded.textToFeatures('Hello');
  // Returns GeoJSON FeatureCollection
});
Original prompt

This section details on the original issue you should resolve

<issue_title>add tests</issue_title>
<issue_description></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.

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 13, 2026

Deploy Preview for inquisitive-praline-20c1ca ready!

Name Link
🔨 Latest commit 42ed4c3
🔍 Latest deploy log https://app.netlify.com/projects/inquisitive-praline-20c1ca/deploys/698f73a5cdb12100086ef5d5
😎 Deploy Preview https://deploy-preview-7--inquisitive-praline-20c1ca.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 13, 2026

Deploy Preview for maptyper ready!

Name Link
🔨 Latest commit 42ed4c3
🔍 Latest deploy log https://app.netlify.com/projects/maptyper/deploys/698f73a593791b00084e17cc
😎 Deploy Preview https://deploy-preview-7--maptyper.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI and others added 2 commits February 13, 2026 18:53
Co-authored-by: yuletide <58695+yuletide@users.noreply.github.com>
Co-authored-by: yuletide <58695+yuletide@users.noreply.github.com>
Copilot AI changed the title [WIP] Add tests for the existing codebase Add Jest test suite for MapTyper class Feb 13, 2026
Copilot AI requested a review from yuletide February 13, 2026 18:58
@yuletide yuletide requested review from Copilot and removed request for yuletide February 13, 2026 19:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive test coverage for the MapTyper class, which previously had no tests. The test suite includes 19 tests covering constructor validation, async font initialization, text-to-GeoJSON conversion, SVG generation, and bounds calculation. The PR also establishes the test infrastructure using Jest with Babel transpilation for ES modules.

Changes:

  • Added comprehensive test suite for MapTyper class with 19 tests covering core functionality
  • Set up Jest testing infrastructure with Babel transpilation for ES module support
  • Added test scripts (test, test:watch, test:coverage) and configured coverage collection
  • Updated .gitignore to exclude node_modules and coverage directories

Reviewed changes

Copilot reviewed 3 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/maptyper.test.js New test file with 19 tests covering MapTyper constructor, font initialization, text conversion, SVG generation, bounds calculation, and options configuration
package.json Added Jest 30.x, Babel, and related test dependencies; configured test scripts
jest.config.js New Jest configuration with jsdom environment, Babel transform, and coverage settings
babel.config.js New Babel configuration for ES module transpilation in tests
.gitignore Added node_modules and coverage to ignored files

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

await new Promise((resolve) => setTimeout(resolve, 10));

expect(callback).toHaveBeenCalledWith(typer);
});
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests do not cover error handling when font loading fails. The MapTyper.initFont method has error handling that rejects the promise with an error message when TextToSVG.load fails (line 56 in maptyper.js: reject('Error loading font ' + err)), but there are no tests that verify this behavior. Add a test case that mocks TextToSVG.load to call the callback with an error and verify that the promise is properly rejected.

Suggested change
});
});
test('should reject when font loading fails', async () => {
// Access the mocked text-to-svg module
const TextToSVG = require('text-to-svg').default;
const loadError = new Error('load failed');
// For this test, make load call its callback with an error
TextToSVG.load.mockImplementationOnce((fontPath, callback) => {
callback(loadError);
});
await expect(MapTyper.initFont('/bad/font.ttf')).rejects.toMatch(
'Error loading font'
);
});

Copilot uses AI. Check for mistakes.
Comment on lines +124 to +173
describe('textToFeatures', () => {
test('should convert text to GeoJSON features after font loads', async () => {
const typer = new MapTyper('/path/to/font.ttf');

// Wait for font to load
await new Promise((resolve) => setTimeout(resolve, 10));

const result = typer.textToFeatures('Hello');

expect(result).toBeDefined();
expect(result.type).toBe('FeatureCollection');
expect(result.features).toBeInstanceOf(Array);
});

test('should handle empty text', async () => {
const typer = new MapTyper('/path/to/font.ttf');

// Wait for font to load
await new Promise((resolve) => setTimeout(resolve, 10));

const result = typer.textToFeatures('');

expect(result).toBeDefined();
expect(result.type).toBe('FeatureCollection');
});

test('should handle text with whitespace', async () => {
const typer = new MapTyper('/path/to/font.ttf');

// Wait for font to load
await new Promise((resolve) => setTimeout(resolve, 10));

const result = typer.textToFeatures('Hello World');

expect(result).toBeDefined();
expect(result.type).toBe('FeatureCollection');
});

test('should handle special characters', async () => {
const typer = new MapTyper('/path/to/font.ttf');

// Wait for font to load
await new Promise((resolve) => setTimeout(resolve, 10));

const result = typer.textToFeatures('Hello! @#$%');

expect(result).toBeDefined();
expect(result.type).toBe('FeatureCollection');
});
});
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests do not cover the scenario where textToFeatures is called before the font is loaded. The MapTyper.textToFeatures method has special handling for this case (lines 102-106 in maptyper.js), logging an error and attempting to return a promise. However, there are no tests that verify this behavior. Add a test that calls textToFeatures immediately after construction (before the font loads) to ensure this edge case is properly handled.

Copilot uses AI. Check for mistakes.
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

3 participants