-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
require in renderer process #11
Comments
Could you elaborate more on "require in renderer process use index.html path as base whereas your plugin use the .js file as base."? Maybe provide some example code so I can understand better |
I think I might understand this question. I have an Angular controller defined in
And this works great when I run my application by simply spawning
Is this because your preprocessor is setting the I have a temporary workaround. Rather than using |
The current views/index.html: <!-- Loads `views/../js/foo.js` (i.e. `js/foo.js`) -->
<script>require('../js/foo');</script> js/foo.js: // Loads `./bar.js` (i.e. `js/bar.js`)
require('./bar');
// This is the context we load scripts as
// That is: The file you are loading in `karma` is a JS file
// someone wouldn't/shouldn't expect it to load from the HTML context
// as the file isn't HTML The reason we need to polyfill |
Well, that's all fair enough, I suppose, but I think the reason that this issue was raised is because there seems to be an incongruity between the behavior in the normal runtime environment versus the testing environment. That is, paths that resolve in the normal runtime environment do not resolve in the testing environment and vice versa. |
Ah, I think I understand now. I will rephrase the problem to verify we are on the same page:
The question seems to be something like: Can we add My answer would be: We could but I would prefer to avoid doing so as it would lead to unpredictable development/testing behavior. As a developer, I would expect a |
Thanks for the response - glad I was able to help clarify! I don't have the same depth of knowledge that you have, but here're my two cents: the testing environment should behave exactly like the normal runtime environment. I totally hear what you're saying, vis-a-vis reasonable developer expectations, but the aim of a testing environment should be to mimic the normal runtime environment, regardless of whether or not the normal runtime environment conforms to "reasonable" expectations. You seem to indicate that "fixing" this problem could result in incongruous behavior between the normal runtime environment and the testing environment, but as far as I'm concerned the problem we're discussing right now is that there is an incongruity of behavior between the normal runtime and testing environments. |
Nope, the behaviors should currently be the same as That being said, I could be wrong about missing some inconsistency between |
I've prepared some code to demonstrate the problem I'm trying to describe.
Let me know if I'm missing something, doing something wrong or if you have any questions. |
Ah, I see. Yea, there's a discrepancy between how we would expect to load the JS files. You are loading via:
whereas I would expect to use
or have a It's been a while since I've touched this repo but I recalled setting up a similar gist to verify we had the majority of the behavior matched. However, now that I look at it again we never tested these different loading mechanisms: https://gist.github.com/twolfson/c6213aa59f7c3f6477 I want to take some time to test further, reflect on which behavior should be considered the default/why, and likely add an option for the opposite setup (e.g.
|
Glad I was able to clearly illustrate the issue. Also, thanks for describing the way in which you would have structured things in order to avoid this issue. Although I'm a software engineer by profession, I'm not employed as a web dev and am keenly aware of the fact that I don't write web development code like a professional...so I'm happy to hear how a more seasoned web developer would structure things! As the repository linked in my last comment indicates, I followed a tutorial to build the "bones" of my minimal Electron app. As you can see in the fourth code block in the Controller & Template section, I am sourcing my scripts using the same syntax they are. Do you not agree with the way they are doing things? Is there something fundamentally different about my use case that requires this kind of script sourcing to be done using different mechanisms? I understand how using this kind of syntax:
Would "work", but also create globals and probably be undesirable. However, I'm not as clear on your second suggestion, regarding the use of a Thanks in advance...please let me know if I can provide any additional information or if there's anything at all I can do to help! |
Sure, here's some clarification/guidance The
Next we have dependency management in the application. The tutorial you link to is following conventions that are ideal for a browser environment and doesn't use The gist of what's going on is:
If you want to continue using that paradigm, it's fine but it should also use the same dependency management system and probably not mix the 2 as it will issues (e.g. confused developers, 2 separate dependency trees) In constrast, http://angular-tips.com/blog/2015/06/using-angular-1-dot-x-with-es6-and-webpack/ In other frameworks like React, they use https://github.com/toranb/react-gulp-browserify-example With |
Updates to the actual issue: I have added a reference application to this repo based on the previous gist: https://gist.github.com/twolfson/c6213aa59f7c3f6477 https://github.com/twolfson/karma-electron/tree/4.1.2/test/reference The resulting values match our discussion so far (as we did the same work but outside of this repo): https://github.com/twolfson/karma-electron/blob/4.1.2/test/reference/js/src-main.js https://github.com/twolfson/karma-electron/blob/4.1.2/test/reference/js/require-main.js The current unmodified behavior for
I think the default expected behavior would be (e.g. when
Then we have the Node.js-like behavior (e.g. when
In addition to this, there's the requested behavior which is to allow a custom To solve these problems, I plan on doing the following:
I'm not certain of the |
The first patch has been released in |
We have added support for module.exports = function (config) {
config.set({
client: {
// Override top level `__filename` to be `/home/.../my-electron-app/index.html`
// where `__dirname` is `/home/.../my-electron-app`
__filenameOverride: __dirname + '/path/to/index.html',
}
});
}; Thanks again for the bug report and clarification |
Hi, sorry for the silence, but I have just noticed that my github was using a trash email and so I have never been notified. I know it is quite late but I can provide more examples if needed. Thanks you @danforbes and @twolfson for having kept this thread alive. |
Thanks for all the information and quick fix, @twolfson! |
Hi,
This module is a good idea because renderer process is very specific. However I have a very simple but I didn't find any solution:
require
in my renderer processkarma-electron
understands my require which is a good improvement in comparison of other karma pluginsIs it normal and is there a option to change this base path (
basePath
in karma doesn't change this path) ?I hope my question is quite understandable.
Thanks
The text was updated successfully, but these errors were encountered: