Output text at the very end of custom Nx workspace generator - nrwl-nx

Is it possible to output/log text at the very end the workspace generator output?
I would like to notify the user of the next steps he/she should do, but my logs are kind of hidden above all the output generated by the tree updates.
export default async function (tree: Tree, schema: GeneratorOptions) {
await applicationGenerator(tree, {
// options go here
});
//format all the new files
await formatFiles(tree);
// log out next steps
logger.info('next steps');
logger.info('* Complete information in /src/environment files');
logger.info('* Adjust example routes in /src/app/app.tsx');
}
The code above results in the following output, as you can see my logs are completely at the top (and nobody would ever see them)

I was having the same problem and judging from this open issue it does not seem to be a way to do it.
What I ended up doing was wrapping the command to run the generator in a node script and then run that script instead:
import {execSync} from "child_process";
execSync('nx workspace-generator your-generator', {stdio: 'inherit'})
console.log('after')

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.

How to get user input in protractor tool

Actually I want to get user input from user whoever runs the script. I do not want to hardcode the testdata path in the script. for example when I run a script to test angularjs using protractor and javascript. User should be able to give path of the testdata, so that I can use that variable inside the script.
You can do this by passing in a params.testData value from the command line.
protractor conf.js --params.testData=D:\path\to\testdata.xlsx
Then in your test you will reference it using the global browser.params object. You will also need to use fs to read the file and process the data. Honestly, it would probably be easier if you created a .json file for the test data instead of an .xlsx but it looks there are libraries out there to help you parse an xlsx document already if you have to stick with that. Check this answer for some examples.
This code will not work as is but the basic idea will be something like this:
before(() => {
const testDataPath = browser.params.testData;
fs.readFile(testDataPath, (err, data) => {
if(err) { // fail? };
const testData = data;
// do some other stuff with test data ...
});
}
You are going to need to do some additional processing of the data from the .xlsx file to get it in the correct format but this should hopefully help get you on the right path.

IPython/Jupyter Installing Extensions

I'm having troubles installing extensions in IPython. The problem is that i can't get the extensions load automatically, i have followed the instructions in the github page but it just doesn't work. According the the homepage i need to modify the custom.js file by adding some lines. I want to install the codefolding, hide_input_all and runtools extensions. This is how my custom.js file looks:
// activate extensions only after Notebook is initialized
require(["base/js/events"], function (events) {
$([IPython.events]).on("app_initialized.NotebookApp", function () {
/* load your extension here */
IPython.load_extensions('usability/codefolding/codefolding')
IPython.load_extensions('usability/runtools/runtools')
require(['/static/custom/hide_input_all.js'])
});
});
The extensions work well if i call them manually, for example, if i type
%%javascript
IPython.load_extensions('usability/runtools/runtools/main');
the runtools appear and works perfectly, but i want the extensions to be loaded automatically and not to have to call them manually every time. Could someone tell me where is my mistake?
There's been a little change to the syntax. Nowadays, $ might not be defined by the time your custom.js loads, so instead of something like
$([IPython.events]).on("app_initialized.NotebookApp", function () {
IPython.load_extensions("whatever");
});
you should do something like
require(['base/js/namespace', 'base/js/events'], function(IPython, events) {
events.on('app_initialized.NotebookApp', function(){
IPython.load_extensions("whatever");
})
});
with the appropriate changes to braces and parentheses. For me, the former will work more often than not, but certainly not always; it fails maybe ~1/3 of the time.
If that doesn't do it for you, open up Developer Tools (or whatever is relevant for your browser) and look at the javascript console for errors. That'll help figure out what's going wrong.

Laravel script stops running after some time

I have this php script that runs for quite a while but after some time (due to browser limit when it stops loading the page) it stops with executing the code.
Basically what it does is fetch 10000 articles using an API and store them one-by-one in my own DB. After looping roughly 1200+ articles, the Google Chrome spinning/loading icon stops and all I get back in return is a blank page. When I check the DB I can see the results in the DB, but however the script didn't loop through all the articles as it should and it stopped.
I know running from CLI would remove the default browser-time-limit when it stops loading, but I don't know how to make a call to a certain controller method in Laravel from command line?
Make an Artisan command. See the docs at http://laravel.com/docs/commands
Since you are in fact seeding a database, a quick and dirty way is to use db:seed to do it for you:
class MyTableSeeder extends Seeder {
public function run()
{
// Do whatever you need to
}
}
Enable it on DatabaseSeeder:
class DatabaseSeeder extends Seeder {
public function run()
{
$this->call('MyTableSeeder');
}
}
And execute it:
php artisan db:seed
A much better way is to create an Artisan Command. Here's another answer I wrote to teach how to create it: Select all rows with a date of right now
remove timeout limit from the web server(mostly from the config file)
Use set_time_limit(0) to force PHP to execute your code for unlimited amount of time.

Eclipse - Export/Save Search Results

Eclipse's Search results view is quite handy with its tree-like structure. Is there any way to export these results to a readable text format or save them to a file for later use?
I've tried using copy & paste but the resulting text format is far from readable.
You can change the mode from tree to list by click 'upper-right corner triangle' ->'show in list', then just copy all the files in the list , it will be a perfect list of search result
I'm using Eclipse Search CSV Export.
No I don't think there is a possibility to export the results yet. (Update: Now there's a suitable plugin available). But you should be able to use the eclipse search framework programmatically an export the entries by yourself.
I did not test the following snipped but implemeted a custom search that way once (using the RetrieverAction class). You should be able to listen to search result changes without the action as well:
TextSearchQueryProvider provider= TextSearchQueryProvider.getPreferred();
// your input (you'll have to implement that one I think...)
TextSearchInput input = new TextSearchQueryProvider.TextSearchInput();
ISearchQuery query= provider.createQuery(input);
ISearchResult result = query.getSearchResult();
result.addListener(new ISearchResultListener() {
public void searchResultChanged(SearchResultEvent e) {
// -> export result
}
});
// run the query
NewSearchUI.runQueryInBackground(query);
Again: I did not test that at all and don't know if there is a better approach as well..