willscott / grunt-jasmine-firefoxaddon

Run jasmine specs in a Firefox addon
Apache License 2.0
0 stars 1 forks source link

grunt jasmine_firefoxaddon fails with jasmin tests depending on Mozilla's addon-sdk #7

Open stefan-walluhn opened 8 years ago

stefan-walluhn commented 8 years ago

If a jasmine test case depends on Mozilla's addon-sdk the grunt task fails with:

$ FIREFOX_BIN=/usr/bin/firefox grunt jasmine_firefoxaddon
Running "build-test-addon:main" (build-test-addon) task
>> Extension staged in .build

Running "browserify:jasmine" (browserify) task
>> Error: Cannot find module 'sdk/timers' from '/home/stefan/gmi.most_used_sites.plugin'
Warning: Error running grunt-browserify. Use --force to continue.

Aborted due to warnings.

I was able to track this being an issue with browserify. Since the addon-sdk is only available in the firefox runtime environment but not in the node/npm-based dev environment, browserify is not able to bundle the addon-sdk modules:

$ grunt -d browserify:jasmine
Running "browserify:jasmine" (browserify) task
[D] Task source: /home/stefan/gmi.most_used_sites.plugin/node_modules/grunt-browserify/tasks/browserify.js
>> Error: Cannot find module 'sdk/timers' from '/home/stefan/gmi.most_used_sites.plugin'
Warning: Error running grunt-browserify. Use --force to continue.

Aborted due to warnings.

I also tried to fiddle around with the addon-sdk sources to make them available in the node/npm-based dev environment to enable browserify to include the modules. Unfortunately, the addon-sdk code does not seem to run with nodejs and brakes with syntax errors.

Running test cases not depending on Mozilla's addon-sdk works out of the box. Am I missing anything in my setup? Is jasmine_firefoxaddon designed to also test against Mozilla's addon-sdk? This is my Gruntfile.js

willscott commented 8 years ago

yeah, I think the basic deal is that since the file is getting loaded in the addon with Components.utils.import (https://github.com/willscott/grunt-jasmine-firefoxaddon/blob/master/tasks/build-test-addon.js#L89) the file is loaded against the lowlevel API for addons, and doesn't have the launchpad and high-level API that JPM packaging set up loaded.

Would be happy to take a pull request if it make sense, but if you're programming in the high-level API, I think you'll do better to start from the testing tools that JPM provides, rather than this fairly brittle tool.

stefan-walluhn commented 8 years ago

Unfortunately the JPM testing tools are on a very basic lever right now, producing more noise than helpful testing and debugging capabilities. This is why I was searching for a possibility to introduce a full featured test suite to my project.

Thanks for your reply. If there is some time (and mind space), I will dig into this and think about a meaningful approach.