Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add tests to cover astro:config cases #13077

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 92 additions & 3 deletions packages/astro/test/serializeManifest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as cheerio from 'cheerio';
import { ServerOnlyModule } from '../dist/core/errors/errors-data.js';
import { AstroError } from '../dist/core/errors/index.js';
import { loadFixture } from './test-utils.js';
import testAdapter from "./test-adapter.js";

describe('astro:manifest/client', () => {
/** @type {import('./test-utils').Fixture} */
Expand Down Expand Up @@ -32,7 +33,7 @@ describe('astro:manifest/client', () => {
});
});

describe('when the experimental flag is enabled', async () => {
describe('when the experimental flag is enabled in dev', async () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/astro-manifest/',
Expand Down Expand Up @@ -73,12 +74,50 @@ describe('astro:manifest/client', () => {
);
});
});

describe('when the experimental flag is enabled in build', async () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/astro-manifest/',
});
await fixture.build();
});

it('should return the expected properties', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);

assert.deepEqual(
$('#config').text(),
JSON.stringify({
base: '/',
i18n: {
defaultLocale: 'en',
locales: ['en', 'fr'],
routing: {
prefixDefaultLocale: false,
redirectToDefaultLocale: true,
fallbackType: 'redirect',
},
},
build: {
format: 'directory',
},
trailingSlash: 'ignore',
compressHTML: true,
site: 'https://astro.build/',
}),
);
});
});

});

describe('astro:manifest/server', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let devServer;
let app

describe('when build', () => {
before(async () => {
Expand All @@ -93,8 +132,9 @@ describe('astro:manifest/server', () => {
assert.equal(error.name, ServerOnlyModule.name);
});
});


describe('when the experimental flag is not enabled', async () => {
describe('when the experimental flag is not enabled in dev', async () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/astro-manifest/',
Expand All @@ -116,7 +156,7 @@ describe('astro:manifest/server', () => {
});
});

describe('when the experimental flag is enabled', async () => {
describe('when the experimental flag is enabled in dev', async () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/astro-manifest/',
Expand All @@ -142,4 +182,53 @@ describe('astro:manifest/server', () => {
assert.ok($('#build-server').text().endsWith('/dist/server/'));
});
});

describe('when the experimental flag is enabled in build', async () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/astro-manifest/',
});
await fixture.build();
});

it('should return the expected properties', async () => {
const html = await fixture.readFile('/server/index.html');
const $ = cheerio.load(html);

assert.ok($('#out-dir').text().endsWith('/dist/'));
assert.ok($('#src-dir').text().endsWith('/src/'));
assert.ok($('#cache-dir').text().endsWith('/.astro/'));
assert.ok($('#root').text().endsWith('/'));
assert.ok($('#build-client').text().endsWith('/dist/client/'));
assert.ok($('#build-server').text().endsWith('/dist/server/'));
});
});

describe('when the experimental flag is enabled in SSR', async () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/astro-manifest/',
adapter: testAdapter(),
output: 'server',
});

await fixture.build();
app = await fixture.loadTestAdapterApp();
});


it('should return the expected properties', async () => {
const request = new Request('http://example.com/server');
const response = await app.render(request);
const html = await response.text();
const $ = cheerio.load(html);

assert.ok($('#out-dir').text().endsWith('/dist/'));
assert.ok($('#src-dir').text().endsWith('/src/'));
assert.ok($('#cache-dir').text().endsWith('/.astro/'));
assert.ok($('#root').text().endsWith('/'));
assert.ok($('#build-client').text().endsWith('/dist/client/'));
assert.ok($('#build-server').text().endsWith('/dist/server/'));
});
});
});
Loading