Working on a project created with the @vue/cli 4.2.2
and Vue CLI Electron Plugin Builder. Vue CLI uses the HtmlWebpackPlugin that automatically generates the index.html
in the public
directory. The </title>
of the relevant index.html
page has the <%= htmlWebpackPlugin.options.title %>
syntax that automatically detects the title of the page from the vue.config.js
file.
vue.config.js
module.exports = {
pluginOptions: {
electronBuilder: {
chainWebpackRendererProcess: config => {
config.plugin("html").tap(args => {
args[0].title = "Stack Overflow";
return args;
});
}
}
}
};
The problem is that when the app starts, there's a millisecond flash where the page title changes from stackoverflow to Stack Overflow. To prevent this, I used the Electron page-title-updated
hook like the following to make sure the app title loads correctly.
main.js
var win = new BrowserWindow({
width: 800,
height: 600,
title: 'Stack Overflow'
});
win.on('page-title-updated', (evt) => {
evt.preventDefault();
});
It works great and there's no window flashing in the </title>
now but when running e2e
test using the Cypress, it just can't find the correct title Stack Overflow and test fails.
test.js
describe("My First Test", () => {
it("ensures the correct title", () => {
cy.visit('/').title().should('eq', 'Stack Overflow')
})
});
The result of Cypress test expected stackoverflow to equal Stack Overflow
. So, the million dollar question is, how do I get the Cypress test pass?