This repository has been archived by the owner on Sep 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
38 lines (31 loc) · 1.46 KB
/
test.js
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
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const constructPlugin = require('./');
let publicFolder = path.resolve(__dirname, 'test');
let pageFilter;
const subject = () => constructPlugin({
publicFolder,
pageFilter,
});
assert.strictEqual(subject().publicFolders.length, 1);
assert.strictEqual(subject().publicFolders[0], path.resolve(process.cwd(), 'test'));
let webpackConfig = subject().customizeWebpackConfig({ plugins: [] });
let pages = JSON.parse(webpackConfig.plugins[0].definitions.HAPPO_GATSBY_PAGES);
assert.strictEqual(pages.length, 3);
assert.strictEqual(pages[0].component, 'foo/bar');
assert.strictEqual(pages[1].component, 'foo');
assert.strictEqual(pages[2].component, 'index');
assert.strictEqual(pages[2].content, 'index content\n');
// Verify that an exception is thrown when the list of pages is empty
pageFilter = () => false;
assert.throws(() => subject().customizeWebpackConfig({ plugins: [] }), /No.*files were found/);
// Verify that you can use the filter to exclude pages
pageFilter = (page) => /bar/.test(page);
webpackConfig = subject().customizeWebpackConfig({ plugins: [] });
pages = JSON.parse(webpackConfig.plugins[0].definitions.HAPPO_GATSBY_PAGES);
assert.strictEqual(pages.length, 1);
assert.strictEqual(pages[0].component, 'foo/bar');
// Verify that the examples file can be opened
console.log(subject().pathToExamplesFile);
assert.strictEqual(fs.existsSync(subject().pathToExamplesFile), true);