测试文件:
describe("Messages", () => {
beforeAll(async () => {
await page.goto("http://dodona.localhost:3000/nl/users/1/token/zeus");
});
it("Check home page title - 2", async () => {
await page.goto("http://dodona.localhost:3000/nl/courses/8", { waitUntil: "domcontentloaded" });
// await page.goto("https://facebook.com", { waitUntil: "domcontentloaded" });
}, 30000);
it("Check home page title", async () => {
await page.goto("https://google.com", { waitUntil: "domcontentloaded" });
}, 1500);
});
jest-puppeteer.config.js
module.exports = {
launch: {
dumpio: true,
headless: false,
args: ["--disable-infobars"],
// devtools: true
},
server: {
command: "rails server",
port: 3000,
launchTimeout: 60000
},
browserContext: "default"
};
jest.config.js
module.exports = {
preset: "jest-puppeteer",
reporters: ["default", "jest-junit"],
globals: {
"ts-jest": {
tsConfig: {
allowJs: true,
},
},
},
roots: ["test/javascript/"],
testMatch: ["**/?(*.)+(spec|test).[t]s"],
transform: {
"^.+\\.ts?$": "ts-jest"
},
globalSetup: "jest-environment-puppeteer/setup",
globalTeardown: "jest-environment-puppeteer/teardown",
testEnvironment: "jest-environment-puppeteer",
};
上面的代码在Check home page title - 2
测试中挂起,直到30秒超时结束。 beforeAll
page.goto是验证用户身份所必需的,以便可以访问和检查身份验证后的页面。
我是在做错什么吗,还是没有为这种类型的测试设置简单的玩笑伪造者代码?如果我要求Check home page title - 2
转到FB并等待内容加载,则可以成功完成。因此,我感到我的Rails服务器启动得不够快,即使它肯定会在30秒钟内启动。