Testing Preprocessor Range Detection in uni-app
This test suite validates the preprocessing functionality in uni-app, specifically focusing on conditional code inclusion based on preprocessor directives. It tests the isInPreprocessor method which determines if a given code position falls within preprocessor blocks.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
dcloudio/uni-app
packages/uni-preprocess/__tests__/range.spec.ts
// import { writeFileSync } from 'node:fs'
// import { resolve } from 'node:path'
import { preprocess } from '../src/index'
describe('preprocess', () => {
test('isInPreprocessor', () => {
const code = `
.test {
color:red
}
// #ifdef B
.test {
color:blue
}
// #ifdef B1
.test {
color:yellow
}
// #endif
.test {
color:black
}
// #endif
.test {
color:green
}
`
const { isInPreprocessor } = preprocess(code, {
context: { B: true },
})
const result: [number, string, boolean][] = []
for (let i = 0; i < code.length; i++) {
result.push([i, code[i], isInPreprocessor(i)])
}
expect(result).toMatchSnapshot()
})
})