mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
update tests
This commit is contained in:
1 parent
4ad3f17684
commit
f4fbd3e6c2
38 files changed
+2190
-103
No files matched your search
@@ -0,0 +1,50 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const glob = require('glob');
|
||||
const { parse } = require('node-html-parser');
|
||||
|
||||
const htmls = glob
|
||||
.sync(path.join(process.cwd(), 'docs/document/zh-cn/**/*.html'))
|
||||
.filter((item) => !item.includes('libraries'))
|
||||
.map((item) => fs.readFileSync(item, 'utf-8'))
|
||||
.map((item) =>
|
||||
parse(item, {
|
||||
lowerCaseTagName: false,
|
||||
comment: true,
|
||||
blockTextElements: {
|
||||
script: false,
|
||||
noscript: false,
|
||||
style: false,
|
||||
pre: true,
|
||||
},
|
||||
}),
|
||||
)
|
||||
.map((item) => item.querySelectorAll('pre'))
|
||||
.map((item) => item.map((pre) => parse(pre.innerHTML).textContent))
|
||||
.flat(Infinity)
|
||||
.filter((item) => item.trim().startsWith('var art'))
|
||||
.map((item) => item.replace(/\/assets/g, 'https://artplayer.org/assets'))
|
||||
.map((item) => item.replace(/\s{3}/g, '\n '));
|
||||
|
||||
const tests = `
|
||||
describe('Document', function() {
|
||||
afterEach(function() {
|
||||
[...Artplayer.instances].forEach(art => {
|
||||
art.destroy(true);
|
||||
});
|
||||
});
|
||||
|
||||
${htmls
|
||||
.map((item, index) => {
|
||||
return `
|
||||
it('Test${index}', function() {
|
||||
${item}
|
||||
|
||||
expect(art.id).to.be.an('number');
|
||||
});`;
|
||||
})
|
||||
.join('\n\n')}
|
||||
});
|
||||
`;
|
||||
|
||||
fs.writeFileSync(path.join(process.cwd(), 'test/document.test.js'), tests);
|
||||
Reference in new issue
Block a user