Skip to content

Conversation

@gauravarora
Copy link

@gauravarora gauravarora commented Oct 2, 2025

Summary

  • Addresses issue Type tests for Meteor packages #13676 by adding TypeScript type tests to verify type definitions work correctly
  • Establishes a pattern for adding type tests to other packages with .d.ts files
  • Added comprehensive type tests for 5 packages: check, random, tracker, fetch, and email

Changes

  • check: Added type tests for Match patterns (Maybe, Optional, OneOf, ObjectIncluding, Where, Integer, Any) and check() assertions
  • random: Added type tests for all Random methods (id, secret, fraction, hexString, choice)
  • tracker: Added type tests for Tracker.autorun, Computation interface, Dependency class, and reactive utilities
  • fetch: Added type tests for fetch(), Headers, Request, and Response APIs
  • email: Added type tests for Email.sendAsync(), hookSend(), customTransport(), and MailComposer

Pattern for other packages

Each package now follows this pattern:

  1. Add 'typescript' to Package.onTest() dependencies
  2. Create a *_test.ts file with type tests using api.mainModule()
  3. Import APIs and verify type signatures, return types, and type narrowing

Fixes #13676

Addresses issue meteor#13676 by adding TypeScript type tests to verify type definitions work correctly. This establishes a pattern for adding type tests to other packages with .d.ts files.

Changes:
- check: Added comprehensive type tests for Match patterns and check() assertions
- random: Added type tests for all Random methods (id, secret, fraction, hexString, choice)
- tracker: Added type tests for Tracker.autorun, Computation, Dependency, and reactive utilities
@netlify
Copy link

netlify bot commented Oct 2, 2025

Deploy Preview for v3-meteor-api-docs canceled.

Name Link
🔨 Latest commit aa49cd7
🔍 Latest deploy log https://app.netlify.com/projects/v3-meteor-api-docs/deploys/68e7769a05fec800087ae2d0

@netlify
Copy link

netlify bot commented Oct 2, 2025

Deploy Preview for v3-migration-docs canceled.

Name Link
🔨 Latest commit aa49cd7
🔍 Latest deploy log https://app.netlify.com/projects/v3-migration-docs/deploys/68e7769a3974b80008735a40

@CLAassistant
Copy link

CLAassistant commented Oct 2, 2025

CLA assistant check
All committers have signed the CLA.

- fetch: Added type tests for fetch(), Headers, Request, and Response APIs
- email: Added type tests for Email.sendAsync(), hookSend(), customTransport(), and MailComposer
@gauravarora gauravarora changed the title Add TypeScript type tests for check, random, and tracker packages Add TypeScript type tests for check, random, email, fetch and tracker packages Oct 2, 2025
import { Tinytest } from "meteor/tinytest";
import { check, Match } from "meteor/check";

Tinytest.add("Check - TypeScript types - basic check function", (test) => {
Copy link
Member

@italojs italojs Oct 20, 2025

Choose a reason for hiding this comment

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

would be better to have a test for "general types" so test string, number, obj...

test.equal(upper, "HELLO");
});

Tinytest.add("Check - TypeScript types - Match.test with primitives", (test) => {
Copy link
Member

Choose a reason for hiding this comment

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

Check lib isnt a typescript feature, all this file have TypeScript types in the test descriptions, bu none of them is testing typescript related things, Number and String is js native

api.use(['check', 'tinytest', 'ejson', 'ecmascript', 'typescript'], ['client', 'server']);

api.addFiles('match_test.js', ['client', 'server']);
api.mainModule('match_test.ts');
Copy link
Member

Choose a reason for hiding this comment

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

the file is .ts but isnt using ts statement 🤷🏻‍♂️
vote to remove it


Tinytest.add("Email - TypeScript types - sendAsync options", (test) => {
// Type check that sendAsync accepts proper options
const options = {
Copy link
Member

Choose a reason for hiding this comment

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

is missing the type EmailOptions

});

Tinytest.add("Email - TypeScript types - hookSend", (test) => {
Email.hookSend((options) => {
Copy link
Member

Choose a reason for hiding this comment

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

missing the type EmailOptions into options Email.hookSend((options: EmailOptions) => {

import { Tinytest } from "meteor/tinytest";
import { fetch, Headers, Request, Response } from "meteor/fetch";

Tinytest.addAsync("Fetch - TypeScript types - fetch function", async (test, done) => {
Copy link
Member

Choose a reason for hiding this comment

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

here we are testing node's fetch, not a method stuff, remove all tests like this, please
featch already have your own tests

});

Tinytest.add("Tracker - TypeScript types - Computation properties", (test) => {
const computation = Tracker.autorun((c) => {
Copy link
Member

Choose a reason for hiding this comment

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

missing the type ...: Tracker.Computation =...

const stopped: boolean = c.stopped;
const promise: Promise<unknown> = c.firstRunPromise;

test.equal(typeof firstRun, "boolean");
Copy link
Member

Choose a reason for hiding this comment

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

it's typescript, Boolean doent work here?


// This ensures the type signature is correct
const sendPromise: Promise<void> = Email.sendAsync(options);
test.equal(typeof sendPromise.then, "function");
Copy link
Member

Choose a reason for hiding this comment

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

it's typescript, instanceof Promise doesnt work here?

test.equal(computation.invalidated, true);

computation.onInvalidate((c: Tracker.Computation) => {
test.equal(typeof c, "object");
Copy link
Member

Choose a reason for hiding this comment

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

should be typeof c, Tracker.Computation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type tests for Meteor packages

4 participants