From 43f87467c6aa060ccd44dc32b2f44461214c7026 Mon Sep 17 00:00:00 2001 From: Abid <56756836+abidjappie@users.noreply.github.com> Date: Mon, 19 Feb 2024 18:36:53 +0900 Subject: [PATCH] Implement test using using assert.fail and assert to check ENOENT. (#10156) --- packages/astro/test/i18n-routing.test.js | 90 +++++++++++------------- 1 file changed, 40 insertions(+), 50 deletions(-) diff --git a/packages/astro/test/i18n-routing.test.js b/packages/astro/test/i18n-routing.test.js index f8477a14e2..3c9a19df6f 100644 --- a/packages/astro/test/i18n-routing.test.js +++ b/packages/astro/test/i18n-routing.test.js @@ -576,22 +576,20 @@ describe('[SSG] i18n routing', () => { it("should NOT render the default locale if there isn't a fallback and the route is missing", async () => { try { await fixture.readFile('/it/start/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } }); it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => { try { await fixture.readFile('/fr/start/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } }); }); @@ -640,22 +638,20 @@ describe('[SSG] i18n routing', () => { it("should NOT render the default locale if there isn't a fallback and the route is missing", async () => { try { await fixture.readFile('/it/start/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } }); it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => { try { await fixture.readFile('/fr/start/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } }); }); @@ -684,11 +680,10 @@ describe('[SSG] i18n routing', () => { it('should return 404 when route contains the default locale', async () => { try { await fixture.readFile('/start/en/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } }); @@ -715,22 +710,20 @@ describe('[SSG] i18n routing', () => { it("should NOT render the default locale if there isn't a fallback and the route is missing", async () => { try { await fixture.readFile('/it/start/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } }); it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => { try { await fixture.readFile('/fr/start/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } }); }); @@ -810,22 +803,20 @@ describe('[SSG] i18n routing', () => { it("should NOT render the default locale if there isn't a fallback and the route is missing", async () => { try { await fixture.readFile('/it/start/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } }); it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => { try { await fixture.readFile('/fr/start/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } }); @@ -932,11 +923,10 @@ describe('[SSG] i18n routing', () => { it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => { try { await fixture.readFile('/fr/start/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } });