Nwjs how to use evalNWBinModule in another created window? - nwjs

In the main window I write the following code and it works:
nw.Window.get(null).evalNWBinModule(null, "./my.bin", "./my.js");
import("./my.js");
but if I create a new window via nw.Window.open(MyOtherURL); where I then move this code, then after running I get an error:
Uncaught (in promise) TypeError: Failed to resolve module specifier
'./my.js'
what is the launch difference and what else do i need to configure?

nw.Window.get() returns a reference to the Window itself, so you can then chain off of it.
nw.Window.open(), does not, but it does have a callback function gives you access to the new window, which you can chain off of.
const url = 'page2.html';
const options = {};
nw.Window.open(url, options, function (win) {
win.evalNWBinModule(null, './my.bin', './my.js');
});
However I'm not sure that will do what you want. You will likely be better off having the code run in your page2.html file directly.

Related

Stop huge error output from testing-library

I love testing-library, have used it a lot in a React project, and I'm trying to use it in an Angular project now - but I've always struggled with the enormous error output, including the HTML text of the render. Not only is this not usually helpful (I couldn't find an element, here's the HTML where it isn't); but it gets truncated, often before the interesting line if you're running in debug mode.
I simply added it as a library alongside the standard Angular Karma+Jasmine setup.
I'm sure you could say the components I'm testing are too large if the HTML output causes my console window to spool for ages, but I have a lot of integration tests in Protractor, and they are SO SLOW :(.
I would say the best solution would be to use the configure method and pass a custom function for getElementError which does what you want.
You can read about configuration here: https://testing-library.com/docs/dom-testing-library/api-configuration
An example of this might look like:
configure({
getElementError: (message: string, container) => {
const error = new Error(message);
error.name = 'TestingLibraryElementError';
error.stack = null;
return error;
},
});
You can then put this in any single test file or use Jest's setupFiles or setupFilesAfterEnv config options to have it run globally.
I am assuming you running jest with rtl in your project.
I personally wouldn't turn it off as it's there to help us, but everyone has a way so if you have your reasons, then fair enough.
1. If you want to disable errors for a specific test, you can mock the console.error.
it('disable error example', () => {
const errorObject = console.error; //store the state of the object
console.error = jest.fn(); // mock the object
// code
//assertion (expect)
console.error = errorObject; // assign it back so you can use it in the next test
});
2. If you want to silence it for all the test, you could use the jest --silent CLI option. Check the docs
The above might even disable the DOM printing that is done by rtl, I am not sure as I haven't tried this, but if you look at the docs I linked, it says
"Prevent tests from printing messages through the console."
Now you almost certainly have everything disabled except the DOM recommendations if the above doesn't work. On that case you might look into react-testing-library's source code and find out what is used for those print statements. Is it a console.log? is it a console.warn? When you got that, just mock it out like option 1 above.
UPDATE
After some digging, I found out that all testing-library DOM printing is built on prettyDOM();
While prettyDOM() can't be disabled you can limit the number of lines to 0, and that would just give you the error message and three dots ... below the message.
Here is an example printout, I messed around with:
TestingLibraryElementError: Unable to find an element with the text: Hello ther. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.
...
All you need to do is to pass in an environment variable before executing your test suite, so for example with an npm script it would look like:
DEBUG_PRINT_LIMIT=0 npm run test
Here is the doc
UPDATE 2:
As per the OP's FR on github this can also be achieved without injecting in a global variable to limit the PrettyDOM line output (in case if it's used elsewhere). The getElementError config option need to be changed:
dom-testing-library/src/config.js
// called when getBy* queries fail. (message, container) => Error
getElementError(message, container) {
const error = new Error(
[message, prettyDOM(container)].filter(Boolean).join('\n\n'),
)
error.name = 'TestingLibraryElementError'
return error
},
The callstack can also be removed
You can change how the message is built by setting the DOM testing library message building function with config. In my Angular project I added this to test.js:
configure({
getElementError: (message: string, container) => {
const error = new Error(message);
error.name = 'TestingLibraryElementError';
error.stack = null;
return error;
},
});
This was answered here: https://github.com/testing-library/dom-testing-library/issues/773 by https://github.com/wyze.

ClrMd Execute "~*k" returns stack traces with clr!DllUnregisterServerInternal instead of correct values

When I execute "~*k" command via ClrMd, it returns stack traces with clr!DllUnregisterServerInternal instead of correct values. It looks like symbols are not loaded.
If I perform "~*k" command directly in WinDBG, everything looks well.
this.DataTarget = DataTarget.LoadCrashDump(pathToMemoryDump, CrashDumpReader.DbgEng);
this.DataTarget.SymbolLocator.SymbolCache = #"C:\symbols";
this.DataTarget.EnumerateModules().ToList().ForEach((m) =>
{
this.DataTarget.SymbolLocator.FindBinary(m);
this.DataTarget.SymbolLocator.FindPdb(m);
});
this.ClrRuntime = DataTarget.ClrVersions[0].CreateRuntime();
Then, I'm using Execute method to perform the query against loaded memory dump:
(IDebugControl)client.Execute(DEBUG_OUTCTL.ALL_CLIENTS, cmd, DEBUG_EXECUTE.DEFAULT);
Do anyone have any suggestion?
My intention to get correct stack traces for native threads.
Set your symbol path
var symbols = DataTarget.DebuggerInterface as IDebugSymbols;
symbols.SetSymbolPath("http://msdl.microsoft.com/download/symbols");

Poltergeist-phantomjs - switching to the new popped up window

Test env: Capybara,poltergeist, phantomjs.
A new window opens up when I click a link in my test case. I was able to switch to the new window and verify text using selenium driver. However, I am unable to switch to the new window with poltergeist. I tried the following method to switch to the new window and none of them worked.
I wanted to see if a new browser is getting open at all and looks like it is.
main = page.driver.browser.window_handles.first
puts main (gives 0)
popup = page.driver.browser.window_handles.last
puts popup (gives 1)
1. within_window(->{ page.title == '2015-11-5.pdf' }) { assert_text(facility_name) }
2. page.switch_to_window(window=popup)
3. page.switch_to_window(page.driver.browser.window_handles.last)
4. page.driver.browser.switch_to().window(page.driver.browser.window_handles.last)
Could someone provide any inputs here? Thanks!
I used the following and the popup is getting generated and the control switches to it.
page.switch_to_window(page.window_opened_by{click_link('Generate Report')})
The new window has a pdf embedded in it.I was able to read and verify the contents of the document when I use selenium driver. With poltergeist, I am unable to read the pdf. Could you give me some pointers on how to proceed?
Capybara has a number of cross driver methods for dealing with this without having to go to driver specific methods.
popup = page.window_opened_by {
click_link('whatever link opens the new window')
}
within_window(popup) do
# perform actions in the new window
end

trying to access Thunderbird-tabmail does not work

I want to open a new tab with a gloda conversation from inside calendar code.
I receive an error from error console:
window not defined (or document not defined), depending on which of the two I use to Access tabmail:
let tabmail = window.document.getElementById("tabmail");
let tabmail = document.getElementById("tabmail");
The code works fine if the js file is included in an overlay xul-file.
But I want to use it outside of xul in my code.
Somewhere in my calendar code (in my 'addevent'), the same code throws the error.
This code is originally called from a rightclick on an email, but several layers deep into calendar code.
In MDN, I read that window is global? So what do I Need to do to add an tab?
This part works if tabmail is properly referenced:
tabmail.openTab("glodaList", {
collection: queryCollection,
message: aCollection.items[0],
title: tabTitle,
background: false
});
So how do I get a reference for tabmail?
Any help is appreciated.
after trying and looking through code for really some time before posting, it took only ca. 20 minutes to accidentally find the solution after submitting the question..
While browsing mailutils on mxr for something else, I found the solution in some function:
mail3PaneWindow = Services.wm.getMostRecentWindow("mail:3pane");
if (mail3PaneWindow) var tabmail = mail3PaneWindow.document.getElementById("tabmail");

Meteor error in trying to use collections

I am currently pulling data from collections in the MongoDB but there are 2 in particular that will not work either giving me the following error:
Exception from sub Assets id i574gxNDc9RdHERNn TypeError: Cannot call method 'find' of undefined
Or:
TypeError: Cannot call method 'attachSchema' of undefined
Or:
Object # has no method 'attachSchema'
depending on how I configure it. Does anyone have an idea of what I am doing wrong. I am using the same code for the ones that work as well as the ones that are throwing errors.
The collection looks like this:
Assets = Collections.Assets = Meteor.Assets;
Querying in server/publish.js:
Meteor.publish("Assets", function (){
return Meteor.Assets.find({});
});
Changing it to:
new Mongo.Collection('Assets');
Gives error:
Exception from sub Assets id ZgzZyNYPmMr5gtFGn TypeError: Cannot call method 'find' of undefined
Running the following from the command line in the top (root) directory of the project might fix this (it helped me):
meteor add aldeed:collection2