The "problem" with elements that depend on Chrome Apps APIs is that you can't test/use them outside of Chrome Apps, so I went ahead and created some gulp tasks to make things easier for me.
The main idea of these tasks is to put the contents of
test, which you would normally run directly, and all dependencies into one Chrome app that would then use
test/index.htmlas main page.
First I take all the files relevant for the element itself + the test/demo files, run the html files through crisper and put the result into the output
components/my-element/folder (following the layout of gh-pages for Polymer elements).
All bower dependencies are run through crisper as well and put into the
For the Chrome App itself only two files are important.
manifest.jsondefines the necessary permissions (e.g. to use
"storage"permission is required).
main.jslaunches the test or demo page.
The gulp task copies those two files to the main output folder, and changes the
window.createcall to point to the right file, e.g at
The Chrome demo and test apps created that way can then be loaded as unpacked extensions.
This works nicely for the demo app, but unfortunately the test app reveals this in the console when starting it:
Uncaught Error: document.write() is not available in packaged apps.
Investigating the problem reveals this line in the web-component-tester to cause the issue, which makes sure that all dependencies are loaded before WCT is actually started.
To work around this issue you have to include the necessary scripts in the test files explicitly...
...and tell it not to load any scripts itself...
web-component-tester/browser.json all the test pages.
So that I don't have to copy the same couple of lines into each of the test files separately, I extended the gulp-copy task to automatically insert the necessary lines in all files that include a reference to
And with this change tests can be run in the Chrome App.
Following the idea of my previous article I also wanted to enable live-reload for this workflow
As opposed to my article where the
livereload.jsis removed for the production build, I did it the other way round here by adding it to the
demo/index.htmlwhen running the gulp-live-task.
Watching for changes, rebuilding the app if necessary and triggering the reload works basically the same though.
And with this I can leave the test and/or demo apps running and see right away if all tests still pass after making changes and if the demos work as expected.
And now back to actually working on my app. All those distractions you run into while traversing (mostly) uncharted waters ☺