aboutsummaryrefslogtreecommitdiff
path: root/packages/integrations/node/test/prerender.test.js
diff options
context:
space:
mode:
authorGravatar Emanuele Stoppa <my.burning@gmail.com> 2024-01-25 16:17:31 +0000
committerGravatar GitHub <noreply@github.com> 2024-01-25 16:17:31 +0000
commitfc21a3c306f552a3048b0a0899b5f21c1c9269c1 (patch)
treeba619951f09147eb2893ec5b5f113014ee3f746e /packages/integrations/node/test/prerender.test.js
parentd688954c5adba75b0d676694fbf5fb0da1c0af13 (diff)
downloadastro-fc21a3c306f552a3048b0a0899b5f21c1c9269c1.tar.gz
astro-fc21a3c306f552a3048b0a0899b5f21c1c9269c1.tar.zst
astro-fc21a3c306f552a3048b0a0899b5f21c1c9269c1.zip
chore(@astrojs/node): use Node.js for testing (#9758)
* chore(@astrojs/node): use Node.js for testing * revert file * address feedback * feedback * Run tests in a single process (#9823) * Run tests in a single process * Make test less flaky * chore: remove module --------- Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
Diffstat (limited to 'packages/integrations/node/test/prerender.test.js')
-rw-r--r--packages/integrations/node/test/prerender.test.js85
1 files changed, 45 insertions, 40 deletions
diff --git a/packages/integrations/node/test/prerender.test.js b/packages/integrations/node/test/prerender.test.js
index 86a7d3a65..ffa5563fa 100644
--- a/packages/integrations/node/test/prerender.test.js
+++ b/packages/integrations/node/test/prerender.test.js
@@ -1,6 +1,7 @@
+import * as assert from 'node:assert/strict';
+import { describe, it, before, after } from 'node:test';
import nodejs from '../dist/index.js';
-import { loadFixture } from './test-utils.js';
-import { expect } from 'chai';
+import { loadFixture, waitServerListen } from './test-utils.js';
import * as cheerio from 'cheerio';
/**
@@ -30,6 +31,7 @@ describe('Prerendering', () => {
const { startServer } = await load();
let res = startServer();
server = res.server;
+ await waitServerListen(server.server);
});
after(async () => {
@@ -43,8 +45,8 @@ describe('Prerendering', () => {
const html = await res.text();
const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('One');
+ assert.equal(res.status, 200);
+ assert.equal($('h1').text(), 'One');
});
it('Can render prerendered route', async () => {
@@ -52,8 +54,8 @@ describe('Prerendering', () => {
const html = await res.text();
const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('Two');
+ assert.equal(res.status, 200);
+ assert.equal($('h1').text(), 'Two');
});
it('Can render prerendered route with redirect and query params', async () => {
@@ -61,8 +63,8 @@ describe('Prerendering', () => {
const html = await res.text();
const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('Two');
+ assert.equal(res.status, 200);
+ assert.equal($('h1').text(), 'Two');
});
it('Can render prerendered route with query params', async () => {
@@ -70,8 +72,8 @@ describe('Prerendering', () => {
const html = await res.text();
const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('Two');
+ assert.equal(res.status, 200);
+ assert.equal($('h1').text(), 'Two');
});
it('Can render prerendered route without trailing slash', async () => {
@@ -80,8 +82,9 @@ describe('Prerendering', () => {
});
const html = await res.text();
const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('Two');
+ assert.equal(res.status, 301);
+ assert.equal(res.headers.get('location'), '/some-base/two/');
+ assert.equal($('h1').text(), "Two")
});
});
@@ -98,6 +101,7 @@ describe('Prerendering', () => {
const { startServer } = await await load();
let res = startServer();
server = res.server;
+ await waitServerListen(server.server);
});
after(async () => {
@@ -111,8 +115,8 @@ describe('Prerendering', () => {
const html = await res.text();
const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('One');
+ assert.equal(res.status, 200);
+ assert.equal($('h1').text(), 'One');
});
it('Can render prerendered route', async () => {
@@ -120,8 +124,8 @@ describe('Prerendering', () => {
const html = await res.text();
const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('Two');
+ assert.equal(res.status, 200);
+ assert.equal($('h1').text(), 'Two');
});
it('Can render prerendered route with redirect and query params', async () => {
@@ -129,8 +133,8 @@ describe('Prerendering', () => {
const html = await res.text();
const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('Two');
+ assert.equal(res.status, 200);
+ assert.equal($('h1').text(), 'Two');
});
it('Can render prerendered route with query params', async () => {
@@ -138,8 +142,8 @@ describe('Prerendering', () => {
const html = await res.text();
const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('Two');
+ assert.equal(res.status, 200);
+ assert.equal($('h1').text(), 'Two');
});
});
@@ -200,6 +204,7 @@ describe('Hybrid rendering', () => {
const { startServer } = await await load();
let res = startServer();
server = res.server;
+ await waitServerListen(server.server);
});
after(async () => {
@@ -212,8 +217,8 @@ describe('Hybrid rendering', () => {
const res = await fetch(`http://${server.host}:${server.port}/some-base/two`);
const html = await res.text();
const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('Two');
+ assert.equal(res.status, 200);
+ assert.equal($('h1').text(), 'Two');
});
it('Can render prerendered route', async () => {
@@ -221,8 +226,8 @@ describe('Hybrid rendering', () => {
const html = await res.text();
const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('One');
+ assert.equal(res.status, 200);
+ assert.equal($('h1').text(), 'One');
});
it('Can render prerendered route with redirect and query params', async () => {
@@ -230,8 +235,8 @@ describe('Hybrid rendering', () => {
const html = await res.text();
const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('One');
+ assert.equal(res.status, 200);
+ assert.equal($('h1').text(), 'One');
});
it('Can render prerendered route with query params', async () => {
@@ -239,18 +244,17 @@ describe('Hybrid rendering', () => {
const html = await res.text();
const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('One');
+ assert.equal(res.status, 200);
+ assert.equal($('h1').text(), 'One');
});
it('Can render prerendered route without trailing slash', async () => {
const res = await fetch(`http://${server.host}:${server.port}/some-base/one`, {
redirect: 'manual',
});
- const html = await res.text();
- const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('One');
+ assert.equal(res.status, 301);
+ assert.equal(res.headers.get('location'), '/some-base/one/');
+ assert.equal($('h1').text(), 'One');
});
});
@@ -266,6 +270,7 @@ describe('Hybrid rendering', () => {
const { startServer } = await await load();
let res = startServer();
server = res.server;
+ await waitServerListen(server.server);
});
after(async () => {
@@ -279,8 +284,8 @@ describe('Hybrid rendering', () => {
const html = await res.text();
const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('Two');
+ assert.equal(res.status, 200);
+ assert.equal($('h1').text(), 'Two');
});
it('Can render prerendered route', async () => {
@@ -288,8 +293,8 @@ describe('Hybrid rendering', () => {
const html = await res.text();
const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('One');
+ assert.equal(res.status, 200);
+ assert.equal($('h1').text(), 'One');
});
it('Can render prerendered route with redirect and query params', async () => {
@@ -297,8 +302,8 @@ describe('Hybrid rendering', () => {
const html = await res.text();
const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('One');
+ assert.equal(res.status, 200);
+ assert.equal($('h1').text(), 'One');
});
it('Can render prerendered route with query params', async () => {
@@ -306,8 +311,8 @@ describe('Hybrid rendering', () => {
const html = await res.text();
const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('One');
+ assert.equal(res.status, 200);
+ assert.equal($('h1').text(), 'One');
});
});
});