Skip to content

Commit

Permalink
Merge pull request #592 from auth0/write-empty-files-pages-undefined-…
Browse files Browse the repository at this point in the history
…yaml

Prevent crash when writing page templates with YAML handler
  • Loading branch information
willvedd authored Jun 27, 2022
2 parents 57944fc + 8a270f3 commit d3fd080
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/context/yaml/handlers/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function dump(context: YAMLContext): Promise<ParsedPages> {
// Dump html to file
const htmlFile = path.join(pagesFolder, `${page.name}.html`);
log.info(`Writing ${htmlFile}`);
fs.writeFileSync(htmlFile, page.html);
fs.writeFileSync(htmlFile, page.html || '');
return {
...page,
html: `./pages/${page.name}.html`,
Expand Down
28 changes: 28 additions & 0 deletions test/context/yaml/pages.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,34 @@ describe('#YAML context pages', () => {
);
});

it('should not throw if page HTML is not defined', async () => {
// See: https://github.com/auth0/auth0-deploy-cli/issues/365
const dir = path.join(testDataDir, 'yaml', 'pagesDump');
cleanThenMkdir(dir);
const context = new Context(
{ AUTH0_INPUT_FILE: path.join(dir, 'tennat.yaml') },
mockMgmtClient()
);

context.assets.pages = [
{ html: undefined, name: 'login' }, // HTML property is not defined here
];

const dumped = await handler.dump(context);
expect(dumped).to.deep.equal({
pages: [
{
html: './pages/login.html',
name: 'login',
},
],
});

const pagesFolder = path.join(dir, 'pages');
expect(fs.readFileSync(path.join(pagesFolder, 'login.html'), 'utf8')).to.deep.equal('');
expect(fs.readdirSync(pagesFolder).length).to.equal(1);
});

it('should dump error_page with html undefined', async () => {
const dir = path.join(testDataDir, 'yaml', 'pagesDump');
cleanThenMkdir(dir);
Expand Down

0 comments on commit d3fd080

Please sign in to comment.