Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meteor 1.3 and testing packages #16

Open
flippyhead opened this issue Apr 7, 2016 · 12 comments
Open

Meteor 1.3 and testing packages #16

flippyhead opened this issue Apr 7, 2016 · 12 comments

Comments

@flippyhead
Copy link

I seem to be missing something. When following the README but using Factory in a package I get errors like this:

TypeError: Object function (collection, attributes) {                                                         
W20160407-10:40:12.710(-7)? (STDERR)   this.collection = collection;                                                                     
W20160407-10:40:12.710(-7)? (STDERR)   this.attributes = attributes;                                                                      
W20160407-10:40:12.710(-7)? (STDERR)   this.afterHooks = [];                                                                              
W20160407-10:40:12.710(-7)? (STDERR) } has no method 'define'

Thank you!

@flippyhead
Copy link
Author

Ideally I could import the Factory in 1.3, using it as a module.

@dburles
Copy link
Collaborator

dburles commented Apr 9, 2016

Hey @flippyhead it looks like you may need to specify the version of the package as it looks as though it's pulled in the very first release. I'll update the package for 1.3 soon.

@ephemer
Copy link

ephemer commented Jul 28, 2016

Hi @dburles, this seems to be happening again in 1.4, in the changelog I see MDG changed something about how packages are imported. Maybe it'll only work now with the api.mainModule() syntax? I'm not sure

I tried the following:

import Package from 'meteor/dburles:factory';
console.log(JSON.stringify(Package)); // => {"Factories":{}}

Which is very weird, because Factories doesn't appear in the source code available online nor is it exported from package.js. I am using version 1.1.0

Update: I forked the package and updated the first couple of lines to look like this:

export const factories = {};

export const Factory = class Factory {

and changed add_files() in package.js to mainModule() and it's working

@dburles
Copy link
Collaborator

dburles commented Jul 29, 2016

Hey @flippyhead I'm pretty sure it should still work, you don't have to import anything as Factory will be global

@ephemer
Copy link

ephemer commented Jul 29, 2016

@dburles I also tried without using any import statements and got exactly the same failure either way on 1.4

@dburles
Copy link
Collaborator

dburles commented Jul 29, 2016

It definitely works, I just double checked on a fresh 1.4 project and everything works fine. I'd recommend trying the same thing, it may help you to debug your existing project.

@BagrijRoman
Copy link

I try to use Factory with Meteor Package test.
I try to import Factory in test file

import { Factory } from 'meteor/dburles:factory';

than I try

let ordersCol = new Mongo.Collection('orders');
Factory.define('userFactory', ordersCol, { name: 'Test record' });

but I has got an error 'Factory.define is not a function'.

Than I try run this part of code in the Meteor test (Not package test) and it works fine.
Looks like it is some problems with using this Package in Meteor packages tests.

@dburles Can you help me import this package to Meteor package test?
Thanks.

@ephemer
Copy link

ephemer commented Oct 13, 2016

@pj-infest this is the same issue I had / still have. I rewrote the file as described above (took about 30 seconds) and it works fine. @dburles didn't seem to get this error, so I dunno what the issue is, just how to fix it ;)

@ephemer
Copy link

ephemer commented Oct 13, 2016

I didn't mention in my report explicitly that it's with testing packages (it is) but it says so in both the issue title and the OP so I'm assuming @dburles is aware..

@dburles
Copy link
Collaborator

dburles commented Oct 14, 2016

Possible to put up a simple reproduction app I can look at? I'm not sure I fully understand where things are going wrong

@BagrijRoman
Copy link

@dburles
Hi.
Here a simple app example with error.
Modified todos app
I add package for test it, named mypackage

Reproduce error recept:

  • change work directory to todos/packages/mypackage
  • run package test (not project test)
    meteor test-packages --driver-package practicalmeteor:mocha --port 3100
  • open browser on adress http://localhost:3100/

First test is successful, but second test from testing package file is failed.

When I run test on client and on server it fails with message
Factory.define is not a function

When I run test only on server it fails with There is already a collection named "authors"
(I take example from off docs).

When I run this code in global Project test it is no errors (but they appear in package tests)

Please help me resolve this problem.

@dburles
Copy link
Collaborator

dburles commented Oct 19, 2016

Hey @pj-infest the problem you're having is the same as what @flippyhead originally posted. Meteor is pulling in the earliest compatible version of this package, which had a different API. You need to specify the version of the package that you're after, the latest version is 1.1.0.

Change api.use('dburles:factory'); to specify 1.1.0: api.use('dburles:factory@1.1.0');

Which will likely result in:

Changes to your project's package version selections:

dburles:factory*  upgraded from 0.1.9 to 1.1.0

Also you don't need to explicitly import Factory. It will be global.

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

No branches or pull requests

4 participants