forked from highlightjs/highlight.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (49 loc) · 1.96 KB
/
index.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict';
const fs = require('fs').promises;
const glob = require('glob');
const hljs = require('../../build');
const path = require('path');
const utility = require('../utility');
hljs.debugMode();
const { getThirdPartyPackages } = require("../../tools/lib/external_language")
function testLanguage(language, {testDir}) {
describe(language, function() {
const where = testDir ?
path.join(testDir, '*.expect.txt') :
utility.buildPath('markup', language, '*.expect.txt');
const filePath = where;
const filenames = glob.sync(filePath);
filenames.forEach(function(filename) {
const testName = path.basename(filename, '.expect.txt');
const sourceName = filename.replace(/\.expect/, '');
it(`should markup ${testName}`, function(done) {
const sourceFile = fs.readFile(sourceName, 'utf-8');
const expectedFile = fs.readFile(filename, 'utf-8');
Promise.all([sourceFile, expectedFile]).then(function([source, expected]) {
const actual = hljs.highlight(language, source).value;
// Uncomment this for major changes that rewrite the test expectations
// which will then need to be manually compared by hand of course
// require('fs').writeFileSync(filename, actual);
actual.trim().should.equal(expected.trim());
done();
}).catch(function(err) { return done(err) });
});
});
});
}
describe('highlight() markup', async() => {
before(async function() {
const markupPath = utility.buildPath('markup');
if (!process.env.ONLY_EXTRA) {
const languages = await fs.readdir(markupPath);
languages.forEach(testLanguage);
}
const thirdPartyPackages = await getThirdPartyPackages();
thirdPartyPackages.forEach(
(pkg) => pkg.names.forEach(
(name, idx) => testLanguage(name, { testDir: pkg.markupTestPaths[idx] })
)
);
});
it("adding dynamic tests...", async function() {}); // this is required to work
});