MCPcopy
hub / github.com/zxlie/FeHelper / runTests

Function runTests

gulpfile.js:303–331  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

301 }
302 }
303 function runTests() {
304 if (!isSilentDetect) console.log('\n运行单元测试...');
305 assert.strictEqual(shouldExcludeFile('path/to/content-script.js'), true, 'Should exclude content-script.js');
306 assert.strictEqual(shouldExcludeFile('path/to/content-script.css'), true, 'Should exclude content-script.css');
307 assert.strictEqual(shouldExcludeFile('path/to/node_modules/file.js'), true, 'Should exclude node_modules files');
308 assert.strictEqual(shouldExcludeFile('path/to/normal.js'), false, 'Should not exclude normal files');
309 const testContent = `
310 <link rel="stylesheet" href="./style.css">
311 <script src="../js/script.js"></script>
312 <img src="/images/test.png">
313 <div style="background: url('./bg.jpg')">
314 <div style="font: url('./font.woff2')">
315 @import '../common.css';
316 <img src="chrome-extension://abcdefgh/static/icon.png">
317 `;
318 const testFilePath = path.join(outputDir, 'test/index.html');
319 referencedFiles.clear();
320 findReferences(testContent, testFilePath);
321 const refs = Array.from(referencedFiles);
322 assert(refs.includes('test/style.css'), 'Should handle relative path with ./');
323 assert(refs.includes('js/script.js'), 'Should handle relative path with ../');
324 assert(refs.includes('images/test.png'), 'Should handle absolute path');
325 assert(refs.includes('test/bg.jpg'), 'Should handle url() in CSS');
326 assert(refs.includes('test/font.woff2'), 'Should handle font url() in CSS');
327 assert(refs.includes('common.css'), 'Should handle @import in CSS');
328 assert(refs.includes('static/icon.png'), 'Should handle chrome-extension urls');
329 referencedFiles.clear();
330 if (!isSilentDetect) console.log('单元测试通过!');
331 }
332 try {
333 runTests();
334 getAllFiles(outputDir);

Callers 1

detectUnusedFilesFunction · 0.85

Calls 3

shouldExcludeFileFunction · 0.85
findReferencesFunction · 0.85
clearMethod · 0.80

Tested by

no test coverage detected