Cypress call out to Laravel commands #6239
Closed
petertgiles
started this conversation in
Ideas
Replies: 2 comments 2 replies
-
This seems to be similar to a recommended approach by Cypress. I think we could expose some of our factories as an artisan commands that possible take JSON as an argument to create the object? I imagine it would look something like the following: import { fakeModel } from "@gc-digital-talent/fake-data";
const fakeModels = fakeModel();
const fakeModelString = JSON.stringify(fakeModels[0]);
cy.exec(`php artisan seed:model ${fakeModelString}`); protected $signature = 'seed:model {data: The data to pass to factory}';
public function handle(): void
{
$modelDataJSON = $this->argument('data');
return Model::factory()->create(json_decode($modelDataJSON));
} |
Beta Was this translation helpful? Give feedback.
2 replies
-
Created #6581 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It was already getting pretty awkward to set up Cypress tests in situations like needing a new application. The steps are something like:
This is going to get even more tricky as we split the ability to do actions up in to an increasing number of roles.
It would be much easier to set this up with Eloquent models directly like we do with PHPUnit tests instead of having to work around all the workflow limitations of the GraphQL API. I know we've worked with Artisan commands before that could do this. And Cypress has the ability to call shell commands. Database seeding is one of the example uses listed on their doc page. Perhaps this could make our Cypress tests simpler?
Beta Was this translation helpful? Give feedback.
All reactions