Maz
Maz

Reputation: 452

Run/Debug CURRENT file in WebStorm

I have a lot of scripts I want to run / debug from Webstorm, but for each I have to go thru the process of "Run > Edit Configurations" and add a new configuration mapped to each file.

Is there a variable / shortcut to tell WebStorm to run / debug currently opened file? Something like ${opened-file} would be great to have a Run Configuration "template".

Thanks.

Upvotes: 22

Views: 4236

Answers (4)

Stanislav Mayorov
Stanislav Mayorov

Reputation: 4452

Application parameters has a macros support (plus icon in the field). You need to use $FilePathRelativeToProjectRoot$ macros.

This example runs node /node_modules/.bin/wdio wdio.local.conf.js --spec foo.js. foo.js is $FilePathRelativeToProjectRoot$

enter image description here

Upvotes: 6

Pnar Sbi Wer
Pnar Sbi Wer

Reputation: 478

You can do 'Run context configuration' to execute the current open file. The default shortcut should be control+shift+R on Mac.

Upvotes: 2

pgl
pgl

Reputation: 7981

One way to do this is right clicking the file, then choosing Run <filename>. This will run the current file using the defaults from the Run Configuration.

Upvotes: 1

gap
gap

Reputation: 2796

I appreciate the pain you're feeling. I have a similar desire. However, there may be a way to accomplish what you're trying to do without it.

I'm using Webstorm + Jasmine for node development. Here are the steps I followed to get a working TDD setup:

  1. install jasmine (Preferences->Frameworks & Frameworks->Node or just from cmd line).
  2. setup test directory (eg, src/test or src/spec)
  3. setup jasmine.json config file in root of test directory. Mine looks like this:
{
  "spec_dir": "src/test",
  "spec_files": [ "**/*[sS]pec.js" ]
}
  1. write a test file:
describe('HelloWorld', function () {
  const HelloWorld = require('../HelloWorld');

  describe('#greeting', function() {
    it('should be friendly', function() {
      expect(new HelloWorld().greeting()).toEqual("Hello, World");
    });
  });
});
  1. setup run/debug config: default node runner with options:

    • pick your node interpreter
    • node argument: node_modules/jasmine/bin/jasmine.js
    • environment variable: JASMINE_CONFIG_PATH = src/test/jasmine.json (set in step 4 above)

      This produces an entry in the .idea/workspace.xml file like this:

<configuration default="true" type="NodeJSConfigurationType" factoryName="Node.js" path-to-node="project" node-parameters="node_modules/jasmine/bin/jasmine.js" working-dir="$PROJECT_DIR$">
   <envs>
     <env name="JASMINE_CONFIG_PATH" value="src/test/jasmine.json" />
   </envs>
</configuration>
  1. Open any test file, and use the keyboard shortcut ctrl+shift+R. This will make a new temporary run config from the default node run config, but with the current test file filled in for the Javascript file option.

I've created a pretty fluid workflow with this setup. Considering that ctrl+R will re-run the last run config, you can be writing the test, use ctrl+shift+R to run it, then start writing the code, and use ctrl+R to re-run that same test file.

Upvotes: 0

Related Questions