Following tutorial, 'TEST-WATCH' is not recognized as an internal or external command, operable program or batch file

Hello!

I’m still new to Meteor and testing javascript code in general. I’m currently following the Meteor Todo App with React tutorial and I’ve encountered an error that I don’t seem to be able to fix. I can’t find anybody else having this issue so I presume it is something simple that I overlooked but I can’t find it for the life of me.

I’m running this command in my terminal (Windows 10 cmd):

TEST-WATCH=1 meteor test --driver-package meteortesting:mocha

But I get this as an error:

'TEST-WATCH' is not recognized as an internal or external command,
operable program or batch file.

If I remove TEST-WATCH=1, it runs fine for 3 iterations then I get the tests work and I get this error:

Exited with code: 0
Your application is crashing. Waiting for file change.

For which people say to add TEST-WATCH=1 or --once.

My tests also works completely fine with --once instead, but only runs once and have to manually rerun the test after each modification.

I’ve also tried using the practicalmeteor:mocha package instead, but I get this error:

 Exception while invoking method 'mocha/runServerTests' Error: invalid reporter "[object Object]"

Which for this one I don’t seem to be the only one with this problem, but from what I quickly read it is recommended to use meteortesting:mocha for now.

Anyway, I’d like to know what I can do to fix the TEST_WATCH problem that I have, do you guys have an idea of what could be the problem? I assume I need to install something more so that my environment variable would be set, or I set it manually, but I can’t find any informations on what do install or set.

Thank you!

Shot in the dark here as I haven’t used windows since XP :smile:, but you may have to use the set or setx command to specify ENV vars.

C:\path\to\project> setx TEST_WATCH=1

Success: Specified value was saved.

C:\path\to\project> meteor test --driver-package meteortesting:mocha

Some things I have read say you may need to restart your command prompt after running setx.

2 Likes

Oh wow that was simple! It worked! Now it run once and waits for modifications. Perfect!

Side note, the command I had to write was slightly different for some reason: setx TEST_WATCH 1, but it works perfectly. So it seems what I needed was to simply have an environment variable named TEST_WATCH of value 1!

My clear lack of knowledge in environment variables is probably why I was pretty much the only one that encountered this problem. So I guess that when you put TEST_WATCH=1 at the beginning of a command sets up an environment variable for that particular execution of that command? Anyway thanks a lot for the help!

1 Like

Glad you got it working.

This is true for Bash and other *nix shells, but not for windows.

A much simpler option is to put your test command in your package.json as a script and use cross-env for setting environment variables

First, install cross-env as a devDependency:

meteor npm install --save-dev cross-env

Then add the test command (or name it whatever you want, eg test-watch) in your package.json:

    "scripts:" {
        "run": "meteor run",
        "test": "cross-env TEST_WATCH=1 meteor test --driver-package meteortesting:mocha"
    }

Then to run tests in watch mode on Windows, Mac or linux you can run:

npm test
Or if you named the script test-watch:
npm run test-watch
3 Likes

thanks. this is a great tip. I was using set x but cross-env is way bettter

2 Likes

somehow cross-env did not work to me(I got a lot of runtime errors) but “setx TEST_WATCH 1” did.

Could it be that you were using TEST-WATCH and not TEST_WATCH (with an underscore)?