Skip to content

Commit

Permalink
Dynamic Sitemap - develop test (#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstockdi committed Jul 21, 2024
1 parent 076ce0f commit e1903c3
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ describe('Build Greenwood With: ', function() {

});

// after(function() {
// runner.teardown([
// path.join(outputPath, '.vercel'),
// ...getOutputTeardownFiles(outputPath)
// ]);
// });
after(function() {
runner.stopCommand();
runner.teardown([
path.join(outputPath, '.greenwood')
]);
});

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

import path from 'path';
import { Runner } from 'gallinago';
import { fileURLToPath } from 'url';

import chai from 'chai';
const expect = chai.expect;

describe('Develop Sitemap With: ', function() {

const LABEL = 'Sitemap Resource plugin output';

const cliPath = path.join(process.cwd(), 'packages/cli/src/index.js');
const outputPath = fileURLToPath(new URL('.', import.meta.url));
const hostname = 'http://localhost';
const port = 1984;
let runner;

before(function() {
this.context = {
hostname: `${hostname}:${port}`
};
runner = new Runner();
});

describe(LABEL, function() {

before(async function() {
runner.setup(outputPath);

return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 5000);

runner.runCommand(cliPath, 'develop', { async: true });
});
});

describe('Sitemap.xml', function() {
let response = {};
let text;

before(async function() {
response = await fetch(`${hostname}:${port}/sitemap.xml`);
text = await response.text();
});

it('should return a 200', function() {
expect(response.status).to.equal(200);
});

it('should return the correct content type', function() {
expect(response.headers.get('content-type')).to.equal('text/xml');
});

it('should contain loc element', function() {
const regex = /<loc>(http:\/\/www\.example\.com\/about\/)<\/loc>/;
const match = text.match(regex);

expect(match[1]).to.equal('http://www.example.com/about/');

});
});
});

after(function() {
runner.stopCommand();
runner.teardown([
path.join(outputPath, '.greenwood')
]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

import { greenwoodPluginAdapterSitemap, greenwoodPluginResourceSitemap } from '../../../src/index.js';

export default {
plugins: [
greenwoodPluginAdapterSitemap(),
greenwoodPluginResourceSitemap
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# About Us

Lorem ipsum.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Home Page

Welcome!
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
async function generateSitemap(compilation){
const urls = compilation.graph.map((page) => {
return ` <url>
<loc>http://www.example.com${page.route}</loc>
</url>`;
});
return `
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${urls.join('\n')}
</urlset>
`;
}



export { generateSitemap };

0 comments on commit e1903c3

Please sign in to comment.