forked from ProjectEvergreen/greenwood
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamic Sitemap - develop test (ProjectEvergreen#1232)
- Loading branch information
Showing
6 changed files
with
111 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
packages/plugin-adapter-sitemap/test/cases/develop.default/develop.default.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
]); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/plugin-adapter-sitemap/test/cases/develop.default/greenwood.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/plugin-adapter-sitemap/test/cases/develop.default/src/pages/about.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# About Us | ||
|
||
Lorem ipsum. |
3 changes: 3 additions & 0 deletions
3
packages/plugin-adapter-sitemap/test/cases/develop.default/src/pages/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## Home Page | ||
|
||
Welcome! |
17 changes: 17 additions & 0 deletions
17
packages/plugin-adapter-sitemap/test/cases/develop.default/src/sitemap.xml.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |