Debug IML in Web Browser

TODO

1. Output a message to the web console

You can use debug inside your IML functions to print a message or mid-results of your code. During the function execution debug messages will be visible inside the console of your browser.

To open the developer console in Google Chrome, open the Chrome Menu in the upper-right-hand corner of the browser window and select More Tools > Developer Tools. You can also use Option + ⌘ + J (on macOS), or Shift + CTRL + J (on Windows/Linux).

By using debug() you can understand what data you are manipulating inside a function.

function add(a, b) {
    	let sum = a + b;
    
        //instead of usual console.log(), use debug().
        debug("a = " + a) 
	debug('b = ' + b)
	debug(`a+b = ${sum}`)
	
	return sum;
}

2. Debug JavaScript snippet in Chrome DevTool

To open the developer console in Google Chrome, open the Chrome Menu in the upper-right-hand corner of the browser window and select More Tools > Developer Tools. You can also use Option + ⌘ + J (on macOS), or Shift + CTRL + J (on Windows/Linux).

  1. Open Developer Tools in Google Chrome.

  2. Go to Sources -> Snippets. Create a new snippet.

  3. Paste your code. Before execution you will need 3 more things:

    1. Input example. You can either type it manually or use debug() inside the IML function on Make and copy input from the developer console of your browser (more about debug() here).

    2. Call function. Since we are testing the function locally, we cannot run a scenario to execute it. To imitate scenario execution we need to call a function by its name and send the input, that we specified before, inside it. Example: myFunction(input) .

    3. Remove all IML functions called inside. All debug() and iml.function() should be removed or replaced by similar JavaScript functions.

  4. Press ⌘ + Enter (on macOS), or Ctrl + Enter (on Windows/Linux).

  5. Click on a line number to put a breakpoint and start debugging! In Scope, you will see variables that you are using at a particular moment. In Console, you will see all your console.log() messages.

  6. If you're interested to explore Chrome DevTools check their docs here.

function removeType(input) {
	debug(input)
	delete input.type; //removes type
	input['year'] = iml.parseNumber(input.year); //parses number from text
	return input;
}

Last updated