Can you run Sapper with NODE_ENV=test

294 views Asked by At

I'm converting a project from Angular + Node.js server --> Sapper. In relation to e2e tests, there is something I can't understand; can I run Sapper with NODE_ENV env variable set to test? When I run export NODE_ENV=test && sapper dev the variable is always dev. How can I fix this?

My current work-around is to build the application, and then start it with node __sapper__/build, but this is not very nice when developing e2e tests.

1

There are 1 answers

2
Casper Dijkstra On

Sapper is an open-source project, so we can check how NODE_ENV is set: https://github.com/sveltejs/sapper.

When running sapper dev, the environmental variable NODE_ENV is set in /src/api/dev.ts

(/src/api/dev.ts)
process.env.NODE_ENV = 'development';

where it's hard-coded to development.

The variable can be set to other values (including testing) in

(/src/cli.ts)
178. process.env.NODE_ENV = process.env.NODE_ENV || 'production';

so I surmise you would need sapper prod (or something similar, check it) to use this NODE_ENV.

You should also check it that doesn't beat the purpose of what you're trying to achieve, perhaps sticking to sapper dev is preferable to running in non-dev mode.