如何解决语音规则引擎 3.2 中的行为变化?
我正在使用 speech-rule-engine 从 MathML 生成英文文本。在尝试从 v3.1.1 升级到 v3.2.0 时,我看到测试由于我不明白的原因而失败。
package.json
{
"name": "failure-example","license": "UNLICENSED","private": true,"engines": {
"node": "14.15.5","npm": "6.14.11"
},"scripts": {
"test": "jest"
},"dependencies": {
"speech-rule-engine": "3.2.0"
},"devDependencies": {
"jest": "^26.6.3"
},"jest": {
"notify": false,"silent": true,"verbose": true
}
}
example.test.js
const sre = require('speech-rule-engine');
beforeAll(() => {
sre.setupEngine({
domain: 'mathspeak'
});
});
test('simple single math',() => {
expect(JSON.parse(JSON.stringify(sre.enginesetup(),['domain','locale','speech','style'])))
.toEqual({
locale: 'en',speech: 'none',style: 'default',domain: 'mathspeak',});
expect(sre.engineReady())
.toBeTruthy();
expect(sre.toSpeech('<math><mrow><msup><mn>3</mn><mn>7</mn></msup></mrow></math>'))
.toBe('3 Superscript 7');
});
运行 npm install
和 npm run test
会导致失败,因为 SRE 返回的是 37 而不是 3 Superscript 7。编辑 package.json 以使用 v3.1.1 引擎并重新运行结果通过测试。
显然有些事情发生了变化,但我完全不知道我需要做些什么来适应。有没有其他人遇到过这种情况,或者看到我显然没有看到什么?
解决方法
问题已解决,在 SRE 维护者的帮助下。问题不在 3.2.0 中,但那个玩笑不会等待 sre 准备好。由于规则已编译到核心中,因此测试仅在 3.1.1 中侥幸正确。以下测试在 3.1.1 中的上述设置以及未加载语言环境的情况下失败:
expect(sre.toSpeech('<math><mo>=</mo></math>'))
.toBe('equals');
Expected: "equals"
Received: "="
主要原因是 jest 无法加载语言环境文件。设置 "silent": false
将显示错误:
Unable to load file: /tmp/tests/node_modules/speech-rule-engine/lib/mathmaps/en.js
TypeError: Cannot read property 'readFileSync' of null
出现这个错误的原因是 jest 不知道它在 node.js 中运行。添加:
"testEnvironment": "node",
package.json
中的 jest 配置导致预期行为。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。