mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
test: improve webContents.savePage() specs (#32744)
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
@@ -3394,20 +3394,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');
|
||||
|
||||
Reference in New Issue
Block a user