0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-31 23:31:30 -05:00

chore(@astrojs/sitemap): migrate tests to node:test (#9892)

* chore(@astrojs/sitemap): migrate tests to `node:test`

* chore(@astrojs/sitemap): remove `chai` and `mocha` from devDependencies
This commit is contained in:
Ming-jun Lu 2024-01-31 17:47:33 +08:00 committed by GitHub
parent 1c4a263d8f
commit 8dc7b39a62
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 33 additions and 35 deletions

View file

@ -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 --timeout 20000"
"test": "astro-scripts test \"test/**/*.test.js\""
},
"dependencies": {
"sitemap": "^7.1.1",
@ -40,8 +40,6 @@
"@astrojs/node": "workspace:*",
"astro": "workspace:*",
"astro-scripts": "workspace:*",
"chai": "^4.3.7",
"mocha": "^10.2.0",
"xml2js": "0.6.2"
},
"publishConfig": {

View file

@ -1,5 +1,6 @@
import { loadFixture, readXML } from './test-utils.js';
import { expect } from 'chai';
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
describe('URLs with base path', () => {
/** @type {import('./test-utils').Fixture} */
@ -17,7 +18,7 @@ describe('URLs with base path', () => {
it('Base path is concatenated correctly', async () => {
const data = await readXML(fixture.readFile('/client/sitemap-0.xml'));
const urls = data.urlset.url;
expect(urls[0].loc[0]).to.equal('http://example.com/base/one/');
assert.equal(urls[0].loc[0], 'http://example.com/base/one/');
});
});
@ -33,7 +34,7 @@ describe('URLs with base path', () => {
it('Base path is concatenated correctly', async () => {
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
const urls = data.urlset.url;
expect(urls[0].loc[0]).to.equal('http://example.com/base/123/');
assert.equal(urls[0].loc[0], 'http://example.com/base/123/');
});
});
});

View file

@ -1,5 +1,6 @@
import { loadFixture, readXML } from './test-utils.js';
import { expect } from 'chai';
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { sitemap } from './fixtures/static/deps.mjs';
describe('Filter support', () => {
@ -22,7 +23,7 @@ describe('Filter support', () => {
it('Just one page is added', async () => {
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
const urls = data.urlset.url;
expect(urls.length).to.equal(1);
assert.equal(urls.length, 1);
});
});
@ -42,7 +43,7 @@ describe('Filter support', () => {
it('Just one page is added', async () => {
const data = await readXML(fixture.readFile('/client/sitemap-0.xml'));
const urls = data.urlset.url;
expect(urls.length).to.equal(1);
assert.equal(urls.length, 1);
});
});
});

View file

@ -1,5 +1,6 @@
import { loadFixture, readXML } from './test-utils.js';
import { expect } from 'chai';
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
describe('routes', () => {
/** @type {import('./test-utils.js').Fixture} */
@ -17,10 +18,10 @@ describe('routes', () => {
});
it('does not include endpoints', async () => {
expect(urls).to.not.include('http://example.com/endpoint.json');
assert.equal(urls.includes('http://example.com/endpoint.json'), false);
});
it('does not include redirects', async () => {
expect(urls).to.not.include('http://example.com/redirect');
assert.equal(urls.includes('http://example.com/redirect'), false);
});
});

View file

@ -1,5 +1,6 @@
import { loadFixture, readXML } from './test-utils.js';
import { expect } from 'chai';
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
describe('SSR support', () => {
/** @type {import('./test-utils.js').Fixture} */
@ -16,7 +17,7 @@ describe('SSR support', () => {
const data = await readXML(fixture.readFile('/client/sitemap-0.xml'));
const urls = data.urlset.url;
expect(urls[0].loc[0]).to.equal('http://example.com/one/');
expect(urls[1].loc[0]).to.equal('http://example.com/two/');
assert.equal(urls[0].loc[0], 'http://example.com/one/');
assert.equal(urls[1].loc[0], 'http://example.com/two/');
});
});

View file

@ -1,5 +1,6 @@
import { loadFixture, readXML } from './test-utils.js';
import { expect } from 'chai';
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
describe('getStaticPaths support', () => {
/** @type {import('./test-utils.js').Fixture} */
@ -19,24 +20,24 @@ describe('getStaticPaths support', () => {
});
it('requires zero config for getStaticPaths', async () => {
expect(urls).to.include('http://example.com/one/');
expect(urls).to.include('http://example.com/two/');
assert.equal(urls.includes('http://example.com/one/'), true);
assert.equal(urls.includes('http://example.com/two/'), true);
});
it('does not include 404 pages', () => {
expect(urls).to.not.include('http://example.com/404/');
assert.equal(urls.includes('http://example.com/404/'), false);
});
it('does not include nested 404 pages', () => {
expect(urls).to.not.include('http://example.com/de/404/');
assert.equal(urls.includes('http://example.com/de/404/'), false);
});
it('includes numerical pages', () => {
expect(urls).to.include('http://example.com/123/');
assert.equal(urls.includes('http://example.com/123/'), true);
});
it('should render the endpoint', async () => {
const page = await fixture.readFile('./it/manifest');
expect(page).to.contain('I\'m a route in the "it" language.');
assert.match(page, /I\'m a route in the "it" language./);
});
});

View file

@ -1,5 +1,6 @@
import { loadFixture, readXML } from './test-utils.js';
import { expect } from 'chai';
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
describe('Trailing slash', () => {
/** @type {import('./test-utils').Fixture} */
@ -21,7 +22,7 @@ describe('Trailing slash', () => {
it('URLs end with trailing slash', async () => {
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
const urls = data.urlset.url;
expect(urls[0].loc[0]).to.equal('http://example.com/one/');
assert.equal(urls[0].loc[0], 'http://example.com/one/');
});
});
@ -40,7 +41,7 @@ describe('Trailing slash', () => {
it('URLs do not end with trailing slash', async () => {
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
const urls = data.urlset.url;
expect(urls[0].loc[0]).to.equal('http://example.com/one');
assert.equal(urls[0].loc[0], 'http://example.com/one');
});
});
});
@ -57,7 +58,7 @@ describe('Trailing slash', () => {
it('URLs do no end with trailing slash', async () => {
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
const urls = data.urlset.url;
expect(urls[0].loc[0]).to.equal('http://example.com/one');
assert.equal(urls[0].loc[0], 'http://example.com/one');
});
describe('with base path', () => {
before(async () => {
@ -72,7 +73,7 @@ describe('Trailing slash', () => {
it('URLs do not end with trailing slash', async () => {
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
const urls = data.urlset.url;
expect(urls[0].loc[0]).to.equal('http://example.com/base/one');
assert.equal(urls[0].loc[0], 'http://example.com/base/one');
});
});
});
@ -89,7 +90,7 @@ describe('Trailing slash', () => {
it('URLs end with trailing slash', async () => {
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
const urls = data.urlset.url;
expect(urls[0].loc[0]).to.equal('http://example.com/one/');
assert.equal(urls[0].loc[0], 'http://example.com/one/');
});
describe('with base path', () => {
before(async () => {
@ -104,7 +105,7 @@ describe('Trailing slash', () => {
it('URLs end with trailing slash', async () => {
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
const urls = data.urlset.url;
expect(urls[0].loc[0]).to.equal('http://example.com/base/one/');
assert.equal(urls[0].loc[0], 'http://example.com/base/one/');
});
});
});

6
pnpm-lock.yaml generated
View file

@ -4600,12 +4600,6 @@ importers:
astro-scripts:
specifier: workspace:*
version: link:../../../scripts
chai:
specifier: ^4.3.7
version: 4.3.10
mocha:
specifier: ^10.2.0
version: 10.2.0
xml2js:
specifier: 0.6.2
version: 0.6.2