test: fix flaky tests in webContents.navigationHistory
(#41705)
test: fix flaky tests by replacing real urls with data urls
This commit is contained in:
parent
32b44aa5c8
commit
c57ce31e84
1 changed files with 20 additions and 33 deletions
|
@ -548,6 +548,9 @@ describe('webContents module', () => {
|
||||||
|
|
||||||
describe('navigationHistory', () => {
|
describe('navigationHistory', () => {
|
||||||
let w: BrowserWindow;
|
let w: BrowserWindow;
|
||||||
|
const urlPage1 = 'data:text/html,<html><head><script>document.title = "Page 1";</script></head><body></body></html>';
|
||||||
|
const urlPage2 = 'data:text/html,<html><head><script>document.title = "Page 2";</script></head><body></body></html>';
|
||||||
|
const urlPage3 = 'data:text/html,<html><head><script>document.title = "Page 3";</script></head><body></body></html>';
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
w = new BrowserWindow({ show: false });
|
w = new BrowserWindow({ show: false });
|
||||||
|
@ -559,25 +562,19 @@ describe('webContents module', () => {
|
||||||
expect(result).to.deep.equal({ url: '', title: '' });
|
expect(result).to.deep.equal({ url: '', title: '' });
|
||||||
});
|
});
|
||||||
it('should fetch navigation entry given a valid index', async () => {
|
it('should fetch navigation entry given a valid index', async () => {
|
||||||
await w.loadURL('https://www.google.com');
|
await w.loadURL(urlPage1);
|
||||||
w.webContents.on('did-finish-load', async () => {
|
const result = w.webContents.navigationHistory.getEntryAtIndex(0);
|
||||||
const result = w.webContents.navigationHistory.getEntryAtIndex(0);
|
expect(result).to.deep.equal({ url: urlPage1, title: 'Page 1' });
|
||||||
expect(result).to.deep.equal({ url: 'https://www.google.com/', title: 'Google' });
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
it('should return null given an invalid index larger than history length', async () => {
|
it('should return null given an invalid index larger than history length', async () => {
|
||||||
await w.loadURL('https://www.google.com');
|
await w.loadURL(urlPage1);
|
||||||
w.webContents.on('did-finish-load', async () => {
|
const result = w.webContents.navigationHistory.getEntryAtIndex(5);
|
||||||
const result = w.webContents.navigationHistory.getEntryAtIndex(5);
|
expect(result).to.be.null();
|
||||||
expect(result).to.be.null();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
it('should return null given an invalid negative index', async () => {
|
it('should return null given an invalid negative index', async () => {
|
||||||
await w.loadURL('https://www.google.com');
|
await w.loadURL(urlPage1);
|
||||||
w.webContents.on('did-finish-load', async () => {
|
const result = w.webContents.navigationHistory.getEntryAtIndex(-1);
|
||||||
const result = w.webContents.navigationHistory.getEntryAtIndex(-1);
|
expect(result).to.be.null();
|
||||||
expect(result).to.be.null();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -590,13 +587,9 @@ describe('webContents module', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return valid active index after a multiple page visits', async () => {
|
it('should return valid active index after a multiple page visits', async () => {
|
||||||
const loadPromise = once(w.webContents, 'did-finish-load');
|
await w.loadURL(urlPage1);
|
||||||
await w.loadURL('https://www.github.com');
|
await w.loadURL(urlPage2);
|
||||||
await loadPromise;
|
await w.loadURL(urlPage3);
|
||||||
await w.loadURL('https://www.google.com');
|
|
||||||
await loadPromise;
|
|
||||||
await w.loadURL('about:blank');
|
|
||||||
await loadPromise;
|
|
||||||
|
|
||||||
expect(w.webContents.navigationHistory.getActiveIndex()).to.equal(2);
|
expect(w.webContents.navigationHistory.getActiveIndex()).to.equal(2);
|
||||||
});
|
});
|
||||||
|
@ -608,20 +601,14 @@ describe('webContents module', () => {
|
||||||
|
|
||||||
describe('navigationHistory.length() API', () => {
|
describe('navigationHistory.length() API', () => {
|
||||||
it('should return valid history length after a single page visit', async () => {
|
it('should return valid history length after a single page visit', async () => {
|
||||||
await w.loadURL('https://www.google.com');
|
await w.loadURL(urlPage1);
|
||||||
w.webContents.on('did-finish-load', async () => {
|
expect(w.webContents.navigationHistory.length()).to.equal(1);
|
||||||
expect(w.webContents.navigationHistory.length()).to.equal(1);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return valid history length after a multiple page visits', async () => {
|
it('should return valid history length after a multiple page visits', async () => {
|
||||||
const loadPromise = once(w.webContents, 'did-finish-load');
|
await w.loadURL(urlPage1);
|
||||||
await w.loadURL('https://www.github.com');
|
await w.loadURL(urlPage2);
|
||||||
await loadPromise;
|
await w.loadURL(urlPage3);
|
||||||
await w.loadURL('https://www.google.com');
|
|
||||||
await loadPromise;
|
|
||||||
await w.loadURL('about:blank');
|
|
||||||
await loadPromise;
|
|
||||||
|
|
||||||
expect(w.webContents.navigationHistory.length()).to.equal(3);
|
expect(w.webContents.navigationHistory.length()).to.equal(3);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue