Testing Script Parser Configuration Handling in dcloudio/uni-app
This test suite validates the script parsing functionality in uni-app’s CLI shared package, focusing on platform-specific configurations and context handling. The tests ensure proper parsing of package.json scripts for different H5 platform variations.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
dcloudio/uni-app
packages/uni-cli-shared/__tests__/scripts.spec.ts
import path from 'path'
import { parseScripts } from '../src/scripts'
describe('filter', () => {
test(`basic`, () => {
const pkgPath = path.resolve(
__dirname,
'examples/custom-scripts/package.json'
)
expect(parseScripts('H5-WEIXIN', pkgPath)).toEqual({
name: 'H5-WEIXIN',
platform: 'H5',
define: {},
context: { 'H5-BASE': true, 'H5-WEIXIN': true, 'H5-QQ': false },
})
expect(parseScripts('H5-QQ', pkgPath)).toEqual({
name: 'H5-QQ',
platform: 'H5',
define: {},
context: { 'H5-BASE': false, 'H5-QQ': true, 'H5-WEIXIN': false },
})
})
})