Testing api: env constant not available?

I’m in the process of setting up my pipelines, which makes me go over all the test coverage and really get into the matter of automated tests.

I’m running RW 0.21.0, when doing yarn rw test api I get a bunch of failed tests on the api side, those are the scaffolded tests.

Here’s what I get in my terminal:

 FAIL   api  api/src/services/products/products.test.ts
  ● Test suite failed to run

    Error: error: Error validating datasource `DS`: The URL for datasource `DS` must start with the protocol `postgresql://`.
      -->  schema.prisma:5
       | 
     4 |   provider = "postgresql"
     5 |   url      = env("DATABASE_URL")
       | 

    Validation Error Count: 1

      at LineStream.<anonymous> (../node_modules/@prisma/client/runtime/index.js:27430:31)
      at LineStream._pushBuffer (../node_modules/@prisma/client/runtime/index.js:24491:19)
      at LineStream._transform (../node_modules/@prisma/client/runtime/index.js:24485:10)

Here’s the usual suspect:

/*
import { products } from './products'
*/

describe('products', () => {
  it('returns true', () => {
    expect(true).toBe(true)
  })
})

Relevant bit of my .env file:

DATABASE_URL=postgresql://fqbfedhvuwsa[...]

Not sure how to fix this and get my api tests up and working…
Apparently members of the community got these to work so it must be something wrong on my side, any help would be much appreciated.

Take a look at this, sounds like it is related

And the accompanying PR

1 Like

Thanks Tobbe, that’s definitely it. Can’t wait to see that doc on testing!

you and me both!

/me cowers away with head down in shame

:wink:

Hahaha!
Gives me the need to get back into RW code in the meantime :p, which is always a pleasure.

1 Like

Pleasure indeed!

And drop by a future Meetup when/if you have the time. 'Cause you’re missed :hugs:

1 Like

Now you are just making sure I can’t elude these forever :stuck_out_tongue: :smiley: tbh, I miss more community time as well \o/ ( might even have some PRs forgotten deep in my basement… #shame )

I’m hoping to be able to get more in touch within the following weeks with a couple of relevant news for the RW community :), as in maybe -finally- an online project and if Fortune favors my boldness, another project, bigger :).

I’ll really need to invest in a webcam by then.

1 Like

I just hit this problem while I was trying to test a single file

yarn rw test api readyHook

it also happens when I run yarn rw test

"@redwoodjs/core": "0.38.0"

This is probably because you’re using postgres, and haven’t setup the TEST_DATABASE_URL env var?

1 Like

that did it!

thanks