From 9f5f16b82d613e4bc57209c315ec5dc93ef2f140 Mon Sep 17 00:00:00 2001 From: Will Vedder Date: Fri, 24 Jun 2022 16:22:54 -0400 Subject: [PATCH 1/2] Writing empty files instead of crashing if page HTML is undefined --- src/context/yaml/handlers/pages.ts | 2 +- test/context/yaml/pages.test.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/context/yaml/handlers/pages.ts b/src/context/yaml/handlers/pages.ts index f059587ed..c04c52265 100644 --- a/src/context/yaml/handlers/pages.ts +++ b/src/context/yaml/handlers/pages.ts @@ -43,7 +43,7 @@ async function dump(context: YAMLContext): Promise { // 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`, diff --git a/test/context/yaml/pages.test.js b/test/context/yaml/pages.test.js index 8600abf44..42b88ca3d 100644 --- a/test/context/yaml/pages.test.js +++ b/test/context/yaml/pages.test.js @@ -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); From bbfe040b68524a2ce15caa9667cb95a33b603cb6 Mon Sep 17 00:00:00 2001 From: Will Vedder Date: Fri, 24 Jun 2022 16:23:06 -0400 Subject: [PATCH 2/2] Adding test --- test/context/yaml/pages.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/context/yaml/pages.test.js b/test/context/yaml/pages.test.js index 42b88ca3d..e7bef57d6 100644 --- a/test/context/yaml/pages.test.js +++ b/test/context/yaml/pages.test.js @@ -136,7 +136,7 @@ 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 + // See: https://github.com/auth0/auth0-deploy-cli/issues/365 const dir = path.join(testDataDir, 'yaml', 'pagesDump'); cleanThenMkdir(dir); const context = new Context( @@ -145,7 +145,7 @@ describe('#YAML context pages', () => { ); context.assets.pages = [ - { html: undefined, name: 'login' }, //HTML property is not defined here + { html: undefined, name: 'login' }, // HTML property is not defined here ]; const dumped = await handler.dump(context); @@ -159,8 +159,8 @@ describe('#YAML context pages', () => { }); 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) + 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 () => {