Closed bajtos closed 3 years ago
As I commented in https://github.com/strongloop/loopback-next/issues/6131#issuecomment-679297030. The way we check pk and fk in lb4 relation
couldn't detect model inheritance.
Prompt:
Scaffold:
Read files frequently slows down the process. That's why some tests take a while
to run. For example, test case
lb4 relation generates model relation for existing property name verifies that a preexisting property will be overwritten: 2675ms
creates both hasMany and blongsTo relations, which makes it extremely slow.
PROS:
CONS:
IMO the relation CLI should keep those checks and validations.
lb4 relation
is one of the basic commands. We should make sure it fails
invalid cases and generate valid relations for users (esp new users). Therefore,
it should preserve those validations. For that reason, I propose the following
to improve the test speed:
context('generates model relation with custom relation name', () => {
const promptArray = [
{
relationType: 'belongsTo',
sourceModel: 'Order',
destinationModel: 'Customer',
foreignKeyName: 'customerId',
relationName: 'my_customer',
},
{
relationType: 'belongsTo',
sourceModel: 'OrderClass',
destinationModel: 'CustomerClass',
relationName: 'my_customer',
},
];
...
Refactor the code. Try to just read corresponding files once. For example,
current design reads the repository files twice (checks the existence of the
repo and the input relation name). Moreover, remove some checks. For example, the check for pks on source/destination models can be removed. Let the code in @repository
handle it.
To fix the inheritance issue, prompt for the name and type of the source (like what controller CLI does). This means that it will be user's responsibility to provide valid inputs.
- remove redundant ones
If they don't decrease the coverage, or we have a good reason not testing them, they should definitely be removed.
- Refactor the code. Try to just read corresponding files once.
👍
Closing as done, see https://github.com/strongloop/loopback-next/pull/6937
See https://github.com/strongloop/loopback-next/issues/5670. Most of the slow tests (taking more than a second to complete) are for the relations.
Let's investigate why are these tests so slow. Do they have expensive setup? Can we find a more efficient way how to test the relation generator?
Acceptance criteria
lb4 relation