-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbuild.plugins.copy-sitemap.spec.js
More file actions
84 lines (69 loc) · 2.13 KB
/
Copy pathbuild.plugins.copy-sitemap.spec.js
File metadata and controls
84 lines (69 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* Use Case
* Run Greenwood with the sitemap adapter plugin.
*
* User Result
* Should generate a static Greenwood build with a sitemap rendered.
*
* User Command
* greenwood build
*
* User Config
* import { greenwoodPluginAdapterSitemap } from '../../../src/index.js';
*
* export default {
* plugins: [
* greenwoodPluginAdapterSitemap()
* ]
* };
*
* User Workspace
* TBD
*/
import chai from 'chai';
import fs from 'fs/promises';
import path from 'path';
import { checkResourceExists } from '../../../../cli/src/lib/resource-utils.js';
import { getSetupFiles } from '../../../../../test/utils.js';
import { Runner } from 'gallinago';
import { fileURLToPath } from 'url';
const expect = chai.expect;
describe('Build Greenwood With: ', function() {
const LABEL = 'Sitemap Adapter plugin output';
const cliPath = path.join(process.cwd(), 'packages/cli/src/index.js');
const outputPath = fileURLToPath(new URL('.', import.meta.url));
const publicDir = path.join(outputPath, 'public');
let runner;
before(function() {
this.context = {
publicDir: path.join(outputPath, 'public')
};
runner = new Runner();
});
describe(LABEL, function() {
before(function() {
runner.setup(outputPath, getSetupFiles(outputPath));
runner.runCommand(cliPath, 'build');
});
describe('sitemap.xml', function() {
it('should be present', async function() {
const sitemapPath = path.join(publicDir, 'sitemap.xml');
const itExists = await checkResourceExists(new URL(`file://${sitemapPath}`));
expect(itExists).to.be.equal(true);
});
it('should have the correct first element in the list', async function() {
const sitemapPath = path.join(publicDir, 'sitemap.xml');
const text = await fs.readFile(sitemapPath, 'utf8');
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')
]);
});
});