side effect of nodejs result in failure of invoking tests.
when I try to test my plugin, I need compose some object like: var config = {name:'john', sex:'male'} or var path = require("path")
These two will get side effects. But at this time, the following tests will not be executed.
Is this a bug or I missed anything?
What does "will get side effects" mean?
var config = {name:'john', sex:'male'}
will not only set the object to config, but also will give out the result {name:'john', sex:'male'}
Sorry, I have no idea what you are talking about.
I tried this on terminal. As I tested, this kind of line will impact the test file. you can reproduce this with a very simple test case.
What you are seeing, in the Node.js console or even in Chrome Developer Tools, is the default behavior. Think of these lines as a feedback line. When executing a JS file with node, these feedback lines are not displayed.
$ node
> var config = {name:'john', sex:'male'};
undefined
> config;
{ name: 'john', sex: 'male' }
>
yes, it is not displayed but it does exist. And it did block the later tests.
@janpio any comments? Or I missed something.
This doesn't make any sense. What you describe is absolutely normal. Of course if you set config, later config has another value. But that is everythign that happens.
I may find the trick. When I try to require this module in the test file, it is not loaded properly.
Actually it can not require other modules as well. Not sure if I missed something.
Still no real idea what you are talking about. Please post some code or a GitHub repo so we can try to understand what you are doing and what is going wrong and how.
Sorry for the confuse. I do not upload the repo to github. I will ask if I can do this then. This now is only internal use.
I have been stuck here for long.
I want to test my plugin which needs read a config file. When I try to require path, the test will not be not invoked at all. As I tested a lot, finally I found it is the issue of require.
As usual, my script resides in myplugin/www/ and I try to add a package.json file in which I specified the module. But not with any luck. you can find the difference between the following path:
mytest/plugins/cordova-plugin-indysdk/www/: under this path, I got all the module installed in node_modules.
mytest/platforms/ios/www/plugins/cordova-plugin-indysdk/www/ : but under this, I only got my script with no module installed. But code under this path will be executed, right?
Did I miss anything?
Does your plugin work in a demo app?
What does it require? How exactly? Is is using a path for that? Which one?
What kind of tests did you write? Where? What do they look like?
- My test is used to test the functionality of the plugin code. But test code can not run now.
- I try to
path = require("path"). But it will fail all the code.
Is is using a path for that? Which one?
- what do you mean?
- I wrote auto test case. By where, I suppose you want to know the repos of the code. But I can not share that now. I will have to ask permission. I have stated the point above. Am I understood?
I don't want to look at your repository, that is out of scope of what I offer for free here on GitHub issues ;)
But I asked a few questions, and if you answer those I might be able to help you a bit. Please answer exactly the questions I asked, each and every one. Best quote the question you are answering before typing your response.
Does your plugin work in a demo app?
I try to prove it with my test code. That's what I do now.
What does it require?
I try to require a module as people do in the normal nodejs code like: `var path = require("path")'
How exactly?
Is is using a path for that? Which one?
Not from a path. I want to import the module which should be local nodejs module I installed with npm install'. And the name of the path is path.
What kind of tests did you write? Where? I try to write an auto test case in the tests/ of my plugin
What do they look like?
it looks like exports.defineAutoTests=function(){}
I try to prove it with my test code. That's what I do now.
Does it work if you manually use it in a test app?
I try to prove it with my test code. That's what I do now.
Does it work if you manually use it in a test app?
No, the test code will need to read a config file but i can not get the path module.
Actually this is the first step of debugging my code. But I can not step forward now.
No, the test code will need to read a config file but i can not get the
pathmodule.
Because of this, I am asking if a test app, a Cordova app you created locally and added this plugin manually, works instead of the tests you are writing.
No. I have not written the front end code. I am not good at it. I just want to see if the code could work. So the test code for me is the easiest way. Anyway to run code, the config will be necessary.