Test is failing when deploying through Seed


#1

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.


#2

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


#3

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$

#4

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.

#5

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


#6

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


#7

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?


#8

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?


#9

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.


#10

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


#11

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


#12

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.