passing argument between grunt task - gruntjs

I run a grunt task which calculates some stuff and puts the result in a variable. Later I want to use this result in another grunt task. I tried a lot of things to share this result between this two tasks but I did not succeed.
Have you got any idea how to do this?

finally I found a good solution,
I use grunt.config
In the task which is calculate the result I had
grunt.config.set('result', result)
And I can access it in other task with
grunt.config('result')

Related

How to run the same grunt task with different configurations (programmatically)?

I've trawled the web for the last 2 hours trying to figure out how to do this so I'm asking here. I've read the documentation but I can't find a good example and I think I may be implementing some sort of anti-pattern or I have missed something very basic but here goes.
I want to loop around an array and perform this task in each loop
grunt.task.run('string-replace:dist');
However, every time I run this loop I need a slightly different config. Different output folder, different replacement array etc etc
I have been changing the config like this.
grunt.config.set('string-replace.dist.options.replacements', translationsArray);
grunt.config.set('string-replace.dist.files.0.dest', 'dist/' + langCode + '/');
Here comes the problem. Grunt does not seem to execute tasks, wait for them to finish and then continue with your code. So it sets up the task for each loop but does not run it, then it changes the config for each loop overwriting the old config each time. Then it runs all the tasks with the last config. I just want to make Grunt execute the task, wait till its done, change the config, rinse and repeat.
Am I doing something really stupid? Grunt documentation seems to be desperately telling me its synchronous but this does not seem to be the case with grunt.task.run. I would also like to point out that I don't want to just register more tasks with the different options because I don't know how many times I might have to run this loop. It is controlled from elsewhere so it can be dynamic and data driven. Unless I'm supposed to register tasks dynamically?

Can phpunit start with a certain test and then keep going?

I use stopOnFailure in phpunit. Just my preference. I'm wondering if there is a way to isolate 1 test and run it, like --filter but then keep going. So that if my test suite finds a failure half way thru all the tests ... I just want to pick up where I left off when I'm done isolating and fixing.
(Not looking for solutions like paratest)
No. But you can configure PHPUnit to start the execution with tests that failed the last time: --order-by=defects.

In airflow, is there a good way to call another dag's task?

I've got dag_prime and dag_tertiary.
dag_prime: Scans through a directory and intends to call dag_tertiary
on each one. Currently a PythonOperator.
dag_tertiary: Scans through the directory passed to it and does (possibly time-intensive) calculations on the contents thereof.
I can call the secondary one from a system call from the python operator, but i feel like there's got to be a better way. I'd also like to consider queuing the dag_tertiary calls, if there's a simple way to do that. Is there a better way than using system calls?
Thanks!
Use airflow.operators.trigger_dagrun for calling one DAG from another.
The details can be found in operator trigger_dagrun Airflow documentation.
Following post gives a good example of using this operator:
https://www.linkedin.com/pulse/airflow-lesson-1-triggerdagrunoperator-siddharth-anand
Use TriggerDagRunOperator from airflow.operators.dagrun_operator and pass the other DAG name to triger_dag_id parameter.
Follow Airflow updated documentation dag_run_operator Airflow Documentation

Run a code snippet before and after tests with testthat

I have a set of R functions which get called from a Ruby application and would like to test them. The R functions access data from a Postgres database so to write tests I need to populate a test database with some sample data.
I would like to avoid cleaning up the database within every test case. It would be nice if I could start a transaction before every test and rollback the transaction after.
The last paragraph of the "Writing Tests" section of this page http://r-pkgs.had.co.nz/tests.html makes me think that it's not possible to execute a block of code before every test case.
Does anyone know of any creative work arounds? I'm considering forking the project and adding the functionality but wanted to make sure I'm not reinventing the wheel.
For anyone who stumbles upon this, I ended up creating a wrapper function for test_that() which I use when getting data from postgres. Below is my solution:
db.test_that <- function(description, test_code) {
dbGetQuery(database_connection, 'BEGIN TRANSACTION')
test_that(description, test_code)
dbRollback(database_connection)
}

Run all Grunt SubTasks except one

I've a bunch of subtasks for grunt watch (e.g. grunt watch:styles, grunt watch:sprites, etc). Then many other tasks run grunt watch. I would like to exclude one task. Is there a way to specify that? Basically run all grunt watch subtasks except grunt watch:dist.
I know I could create another task and only specify the subtasks I'm actually interested on, however, if I add another subtask later, that means now I've to add it, so I would rather not do it that way.
Thanks
There might be a better way, but this is doing the trick for now:
grunt.registerTask('watch:basic', function () {
delete grunt.config.data.watch.dist;
grunt.task.run('watch');
});
Fortunately, in this case, I don't have other tasks that might run grunt watch:dist, so it's safe to simply remove the config, but I can think of other cases where this approach would create conflicts.

Resources