Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ang-zeyu committed Dec 7, 2020
1 parent 9165ec5 commit c414f50
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 185 deletions.
37 changes: 0 additions & 37 deletions packages/core/test/unit/Page.data.js

This file was deleted.

57 changes: 0 additions & 57 deletions packages/core/test/unit/Page.test.js

This file was deleted.

2 changes: 2 additions & 0 deletions packages/core/test/unit/Site.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jest.mock('fs');
jest.mock('walk-sync');
jest.mock('gh-pages');
jest.mock('../../src/Page');
jest.mock('../../src/plugins/PluginManager');
jest.mock('simple-git', () => () => ({
...jest.requireActual('simple-git')(),
// A test file should reduce dependencies on external libraries; use pure js functions instead.
Expand Down Expand Up @@ -73,6 +74,7 @@ test('Site baseurls are correct for sub nested subsites', async () => {
const baseUrlMapExpected = new Set(['', 'sub', 'sub/sub', 'otherSub/sub'].map(url => path.resolve(url)));

const site = new Site('./', '_site');
await site.readSiteConfig();
await site.collectBaseUrl();
expect(site.baseUrlMap).toEqual(baseUrlMapExpected);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const path = require('path');
const cheerio = require('cheerio');
const htmlparser = require('htmlparser2');
const { NodeProcessor } = require('../../src/html/NodeProcessor');
const { getNewDefaultNodeProcessor } = require('../utils/utils');
const testData = require('./NodeProcessor.data');
const { Context } = require('../../../src/html/Context');

/**
* Runs the processNode or postProcessNode method of NodeProcessor on the provided
Expand All @@ -15,10 +17,12 @@ const processAndVerifyTemplate = (template, expectedTemplate, postProcess = fals
const handler = new htmlparser.DomHandler((error, dom) => {
expect(error).toBeFalsy();

const nodeProcessor = getNewDefaultNodeProcessor();

if (postProcess) {
dom.forEach(node => NodeProcessor.postProcessNode(node));
dom.forEach(node => nodeProcessor.postProcessNode(node));
} else {
dom.forEach(node => NodeProcessor.processNode(node));
dom.forEach(node => nodeProcessor.processNode(node, new Context(path.resolve(''))));
}
const result = cheerio.html(dom);

Expand Down Expand Up @@ -138,17 +142,12 @@ test('processNode processes dropdown with header slot taking priority over heade
});

test('renderFile converts markdown headers to <h1> with an id', async () => {
const nodeProcessor = new NodeProcessor({ headerIdMap: {} });
const nodeProcessor = getNewDefaultNodeProcessor();
const indexPath = 'index.md';

const index = ['# Index'].join('\n');

const result = await nodeProcessor.process(indexPath, index);
const result = await nodeProcessor.process(indexPath, '# Index');

const expected = [
'<h1 id="index"><span id="index" class="anchor"></span>Index</h1>',
'',
].join('\n');
const expected = ['<h1 id="index"><span id="index" class="anchor"></span>Index</h1>'].join('\n');

expect(result).toEqual(expected);
});
Loading

0 comments on commit c414f50

Please sign in to comment.