nativescript-schematics icon indicating copy to clipboard operation
nativescript-schematics copied to clipboard

Testing errors for migrate-module are not accurate

Open sebawita opened this issue 6 years ago • 0 comments

Environment Provide the content of the package.json file in the project:

Describe the bug The following test failures: When the module has a component https://github.com/NativeScript/nativescript-schematics/blob/master/src/migrate-module/index_spec.ts#L67

** When the module has a provider** https://github.com/NativeScript/nativescript-schematics/blob/master/src/migrate-module/index_spec.ts#L97

Don't reflect what is happening when executing the schematic ng g migrate-module --name=my-module.

When I comment out the following code (which calls filter() to hide the web version of the ngmodule file): https://github.com/NativeScript/nativescript-schematics/blob/master/src/generate/module/index.ts#L63-L70

and run npm run test

The previously mentioned tests fail.

However, when I try to reproduce the issues in a real project. The scenario in which I run the migrate-module schematic on a module:

  • with no components - it works, like in tests
  • with a component - it works, while this test fails
  • with a provider - it works, while this test fails

To Reproduce

Step 1 Comment out this code (you might also need to remove the filter import): https://github.com/NativeScript/nativescript-schematics/blob/master/src/generate/module/index.ts#L63-L70

run npm run test

This will cause the two tests to fail.

Step 2 Build the NativeScript schematics and install locally

npm run build
npm i -g ./

Create a new code-sharing project

ng new -c=@nativescript/schematics shared-app --shared
cd shared-app

In the project delete the @nativescript folder from node_modules. This should force your project to fall back to the globally installed @nativescript/schematics.

Now generate a new module and add a component to it:

ng g m admin --no-nativescript
ng g c admin/hello --no-nativescript

Finally, migrate the module:

ng g migrate-module --name=admin

Unlike in the tests, this doesn't fail in a real app. This leads me to a conclusion, that there is something wrong with the test.

Expected behavior The tests shouldn't be failing.

Sample project

Additional context

What is strange here, is that the When the name of existing module is provided test, works fine. Which performs a very similar task, which should supposedly require the commented out filter() code

sebawita avatar Feb 15 '19 16:02 sebawita