Lunch.json
The following configuration can enable us to run whatever file in debug mode.
{ "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Debug File", "program": "${file}", "env": { "NODE_ENV": "some-stage", "BDSONS_DB_PWD": "some-password" }, "cwd": "${workspaceFolder}" } ] }
It is worth noting that some test cases also require specific environment variable. But how do we actually run a test file using library like ava (which is very similar to pytest
)?
For that we need an analog of if __name__ == "__main__":
in python, which turns out to be
if (require.main === module) { // our test function }
By using these we can design a test file that can be both executed by test library and also by developer individually.