Test is failing when deploying through Seed

Hi,

I just recreated the project from scratch. Now I suddently are receiving an error with the test suite, when deploying through Seed.
The error I receive is the following:

FAIL tests/billing.test.js
  ● Test suite failed to run

    /tmp/seed/source/tests/billing.test.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { calculateCost } from "../libs/billing-lib";
                                                                                             ^^^^^^
    
    SyntaxError: Unexpected token import
      
      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:305:17)
          at Generator.next (<anonymous>)
          at new Promise (<anonymous>)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.878s
Ran all test suites.
npm ERR! Test failed.  See above for more details.

2018/11/24 14:07:38 Error: exec: internal error

Anyone else that have received this error or knows how to fix it?

Kind regards.

Do you see this error when you run it locally? Using npm run test.

Yes.

Here’s the console outout:

MacBook-Pro:backend user$ npm run test

> notes-app-api@1.1.2 test /Users/user/workspaces/app/backend
> jest

 FAIL  tests/billing.test.js
  ● Test suite failed to run

    /Users/user/workspaces/app/backend/tests/billing.test.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { calculateCost } from "../libs/billing-lib";
                                                                                                    ^
    
    SyntaxError: Unexpected token {
      
      at new Script (vm.js:74:7)
          at Generator.next (<anonymous>)
          at new Promise (<anonymous>)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.277s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! notes-app-api@1.1.2 test: `jest`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the notes-app-api@1.1.2 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/user/.npm/_logs/2018-11-25T19_10_56_468Z-debug.log
MacBook-Pro:backend user$

I just clone the repo

and ran:

$ npm install
$ npm run test

> notes-app-api@1.1.0 test /Users/jayair/Desktop/tutorial-project/tutorial-api-jest-test
> jest

 PASS  tests/billing.test.js
  ✓ Lowest tier (6ms)
  ✓ Middle tier (1ms)
  ✓ Highest tier

Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        1.902s
Ran all test suites.

Must be some changes I’ve made then. Just can’t figure it out and the debug output dosen’t reveals that much…

It just seems like serverless-webpack isn’t doing it’s thing. I would check the package.json and serverless.yml against the repo.

I’ve just cloned the repo again and ran the test with the same error. Must some environment things then? But then its weird it also fails on Seed?

I guess it might have something to do with the folder structure? If I clone the repo into a new folder it works fine. But if I clone it into a folder with a parent folder of /backend and no folder named serverless-stack-demo-api it dosen’t work?

Yeah in that case you need to change the path in the settings for the service to /backend. By default it points to the root path.

Hi again. it worked, have spend a lot of time trying to figure this one out :slight_smile:

What does your serverless.yml file look like here? @tstarkdk

Hi, just as the one from the repo above. Only changes to it, is the name of the service and the region in which its created.

Regardless of new clone, I too am getting this error.
macos reports the file-type to be javascript but the error message indicates jest may not consider it javascript.
Has anyone found the root-cause / solution?

So, apparently there exists some issue with babel transforming ES2015 and beyond into javascript that jest finds acceptable.

Here is my solution.
Go to…
https://babeljs.io/docs/en/6.26.3/

Follow instructions for “ES2015 and beyond”

Don’t forget to add babel configuration to your package.json !

{
  "babel": {
    "presets": ["env"]
  },
}

This is NOT a solution, it broke the serverless deployment.

Thanks for digging into the issue. We are now moving towards using the serverless-bundle. You can follow these instructions to upgrade your project here.

I too am having this issue, frustrating as the error doesn’t give much

Whats the error you are getting? You also might be using an older version of the tutorial. Compare your package.json to the one we are using in the tutorial?