21 lines
1.5 KiB
JavaScript
21 lines
1.5 KiB
JavaScript
'use strict'
|
|
const assert=require('assert'),fs=require('fs'),path=require('path'),cp=require('child_process')
|
|
const fix=require('./fix-template-expressions.cjs')
|
|
assert.equal(fix(String.raw`{{ modalName==\'Modal\' ? 'show' : '' }}`),`{{ modalName=='Modal' ? 'show' : '' }}`)
|
|
assert.equal(fix(String.raw`{{ 'height:' + (height + \'px\') }}`),`{{ 'height:' + (height + 'px') }}`)
|
|
const escaped=String.raw`{{ name === 'O\'Brien' ? 'show' : '' }}`
|
|
assert.equal(fix(escaped),escaped)
|
|
assert.throws(()=>fix(String.raw`{{ value + \'unterminated }}`),/Unparseable/)
|
|
const root=path.resolve(__dirname,'../../../.local-acceptance')
|
|
const build=path.join(root,'mp-mock-build/weapp')
|
|
const compiler=process.argv[2]
|
|
if(!compiler)throw Error('Pass the installed WeChat wcc.exe path for full template validation')
|
|
const files=[]
|
|
function walk(dir){for(const e of fs.readdirSync(dir,{withFileTypes:true})){const p=path.join(dir,e.name);if(e.isDirectory())walk(p);else if(p.endsWith('.wxml'))files.push(path.relative(build,p).replace(/\\/g,'/'))}}
|
|
walk(build)
|
|
const output=path.join(root,'logs/wxml-compiled.js')
|
|
const result=cp.spawnSync(compiler,['-o',output,...files],{cwd:build,encoding:'utf8',maxBuffer:4*1024*1024})
|
|
fs.writeFileSync(path.join(root,'logs/wxml-compile.log'),(result.stdout||'')+(result.stderr||''))
|
|
if(result.error || result.status!==0)throw Error('WXML compiler failed: '+(result.error?result.error.code:result.status)+'; inspect wxml-compile.log')
|
|
console.log('PASS: escaping regression checks and official WXML compilation of '+files.length+' templates')
|