How to debug Uglified code - javascript

I have coffee script in my rails project that is easy enough to turn into javascript. The js files are hosted locally in my dev environment in which they work as expected.
When I push to Heroku though, certain behaviour is not occurring (though plenty of stuff within the same file is working as expected). The console is not giving me any errors and the script I'm worried about is now merged with a bunch of other js files and uglified.
How do I find out what the problem is?

Related

Turbogears integration with Require JS

So I have never used turbogears before but the company I am interning at has turbogears to run their JS files. I am trying to integrate my new JS code into their files but running into repeated errors just calling the scripts and was wondering if anyone had any experience with this.
The code so far
<script type="text/javascript" data-main="${tg.url('/pv/demo.js')}" src="${tg.url('/pv/js/require.js')}"></script>
So I know it finds the require JS file with the $(tg.url()) command but I am experiencing issues with it calling other JS files in the pv directory. Getting a red GET and failure to load resource in my console.
Idea (terrible one)
If I call each script in the html file using the turgogears command which would honestly take some time since there are around 20 files. It wouldn't look as clean too.
Question
Is there a way to run that command on all the files or make it work with require.js different from what I had before?
UPDATE
Hey so in require js we have the command
requirejs.config({
'baseUrl': 'src',
});
Which well tell the html page to load up all the JS files in the src file first.
But if I need to run turbogears in the HTML page for it to fetch files how would I go about doing that? I did try to copy and paste the command of
${tg.url('/pv/src')}
but that sure as hell didn't work. Any suggestions
?
tg.url just returns the string of url, so there is usually no difference between writing /py/demo.js and ${tg.url('/pv/demo.js')}.
What tg.url will do for you is to compensate for SCRIPT_NAME in case your application is running on a subpath, but when developing locally through gearbox or when deploying on the root of a virtual host you shouldn't notice any difference in the generated urls.
Can you try to better express your problem? It seems to me it might be more related to requirejs than to turbogears itself and you might need to set requirejs baseUrl ( see http://requirejs.org/docs/api.html#config-baseUrl )

TypeScript comes down with JavaScript files

Been struggling with something and I can't find any specific information around this.
I have an application, I'm trying to unit test (Jasmine), but for some reason, the testing project brings down the TS files alongside the generated JS, which is causing some unexpected behaviour:
I figured it has something to do with they way I'm building up the spec runner page, in my case, I wrote a back-end method that loads the necessary JS files from the project I am testing, and adding the references to the JS files to a section on the site, designated for this.
the files are added using their web URL, and not the physical location on the server, for example:
http://directives/Tests.js
Is there a way to stop IIS from bringing down the TS files as well?

Typescript and the Chrome Debugger (F12 Tools)

I am trying to understand how the Chrome Debugger (F12 tools) connects things up to allow Typescript debugging.
I had a simple project that was working fine. And I decided to put some of my files a single folder deeper. (I took my test.html, test.ts and the generated test.js and put them in a folder called "views/test" where before they were just in "views".)
When I did that, the ts file stopped showing up in the list of files in the debugger. I could get it to show up if I mapped the network level folders to my files. But breakpoints would not work.
When I rolled back to the flatter file structure the ts file is there and can be debugged against.
So, why did it not allow me to see and debug against the ts file when it was nested one level deeper?
Note: I did several "Empty Cache and Hard Reload"s while testing this.
It sounds like you might need to regenerate your source maps, as those will reference specific segments in the specific TypeScript source file. If you move your .ts files without recreating the source maps, then the Chrome debugger won't know where to look for the TypeScript source.

Rails asset pipeline hangs

I am running Rails 3.2 in the development environment. Somehow, I have gotten into a situation where any change to code while debugging hangs up in the asset pipeline while trying to deliver the new page. By hangs, I means it takes a very very long time which usually causes a timeout somewhere. At present I'm debugging some javascript so all of the assets are unchanged except for one JS file. There are no error messages I can see anywhere. When I use Chrome to look at network activity it is always hung on a pending delivery of application.js, which is where the js manifest lives.
The work around seems to be:
clear the cookies and cache on the browser
restart the app server
go to localhost:3000 to re-sign-in.
I have to do this every time I change a line of code in JS.
Clearly I am doing something wrong and this used to work fine. No new gems, so new workflow. I did not accidentally precompile assets to my knowledge.
Why would the pipeline hang delivering my custom JS (not bootstrap or angular)? Why in such a way that the work around works?
I notice several unresolved questions about this so if anyone has a clue it might help a few of us.
I just had the same experience. Deleting Rails' tmp folder seems to have solved it for now.

How do I configure paths to my javascript files in the Jasmine / Maven autogenerated ManualSpecRunner.html?

I think the question says most of it. I have an autogenerated ManualSpecRunner.html file as created by maven / jasmine plug-in and I've got it to put itself into the deployable .war by using:
<jasmineTargetDir>${basedir}/pathForMyWebapp</jasmineTargetDir>
However, all the links to js files within the ManualSpecRunner.html are hard coded file:/// references - this is a bit mental, I want them to just be the relative paths to the files that are also in the webapp i.e.
Currently it gives me this path:
file:///home/username/code/HEAD/pathForMyWebapp/js/yui.js
whereas I need it to have the far more simple
/pathForMyWebapp/js/yui.js
I have tried changing two other variables in the maven script, but neither seems to have the desired effect, neither of these configuration options do what I need, the second having seemingly no effect:
<jsSrcDir>/pathForMyWebapp</jsSrcDir>
nor
<jsTestSrcDir>/pathForMyWebapp</jsTestSrcDir>
I've looked through the documentation but think I must be missing something (also, more notes on various config params listed in https://github.com/searls/jasmine-maven-plugin/blob/master/src/main/java/com/github/searls/jasmine/AbstractJasmineMojo.java are meant to do would be helpful so I can work out if I'm doing it wrong or if it's not possible!)
Any suggestions?
[p.s. I've changed some of the path names as they've got sensitive info in them, so please ignore their oddness!]
I think I understand the source of your confusion. It looks like you're trying to direct the target of the jasmine-maven-plugin to a directory inside your project's packaged *.war file so that you can run your specs against the code after it's deployed to a server, is that correct?
Unfortunately, the plugin wasn't designed with that use in mind. The jasmineTargetDir directory is usually left at its default value of target/jasmine and wasn't intended to be bundled with your application (it's analogous to the target/surefire-reports generated by maven-surefire-plugin for Java unit tests). So the reason that the script tags in ManualSpecRunner.html point to invalid locations is because that file is generated in order to be run from the local filesystem in a browser from the workstation that's building the project (to facilitate TDD).
All of that to say, if I'm reading your intention right, I think it'd be a cool feature to build a third spec runner that could be deployed with the app and executed remotely. (Especially if the project's Jasmine specs are functional/integration as opposed to isolated unit tests.) Unfortunately that's not something the project does yet.
I'm afraid that for now, if you needed to bundle the jasmine tests and execute them on the deployed server, you would need to copy ManualSpecRunner.html and jasmine into your src/main/webapp, fix the script tag references, and then manually maintain it as files are added and removed.
Make sense?

Categories

Resources