Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

side effect of nodejs result in failure of invoking tests. #42

Open
nobody4t opened this issue Apr 17, 2019 · 19 comments
Open

side effect of nodejs result in failure of invoking tests. #42

nobody4t opened this issue Apr 17, 2019 · 19 comments

Comments

@nobody4t
Copy link

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?

@janpio
Copy link
Member

janpio commented Apr 17, 2019

What does "will get side effects" mean?

@nobody4t
Copy link
Author

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

@janpio
Copy link
Member

janpio commented Apr 17, 2019

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

@nobody4t
Copy link
Author

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.

@erisu
Copy link
Member

erisu commented Apr 18, 2019

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

@nobody4t
Copy link
Author

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

@janpio any comments? Or I missed something.

@janpio
Copy link
Member

janpio commented Apr 19, 2019

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.

@nobody4t
Copy link
Author

nobody4t commented Apr 24, 2019

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

@nobody4t
Copy link
Author

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

@janpio
Copy link
Member

janpio commented Apr 24, 2019

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.

@nobody4t
Copy link
Author

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?

@janpio
Copy link
Member

janpio commented Apr 30, 2019

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?

@nobody4t
Copy link
Author

nobody4t commented May 1, 2019

  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?

@janpio
Copy link
Member

janpio commented May 1, 2019

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.

@nobody4t
Copy link
Author

nobody4t commented May 1, 2019

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

@janpio
Copy link
Member

janpio commented May 1, 2019

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?

@nobody4t
Copy link
Author

nobody4t commented May 5, 2019

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.

@janpio
Copy link
Member

janpio commented May 5, 2019

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.

@nobody4t
Copy link
Author

nobody4t commented May 7, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants