我想测试我的服务器。这是我的测试:
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);
});
});
但在我可以访问我的服务器的 get-function 之前,我收到以下错误:
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)
我发现的所有解决方案都不适合我的问题。那么如何在我的测试中访问这些令人眼花缭乱的环境变量,为什么它们会在测试中丢失?