versolearning / meteor-factory

Meteor package for creating test data or generating fixtures
https://atmospherejs.com/dburles/factory
MIT License
107 stars 22 forks source link

Meteor 1.3 and testing packages #16

Open flippyhead opened 8 years ago

flippyhead commented 8 years ago

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 commented 8 years ago

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

dburles commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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

ephemer commented 8 years ago

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

dburles commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

@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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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

Reproduce error recept:

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 commented 8 years ago

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.