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

ReferenceError: Can't find variable: exports - karma #12

Closed
mwoodsmall opened this issue Apr 15, 2016 · 9 comments
Closed

ReferenceError: Can't find variable: exports - karma #12

mwoodsmall opened this issue Apr 15, 2016 · 9 comments
Labels

Comments

@mwoodsmall
Copy link

I'm getting this error when I am running my tests. I am using angular2-seed.

When running npm test I was initially getting: 404: /base/angular2-toaster/angular2-toaster.js

That issue was easily fixed by adding 'node_modules/angular2-toaster/angular2-toaster.js' to my karma.conf.js file.

After adding that, I began getting the error ReferenceError: Can't find variable: exports

@Stabzs
Copy link
Owner

Stabzs commented Apr 15, 2016

Are you loading `'node_modules/traceur/bin/traceur-runtime.js', // Required by PhantomJS2, otherwise it shouts ReferenceError: Can't find variable: require' before attempting to load angular2-toaster? Also, are you mapping it at all in your systemjs configuration?

@mwoodsmall
Copy link
Author

Yes I am doing both of those... my suspicion is that maybe my mapping is wrong. I'll play around with that some more.

@mwoodsmall
Copy link
Author

here is my System.config in my test.main.js

System.config({
  baseURL: '/base/',
  defaultJSExtensions: true,
  paths: {
    'angular2/*': 'node_modules/angular2/*.js',
    'rxjs/*': 'node_modules/rxjs/*.js'
  },
  map: {
    'angular2-toaster': 'node_modules/angular2-toaster'
  }
});

That looks right doesn't it?

@Stabzs
Copy link
Owner

Stabzs commented Apr 15, 2016

Yes, the mapping looks correct.

In hindsight, I do remember having a lot of issues implementing the karma test runner. Note that the https://github.com/Stabzs/Angular2-Toaster/blob/master/karma-test-shim.js used is a bit different from what is used in the seed. If you follow it, something like

Promise.all([
    System.import('angular2/src/platform/browser/browser_adapter'),
    System.import('angular2/platform/testing/browser'),
    System.import('angular2/testing')
    System.import('angular2-toaster')
]).

might be necessary.

In this case, I suspect that angular2-toaster is loading before traceur is loaded to properly polyfill export. Have you verified loading order?

@mwoodsmall
Copy link
Author

I haven't verified loading order yet. Your suspicion sounds reasonable though. I'll take a look into that.

@Stabzs
Copy link
Owner

Stabzs commented Apr 20, 2016

If there's anything I can do to help track it down, please feel free to let me know :)

@mwoodsmall
Copy link
Author

@Stabzs I got things working.... not super happy about what I ended up with, tho, I will post again tonight with more details

@mwoodsmall
Copy link
Author

to get my tests running, I had to add

{ pattern: 'node_modules/angular2-toaster/angular2-toaster.js', included: false },
{ pattern: 'node_modules/angular2-toaster/lib/*.js', included: false },

to the files section of my karma configuration file.

Then, in test-main.js I had to modify System.config to add path for angular2-toastr and map it.

System.config({
  baseURL: '/base/',
  defaultJSExtensions: true,
  paths: {
    'angular2/*': 'node_modules/angular2/*.js',
    'rxjs/*': 'node_modules/rxjs/*.js',
    'angular2-toaster/*': 'node_modules/angular2-toaster/lib/*.js'
  },
  map: {
    'angular2-toaster': 'node_modules/angular2-toaster'
  }
});

Then in the same file, I had to import it using System.import

Promise.all([
  System.import('angular2/src/platform/browser/browser_adapter'),
  System.import('angular2/platform/testing/browser'),
  System.import('angular2/testing'),
  System.import('angular2-toaster/angular2-toaster')
])

@Stabzs
Copy link
Owner

Stabzs commented Apr 24, 2016

Thanks for the details and perseverance on this issue.

I'm not certain if there's a better way to structure this or if the library could make this type of testing easier. I'm open to suggestions but I'll be closing the issue for now since I don't think it's necessarily something the library is doing incorrectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants