Open flippyhead opened 8 years ago
Ideally I could import the Factory in 1.3, using it as a module.
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.
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
Hey @flippyhead I'm pretty sure it should still work, you don't have to import
anything as Factory
will be global
@dburles I also tried without using any import
statements and got exactly the same failure either way on 1.4
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.
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.
@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 ;)
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..
Possible to put up a simple reproduction app I can look at? I'm not sure I fully understand where things are going wrong
@dburles
Hi.
Here a simple app example with error.
Modified todos app
I add package for test it, named mypackage
Reproduce error recept:
todos/packages/mypackage
meteor test-packages --driver-package practicalmeteor:mocha --port 3100
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.
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.
I seem to be missing something. When following the README but using Factory in a package I get errors like this:
Thank you!