test: improve webContents.savePage() specs (#32727)
This commit is contained in:
parent
7442905dd2
commit
fb3f5e490e
1 changed files with 25 additions and 6 deletions
|
@ -3419,20 +3419,39 @@ describe('BrowserWindow module', () => {
|
|||
const savePageJsPath = path.join(savePageDir, 'save_page_files', 'test.js');
|
||||
const savePageCssPath = path.join(savePageDir, 'save_page_files', 'test.css');
|
||||
|
||||
after(() => {
|
||||
afterEach(() => {
|
||||
closeAllWindows();
|
||||
|
||||
try {
|
||||
fs.unlinkSync(savePageCssPath);
|
||||
fs.unlinkSync(savePageJsPath);
|
||||
fs.unlinkSync(savePageHtmlPath);
|
||||
fs.rmdirSync(path.join(savePageDir, 'save_page_files'));
|
||||
fs.rmdirSync(savePageDir);
|
||||
} catch (e) {
|
||||
// Ignore error
|
||||
}
|
||||
} catch {}
|
||||
});
|
||||
afterEach(closeAllWindows);
|
||||
|
||||
it('should save page to disk', async () => {
|
||||
it('should save page to disk with HTMLOnly', async () => {
|
||||
const w = new BrowserWindow({ show: false });
|
||||
await w.loadFile(path.join(fixtures, 'pages', 'save_page', 'index.html'));
|
||||
await w.webContents.savePage(savePageHtmlPath, 'HTMLOnly');
|
||||
|
||||
expect(fs.existsSync(savePageHtmlPath)).to.be.true('html path');
|
||||
expect(fs.existsSync(savePageJsPath)).to.be.false('js path');
|
||||
expect(fs.existsSync(savePageCssPath)).to.be.false('css path');
|
||||
});
|
||||
|
||||
it('should save page to disk with MHTML', async () => {
|
||||
const w = new BrowserWindow({ show: false });
|
||||
await w.loadFile(path.join(fixtures, 'pages', 'save_page', 'index.html'));
|
||||
await w.webContents.savePage(savePageHtmlPath, 'MHTML');
|
||||
|
||||
expect(fs.existsSync(savePageHtmlPath)).to.be.true('html path');
|
||||
expect(fs.existsSync(savePageJsPath)).to.be.false('js path');
|
||||
expect(fs.existsSync(savePageCssPath)).to.be.false('css path');
|
||||
});
|
||||
|
||||
it('should save page to disk with HTMLComplete', async () => {
|
||||
const w = new BrowserWindow({ show: false });
|
||||
await w.loadFile(path.join(fixtures, 'pages', 'save_page', 'index.html'));
|
||||
await w.webContents.savePage(savePageHtmlPath, 'HTMLComplete');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue