Skip to content

Feature: async validate support - #96

Open
jankapunkt wants to merge 8 commits into
meteor:masterfrom
jankapunkt:feature/async-validate-support
Open

jankapunkt wants to merge 8 commits into
meteor:masterfrom
jankapunkt:feature/async-validate-support

Conversation

@jankapunkt

@jankapunkt jankapunkt commented Oct 20, 2026 •

Copy link
Copy Markdown

This PR is adding support for async validate functions (#94). By doing so, this library now supports SimpleSchema 3+ (thanks to @harryadel) which now is fully async.

The implementation is fully backwards compatible!

As a side effect and to ensure this backwards compatibility, the entire test suite has been massively extended and enriched by code coverage generation. Additionally, the package.json allows to extend this library with respective linting tooling (not covered by this PR).

The files in coverage-support are solely for collecting coverage and are not added to the package or have any influence on the package execution logic or workflow.

New coverage is after added over 30 new tests:

---------------------|---------|----------|---------|---------|-------------------
File                 | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
---------------------|---------|----------|---------|---------|-------------------
All files            |    82.6 |       80 |   76.92 |   86.36 |                   
 validated-method.js |    82.6 |       80 |   76.92 |   86.36 | 93-122            
---------------------|---------|----------|---------|---------|-------------------

Finally, I added a CI file as an example setup and an test:ci script.

Alltogether this PR is expected to improve the library in terms of reliability and long term maintainability.

@nachocodoner @italojs I cannot request you as reviewers somehow so I instead directly mention you here :-)

@jankapunkt

Copy link
Copy Markdown
Author

@nachocodoner @italojs is this on your radar?

Comment thread package.js Resolved
Comment thread .github/workflows/testsuite.yml Resolved
@harryadel

Copy link
Copy Markdown

Thanks for the PR @jankapunkt, the _execute change itself looks good and is backwards compatible. I checked the branch out and ran it locally on Meteor 3.5.4; the server suite passes (76 tests). A few things are blocking though:

1. Meteor 2.x can't work with the current test dependencies

package.js now declares api.versionsFrom(['2.3', '3.0']) and the CI matrix includes 2.3 and 2.16, but Package.onTest pulls in:

  • aldeed:simple-schema@3.0.0, which declares api.versionsFrom(['3.0']) only
  • meteortesting:mocha@3.0.0, which requires Meteor 2.8+
  • chai@^6 from npm, which is ESM-only

So the test suite can't even resolve on 2.3 / 2.16. The new test propagates errors if no callback is passed also asserts Meteor 3 server semantics (the returned promise rejects), which differs on 2.x. I'd suggest dropping 2.x entirely: versionsFrom(['3.0']) and a 3.x-only matrix. If you want to keep 2.x in versionsFrom, the test deps need to be split so the 2.x runs actually exercise something.

2. test:ci fails and then hangs

After meteor npm ci at the repo root, TEST_BROWSER_DRIVER=puppeteer meteor test-packages ... fails with Cannot find module 'puppeteer': meteortesting:browser-tests resolves it from the temporary test app in /tmp, not from the package directory. The Meteor process then never exits despite --once (I killed it after 40 min). In Actions this would eat the full job timeout per matrix entry. Also note this repo has never had a workflow run, so the CI in this PR hasn't actually executed anywhere yet.

3. Async validators don't short-circuit on the client with .call()

Meteor 3's client apply only logs a debug warning when a stub returns a promise; the rejected validation promise is never treated as a stub exception. So with an async validator and method.call(), throwStubExceptions does nothing, the server is still invoked, and the client gets an unhandled rejection plus a console warning on every call. Only callAsync behaves correctly. This should at least be documented in the README (which currently doesn't mention async validate at all), and ideally call() should throw a clear error on the client when validate returns a thenable.

Smaller things: CHANGELOG and version bump are missing (dropping Meteor 1 is breaking), and the assertThrows test helper has its assert.fail inside the try, so it passes silently when fn doesn't throw and no message is given.

@jankapunkt

Copy link
Copy Markdown
Author

@harryadel thanks for the thorough testing, fixing these and get back to you

* fix: run headless with 100% coverage and 2x/3x compat

* fix: make ci compatible with mulziple lock files

* fix: error handling for unsupported callAsync

* fix: handle missing test case on supported vs unsupported callAsync

* fix: add missing guard clause to tests to support 2.3

* fix: add missing 2.3 test
@jankapunkt

jankapunkt commented Oct 31, 2026 •

Copy link
Copy Markdown
Author

@harryadel here are the fixes:

  • 2.x and 3.x compat (2.3, 2.16, 3.0.4, 3.5.x)
  • updated CI accordingly (see https://github.com/jankapunkt/validated-method/actions)
  • added extra guard clauses in tests and code, based on support of callAsync and applyAsync which does not exist in 2.3 but ongoing from 2.8
  • managed to use chai 4.x which is not ESM-only
  • managed to find support correct puppeteer
  • coverage is 100% for all versions except 2.3 which can never reach 100% by design
All tests finished!

--------------------------------
SERVER FAILURES: 0
CLIENT FAILURES: 0
--------------------------------
---------------------|---------|----------|---------|---------|-------------------
File                 | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
---------------------|---------|----------|---------|---------|-------------------
All files            |     100 |      100 |     100 |     100 |                   
 validated-method.js |     100 |      100 |     100 |     100 |                   
---------------------|---------|----------|---------|---------|-------------------

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.

3 participants