mirror of
https://github.com/withastro/astro.git
synced 2025-02-17 22:44:24 -05:00
chore: Migrate ssr-*.test.js
to node:test
(#10053)
* chore: Migrate ssr-*.test.js to node:test * revert Production function in ssr-error-pages * revert ssr-error-pages.test.js * fix: add missing path at ssr-split-manifest --------- Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com> Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
This commit is contained in:
parent
8f37cf72cb
commit
2a70113f7e
18 changed files with 177 additions and 145 deletions
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, before, it } from 'node:test';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import { viteID } from '../dist/core/util.js';
|
||||
|
||||
|
@ -58,11 +59,11 @@ describe('Integration buildConfig hook', () => {
|
|||
|
||||
it('Puts client files in the client folder', async () => {
|
||||
let data = await fixture.readFile('/.root/client/cars.json');
|
||||
expect(data).to.not.be.undefined;
|
||||
assert.notEqual(data, undefined);
|
||||
});
|
||||
|
||||
it('Puts the server entry into the server folder', async () => {
|
||||
let data = await fixture.readFile('/.root/server/entry.mjs');
|
||||
expect(data).to.not.be.undefined;
|
||||
assert.notEqual(data, undefined);
|
||||
});
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { after, describe, before, it } from 'node:test';
|
||||
import net from 'node:net';
|
||||
import testAdapter from './test-adapter.js';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
|
@ -21,32 +22,32 @@ describe('API routes in SSR', () => {
|
|||
const request = new Request('http://example.com/');
|
||||
const response = await app.render(request);
|
||||
const html = await response.text();
|
||||
expect(html).to.not.be.empty;
|
||||
assert.notEqual(html, '');
|
||||
});
|
||||
|
||||
it('Can load the API route too', async () => {
|
||||
const app = await fixture.loadTestAdapterApp();
|
||||
const request = new Request('http://example.com/food.json');
|
||||
const response = await app.render(request);
|
||||
expect(response.status).to.equal(200);
|
||||
assert.equal(response.status, 200);
|
||||
const body = await response.json();
|
||||
expect(body.length).to.equal(3);
|
||||
assert.equal(body.length, 3);
|
||||
});
|
||||
|
||||
it('Has valid api context', async () => {
|
||||
const app = await fixture.loadTestAdapterApp();
|
||||
const request = new Request('http://example.com/context/any');
|
||||
const response = await app.render(request);
|
||||
expect(response.status).to.equal(200);
|
||||
assert.equal(response.status, 200);
|
||||
const data = await response.json();
|
||||
expect(data.cookiesExist).to.equal(true);
|
||||
expect(data.requestExist).to.equal(true);
|
||||
expect(data.redirectExist).to.equal(true);
|
||||
expect(data.propsExist).to.equal(true);
|
||||
expect(data.params).to.deep.equal({ param: 'any' });
|
||||
expect(data.generator).to.match(/^Astro v/);
|
||||
expect(data.url).to.equal('http://example.com/context/any');
|
||||
expect(data.clientAddress).to.equal('0.0.0.0');
|
||||
assert.equal(data.cookiesExist, true);
|
||||
assert.equal(data.requestExist, true);
|
||||
assert.equal(data.redirectExist, true);
|
||||
assert.equal(data.propsExist, true);
|
||||
assert.deepEqual(data.params, { param: 'any' });
|
||||
assert.match(data.generator, /^Astro v/);
|
||||
assert.equal(data.url, 'http://example.com/context/any');
|
||||
assert.equal(data.clientAddress, '0.0.0.0');
|
||||
});
|
||||
|
||||
describe('API Routes - Dev', () => {
|
||||
|
@ -64,9 +65,9 @@ describe('API routes in SSR', () => {
|
|||
method: 'POST',
|
||||
body: `some data`,
|
||||
});
|
||||
expect(response.status).to.equal(200);
|
||||
assert.equal(response.status, 200);
|
||||
const text = await response.text();
|
||||
expect(text).to.equal(`ok`);
|
||||
assert.equal(text, 'ok');
|
||||
});
|
||||
|
||||
it('Can be passed binary data from multipart formdata', async () => {
|
||||
|
@ -82,7 +83,7 @@ describe('API routes in SSR', () => {
|
|||
body: formData,
|
||||
});
|
||||
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
});
|
||||
|
||||
it('Can set multiple headers of the same type', async () => {
|
||||
|
@ -113,7 +114,7 @@ describe('API routes in SSR', () => {
|
|||
count++;
|
||||
}
|
||||
|
||||
expect(count).to.equal(2, 'Found two seperate set-cookie response headers');
|
||||
assert.equal(count, 2, 'Found two seperate set-cookie response headers');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, before, it } from 'node:test';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import testAdapter from './test-adapter.js';
|
||||
|
||||
|
@ -21,7 +22,7 @@ describe('SSR Assets', () => {
|
|||
const app = await fixture.loadTestAdapterApp();
|
||||
/** @type {Set<string>} */
|
||||
const assets = app.manifest.assets;
|
||||
expect(assets.size).to.equal(1);
|
||||
expect(Array.from(assets)[0].endsWith('.css')).to.be.true;
|
||||
assert.equal(assets.size, 1);
|
||||
assert.equal(Array.from(assets)[0].endsWith('.css'), true);
|
||||
});
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, before, it } from 'node:test';
|
||||
import { load as cheerioLoad } from 'cheerio';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import testAdapter from './test-adapter.js';
|
||||
|
@ -56,27 +57,27 @@ describe('Dynamic pages in SSR', () => {
|
|||
it('Do not have to implement getStaticPaths', async () => {
|
||||
const html = await fetchHTML('/123');
|
||||
const $ = cheerioLoad(html);
|
||||
expect($('h1').text()).to.equal('Item 123');
|
||||
assert.equal($('h1').text(), 'Item 123');
|
||||
});
|
||||
|
||||
it('Includes page styles', async () => {
|
||||
const html = await fetchHTML('/123');
|
||||
const $ = cheerioLoad(html);
|
||||
expect($('link').length).to.equal(1);
|
||||
assert.equal($('link').length, 1);
|
||||
});
|
||||
|
||||
it('Dynamic API routes work', async () => {
|
||||
const json = await fetchJSON('/api/products/33');
|
||||
expect(json.id).to.equal('33');
|
||||
assert.equal(json.id, '33');
|
||||
});
|
||||
|
||||
it('Injected route work', async () => {
|
||||
const json = await fetchJSON('/path-alias/33');
|
||||
expect(json.id).to.equal('33');
|
||||
assert.equal(json.id, '33');
|
||||
});
|
||||
|
||||
it('Public assets take priority', async () => {
|
||||
const favicon = await matchRoute('/favicon.ico');
|
||||
expect(favicon).to.equal(undefined);
|
||||
assert.equal(favicon, undefined);
|
||||
});
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, before, it } from 'node:test';
|
||||
import * as cheerio from 'cheerio';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import testAdapter from './test-adapter.js';
|
||||
|
@ -22,6 +23,6 @@ describe('SSR Environment Variables', () => {
|
|||
const response = await app.render(request);
|
||||
const html = await response.text();
|
||||
const $ = cheerio.load(html);
|
||||
expect($('#ssr').text()).to.equal('true');
|
||||
assert.equal($('#ssr').text(), 'true');
|
||||
});
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { after, describe, before, it } from 'node:test';
|
||||
import { load as cheerioLoad } from 'cheerio';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import testAdapter from './test-adapter.js';
|
||||
|
@ -31,7 +32,7 @@ describe('Hoisted inline scripts in SSR', () => {
|
|||
it('scripts get included', async () => {
|
||||
const html = await fetchHTML(fixture, '/');
|
||||
const $ = cheerioLoad(html);
|
||||
expect($('script').length).to.equal(1);
|
||||
assert.equal($('script').length, 1);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -49,7 +50,7 @@ describe('Hoisted inline scripts in SSR', () => {
|
|||
it('Inlined scripts get included without base path in the script', async () => {
|
||||
const html = await fetchHTML(fixture, '/hello/');
|
||||
const $ = cheerioLoad(html);
|
||||
expect($('script').html()).to.equal('console.log("hello world");\n');
|
||||
assert.equal($('script').html(), 'console.log("hello world");\n');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -74,7 +75,7 @@ describe('Hoisted external scripts in SSR', () => {
|
|||
it('script has correct path', async () => {
|
||||
const html = await fetchHTML(fixture, '/');
|
||||
const $ = cheerioLoad(html);
|
||||
expect($('script').attr('src')).to.match(/^\/_astro\/hoisted\..{8}\.js$/);
|
||||
assert.match($('script').attr('src'), /^\/_astro\/hoisted\..{8}\.js$/);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -95,7 +96,7 @@ describe('Hoisted external scripts in SSR', () => {
|
|||
it('script has correct path', async () => {
|
||||
const html = await fetchHTML(fixture, '/hello/');
|
||||
const $ = cheerioLoad(html);
|
||||
expect($('script').attr('src')).to.match(/^\/hello\/_astro\/hoisted\..{8}\.js$/);
|
||||
assert.match($('script').attr('src'), /^\/hello\/_astro\/hoisted\..{8}\.js$/);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -118,7 +119,8 @@ describe('Hoisted external scripts in SSR', () => {
|
|||
it('script has correct path', async () => {
|
||||
const html = await fetchHTML(fixture, '/');
|
||||
const $ = cheerioLoad(html);
|
||||
expect($('script').attr('src')).to.match(
|
||||
assert.match(
|
||||
$('script').attr('src'),
|
||||
/^https:\/\/cdn\.example\.com\/_astro\/hoisted\..{8}\.js$/
|
||||
);
|
||||
});
|
||||
|
@ -147,7 +149,7 @@ describe('Hoisted external scripts in SSR', () => {
|
|||
it('script has correct path', async () => {
|
||||
const html = await fetchHTML(fixture, '/');
|
||||
const $ = cheerioLoad(html);
|
||||
expect($('script').attr('src')).to.match(/^\/assets\/entry\..{8}\.mjs$/);
|
||||
assert.match($('script').attr('src'), /^\/assets\/entry\..{8}\.mjs$/);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -175,7 +177,7 @@ describe('Hoisted external scripts in SSR', () => {
|
|||
it('script has correct path', async () => {
|
||||
const html = await fetchHTML(fixture, '/hello/');
|
||||
const $ = cheerioLoad(html);
|
||||
expect($('script').attr('src')).to.match(/^\/hello\/assets\/entry\..{8}\.mjs$/);
|
||||
assert.match($('script').attr('src'), /^\/hello\/assets\/entry\..{8}\.mjs$/);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -205,7 +207,8 @@ describe('Hoisted external scripts in SSR', () => {
|
|||
it('script has correct path', async () => {
|
||||
const html = await fetchHTML(fixture, '/');
|
||||
const $ = cheerioLoad(html);
|
||||
expect($('script').attr('src')).to.match(
|
||||
assert.match(
|
||||
$('script').attr('src'),
|
||||
/^https:\/\/cdn\.example\.com\/assets\/entry\..{8}\.mjs$/
|
||||
);
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, before, it } from 'node:test';
|
||||
import * as cheerio from 'cheerio';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import testAdapter from './test-adapter.js';
|
||||
|
@ -24,10 +25,10 @@ describe('SSR with Large Array and client rendering', () => {
|
|||
const html = new TextDecoder().decode(data);
|
||||
|
||||
const $ = cheerio.load(html);
|
||||
expect($('head meta[name="viewport"]')).to.have.a.lengthOf(1);
|
||||
expect($('head link[rel="icon"]')).to.have.a.lengthOf(1);
|
||||
expect($('main')).to.have.a.lengthOf(1);
|
||||
expect($('astro-island')).to.have.a.lengthOf(1);
|
||||
expect($('h1').text()).to.equal('Hello, Solid!');
|
||||
assert.equal($('head meta[name="viewport"]').length, 1);
|
||||
assert.equal($('head link[rel="icon"]').length, 1);
|
||||
assert.equal($('main').length, 1);
|
||||
assert.equal($('astro-island').length, 1);
|
||||
assert.equal($('h1').text(), 'Hello, Solid!');
|
||||
});
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, before, it } from 'node:test';
|
||||
import { load as cheerioLoad } from 'cheerio';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import testAdapter from './test-adapter.js';
|
||||
|
@ -27,6 +28,6 @@ describe('Lit integration in SSR', () => {
|
|||
it('Is able to load', async () => {
|
||||
const html = await fetchHTML('/');
|
||||
const $ = cheerioLoad(html);
|
||||
expect($('#str').text()).to.equal('initialized');
|
||||
assert.equal($('#str').text(), 'initialized');
|
||||
});
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, before, it } from 'node:test';
|
||||
import * as cheerio from 'cheerio';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import testAdapter from './test-adapter.js';
|
||||
|
@ -24,7 +25,7 @@ describe('SSR Astro.locals from server', () => {
|
|||
const html = await response.text();
|
||||
|
||||
const $ = cheerio.load(html);
|
||||
expect($('#foo').text()).to.equal('bar');
|
||||
assert.equal($('#foo').text(), 'bar');
|
||||
});
|
||||
|
||||
it('Can access Astro.locals in api context', async () => {
|
||||
|
@ -32,9 +33,9 @@ describe('SSR Astro.locals from server', () => {
|
|||
const request = new Request('http://example.com/api');
|
||||
const locals = { foo: 'bar' };
|
||||
const response = await app.render(request, undefined, locals);
|
||||
expect(response.status).to.equal(200);
|
||||
assert.equal(response.status, 200);
|
||||
const body = await response.json();
|
||||
|
||||
expect(body.foo).to.equal('bar');
|
||||
assert.equal(body.foo, 'bar');
|
||||
});
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, before, it } from 'node:test';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import testAdapter from './test-adapter.js';
|
||||
import * as cheerio from 'cheerio';
|
||||
|
@ -25,12 +26,12 @@ describe('astro:ssr-manifest', () => {
|
|||
const html = await response.text();
|
||||
|
||||
const $ = cheerio.load(html);
|
||||
expect($('#assets').text()).to.match(/\["\/_astro\/index.([\w-]{8})\.css"\]/);
|
||||
assert.match($('#assets').text(), /\["\/_astro\/index.([\w-]{8})\.css"\]/);
|
||||
});
|
||||
|
||||
it('includes compressHTML', async () => {
|
||||
const app = await fixture.loadTestAdapterApp();
|
||||
expect(app.manifest).to.haveOwnProperty('compressHTML');
|
||||
expect(app.manifest.compressHTML).to.be.true;
|
||||
assert.equal(app.manifest.compressHTML, true);
|
||||
assert.equal(app.manifest.compressHTML, true);
|
||||
});
|
||||
});
|
|
@ -1,10 +1,11 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, before, it } from 'node:test';
|
||||
import * as cheerio from 'cheerio';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import testAdapter from './test-adapter.js';
|
||||
|
||||
describe('Astro.params in SSR', () => {
|
||||
/** @type {import('./test-utils').Fixture} */
|
||||
/** @type {import('./test-utils.js').Fixture} */
|
||||
let fixture;
|
||||
|
||||
before(async () => {
|
||||
|
@ -21,10 +22,10 @@ describe('Astro.params in SSR', () => {
|
|||
const app = await fixture.loadTestAdapterApp();
|
||||
const request = new Request('http://example.com/users/houston/food');
|
||||
const response = await app.render(request);
|
||||
expect(response.status).to.equal(200);
|
||||
assert.equal(response.status, 200);
|
||||
const html = await response.text();
|
||||
const $ = cheerio.load(html);
|
||||
expect($('.category').text()).to.equal('food');
|
||||
assert.equal($('.category').text(), 'food');
|
||||
});
|
||||
|
||||
describe('Non-english characters in the URL', () => {
|
||||
|
@ -32,10 +33,10 @@ describe('Astro.params in SSR', () => {
|
|||
const app = await fixture.loadTestAdapterApp();
|
||||
const request = new Request('http://example.com/users/houston/東西/food');
|
||||
const response = await app.render(request);
|
||||
expect(response.status).to.equal(200);
|
||||
assert.equal(response.status, 200);
|
||||
const html = await response.text();
|
||||
const $ = cheerio.load(html);
|
||||
expect($('.category').text()).to.equal('food');
|
||||
assert.equal($('.category').text(), 'food');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -43,9 +44,9 @@ describe('Astro.params in SSR', () => {
|
|||
const app = await fixture.loadTestAdapterApp();
|
||||
const request = new Request('http://example.com/users/houston/%25');
|
||||
const response = await app.render(request);
|
||||
expect(response.status).to.equal(200);
|
||||
assert.equal(response.status, 200);
|
||||
const html = await response.text();
|
||||
const $ = cheerio.load(html);
|
||||
expect($('.category').text()).to.equal('%');
|
||||
assert.equal($('.category').text(), '%');
|
||||
});
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, before, it } from 'node:test';
|
||||
import { load as cheerioLoad } from 'cheerio';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import testAdapter from './test-adapter.js';
|
||||
|
@ -22,11 +23,20 @@ describe('Using the Partytown integration in SSR', () => {
|
|||
const response = await app.render(request);
|
||||
const html = await response.text();
|
||||
const $ = cheerioLoad(html);
|
||||
expect($('script')).to.have.a.lengthOf(1);
|
||||
assert.equal($('script').length, 1);
|
||||
});
|
||||
|
||||
it('The partytown scripts are in the manifest', async () => {
|
||||
const app = await fixture.loadTestAdapterApp();
|
||||
expect(app.manifest.assets).to.contain('/~partytown/partytown-sw.js');
|
||||
const partytownScript = '/~partytown/partytown-sw.js';
|
||||
const assets = app.manifest.assets;
|
||||
let found = false;
|
||||
for (const asset of assets) {
|
||||
if (asset === partytownScript) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert.equal(found, true);
|
||||
});
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { after, afterEach, describe, before, it } from 'node:test';
|
||||
import * as cheerio from 'cheerio';
|
||||
import testAdapter from './test-adapter.js';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
|
@ -30,15 +31,15 @@ describe('Prerender', () => {
|
|||
|
||||
it('is only called once during build', () => {
|
||||
// useless expect; if build() throws in setup then this test fails
|
||||
expect(true).to.equal(true);
|
||||
assert.equal(true, true);
|
||||
});
|
||||
|
||||
it('Astro.url sets the current pathname', async () => {
|
||||
const html = await fixture.readFile('/client/food/tacos/index.html');
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
expect($('#props').text()).to.equal('10');
|
||||
expect($('#url').text()).to.equal('/blog/food/tacos/');
|
||||
assert.equal($('#props').text(), '10');
|
||||
assert.equal($('#url').text(), '/blog/food/tacos/');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -62,42 +63,43 @@ describe('Prerender', () => {
|
|||
it('only calls prerender getStaticPaths once', async function () {
|
||||
// Sometimes this fail in CI as the chokidar watcher triggers an update and invalidates the route cache,
|
||||
// causing getStaticPaths to be called twice. Workaround this with 2 retries for now.
|
||||
this.retries(2);
|
||||
// it was used in the original test using chai, but it's not available in the current version of node:test
|
||||
// this.retries(2);
|
||||
|
||||
let res = await fixture.fetch('/blog/a');
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
|
||||
res = await fixture.fetch('/blog/b');
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
|
||||
res = await fixture.fetch('/blog/c');
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
});
|
||||
|
||||
describe('404 behavior', () => {
|
||||
it('resolves 200 on matching static path - named params', async () => {
|
||||
const res = await fixture.fetch('/blog/pizza/provolone-sausage');
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
});
|
||||
|
||||
it('resolves 404 on pattern match without static path - named params', async () => {
|
||||
const res = await fixture.fetch('/blog/pizza/provolone-pineapple');
|
||||
const html = await res.text();
|
||||
expect(res.status).to.equal(404);
|
||||
expect(html).to.match(/404/);
|
||||
assert.equal(res.status, 404);
|
||||
assert.match(html, /404/);
|
||||
});
|
||||
|
||||
it('resolves 200 on matching static path - rest params', async () => {
|
||||
const res = await fixture.fetch('/blog/pizza/grimaldis/new-york');
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
});
|
||||
|
||||
it('resolves 404 on pattern match without static path - rest params', async () => {
|
||||
const res = await fixture.fetch('/blog/pizza/pizza-hut');
|
||||
const html = await res.text();
|
||||
|
||||
expect(res.status).to.equal(404);
|
||||
expect(html).to.match(/404/);
|
||||
assert.equal(res.status, 404);
|
||||
assert.match(html, /404/);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -105,13 +107,13 @@ describe('Prerender', () => {
|
|||
it('resolves 200 on matching static path - string params', async () => {
|
||||
// route provided with { params: { year: "2022", slug: "post-2" }}
|
||||
const res = await fixture.fetch('/blog/blog/2022/post-1');
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
});
|
||||
|
||||
it('resolves 200 on matching static path - numeric params', async () => {
|
||||
// route provided with { params: { year: 2022, slug: "post-2" }}
|
||||
const res = await fixture.fetch('/blog/blog/2022/post-2');
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -119,13 +121,14 @@ describe('Prerender', () => {
|
|||
// routes params provided for pages /posts/1, /posts/2, and /posts/3
|
||||
for (const page of [1, 2, 3]) {
|
||||
let res = await fixture.fetch(`/blog/posts/${page}`);
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
|
||||
const html = await res.text();
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
const canonical = $('link[rel=canonical]');
|
||||
expect(canonical.attr('href')).to.equal(
|
||||
assert.equal(
|
||||
canonical.attr('href'),
|
||||
`https://mysite.dev/blog/posts/${page}`,
|
||||
`doesn't trim the /${page} route param`
|
||||
);
|
||||
|
@ -161,15 +164,15 @@ describe('Prerender', () => {
|
|||
|
||||
it('is only called once during build', () => {
|
||||
// useless expect; if build() throws in setup then this test fails
|
||||
expect(true).to.equal(true);
|
||||
assert.equal(true, true);
|
||||
});
|
||||
|
||||
it('Astro.url sets the current pathname', async () => {
|
||||
const html = await fixture.readFile('/client/food/tacos/index.html');
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
expect($('#props').text()).to.equal('10');
|
||||
expect($('#url').text()).to.equal('/blog/food/tacos/');
|
||||
assert.equal($('#props').text(), '10');
|
||||
assert.equal($('#url').text(), '/blog/food/tacos/');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -192,39 +195,39 @@ describe('Prerender', () => {
|
|||
|
||||
it('only calls hybrid getStaticPaths once', async () => {
|
||||
let res = await fixture.fetch('/blog/a');
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
|
||||
res = await fixture.fetch('/blog/b');
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
|
||||
res = await fixture.fetch('/blog/c');
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
});
|
||||
|
||||
describe('404 behavior', () => {
|
||||
it('resolves 200 on matching static path - named params', async () => {
|
||||
const res = await fixture.fetch('/blog/pizza/provolone-sausage');
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
});
|
||||
|
||||
it('resolves 404 on pattern match without static path - named params', async () => {
|
||||
const res = await fixture.fetch('/blog/pizza/provolone-pineapple');
|
||||
const html = await res.text();
|
||||
expect(res.status).to.equal(404);
|
||||
expect(html).to.match(/404/);
|
||||
assert.equal(res.status, 404);
|
||||
assert.match(html, /404/);
|
||||
});
|
||||
|
||||
it('resolves 200 on matching static path - rest params', async () => {
|
||||
const res = await fixture.fetch('/blog/pizza/grimaldis/new-york');
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
});
|
||||
|
||||
it('resolves 404 on pattern match without static path - rest params', async () => {
|
||||
const res = await fixture.fetch('/blog/pizza/pizza-hut');
|
||||
const html = await res.text();
|
||||
|
||||
expect(res.status).to.equal(404);
|
||||
expect(html).to.match(/404/);
|
||||
assert.equal(res.status, 404);
|
||||
assert.match(html, /404/);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -232,13 +235,13 @@ describe('Prerender', () => {
|
|||
it('resolves 200 on matching static path - string params', async () => {
|
||||
// route provided with { params: { year: "2022", slug: "post-2" }}
|
||||
const res = await fixture.fetch('/blog/blog/2022/post-1');
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
});
|
||||
|
||||
it('resolves 200 on matching static path - numeric params', async () => {
|
||||
// route provided with { params: { year: 2022, slug: "post-2" }}
|
||||
const res = await fixture.fetch('/blog/blog/2022/post-2');
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -246,13 +249,14 @@ describe('Prerender', () => {
|
|||
// routes params provided for pages /posts/1, /posts/2, and /posts/3
|
||||
for (const page of [1, 2, 3]) {
|
||||
let res = await fixture.fetch(`/blog/posts/${page}`);
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
|
||||
const html = await res.text();
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
const canonical = $('link[rel=canonical]');
|
||||
expect(canonical.attr('href')).to.equal(
|
||||
assert.equal(
|
||||
canonical.attr('href'),
|
||||
`https://mysite.dev/blog/posts/${page}`,
|
||||
`doesn't trim the /${page} route param`
|
||||
);
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, before, it } from 'node:test';
|
||||
import * as cheerio from 'cheerio';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import testAdapter from './test-adapter.js';
|
||||
|
@ -23,14 +24,14 @@ describe('SSR: prerender', () => {
|
|||
const app = await fixture.loadTestAdapterApp();
|
||||
const request = new Request('http://example.com/static');
|
||||
const response = await app.render(request);
|
||||
expect(response.status).to.equal(404);
|
||||
assert.equal(response.status, 404);
|
||||
});
|
||||
|
||||
it('includes prerendered pages in the asset manifest', async () => {
|
||||
const app = await fixture.loadTestAdapterApp();
|
||||
/** @type {Set<string>} */
|
||||
const assets = app.manifest.assets;
|
||||
expect(assets).to.contain('/static/index.html');
|
||||
assert.equal(assets.has('/static/index.html'), true);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -39,10 +40,10 @@ describe('SSR: prerender', () => {
|
|||
const app = await fixture.loadTestAdapterApp();
|
||||
const request = new Request('http://example.com/users/houston');
|
||||
const response = await app.render(request);
|
||||
expect(response.status).to.equal(200);
|
||||
assert.equal(response.status, 200);
|
||||
const html = await response.text();
|
||||
const $ = cheerio.load(html);
|
||||
expect($('.user').text()).to.equal('houston');
|
||||
assert.equal($('.user').text(), 'houston');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -52,10 +53,10 @@ describe('SSR: prerender', () => {
|
|||
const app = await fixture.loadTestAdapterApp();
|
||||
const request = new Request('http://example.com/some');
|
||||
const response = await app.render(request);
|
||||
expect(response.status).to.equal(200);
|
||||
assert.equal(response.status, 200);
|
||||
const html = await response.text();
|
||||
const $ = cheerio.load(html);
|
||||
expect($('p').text()).to.include('not give 404');
|
||||
assert.equal($('p').text().includes('not give 404'), true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -94,13 +95,13 @@ describe('Integrations can hook into the prerendering decision', () => {
|
|||
const app = await fixture.loadTestAdapterApp();
|
||||
const request = new Request('http://example.com/static');
|
||||
const response = await app.render(request);
|
||||
expect(response.status).to.equal(200);
|
||||
assert.equal(response.status, 200);
|
||||
});
|
||||
|
||||
it('An integration can turn a normal page to a prerendered one', async () => {
|
||||
const app = await fixture.loadTestAdapterApp();
|
||||
const request = new Request('http://example.com/not-prerendered');
|
||||
const response = await app.render(request);
|
||||
expect(response.status).to.equal(404);
|
||||
assert.equal(response.status, 404);
|
||||
});
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, before, it } from 'node:test';
|
||||
import { load as cheerioLoad } from 'cheerio';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import testAdapter from './test-adapter.js';
|
||||
|
@ -36,66 +37,65 @@ describe('Using Astro.request in SSR', () => {
|
|||
const app = await fixture.loadTestAdapterApp();
|
||||
const request = new Request('http://example.com/subpath/request');
|
||||
const response = await app.render(request);
|
||||
expect(response.status).to.equal(200);
|
||||
assert.equal(response.status, 200);
|
||||
const html = await response.text();
|
||||
const $ = cheerioLoad(html);
|
||||
expect($('#origin').text()).to.equal('http://example.com');
|
||||
assert.equal($('#origin').text(), 'http://example.com');
|
||||
});
|
||||
|
||||
it('Duplicate slashes are collapsed', async () => {
|
||||
const app = await fixture.loadTestAdapterApp();
|
||||
const request = new Request('http://example.com/subpath////request/////');
|
||||
const response = await app.render(request);
|
||||
expect(response.status).to.equal(200);
|
||||
assert.equal(response.status, 200);
|
||||
const html = await response.text();
|
||||
const $ = cheerioLoad(html);
|
||||
expect($('#origin').text()).to.equal('http://example.com');
|
||||
expect($('#pathname').text()).to.equal('/subpath/request/');
|
||||
expect($('#request-pathname').text()).to.equal('/subpath/request/');
|
||||
assert.equal($('#origin').text(), 'http://example.com');
|
||||
assert.equal($('#pathname').text(), '/subpath/request/');
|
||||
assert.equal($('#request-pathname').text(), '/subpath/request/');
|
||||
});
|
||||
|
||||
it('public file is copied over', async () => {
|
||||
const json = await fixture.readFile('/client/cars.json');
|
||||
expect(json).to.not.be.undefined;
|
||||
assert.notEqual(json, undefined);
|
||||
});
|
||||
|
||||
it('CSS assets have their base prefix', async () => {
|
||||
const app = await fixture.loadTestAdapterApp();
|
||||
let request = new Request('http://example.com/subpath/request');
|
||||
let response = await app.render(request);
|
||||
expect(response.status).to.equal(200);
|
||||
assert.equal(response.status, 200);
|
||||
const html = await response.text();
|
||||
const $ = cheerioLoad(html);
|
||||
|
||||
const linkHref = $('link').attr('href');
|
||||
expect(linkHref.startsWith('/subpath/')).to.equal(true);
|
||||
assert.equal(linkHref.startsWith('/subpath/'), true);
|
||||
|
||||
request = new Request('http://example.com' + linkHref);
|
||||
response = await app.render(request);
|
||||
|
||||
expect(response.status).to.equal(200);
|
||||
assert.equal(response.status, 200);
|
||||
const css = await response.text();
|
||||
expect(css).to.not.be.an('undefined');
|
||||
assert.notEqual(css, undefined);
|
||||
});
|
||||
|
||||
it('script assets have their base prefix', async () => {
|
||||
const app = await fixture.loadTestAdapterApp();
|
||||
let request = new Request('http://example.com/subpath/request');
|
||||
let response = await app.render(request);
|
||||
expect(response.status).to.equal(200);
|
||||
assert.equal(response.status, 200);
|
||||
const html = await response.text();
|
||||
const $ = cheerioLoad(html);
|
||||
|
||||
for (const el of $('script')) {
|
||||
const scriptSrc = $(el).attr('src');
|
||||
expect(scriptSrc.startsWith('/subpath/')).to.equal(true);
|
||||
|
||||
assert.equal(scriptSrc.startsWith('/subpath/'), true);
|
||||
request = new Request('http://example.com' + scriptSrc);
|
||||
response = await app.render(request);
|
||||
|
||||
expect(response.status).to.equal(200);
|
||||
assert.equal(response.status, 200);
|
||||
const js = await response.text();
|
||||
expect(js).to.not.be.an('undefined');
|
||||
assert.notEqual(js, undefined);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -103,8 +103,8 @@ describe('Using Astro.request in SSR', () => {
|
|||
const app = await fixture.loadTestAdapterApp();
|
||||
const request = new Request('http://example.com/subpath/cars.json');
|
||||
const response = await app.render(request);
|
||||
expect(response.status).to.equal(200);
|
||||
assert.equal(response.status, 200);
|
||||
const data = await response.json();
|
||||
expect(data).to.be.an('array');
|
||||
assert.equal(data instanceof Array, true);
|
||||
});
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, before, it } from 'node:test';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import testAdapter from './test-adapter.js';
|
||||
|
||||
|
@ -19,14 +20,14 @@ describe('Using Astro.response in SSR', () => {
|
|||
const app = await fixture.loadTestAdapterApp();
|
||||
const request = new Request('http://example.com/status-code');
|
||||
const response = await app.render(request);
|
||||
expect(response.status).to.equal(404);
|
||||
assert.equal(response.status, 404);
|
||||
});
|
||||
|
||||
it('Can set the statusText', async () => {
|
||||
const app = await fixture.loadTestAdapterApp();
|
||||
const request = new Request('http://example.com/status-code');
|
||||
const response = await app.render(request);
|
||||
expect(response.statusText).to.equal('Oops');
|
||||
assert.equal(response.statusText, 'Oops');
|
||||
});
|
||||
|
||||
it('Can set headers for 404 page', async () => {
|
||||
|
@ -34,7 +35,7 @@ describe('Using Astro.response in SSR', () => {
|
|||
const request = new Request('http://example.com/status-code');
|
||||
const response = await app.render(request);
|
||||
const headers = response.headers;
|
||||
expect(headers.get('one-two')).to.equal('three');
|
||||
assert.equal(headers.get('one-two'), 'three');
|
||||
});
|
||||
|
||||
it('Can add headers', async () => {
|
||||
|
@ -42,8 +43,8 @@ describe('Using Astro.response in SSR', () => {
|
|||
const request = new Request('http://example.com/some-header');
|
||||
const response = await app.render(request);
|
||||
const headers = response.headers;
|
||||
expect(headers.get('one-two')).to.equal('three');
|
||||
expect(headers.get('four-five')).to.equal('six');
|
||||
expect(headers.get('Cache-Control')).to.equal(`max-age=0, s-maxage=86400`);
|
||||
assert.equal(headers.get('one-two'), 'three');
|
||||
assert.equal(headers.get('four-five'), 'six');
|
||||
assert.equal(headers.get('Cache-Control'), `max-age=0, s-maxage=86400`);
|
||||
});
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, before, it } from 'node:test';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import testAdapter from './test-adapter.js';
|
||||
|
||||
|
@ -20,6 +21,6 @@ describe('SSR Hydrated component scripts', () => {
|
|||
|
||||
/** @type {Set<string>} */
|
||||
const assets = app.manifest.assets;
|
||||
expect(assets.size).to.be.greaterThan(0);
|
||||
assert.ok(assets.size > 0);
|
||||
});
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, before, it } from 'node:test';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import testAdapter from './test-adapter.js';
|
||||
import * as cheerio from 'cheerio';
|
||||
|
@ -45,17 +46,18 @@ describe('astro:ssr-manifest, split', () => {
|
|||
const html = await response.text();
|
||||
|
||||
const $ = cheerio.load(html);
|
||||
expect($('#assets').text()).to.match(
|
||||
assert.match(
|
||||
$('#assets').text(),
|
||||
/\["\/_astro\/index\.([\w-]{8})\.css","\/prerender\/index\.html"\]/
|
||||
);
|
||||
});
|
||||
|
||||
it('should give access to entry points that exists on file system', async () => {
|
||||
// number of the pages inside src/
|
||||
expect(entryPoints.size).to.equal(6);
|
||||
assert.equal(entryPoints.size, 6);
|
||||
for (const fileUrl of entryPoints.values()) {
|
||||
let filePath = fileURLToPath(fileUrl);
|
||||
expect(existsSync(filePath)).to.be.true;
|
||||
assert.equal(existsSync(filePath), true);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -66,7 +68,7 @@ describe('astro:ssr-manifest, split', () => {
|
|||
encoding: 'utf8',
|
||||
}
|
||||
);
|
||||
expect(text.includes('<title>Pre render me</title>')).to.be.true;
|
||||
assert.equal(text.includes('<title>Pre render me</title>'), true);
|
||||
});
|
||||
|
||||
it('should emit an entry point to request the pre-rendered page', async () => {
|
||||
|
@ -75,7 +77,7 @@ describe('astro:ssr-manifest, split', () => {
|
|||
const request = new Request('http://example.com/');
|
||||
const response = await app.render(request);
|
||||
const html = await response.text();
|
||||
expect(html.includes('<title>Pre render me</title>')).to.be.true;
|
||||
assert.equal(html.includes('<title>Pre render me</title>'), true);
|
||||
});
|
||||
|
||||
describe('when function per route is enabled', async () => {
|
||||
|
@ -109,7 +111,7 @@ describe('astro:ssr-manifest, split', () => {
|
|||
const request = new Request('http://example.com/');
|
||||
const response = await app.render(request);
|
||||
const html = await response.text();
|
||||
expect(html.includes('<title>Testing</title>')).to.be.true;
|
||||
assert.equal(html.includes('<title>Testing</title>'), true);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue