Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Ionic Vue -> Jest unit tests are failing to run in any test #25223

Closed
4 of 7 tasks
marimendez88 opened this issue May 2, 2022 · 2 comments
Closed
4 of 7 tasks

bug: Ionic Vue -> Jest unit tests are failing to run in any test #25223

marimendez88 opened this issue May 2, 2022 · 2 comments
Labels
needs: reply the issue needs a response from the user

Comments

@marimendez88
Copy link

marimendez88 commented May 2, 2022

Prerequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x
  • Nightly

Current Behavior

An NX - Ionic and Vue workspace fails to run tests, many solutions tested and any seems to fix the issue:

This is the error message:

  ● Test suite failed to run

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation

AND:

Screen Shot 2022-04-16 at 14 35 05

Expected Behavior

  • Ability to run any unit tests without issues
  • Ability to run the test without any other configuration to ignore patterns or support nx libraries

Steps to Reproduce

  1. Create empty workspace: Run npx create-nx-workspace@^13.0.0
  2. select → apps option
  3. Install testing dependencies: npm install @nrwl/cypress@^13.0.0 @nrwl/jest@^13.0.0 @nrwl/linter@^13.0.0 --save-dev
  4. Install nx vue plugin : npm install @nx-plus/vue --save-dev
  5. Creating sample app: nx g @nx-plus/vue:app sample-app
  6. Install ionic npm i @ionic/vue npm i @ionic/vue-router
  7. Update main.ts under sample-app to use ionic
  8. Creating sample lib nx g @nx-plus/vue:lib sample-lib
  9. Create a header test component under sample-lib
  10. Import the header component into the sample app to use it
  11. Successfully served and components are shown as expected
  12. Run a test, error happens.

Code Reproduction URL

https://github.com/marimendez88/of-jest-issue

Ionic Info

Ionic:

   Ionic CLI : 6.16.3

Utility:

   cordova-res : not installed globally
   native-run  : not installed globally

System:

   NodeJS : v14.17.1
   npm    : 6.14.13
   OS     : macOS Monterey

Additional Information

Failure Logs

This is the error message:

  ● Test suite failed to run

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation

    Details:

    /of-jest-issue/apps/sample-app/src/components/HelloWorld.vue:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { defineComponent } from 'vue';
                                                                                      ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      1 | import { shallowMount } from '@vue/test-utils';
    > 2 | import HelloWorld from '../../src/components/HelloWorld.vue';
        | ^
      3 |
      4 | describe('HelloWorld.vue', () => {
      5 |   it('renders props.msg when passed', () => {

      at Runtime.createScriptFromCode (../../node_modules/jest-runtime/build/index.js:1728:14)
      at Object.<anonymous> (tests/unit/example.spec.ts:2:1)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        5.015 s
Ran all test suites.

Environment

 >  NX   Report complete - copy this into the issue template

   Node : 14.17.1
   OS   : darwin x64
   npm  : 6.14.13

   nx : 13.10.3
   @nrwl/angular : Not Found
   @nrwl/cypress : 13.10.3
   @nrwl/detox : Not Found
   @nrwl/devkit : 13.10.3
   @nrwl/eslint-plugin-nx : 13.10.3
   @nrwl/express : Not Found
   @nrwl/jest : 13.10.3
   @nrwl/js : Not Found
   @nrwl/linter : 13.10.3
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : Not Found
   @nrwl/workspace : 13.10.3
   typescript : 4.6.4
   rxjs : 6.6.7
   ---------------------------------------
   Community plugins:
   	 @nx-plus/vue: 13.0.1

Solutions tested:

Related Issues:

#24026
nrwl/nx#10100

Investigation made:

@ionitron-bot ionitron-bot bot added the triage label May 2, 2022
@marimendez88 marimendez88 changed the title bug: bug: Ionic Vue -> Jest unit tests are failing to run in any test May 2, 2022
@liamdebeasi liamdebeasi self-assigned this May 2, 2022
@liamdebeasi
Copy link
Contributor

Thanks for the issue. I do not see anything in the error log that would indicate that this is an Ionic issue. The error appears to be coming from within your project code, not Ionic's code.

Are you able to provide a minimal reproduction that only uses Vue + Ionic without the Nx plugins?

@ionitron-bot
Copy link

ionitron-bot bot commented May 16, 2022

Thanks for the issue! This issue is being closed due to the lack of a reply. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

Thank you for using Ionic!

@ionitron-bot ionitron-bot bot closed this as completed May 16, 2022
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators May 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs: reply the issue needs a response from the user
Projects
None yet
Development

No branches or pull requests

2 participants