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

Jest tests fail to run in Angular 10 #10251

Closed
rulamon opened this issue Jul 6, 2020 · 3 comments
Closed

Jest tests fail to run in Angular 10 #10251

rulamon opened this issue Jul 6, 2020 · 3 comments

Comments

@rulamon
Copy link

rulamon commented Jul 6, 2020

🐛 Bug Report

After updating to Angular 10, when running tests I get this exception, before our tests worked fine. Posted this in the angular/cli repository as well: angular/angular-cli#18155

console.error                                                                                                                                                               
  Error: Uncaught [TypeError: A dynamic import callback was not specified.]                                                                                                 
      at reportException (C:\Users\Rubenn\AC\acro-companion\node_modules\jest-environment-jsdom\node_modules\jsdom\lib\jsdom\living\helpers\runtime-script-errors.js:62:24) 
      at Timeout.task [as _onTimeout] (C:\Users\Rubenn\AC\acro-companion\node_modules\jest-environment-jsdom\node_modules\jsdom\lib\jsdom\browser\Window.js:396:9)          
      at listOnTimeout (internal/timers.js:551:17)                                                                                                                          
      at processTimers (internal/timers.js:494:7) TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.                          
      at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:31:9)                                                                                      
      at C:\Users\Rubenn\AC\acro-companion\node_modules\src\auth\auth.ts:58:52                                                                                              
      at ZoneDelegate.invoke (C:\Users\Rubenn\AC\acro-companion\node_modules\zone.js\dist\zone.js:386:30)                                                                   
      at ProxyZoneSpec.onInvoke (C:\Users\Rubenn\AC\acro-companion\node_modules\zone.js\dist\proxy.js:117:43)                                                               
      at ZoneDelegate.invoke (C:\Users\Rubenn\AC\acro-companion\node_modules\zone.js\dist\zone.js:385:36)                                                                   
      at Zone.run (C:\Users\Rubenn\AC\acro-companion\node_modules\zone.js\dist\zone.js:143:47)                                                                              
      at NgZone.runOutsideAngular (C:\Users\Rubenn\AC\packages\core\src\zone\ng_zone.ts:227:50)                                                                             
      at SwitchMapSubscriber.project (C:\Users\Rubenn\AC\acro-companion\node_modules\src\auth\auth.ts:58:28)                                                                
      at SwitchMapSubscriber._next (C:\Users\Rubenn\AC\acro-companion\node_modules\rxjs\src\internal\operators\switchMap.ts:123:21)                                         
      at SwitchMapSubscriber.Subscriber.next (C:\Users\Rubenn\AC\acro-companion\node_modules\rxjs\src\internal\Subscriber.ts:99:12) {                                       
    code: 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING'                                                                                                                          
  }                                                                                                                                                                         

To Reproduce

Steps to reproduce the behavior:
It happens when I simply run the tests in jest.

jest.config.js

const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { compilerOptions } = require('./tsconfig.base');

module.exports = {
  preset: 'jest-preset-angular',
  roots: ['<rootDir>/spec/tests'],
  testMatch: ['**/+(*.)+(spec).+(ts)'],
  setupFilesAfterEnv: ['<rootDir>/src/test.ts'],
  collectCoverage: true,
  coverageReporters: ['html'],
  coverageDirectory: 'coverage/my-app',
  moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths || {}, {
    prefix: '<rootDir>/',
  }),
  testEnvironment: 'jsdom', //default

  globals: {
    'ts-jest': {
      allowSyntheticDefaultImports: true,
    },
  },
  transform: {
    '^.+\\.js$': 'babel-jest',
  },
};

Expected behavior

Test should run normally, which they did prior to angular 10 update.

Link to repl or repo (highly encouraged)

envinfo

 System:
    OS: Windows 10 10.0.18362
    CPU: (4) x64 Intel(R) Core(TM) i5-3330 CPU @ 3.00GHz
  Binaries:
    Node: 14.5.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.4 - ~\AC\acro-companion\node_modules\.bin\yarn.CMD
    npm: 6.14.5 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: 26.0.1 => 26.0.1
@ahnpnl
Copy link
Contributor

ahnpnl commented Jul 8, 2020

Hi, I would encourage to move this issue to jest-preset-angular repo. The stack trace doesn’t seem to be related to jest itself.

Moreover, if you create the issue for jest-preset-angular, please also include your repo so it’s easier to check if everything is correctly configured.

@SimenB
Copy link
Member

SimenB commented Oct 11, 2020

at C:\Users\Rubenn\AC\acro-companion\node_modules\src\auth\auth.ts:58:52 seems to use untranspiled import() which Jest doesn't support (yet - I just opened a PR adding support for it: #10620).

Beyond that, this bug report isn't really actionable without a reproduction, so I'll close it. Feel free to open up a new issue with a reproducion

@SimenB SimenB closed this as completed Oct 11, 2020
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants