cordova-plugin-test-framework icon indicating copy to clipboard operation
cordova-plugin-test-framework copied to clipboard

side effect of nodejs result in failure of invoking tests.

Open nobody4t opened this issue 6 years ago • 19 comments

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?

nobody4t avatar Apr 17 '19 12:04 nobody4t

What does "will get side effects" mean?

janpio avatar Apr 17 '19 12:04 janpio

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'}

nobody4t avatar Apr 17 '19 12:04 nobody4t

Sorry, I have no idea what you are talking about.

janpio avatar Apr 17 '19 13:04 janpio

Screen Shot 2019-04-18 at 09 18 31

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.

nobody4t avatar Apr 18 '19 01:04 nobody4t

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' }
>

erisu avatar Apr 18 '19 02:04 erisu

yes, it is not displayed but it does exist. And it did block the later tests.

@janpio any comments? Or I missed something.

nobody4t avatar Apr 19 '19 08:04 nobody4t

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.

janpio avatar Apr 19 '19 09:04 janpio

I may find the trick. When I try to require this module in the test file, it is not loaded properly.

nobody4t avatar Apr 24 '19 07:04 nobody4t

Actually it can not require other modules as well. Not sure if I missed something.

nobody4t avatar Apr 24 '19 09:04 nobody4t

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.

janpio avatar Apr 24 '19 09:04 janpio

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?

nobody4t avatar Apr 30 '19 09:04 nobody4t

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?

janpio avatar Apr 30 '19 09:04 janpio

  1. My test is used to test the functionality of the plugin code. But test code can not run now.
  2. I try to path = require("path"). But it will fail all the code.

Is is using a path for that? Which one?

  1. what do you mean?
  2. 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?

nobody4t avatar May 01 '19 13:05 nobody4t

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.

janpio avatar May 01 '19 16:05 janpio

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(){}

nobody4t avatar May 01 '19 23:05 nobody4t

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?

janpio avatar May 01 '19 23:05 janpio

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.

nobody4t avatar May 05 '19 01:05 nobody4t

No, the test code will need to read a config file but i can not get the path module.

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.

janpio avatar May 05 '19 17:05 janpio

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.

nobody4t avatar May 07 '19 09:05 nobody4t