Skip to content

Commit

Permalink
test: improve webContents.savePage() specs (#32727)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Feb 3, 2022
1 parent 7442905 commit fb3f5e4
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions spec-main/api-browser-window-spec.ts
Expand Up @@ -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 {}
});

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');
});
afterEach(closeAllWindows);

it('should save page to disk', async () => {
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');
Expand Down

0 comments on commit fb3f5e4

Please sign in to comment.