mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 10:56:15 -08:00
自动从文档生成测试用例
This commit is contained in:
1 parent
12c64e41fb
commit
c752982738
5 files changed
+1171
-57
No files matched your search
@@ -0,0 +1,40 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const logger = require('./logger');
|
||||
|
||||
try {
|
||||
const documentText = fs.readFileSync(path.resolve(__dirname, '../docs/document/README.md'), 'utf-8');
|
||||
const jsTests = documentText.match(/\[Run Code\]\(\/([\s\S]*?)\)\n\n\`{3}js([\s\S]*?)\`{3}/g);
|
||||
const jsBlocks = jsTests.map(item => {
|
||||
const result = item.match(/\[Run Code\]\(\/([\s\S]*)\)\n\n\`{3}js([\s\S]*?)\`{3}/);
|
||||
return {
|
||||
name: result[1],
|
||||
code: result[2],
|
||||
};
|
||||
});
|
||||
|
||||
fs.writeFileSync(
|
||||
path.resolve(__dirname, '../test/document.test.js'),
|
||||
`
|
||||
describe('Option', function() {
|
||||
afterEach(function() {
|
||||
[...Artplayer.instances].forEach(art => {
|
||||
art.destroy(true);
|
||||
});
|
||||
});
|
||||
|
||||
${jsBlocks
|
||||
.map(item => {
|
||||
return `
|
||||
it(\`${item.name}\`, function() {
|
||||
${item.code}
|
||||
});
|
||||
`;
|
||||
})
|
||||
.join('\n')};
|
||||
});
|
||||
`,
|
||||
);
|
||||
} catch (error) {
|
||||
logger.fatal(error);
|
||||
}
|
||||
Reference in new issue
Block a user