diff options
Diffstat (limited to 'packages/integrations/netlify/test')
8 files changed, 55 insertions, 64 deletions
diff --git a/packages/integrations/netlify/test/functions/cookies.test.js b/packages/integrations/netlify/test/functions/cookies.test.js index cb81d097a..9d25a873e 100644 --- a/packages/integrations/netlify/test/functions/cookies.test.js +++ b/packages/integrations/netlify/test/functions/cookies.test.js @@ -1,5 +1,6 @@ import { loadFixture } from '@astrojs/test-utils'; -import { expect } from 'chai'; +import { describe, it, before } from 'node:test'; +import * as assert from 'node:assert/strict'; describe('Cookies', () => { let fixture; @@ -19,9 +20,9 @@ describe('Cookies', () => { new Request('http://example.com/login', { method: 'POST', body: '{}' }), {} ); - expect(resp.status).to.equal(301); - expect(resp.headers.get('location')).to.equal('/'); - expect(resp.headers.getSetCookie()).to.eql(['foo=foo; HttpOnly', 'bar=bar; HttpOnly']); + assert.equal(resp.status,301); + assert.equal(resp.headers.get('location'),'/'); + assert.deepEqual(resp.headers.getSetCookie(),['foo=foo; HttpOnly', 'bar=bar; HttpOnly']); }); it('renders dynamic 404 page', async () => { @@ -38,9 +39,9 @@ describe('Cookies', () => { }), {} ); - expect(resp.status).to.equal(404); + assert.equal(resp.status,404); const text = await resp.text(); - expect(text).to.contain('This is my custom 404 page'); - expect(text).to.contain('x-test: bar'); + assert.equal(text.includes('This is my custom 404 page'),true); + assert.equal(text.includes('x-test: bar'),true); }); }); diff --git a/packages/integrations/netlify/test/functions/edge-middleware.test.js b/packages/integrations/netlify/test/functions/edge-middleware.test.js index 867dd2a11..42de398c6 100644 --- a/packages/integrations/netlify/test/functions/edge-middleware.test.js +++ b/packages/integrations/netlify/test/functions/edge-middleware.test.js @@ -1,5 +1,6 @@ import { loadFixture } from '@astrojs/test-utils'; -import { expect } from 'chai'; +import { describe, it, before, after } from 'node:test'; +import * as assert from 'node:assert/strict'; describe('Middleware', () => { const root = new URL('./fixtures/middleware/', import.meta.url); @@ -13,15 +14,19 @@ describe('Middleware', () => { }); it('emits no edge function', async () => { - expect(fixture.pathExists('../.netlify/edge-functions/middleware/middleware.mjs')).to.be - .false; + assert.equal(fixture.pathExists('../.netlify/edge-functions/middleware/middleware.mjs'), false) }); it('applies middleware to static files at build-time', async () => { // prerendered page has middleware applied at build time const prerenderedPage = await fixture.readFile('prerender/index.html'); - expect(prerenderedPage).to.contain('<title>Middleware</title>'); + assert.equal(prerenderedPage.includes('<title>Middleware</title>'),true); }); + + after(async () => { + process.env.EDGE_MIDDLEWARE = undefined; + await fixture.clean(); + }) }); describe('edgeMiddleware: true', () => { @@ -36,12 +41,17 @@ describe('Middleware', () => { const contents = await fixture.readFile( '../.netlify/edge-functions/middleware/middleware.mjs' ); - expect(contents.includes('"Hello world"')).to.be.false; + assert.equal(contents.includes('"Hello world"'), false); }); it.skip('does not apply middleware during prerendering', async () => { const prerenderedPage = await fixture.readFile('prerender/index.html'); - expect(prerenderedPage).to.contain('<title></title>'); + assert.equal(prerenderedPage.includes('<title></title>'),true); }); + + after(async () => { + process.env.EDGE_MIDDLEWARE = undefined; + await fixture.clean(); + }) }); }); diff --git a/packages/integrations/netlify/test/functions/image-cdn.test.js b/packages/integrations/netlify/test/functions/image-cdn.test.js index 1737513a4..7a0060bff 100644 --- a/packages/integrations/netlify/test/functions/image-cdn.test.js +++ b/packages/integrations/netlify/test/functions/image-cdn.test.js @@ -1,6 +1,6 @@ -import { describe } from 'node:test'; import { loadFixture } from '@astrojs/test-utils'; -import { expect } from 'chai'; +import { describe, it, after } from 'node:test'; +import * as assert from 'node:assert/strict'; describe('Image CDN', () => { const root = new URL('./fixtures/middleware/', import.meta.url); @@ -11,20 +11,24 @@ describe('Image CDN', () => { await fixture.build(); const astronautPage = await fixture.readFile('astronaut/index.html'); - expect(astronautPage).contains(`src="/_astro/astronaut.`); + assert.equal(astronautPage.includes(`src="/_astro/astronaut.`),true); }); + }); describe('when running inside of netlify', () => { - it('enables Netlify Image CDN', async () => { + after(() => { + process.env.NETLIFY = undefined; + process.env.DISABLE_IMAGE_CDN = undefined; + }); + + it('enables Netlify Image CDN',async () => { process.env.NETLIFY = 'true'; const fixture = await loadFixture({ root }); await fixture.build(); const astronautPage = await fixture.readFile('astronaut/index.html'); - expect(astronautPage).contains(`src="/.netlify/image`); - - process.env.NETLIFY = undefined; + assert.equal(astronautPage.includes(`src="/.netlify/image`),true); }); it('respects image CDN opt-out', async () => { @@ -34,10 +38,7 @@ describe('Image CDN', () => { await fixture.build(); const astronautPage = await fixture.readFile('astronaut/index.html'); - expect(astronautPage).contains(`src="/_astro/astronaut.`); - - process.env.NETLIFY = undefined; - process.env.DISABLE_IMAGE_CDN = undefined; + assert.equal(astronautPage.includes(`src="/_astro/astronaut.`),true); }); }); }); diff --git a/packages/integrations/netlify/test/functions/redirects.test.js b/packages/integrations/netlify/test/functions/redirects.test.js index eb9b32945..ab4d426ba 100644 --- a/packages/integrations/netlify/test/functions/redirects.test.js +++ b/packages/integrations/netlify/test/functions/redirects.test.js @@ -1,6 +1,7 @@ import { createServer } from 'http'; import { loadFixture } from '@astrojs/test-utils'; -import { expect } from 'chai'; +import { describe, it, before } from 'node:test'; +import * as assert from 'node:assert/strict'; describe('SSR - Redirects', () => { let fixture; @@ -13,8 +14,9 @@ describe('SSR - Redirects', () => { it('Creates a redirects file', async () => { const redirects = await fixture.readFile('./_redirects'); const parts = redirects.split(/\s+/); - expect(parts).to.deep.equal(['', '/other', '/', '301', '']); - expect(redirects).to.matchSnapshot(); + assert.deepEqual(parts,['', '/other', '/', '301', '']); + // Snapshots are not supported in Node.js test yet (https://github.com/nodejs/node/issues/48260) + assert.equal(redirects,'\n/other / 301\n'); }); it('Does not create .html files', async () => { @@ -24,7 +26,7 @@ describe('SSR - Redirects', () => { } catch { hasErrored = true; } - expect(hasErrored).to.equal(true, 'this file should not exist'); + assert.equal(hasErrored,true, 'this file should not exist'); }); it('renders static 404 page', async () => { @@ -34,10 +36,10 @@ describe('SSR - Redirects', () => { ); const { default: handler } = await import(entryURL); const resp = await handler(new Request('http://example.com/nonexistant-page'), {}); - expect(resp.status).to.equal(404); - expect(resp.headers.get('content-type')).to.equal('text/html; charset=utf-8'); + assert.equal(resp.status,404); + assert.equal(resp.headers.get('content-type'),'text/html; charset=utf-8'); const text = await resp.text(); - expect(text).to.contain('This is my static 404 page'); + assert.equal(text.includes('This is my static 404 page'),true); }); it('does not pass through 404 request', async () => { @@ -54,8 +56,8 @@ describe('SSR - Redirects', () => { ); const { default: handler } = await import(entryURL); const resp = await handler(new Request('http://localhost:5678/nonexistant-page'), {}); - expect(resp.status).to.equal(404); - expect(testServerCalls).to.equal(0); + assert.equal(resp.status,404); + assert.equal(testServerCalls,0); testServer.close(); }); }); diff --git a/packages/integrations/netlify/test/functions/redirects.test.js.snap b/packages/integrations/netlify/test/functions/redirects.test.js.snap deleted file mode 100644 index b781001e4..000000000 --- a/packages/integrations/netlify/test/functions/redirects.test.js.snap +++ /dev/null @@ -1,13 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`SSG - Redirects Creates a redirects file 1`] = ` -" -/other / 301 -" -`; - -exports[`SSR - Redirects Creates a redirects file 1`] = ` -" -/other / 301 -" -`; diff --git a/packages/integrations/netlify/test/hosted/hosted.test.js b/packages/integrations/netlify/test/hosted/hosted.test.js index 2a53ce806..95d808031 100644 --- a/packages/integrations/netlify/test/hosted/hosted.test.js +++ b/packages/integrations/netlify/test/hosted/hosted.test.js @@ -1,4 +1,5 @@ -import { expect } from 'chai'; +import { describe, it, before } from 'node:test'; +import * as assert from 'node:assert/strict'; const NETLIFY_TEST_URL = 'https://curious-boba-495d6d.netlify.app'; @@ -8,7 +9,7 @@ describe('Hosted Netlify Tests', () => { `${NETLIFY_TEST_URL}/_image?href=%2F_astro%2Fpenguin.e9c64733.png&w=300&f=webp` ); - expect(image.status).to.equal(200); + assert.equal(image.status,200); }); it('Server returns fresh content', async () => { @@ -16,6 +17,6 @@ describe('Hosted Netlify Tests', () => { const responseTwo = await fetch(`${NETLIFY_TEST_URL}/time`); - expect(responseOne.body).to.not.equal(responseTwo.body); + assert.notEqual(responseOne.body,responseTwo.body); }); }); diff --git a/packages/integrations/netlify/test/setup.js b/packages/integrations/netlify/test/setup.js deleted file mode 100644 index 5862aed44..000000000 --- a/packages/integrations/netlify/test/setup.js +++ /dev/null @@ -1,12 +0,0 @@ -import { use } from 'chai'; -import chaiJestSnapshot from 'chai-jest-snapshot'; - -use(chaiJestSnapshot); - -before(() => { - chaiJestSnapshot.resetSnapshotRegistry(); -}); - -beforeEach(function () { - chaiJestSnapshot.configureUsingMochaContext(this); -}); diff --git a/packages/integrations/netlify/test/static/redirects.test.js b/packages/integrations/netlify/test/static/redirects.test.js index 2e39be303..ea6864a10 100644 --- a/packages/integrations/netlify/test/static/redirects.test.js +++ b/packages/integrations/netlify/test/static/redirects.test.js @@ -1,5 +1,6 @@ import { loadFixture } from '@astrojs/test-utils'; -import { expect } from 'chai'; +import { describe, it, before } from 'node:test'; +import * as assert from 'node:assert/strict'; describe('SSG - Redirects', () => { let fixture; @@ -12,7 +13,7 @@ describe('SSG - Redirects', () => { it('Creates a redirects file', async () => { const redirects = await fixture.readFile('./_redirects'); const parts = redirects.split(/\s+/); - expect(parts).to.deep.equal([ + assert.deepEqual(parts, [ '', '/two', @@ -28,6 +29,6 @@ describe('SSG - Redirects', () => { '301', '', - ]); + ]) }); }); |