Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion packages/integrations/sitemap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
"build:ci": "astro-scripts build \"src/**/*.ts\"",
"dev": "astro-scripts dev \"src/**/*.ts\"",
"test": "astro-scripts test \"test/**/*.test.js\""
"test": "astro-scripts test \"test/**/*.test.ts\"",
"typecheck:tests": "tsc --build tsconfig.test.json"
},
"dependencies": {
"sitemap": "^9.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { loadFixture, readXML } from './test-utils.js';
import type { Fixture } from '../../../astro/test/test-utils.js';

describe('URLs with base path', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let fixture: Fixture;

describe('using node adapter', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/ssr/',
base: '/base',
});
await fixture.build();
await fixture.build({});
});

it('Base path is concatenated correctly', async () => {
Expand All @@ -34,7 +34,7 @@ describe('URLs with base path', () => {
root: './fixtures/static/',
base: '/base',
});
await fixture.build();
await fixture.build({});
});

it('Base path is concatenated correctly', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { EnumChangefreq } from 'sitemap';
import { sitemap } from './fixtures/static/deps.mjs';
import { loadFixture, readXML } from './test-utils.js';
import type { Fixture } from '../../../astro/test/test-utils.js';

describe('Sitemap with chunked files', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;
/** @type {string[]} */
let blogUrls;
let glossaryUrls;
let pagesUrls;
let fixture: Fixture;
let blogUrls: string[];
let glossaryUrls: string[];
let pagesUrls: string[];

before(async () => {
fixture = await loadFixture({
Expand All @@ -22,15 +22,17 @@ describe('Sitemap with chunked files', () => {
chunks: {
blog: (item) => {
if (item.url.includes('blog')) {
item.changefreq = 'weekly';
item.changefreq = EnumChangefreq.WEEKLY;
// @ts-expect-error - a string is expected but the original JS code assigns a Date object here
item.lastmod = new Date();
item.priority = 0.9;
return item;
}
},
glossary: (item) => {
if (item.url.includes('glossary')) {
item.changefreq = 'weekly';
item.changefreq = EnumChangefreq.WEEKLY;
// @ts-expect-error - a string is expected but the original JS code assigns a Date object here
item.lastmod = new Date();
item.priority = 0.9;
return item;
Expand All @@ -40,10 +42,10 @@ describe('Sitemap with chunked files', () => {
}),
],
});
await fixture.build();
const flatMapUrls = async (file) => {
await fixture.build({});
const flatMapUrls = async (file: string) => {
const data = await readXML(fixture.readFile(file));
return data.urlset.url.map((url) => url.loc[0]);
return data.urlset.url.map((url: { loc: string[] }) => url.loc[0]);
};
blogUrls = await flatMapUrls('sitemap-blog-0.xml');
glossaryUrls = await flatMapUrls('sitemap-glossary-0.xml');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { sitemap } from './fixtures/static/deps.mjs';
import { loadFixture, readXML } from './test-utils.js';
import type { Fixture } from '../../../astro/test/test-utils.js';

describe('Config', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;
let fixture: Fixture;

describe('Static', () => {
before(async () => {
Expand All @@ -18,7 +18,7 @@ describe('Config', () => {
}),
],
});
await fixture.build();
await fixture.build({});
});

it('filter: Just one page is added', async () => {
Expand Down Expand Up @@ -55,7 +55,7 @@ describe('Config', () => {
}),
],
});
await fixture.build();
await fixture.build({});
});

it('filter: Just one page is added', async () => {
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('Config', () => {
}),
],
});
await fixture.build();
await fixture.build({});
});

it('filenameBase: Sets the generated sitemap filename', async () => {
Expand All @@ -119,7 +119,7 @@ describe('Config', () => {
}),
],
});
await assert.rejects(fixture.build(), /^Error: filter error$/);
await assert.rejects(fixture.build({}), /^Error: filter error$/);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { sitemap } from './fixtures/static/deps.mjs';
import { loadFixture, readXML } from './test-utils.js';
import type { Fixture } from '../../../astro/test/test-utils.js';

describe('Sitemap with custom pages', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;
/** @type {string[]} */
let urls;
let fixture: Fixture;
let urls: string[];

before(async () => {
fixture = await loadFixture({
Expand All @@ -18,9 +17,9 @@ describe('Sitemap with custom pages', () => {
}),
],
});
await fixture.build();
await fixture.build({});
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
urls = data.urlset.url.map((url) => url.loc[0]);
urls = data.urlset.url.map((url: { loc: string[] }) => url.loc[0]);
});

it('includes defined custom pages', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { sitemap } from './fixtures/static/deps.mjs';
import { loadFixture, readXML } from './test-utils.js';
import type { Fixture } from '../../../astro/test/test-utils.js';

describe('Custom sitemaps', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;
/** @type {{ [key: string]: string }} */
let sitemaps;
let fixture: Fixture;
let sitemaps: { loc: string; lastmod: string }[];

before(async () => {
fixture = await loadFixture({
Expand All @@ -19,9 +18,12 @@ describe('Custom sitemaps', () => {
}),
],
});
await fixture.build();
await fixture.build({});
const data = await readXML(fixture.readFile('/sitemap-index.xml'));
sitemaps = data.sitemapindex.sitemap.map((s) => ({ loc: s.loc[0], lastmod: s.lastmod[0] }));
sitemaps = data.sitemapindex.sitemap.map((s: { loc: string[]; lastmod: string[] }) => ({
loc: s.loc[0],
lastmod: s.lastmod[0],
}));
});

it('includes defined custom sitemaps', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { loadFixture, readXML } from './test-utils.js';
import type { Fixture } from '../../../astro/test/test-utils.js';

describe('Dynamic with rest parameter', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({
root: './fixtures/dynamic',
});
await fixture.build();
await fixture.build({});
});

it('Should generate correct urls', async () => {
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
const urls = data.urlset.url.map((url) => url.loc[0]);
const urls = data.urlset.url.map((url: { loc: string[] }) => url.loc[0]);

assert.ok(urls.includes('http://example.com/'));
assert.ok(urls.includes('http://example.com/blog/'));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { loadFixture, readXML } from './test-utils.js';
import type { Fixture } from '../../../astro/test/test-utils.js';

describe('i18n fallback', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;
/** @type {string[]} */
let urls;
let fixture: Fixture;
let urls: string[];

before(async () => {
fixture = await loadFixture({
root: './fixtures/i18n-fallback/',
});
await fixture.build();
await fixture.build({});
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
urls = data.urlset.url.map((url) => url.loc[0]);
urls = data.urlset.url.map((url: { loc: string[] }) => url.loc[0]);
});

it('includes default locale pages', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { sitemap } from './fixtures/static/deps.mjs';
import { loadFixture } from './test-utils.js';
import type { Fixture } from '../../../astro/test/test-utils.js';

describe('Namespaces Configuration', () => {
let fixture;
let fixture: Fixture;

describe('Default namespaces', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/static/',
integrations: [sitemap()],
});
await fixture.build();
await fixture.build({});
});

it('includes all default namespaces', async () => {
Expand All @@ -36,7 +37,7 @@ describe('Namespaces Configuration', () => {
}),
],
});
await fixture.build();
await fixture.build({});
});

it('excludes news namespace but includes others', async () => {
Expand All @@ -63,7 +64,7 @@ describe('Namespaces Configuration', () => {
}),
],
});
await fixture.build();
await fixture.build({});
});

