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.

Jest issue with aws-amplify-angular.module

See original GitHub issue

** Which Category is your question related to? ** aws-amplify-angular ** What AWS Services are you utilizing? ** Congito User pool ** Provide additional details e.g. code snippets ** I am using aws-amplify- angular in a nx project. I’m using jest with jest-preset-angular for unit test the app.

I’m getting an error that I can reproduce. I created a repo to show the issue: https://github.com/jdavidhermoso/nx-jest-issue

I know its not a problem with aws-amplify, but maybe someone has faced the same issue. I’m probably not configuring well jest. I assume the issue is that aws-amplify-angular is not transpiled, so I need to add babel and transformignorepatterns to Jest configuration. I tried using babel to transpile aws-amplify-angular following this guide (https://github.com/thymikee/jest-preset-angular#unexpected-token-importexportother), but didn’t work.

Thanks in advance, and sorry if it’s not the better place to create this issue.

FAIL  apps/myapp/src/app/app.component.spec.ts
  ● Test suite failed to run

    Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • 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/en/configuration.html

    Details:

    /Users/hermosoj/Desktop/dev/nx-jest-issue/node_modules/aws-amplify-angular/index.ts:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export { AmplifyAngularModule } from './src/aws-amplify-angular.module';
                                                                                             ^^^^^^

    SyntaxError: Unexpected token export



      at ScriptTransformer._transformAndBuildScript (../../node_modules/@jest/transform/build/ScriptTransformer.js:471:17)
      at Object.<anonymous> (src/app/app.component.ts:169:25)
      at Object.<anonymous> (src/app/app.component.spec.ts:3:1)

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
ErikHDevcommented, Jan 16, 2020

FYI, having the same exact issue with Nrwl and this amplify library “unable to require ‘.d.ts’ file”. I was able to fix the " Jest encountered an unexpected token" by adding this into my jest.config file.

transformIgnorePatterns: [ "node_modules/(?!@ngrx|@agm/core|@aws-amplify|aws-amplify-angular)" ],

But now I’m getting the dreaded “d.ts error” that I can seem to fix. I followed the suggestion here and added both

isolatedModules Set isolatedModules to true in packages/my-app/jest.config.js.

preserveSymlinks Set preserveSymlinks to true in packages/my-app/tsconfig.json.

But same error. If anyone knows please let me know 😃

1reaction
mattmbrightsidecommented, Jan 30, 2020

Same issue, please help!

` ● Test suite failed to run

Jest encountered an unexpected token

Details:

/node_modules/aws-amplify-angular/index.ts:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export { AmplifyAngularModule } from './src/aws-amplify-angular.module';
                                                                                         ^^^^^^

SyntaxError: Unexpected token export

  2 | import { Auth } from 'aws-amplify';
  3 | import { Router } from '@angular/router';
> 4 | import { AmplifyService } from 'aws-amplify-angular';
    | ^

at ScriptTransformer._transformAndBuildScript (…/…/node_modules/@jest/transform/build/ScriptTransformer.js:537:17) at ScriptTransformer.transform (…/…/node_modules/@jest/transform/build/ScriptTransformer.js:579:25) at Object.<anonymous> (src/app/app.component.ts:4:1)

`

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to mock AWS Amplify library in Angular?
Save this answer. Show activity on this post. I manage to get rid of the error. You need to import Auth in the...
Read more >
Testing your Amplify Application with Jest and Cypress
In this post we will be writing static, unit, integration and end-to-end (e2e) tests for a web app deployed with the Amplify Console...
Read more >
Deploy a Web Application on AWS Amplify | Module 1
In this module, you will create a new web application using React, a JavaScript library for building user interfaces, and learn how to...
Read more >
Building a reusable testing pipeline for AWS Amplify plugins
The E2E tests remain in the planning stage. The unit and integration testing framework use Jest, a JavaScript Testing Framework designed to ...
Read more >
Troubleshooting AWS CodeBuild
Apache Maven builds reference artifacts from the wrong repository. Issue: When you use Maven with an AWS CodeBuild-provided Java build environment, Maven pulls ......
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