How to access RAZZLE variables in process.env when testing a server with JEST?

175 Views Asked by At

I want to test my server. Here is my test:

const request = require("supertest");
const server = require("./server.js");

describe('server', () => {
  test('should response 200', async () => {
    const response = await request(server).get("/api/meta");
    expect(response.statusCode).toBe(200);
  });
});

But before I can access the get-function of my server, I receive following error:

FAIL  src/server.test.js
  ● Test suite failed to run

    TypeError: root path required

      22 | server
      23 |   .disable("x-powered-by")
    > 24 |   .use(express.static(process.env.RAZZLE_PUBLIC_DIR))
         |                ^
      25 |   .use(cookieParser())
      26 |   .use(
      27 |     session({

      at Function.static (node_modules/serve-static/index.js:40:11)
      at Object.<anonymous> (src/server.js:24:16)
      at Object.<anonymous> (src/server.test.js:2:16)

All solutions I found don't fit my problem. So how can I access these razzle env-variables in my test and why are they lost in the test?

0

There are 0 best solutions below