it('excludes all optional namespaces', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { loadFixture, readXML } from './test-utils.js';
import type { Fixture } from '../../../astro/test/test-utils.js';

describe('routes', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;
/** @type {string[]} */
let urls;
let fixture: Fixture;
let urls: string[];

before(async () => {
fixture = await loadFixture({
root: './fixtures/static/',
});
await fixture.build();
await fixture.build({});
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
urls = data.urlset.url.map((url) => url.loc[0]);
urls = data.urlset.url.map((url: { loc: string[] }) => url.loc[0]);
});

it('does not include endpoints', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { loadFixture, readXML } from './test-utils.js';
import type { Fixture } from '../../../astro/test/test-utils.js';

describe('SSR support', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({
root: './fixtures/ssr/',
});
await fixture.build();
await fixture.build({});
});

it('SSR pages require zero config', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { loadFixture, readXML } from './test-utils.js';
import type { Fixture } from '../../../astro/test/test-utils.js';

describe('getStaticPaths support', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;
/** @type {string[]} */
let urls;
let fixture: Fixture;
let urls: string[];

before(async () => {
fixture = await loadFixture({
root: './fixtures/static/',
trailingSlash: 'always',
});
await fixture.build();
await fixture.build({});

const data = await readXML(fixture.readFile('/sitemap-0.xml'));
urls = data.urlset.url.map((url) => url.loc[0]);
urls = data.urlset.url.map((url: { loc: string[] }) => url.loc[0]);
});

it('requires zero config for getStaticPaths', async () => {
Expand Down
Loading
Loading