question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 are tested and any seems to fix the issue: Screen Shot 2022-05-20 at 08 49 27

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:
  /Users/ricardomadrid/Documents/openforge/of-jest-issue/node_modules/@ionic/core/components/ion-accordion.js:4
  import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
  ^^^^^^
  SyntaxError: Cannot use import statement outside a module
   at Runtime.createScriptFromCode (../../node_modules/jest-runtime/build/index.js:1728:14)
Test Suites: 1 failed, 1 total
Tests:    0 total
Snapshots:  0 total
Time:    3.398 s
Ran all test suites.
 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
 >  NX  Ran target test for project sample-lib (4s)
 
  βœ–  1/1 failed
  βœ”  0/1 succeeded [0 read from cache]

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

Create empty workspace: Run npx create-nx-workspace@^13.0.0 select β†’ apps option Install testing dependencies: npm install @nrwl/cypress@^13.0.0 @nrwl/jest@^13.0.0 @nrwl/linter@^13.0.0 --save-dev Install nx vue plugin : npm install @nx-plus/vue --save-dev Creating sample app: nx g @nx-plus/vue:app sample-app Install ionic npm i @ionic/vue npm i @ionic/vue-router Update main.ts under sample-app to use ionic Creating sample lib nx g @nx-plus/vue:lib sample-lib Create a header test component under sample-lib Import the header component into the sample app to use it Successfully served and components are shown as expected 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:

Resources:

Related Issues:

Investigation made:

Collaboration with: @Ricardo385

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
marimendez88commented, May 24, 2022

Hey @liamdebeasi , thank you, I already did the steps mentioned but still no luck, I will try to provide a ionic - vue repo as soon as I can!

0reactions
ionitron-bot[bot]commented, Jun 14, 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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue jest tests failing when expected to pass - Stack Overflow
The first test try's to see if the message is properly inserted in the component. The second test checks if the error variable...
Read more >
Unit testing with Jest | Vue.js 3 By Example - Packt Subscription
These are tests that we can run in quick repetition to make sure that our code is not broken. When any tests fail,...
Read more >
PyCharm 181.4203.547 Release Notes | Knowledge Base
Feature PY‑20770 Support Python 3.6 asynchronous generators and comprehensions Feature PY‑21768 Semantic highlighting for Python Bug PY‑19573 Python console ‑ no output under OS X Bug...
Read more >
Lesson 8: Setting up Tests with Jest and Cypress | Elite Ionic
Running Tests. In order to run all of the unit tests in the application you just need to run the following command: npm...
Read more >
Angular Unit and End-to-End Testing for Ionic App Components
When an @ionic/angular application is generated using the Ionic CLI, it is automatically set up for unit testing and end-to-end testing of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found