mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
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>
This commit is contained in:
parent
d688954c5a
commit
fc21a3c306
17 changed files with 183 additions and 144 deletions
|
@ -30,7 +30,7 @@
|
|||
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
|
||||
"build:ci": "astro-scripts build \"src/**/*.ts\"",
|
||||
"dev": "astro-scripts dev \"src/**/*.ts\"",
|
||||
"test": "mocha --exit --timeout 20000 test/"
|
||||
"test": "astro-scripts test \"test/**/*.test.js\""
|
||||
},
|
||||
"dependencies": {
|
||||
"send": "^0.18.0",
|
||||
|
@ -45,10 +45,8 @@
|
|||
"@types/server-destroy": "^1.0.3",
|
||||
"astro": "workspace:*",
|
||||
"astro-scripts": "workspace:*",
|
||||
"chai": "^4.3.7",
|
||||
"cheerio": "1.0.0-rc.12",
|
||||
"express": "^4.18.2",
|
||||
"mocha": "^10.2.0",
|
||||
"node-mocks-http": "^1.13.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import nodejs from '../dist/index.js';
|
||||
import { loadFixture, createRequestAndResponse } from './test-utils.js';
|
||||
import { expect } from 'chai';
|
||||
import crypto from 'node:crypto';
|
||||
import { describe, it, before } from 'node:test';
|
||||
import * as assert from 'node:assert/strict';
|
||||
|
||||
describe('API routes', () => {
|
||||
/** @type {import('./test-utils').Fixture} */
|
||||
|
@ -33,9 +34,9 @@ describe('API routes', () => {
|
|||
|
||||
let json = JSON.parse(buffer.toString('utf-8'));
|
||||
|
||||
expect(json.length).to.equal(1);
|
||||
assert.equal(json.length, 1);
|
||||
|
||||
expect(json[0].name).to.equal('Broccoli Soup');
|
||||
assert.equal(json[0].name, 'Broccoli Soup');
|
||||
});
|
||||
|
||||
it('Can get binary data', async () => {
|
||||
|
@ -54,7 +55,7 @@ describe('API routes', () => {
|
|||
|
||||
let [out] = await done;
|
||||
let arr = Array.from(new Uint8Array(out.buffer));
|
||||
expect(arr).to.deep.equal([5, 4, 3, 2, 1]);
|
||||
assert.deepEqual(arr, [5, 4, 3, 2, 1]);
|
||||
});
|
||||
|
||||
it('Can post large binary data', async () => {
|
||||
|
@ -87,7 +88,7 @@ describe('API routes', () => {
|
|||
});
|
||||
|
||||
let [out] = await done;
|
||||
expect(new Uint8Array(out.buffer)).to.deep.equal(expectedDigest);
|
||||
assert.deepEqual(new Uint8Array(out.buffer), new Uint8Array(expectedDigest));
|
||||
});
|
||||
|
||||
it('Can bail on streaming', async () => {
|
||||
|
@ -106,6 +107,6 @@ describe('API routes', () => {
|
|||
|
||||
await done;
|
||||
|
||||
expect(locals).to.deep.include({ cancelledByTheServer: true });
|
||||
assert.deepEqual(locals, { cancelledByTheServer: true });
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
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 * as cheerio from 'cheerio';
|
||||
|
@ -30,7 +31,7 @@ describe('Assets', () => {
|
|||
it('Assets within the _astro folder should be given immutable headers', async () => {
|
||||
let response = await fixture.fetch('/text-file');
|
||||
let cacheControl = response.headers.get('cache-control');
|
||||
expect(cacheControl).to.equal(null);
|
||||
assert.equal(cacheControl, null);
|
||||
const html = await response.text();
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
|
@ -38,6 +39,6 @@ describe('Assets', () => {
|
|||
const fileURL = $('a').attr('href');
|
||||
response = await fixture.fetch(fileURL);
|
||||
cacheControl = response.headers.get('cache-control');
|
||||
expect(cacheControl).to.equal('public, max-age=31536000, immutable');
|
||||
assert.equal(cacheControl, 'public, max-age=31536000, immutable');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
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';
|
||||
|
||||
|
@ -32,15 +33,17 @@ describe('Bad URLs', () => {
|
|||
'%20foobar%',
|
||||
];
|
||||
|
||||
const statusCodes = [400, 404, 500];
|
||||
for (const weirdUrl of weirdURLs) {
|
||||
const fetchResult = await fixture.fetch(weirdUrl);
|
||||
expect([400, 404, 500]).to.include(
|
||||
fetchResult.status,
|
||||
assert.equal(
|
||||
statusCodes.includes(fetchResult.status),
|
||||
true,
|
||||
`${weirdUrl} returned something else than 400, 404, or 500`
|
||||
);
|
||||
}
|
||||
const stillWork = await fixture.fetch('/');
|
||||
const text = await stillWork.text();
|
||||
expect(text).to.equal('<!DOCTYPE html>Hello!');
|
||||
assert.equal(text, '<!DOCTYPE html>Hello!');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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, createRequestAndResponse } from './test-utils.js';
|
||||
import { expect } from 'chai';
|
||||
|
||||
describe('Encoded Pathname', () => {
|
||||
/** @type {import('./test-utils').Fixture} */
|
||||
|
@ -25,7 +26,7 @@ describe('Encoded Pathname', () => {
|
|||
req.send();
|
||||
|
||||
const html = await text();
|
||||
expect(html).to.include('什么</h1>');
|
||||
assert.equal(html.includes('什么</h1>'), true);
|
||||
});
|
||||
|
||||
it('Can get a Markdown file', async () => {
|
||||
|
@ -39,6 +40,6 @@ describe('Encoded Pathname', () => {
|
|||
req.send();
|
||||
|
||||
const html = await text();
|
||||
expect(html).to.include('什么</h1>');
|
||||
assert.equal(html.includes('什么</h1>'), true);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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 * as cheerio from 'cheerio';
|
||||
|
||||
describe('Errors', () => {
|
||||
|
@ -13,21 +14,19 @@ describe('Errors', () => {
|
|||
});
|
||||
await fixture.build();
|
||||
});
|
||||
describe('Within the stream', async () => {
|
||||
let devPreview;
|
||||
let devPreview;
|
||||
|
||||
before(async () => {
|
||||
devPreview = await fixture.preview();
|
||||
});
|
||||
after(async () => {
|
||||
await devPreview.stop();
|
||||
});
|
||||
it('when mode is standalone', async () => {
|
||||
const res = await fixture.fetch('/in-stream');
|
||||
const html = await res.text();
|
||||
const $ = cheerio.load(html);
|
||||
before(async () => {
|
||||
devPreview = await fixture.preview();
|
||||
});
|
||||
after(async () => {
|
||||
await devPreview.stop();
|
||||
});
|
||||
it('when mode is standalone', async () => {
|
||||
const res = await fixture.fetch('/in-stream');
|
||||
const html = await res.text();
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
expect($('p').text().trim()).to.equal('Internal server error');
|
||||
});
|
||||
assert.equal($('p').text().trim(), 'Internal server error');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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, createRequestAndResponse } from './test-utils.js';
|
||||
import { expect } from 'chai';
|
||||
|
||||
describe('Node Adapter Headers', () => {
|
||||
/** @type {import('./test-utils').Fixture} */
|
||||
|
@ -143,5 +144,5 @@ async function runTest(url, expectedHeaders) {
|
|||
await done;
|
||||
const headers = res.getHeaders();
|
||||
|
||||
expect(headers).to.deep.equal(expectedHeaders);
|
||||
assert.deepEqual(headers, expectedHeaders);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
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';
|
||||
|
||||
|
@ -24,12 +25,12 @@ describe.skip('Image endpoint', () => {
|
|||
|
||||
it('it returns images', async () => {
|
||||
const res = await fixture.fetch('/');
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
|
||||
const resImage = await fixture.fetch(
|
||||
'/_image?href=/_astro/some_penguin.97ef5f92.png&w=50&f=webp'
|
||||
);
|
||||
|
||||
expect(resImage.status).to.equal(200);
|
||||
assert.equal(resImage.status, 200);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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, createRequestAndResponse } from './test-utils.js';
|
||||
import { expect } from 'chai';
|
||||
|
||||
describe('API routes', () => {
|
||||
/** @type {import('./test-utils').Fixture} */
|
||||
|
@ -28,7 +29,7 @@ describe('API routes', () => {
|
|||
|
||||
let html = await text();
|
||||
|
||||
expect(html).to.contain('<h1>bar</h1>');
|
||||
assert.equal(html.includes('<h1>bar</h1>'), true);
|
||||
});
|
||||
|
||||
it('Throws an error when provided non-objects as locals', async () => {
|
||||
|
@ -41,7 +42,7 @@ describe('API routes', () => {
|
|||
req.send();
|
||||
|
||||
await done;
|
||||
expect(res).to.deep.include({ statusCode: 500 });
|
||||
assert.equal(res.statusCode, 500);
|
||||
});
|
||||
|
||||
it('Can use locals added by astro middleware', async () => {
|
||||
|
@ -56,7 +57,7 @@ describe('API routes', () => {
|
|||
|
||||
const html = await text();
|
||||
|
||||
expect(html).to.contain('<h1>baz</h1>');
|
||||
assert.equal(html.includes('<h1>baz</h1>'), true);
|
||||
});
|
||||
|
||||
it('Can access locals in API', async () => {
|
||||
|
@ -75,6 +76,6 @@ describe('API routes', () => {
|
|||
|
||||
let json = JSON.parse(buffer.toString('utf-8'));
|
||||
|
||||
expect(json.foo).to.equal('bar');
|
||||
assert.equal(json.foo, 'bar');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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';
|
||||
import express from 'express';
|
||||
|
||||
|
@ -31,6 +32,7 @@ describe('behavior from middleware, standalone', () => {
|
|||
const { startServer } = await load();
|
||||
let res = startServer();
|
||||
server = res.server;
|
||||
await waitServerListen(server.server);
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
|
@ -43,13 +45,13 @@ describe('behavior from middleware, standalone', () => {
|
|||
it('when mode is standalone', async () => {
|
||||
const res = await fetch(`http://${server.host}:${server.port}/error-page`);
|
||||
|
||||
expect(res.status).to.equal(404);
|
||||
assert.equal(res.status, 404);
|
||||
|
||||
const html = await res.text();
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
const body = $('body');
|
||||
expect(body.text()).to.equal('Page does not exist');
|
||||
assert.equal(body.text().includes('Page does not exist'), true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -82,12 +84,12 @@ describe('behavior from middleware, middleware', () => {
|
|||
it('when mode is standalone', async () => {
|
||||
const res = await fetch(`http://localhost:8888/ssr`);
|
||||
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
|
||||
const html = await res.text();
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
const body = $('body');
|
||||
expect(body.text()).to.contain("Here's a random number");
|
||||
assert.equal(body.text().includes("Here's a random number"), true);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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';
|
||||
|
||||
/**
|
||||
|
@ -37,6 +38,7 @@ describe('Prerender 404', () => {
|
|||
const { startServer } = await load();
|
||||
let res = startServer();
|
||||
server = res.server;
|
||||
await waitServerListen(server.server);
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
|
@ -50,8 +52,8 @@ describe('Prerender 404', () => {
|
|||
const html = await res.text();
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
expect(res.status).to.equal(200);
|
||||
expect($('h1').text()).to.equal('Hello world!');
|
||||
assert.equal(res.status, 200);
|
||||
assert.equal($('h1').text(), 'Hello world!');
|
||||
});
|
||||
|
||||
it('Can handle prerendered 404', async () => {
|
||||
|
@ -60,20 +62,20 @@ describe('Prerender 404', () => {
|
|||
const res2 = await fetch(url);
|
||||
const res3 = await fetch(url);
|
||||
|
||||
expect(res1.status).to.equal(404);
|
||||
expect(res2.status).to.equal(404);
|
||||
expect(res3.status).to.equal(404);
|
||||
assert.equal(res1.status, 404);
|
||||
assert.equal(res2.status, 404);
|
||||
assert.equal(res3.status, 404);
|
||||
|
||||
const html1 = await res1.text();
|
||||
const html2 = await res2.text();
|
||||
const html3 = await res3.text();
|
||||
|
||||
expect(html1).to.equal(html2);
|
||||
expect(html2).to.equal(html3);
|
||||
assert.equal(html1, html2);
|
||||
assert.equal(html2, html3);
|
||||
|
||||
const $ = cheerio.load(html1);
|
||||
|
||||
expect($('body').text()).to.equal('Page does not exist');
|
||||
assert.equal($('body').text(), 'Page does not exist');
|
||||
});
|
||||
|
||||
it(' Can handle prerendered 500 called indirectly', async () => {
|
||||
|
@ -82,16 +84,16 @@ describe('Prerender 404', () => {
|
|||
const response2 = await fetch(url);
|
||||
const response3 = await fetch(url);
|
||||
|
||||
expect(response1.status).to.equal(500);
|
||||
assert.equal(response1.status, 500);
|
||||
|
||||
const html1 = await response1.text();
|
||||
const html2 = await response2.text();
|
||||
const html3 = await response3.text();
|
||||
|
||||
expect(html1).to.contain('Something went wrong');
|
||||
assert.equal(html1.includes('Something went wrong'), true);
|
||||
|
||||
expect(html1).to.equal(html2);
|
||||
expect(html2).to.equal(html3);
|
||||
assert.equal(html1, html2);
|
||||
assert.equal(html2, html3);
|
||||
});
|
||||
|
||||
it('prerendered 500 page includes expected styles', async () => {
|
||||
|
@ -100,7 +102,7 @@ describe('Prerender 404', () => {
|
|||
const $ = cheerio.load(html);
|
||||
|
||||
// length will be 0 if the stylesheet does not get included
|
||||
expect($('style')).to.have.a.lengthOf(1);
|
||||
assert.equal($('style').length, 1);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -121,6 +123,7 @@ describe('Prerender 404', () => {
|
|||
const { startServer } = await load();
|
||||
let res = startServer();
|
||||
server = res.server;
|
||||
await waitServerListen(server.server);
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
|
@ -134,8 +137,8 @@ describe('Prerender 404', () => {
|
|||
const html = await res.text();
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
expect(res.status).to.equal(200);
|
||||
expect($('h1').text()).to.equal('Hello world!');
|
||||
assert.equal(res.status, 200);
|
||||
assert.equal($('h1').text(), 'Hello world!');
|
||||
});
|
||||
|
||||
it('Can handle prerendered 404', async () => {
|
||||
|
@ -144,20 +147,20 @@ describe('Prerender 404', () => {
|
|||
const res2 = await fetch(url);
|
||||
const res3 = await fetch(url);
|
||||
|
||||
expect(res1.status).to.equal(404);
|
||||
expect(res2.status).to.equal(404);
|
||||
expect(res3.status).to.equal(404);
|
||||
assert.equal(res1.status, 404);
|
||||
assert.equal(res2.status, 404);
|
||||
assert.equal(res3.status, 404);
|
||||
|
||||
const html1 = await res1.text();
|
||||
const html2 = await res2.text();
|
||||
const html3 = await res3.text();
|
||||
|
||||
expect(html1).to.equal(html2);
|
||||
expect(html2).to.equal(html3);
|
||||
assert.equal(html1, html2);
|
||||
assert.equal(html2, html3);
|
||||
|
||||
const $ = cheerio.load(html1);
|
||||
|
||||
expect($('body').text()).to.equal('Page does not exist');
|
||||
assert.equal($('body').text(), 'Page does not exist');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -184,6 +187,7 @@ describe('Hybrid 404', () => {
|
|||
const { startServer } = await load();
|
||||
let res = startServer();
|
||||
server = res.server;
|
||||
await waitServerListen(server.server);
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
|
@ -197,8 +201,8 @@ describe('Hybrid 404', () => {
|
|||
const html = await res.text();
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
expect(res.status).to.equal(200);
|
||||
expect($('h1').text()).to.equal('Hello world!');
|
||||
assert.equal(res.status, 200);
|
||||
assert.equal($('h1').text(), 'Hello world!');
|
||||
});
|
||||
|
||||
it('Can handle prerendered 404', async () => {
|
||||
|
@ -207,20 +211,20 @@ describe('Hybrid 404', () => {
|
|||
const res2 = await fetch(url);
|
||||
const res3 = await fetch(url);
|
||||
|
||||
expect(res1.status).to.equal(404);
|
||||
expect(res2.status).to.equal(404);
|
||||
expect(res3.status).to.equal(404);
|
||||
assert.equal(res1.status, 404);
|
||||
assert.equal(res2.status, 404);
|
||||
assert.equal(res3.status, 404);
|
||||
|
||||
const html1 = await res1.text();
|
||||
const html2 = await res2.text();
|
||||
const html3 = await res3.text();
|
||||
|
||||
expect(html1).to.equal(html2);
|
||||
expect(html2).to.equal(html3);
|
||||
assert.equal(html1, html2);
|
||||
assert.equal(html2, html3);
|
||||
|
||||
const $ = cheerio.load(html1);
|
||||
|
||||
expect($('body').text()).to.equal('Page does not exist');
|
||||
assert.equal($('body').text(), 'Page does not exist');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -240,6 +244,7 @@ describe('Hybrid 404', () => {
|
|||
const { startServer } = await load();
|
||||
let res = startServer();
|
||||
server = res.server;
|
||||
await waitServerListen(server.server);
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
|
@ -253,8 +258,8 @@ describe('Hybrid 404', () => {
|
|||
const html = await res.text();
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
expect(res.status).to.equal(200);
|
||||
expect($('h1').text()).to.equal('Hello world!');
|
||||
assert.equal(res.status, 200);
|
||||
assert.equal($('h1').text(), 'Hello world!');
|
||||
});
|
||||
|
||||
it('Can handle prerendered 404', async () => {
|
||||
|
@ -263,20 +268,20 @@ describe('Hybrid 404', () => {
|
|||
const res2 = await fetch(url);
|
||||
const res3 = await fetch(url);
|
||||
|
||||
expect(res1.status).to.equal(404);
|
||||
expect(res2.status).to.equal(404);
|
||||
expect(res3.status).to.equal(404);
|
||||
assert.equal(res1.status, 404);
|
||||
assert.equal(res2.status, 404);
|
||||
assert.equal(res3.status, 404);
|
||||
|
||||
const html1 = await res1.text();
|
||||
const html2 = await res2.text();
|
||||
const html3 = await res3.text();
|
||||
|
||||
expect(html1).to.equal(html2);
|
||||
expect(html2).to.equal(html3);
|
||||
assert.equal(html1, html2);
|
||||
assert.equal(html2, html3);
|
||||
|
||||
const $ = cheerio.load(html1);
|
||||
|
||||
expect($('body').text()).to.equal('Page does not exist');
|
||||
assert.equal($('body').text(), 'Page does not exist');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -64,3 +64,11 @@ export function buffersToString(buffers) {
|
|||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
export function waitServerListen(server) {
|
||||
return new Promise((resolve) => {
|
||||
server.on('listening', () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import * as assert from 'node:assert/strict';
|
||||
import { describe, it, before } from 'node:test';
|
||||
import { TLSSocket } from 'node:tls';
|
||||
import nodejs from '../dist/index.js';
|
||||
import { createRequestAndResponse, loadFixture } from './test-utils.js';
|
||||
|
@ -26,7 +27,7 @@ describe('URL protocol', () => {
|
|||
req.send();
|
||||
|
||||
const html = await text();
|
||||
expect(html).to.include('http:');
|
||||
assert.equal(html.includes('http:'), true);
|
||||
});
|
||||
|
||||
it('return https when secure', async () => {
|
||||
|
@ -40,7 +41,7 @@ describe('URL protocol', () => {
|
|||
req.send();
|
||||
|
||||
const html = await text();
|
||||
expect(html).to.include('https:');
|
||||
assert.equal(html.includes('https:'), true);
|
||||
});
|
||||
|
||||
it('return http when the X-Forwarded-Proto header is set to http', async () => {
|
||||
|
@ -54,7 +55,7 @@ describe('URL protocol', () => {
|
|||
req.send();
|
||||
|
||||
const html = await text();
|
||||
expect(html).to.include('http:');
|
||||
assert.equal(html.includes('http:'), true);
|
||||
});
|
||||
|
||||
it('return https when the X-Forwarded-Proto header is set to https', async () => {
|
||||
|
@ -68,6 +69,6 @@ describe('URL protocol', () => {
|
|||
req.send();
|
||||
|
||||
const html = await text();
|
||||
expect(html).to.include('https:');
|
||||
assert.equal(html.includes('https:'), true);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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';
|
||||
|
||||
describe('test URIs beginning with a dot', () => {
|
||||
/** @type {import('./test-utils').Fixture} */
|
||||
|
@ -29,17 +30,17 @@ describe('test URIs beginning with a dot', () => {
|
|||
it('can load a valid well-known URI', async () => {
|
||||
const res = await fixture.fetch('/.well-known/apple-app-site-association');
|
||||
|
||||
expect(res.status).to.equal(200);
|
||||
assert.equal(res.status, 200);
|
||||
|
||||
const json = await res.json();
|
||||
|
||||
expect(json).to.deep.equal({ applinks: {} });
|
||||
assert.notStrictEqual(json.applinks, {});
|
||||
});
|
||||
|
||||
it('cannot load a dot folder that is not a well-known URI', async () => {
|
||||
const res = await fixture.fetch('/.hidden/file.json');
|
||||
|
||||
expect(res.status).to.equal(404);
|
||||
assert.equal(res.status, 404);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4350,18 +4350,12 @@ importers:
|
|||
astro-scripts:
|
||||
specifier: workspace:*
|
||||
version: link:../../../scripts
|
||||
chai:
|
||||
specifier: ^4.3.7
|
||||
version: 4.3.10
|
||||
cheerio:
|
||||
specifier: 1.0.0-rc.12
|
||||
version: 1.0.0-rc.12
|
||||
express:
|
||||
specifier: ^4.18.2
|
||||
version: 4.18.2
|
||||
mocha:
|
||||
specifier: ^10.2.0
|
||||
version: 10.2.0
|
||||
node-mocks-http:
|
||||
specifier: ^1.13.0
|
||||
version: 1.14.0
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
import { run } from 'node:test';
|
||||
import { spec } from 'node:test/reporters';
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
import arg from 'arg';
|
||||
import glob from 'tiny-glob';
|
||||
|
||||
|
@ -36,6 +39,20 @@ export default async function test() {
|
|||
process.env.NODE_OPTIONS += ' --test-only';
|
||||
}
|
||||
|
||||
if (!args['--parallel']) {
|
||||
// If not parallel, we create a temporary file that imports all the test files
|
||||
// so that it all runs in a single process.
|
||||
const tempTestFile = path.resolve('./node_modules/.astro/test.mjs');
|
||||
await fs.mkdir(path.dirname(tempTestFile), { recursive: true });
|
||||
await fs.writeFile(
|
||||
tempTestFile,
|
||||
files.map((f) => `import ${JSON.stringify(pathToFileURL(f).toString())};`).join('\n')
|
||||
);
|
||||
|
||||
files.length = 0;
|
||||
files.push(tempTestFile);
|
||||
}
|
||||
|
||||
// https://nodejs.org/api/test.html#runoptions
|
||||
run({
|
||||
files,
|
||||
|
|
Loading…
Reference in a new issue