iron-meteor / iron-layout

Dynamic layout with support for rendering dynamic templates into regions.
MIT License
46 stars 11 forks source link

Problem with tinytest #15

Closed robwatkin closed 8 years ago

robwatkin commented 9 years ago

I've hit a problem when using iron:router in a package with Tinytest. The issue has already been raised (next door) https://github.com/iron-meteor/iron-router/issues/1349. It can easily be replicated as follows:

$ meteor create dummy
$ cd dummy
$ meteor create --package paq

Then add iron router into the package.js file

Package.onUse(function(api) {
  api.versionsFrom('1.1.0.2');
  api.use('iron:router');
  api.addFiles('paq.js');
});

Running the tests gives the following in the browser console

Uncaught TypeError: Template.__create__ is not a function
Uncaught TypeError: undefined is not a function
Uncaught TypeError: Cannot read property 'RouteController' of undefined
Exception in defer callback: TypeError: Cannot read property 'insert' of undefined
at Utils.extend.autoRender (http://localhost:3000/packages/iron_router.js?21e016398976d1792ea62f1079e9141f6b298416:1627:17)
at http://localhost:3000/packages/iron_router.js?21e016398976d1792ea62f1079e9141f6b298416:1456:16
at _.extend.withValue (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:955:17)
at withoutInvocation (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:435:45)
at Object.Meteor.bindEnvironment (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:983:22)
at onGlobalMessage (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:372:23)

I have tried mocking it with mocks.js

Template = function() { /* do nothing */ }

and package.js

Package.onTest(function(api) {
  api.use('tinytest');
  api.addFiles('mocks.js');
  api.use('paq');
  api.addFiles('paq-tests.js');
});

but I still get the error.

seeekr commented 9 years ago

What happens if you set the api.use for iron:router only for the client? Maybe noone has ever thought of making sure that tests actually work if iron:router is also included for the server?

api.use('iron:router', 'client');

robwatkin commented 9 years ago

Thanks for the idea @seeekr . I just tried it and still see the error

Rob

brettle commented 9 years ago

This fixes it for me:

  api.use('iron:router@1.0.0');

My understanding is that when the test app is created, Meteor picks the latest patch of the earliest major.minor that satisfy the constraints. Without the @1.0.0, that means the latest patch of the earliest major.minor that claims to work with Meteor 1.1.0.2. So without the @1.0.0, I get:

$ grep iron:router /tmp/meteor-test-*/.meteor/versions
iron:router@0.9.1

With the @1.0.0, I get:

$ grep iron:router /tmp/meteor-test-*/.meteor/versions
iron:router@1.0.9

Strictly speaking, this appears to be bug in the iron:layout@0.3.0 package. I get the same error when using api.use('iron:layout)' instead of api.use('iron:router'), and adding @1.0.0 fixes it. When I don't specify a version, I get iron:layout@0.3.0.

I don't know how the iron:layout maintainers would best or most easily fix this. Do they need to publish a fixed iron:layout@0.3.1? Do they actually need to fix the bug in the code, or, if the problem is caused by a change in one of its dependencies, can they just change the dependencies of iron:layout@0.3.1 so that it isn't compatible with whatever dependency versions are causing the problem?