Hello! I have a question that has little to do wit...
# prisma-whats-new
p
Hello! I have a question that has little to do with Prisma, but since y’all are cool, I’ll ask it anyways 😛 In WebStorm, before running Jest, I’m trying to load my
.env
file before. Any idea what the node options I could provide would be, to load dotenv before running Jest?
😂 1
n
you might also consider running dotenv from within your tests: https://github.com/motdotla/dotenv
p
Actually I tried that, it simply doesn’t work! I’m using
import * as dotenv from 'dotenv'
then running
dotenv.load()
This is why I ended up with the script
"test": "dotenv jest"
which works well
But don’t worry about it; as I said, it’s a bit out of place 🙂
n
I think it's great to share experience and thoughts about such topics here! 🙂 Feel free to create a topic in the Forum as well, if you find no satisfying answer here.
👍 1
@James, can you elaborate on your
source
suggestion?
j
i dont know - i just googled it. source .env is the bash way of importing vars into env vars
i'm just jealous you're testing 😄
h
pretty sure you could run dotenv via the node options
-r dotenv
something like that
p
That’s actually the first thing I tried, but it unfortunately did not work
@James I have a very good coverage rate actually! I’m going to try and publish a boilerplate based on @lawjolla’s permissions stub but with TypeScript and 100% jest coverage.
😍 1
m
@picosam I used
"test": "dotenv -e config/test.env jest",
in my package.json scripts section
p
Thanks @max, actually
”dotenv jest”
simply works. But I also found a way around the WebStorm issue. As I said, I’ll try and put this together on a repository next week.
👍 2
l
When in doubt, I hack
require('dotenv').config()
and it all works 🙂 I use that a lot with QuokkaJS (big recommendation if you haven't taken a look at it -- it's a scratch file runtime that can also run real files)
Also, if anyone would do a proper config tutorial with WS/IntelliJ and GraphQL, that would be a giant help. I'm constantly fighting all of the config and have no idea what I'm doing.
Super interested in how people are testing JS GraphQL servers. Elixir really had this area nailed
p
@lawjolla I’m working on it. The reason
require('dotenv').config()
wasn’t working at first was simply because the current working directory was incorrectly set by WebStorm
I ended up using
globalSetup
and loading it this way after all. I’ll try and put references to GitHub issues that explain why, for instance, I use JavaScript for globalSetup though I’m using TypeScript for everything else!
💯 1
@max if you’re still interested in seeing a working test case list: https://github.com/coformatique/prisma-auth0-starter
👍 2
n
that looks awesome, thanks for sharing @picosam 😊