jestjs - SyntaxError: Unexpected token export with SPFx solution while running Jest
问题描述
I am getting this error:
FAIL src\webparts\crud\__test__\CrudWebPart.test.tsx
● Test suite failed to run
C:\Users\admin\Desktop\github\crud-simple-test\node_modules\@microsoft\sp-http\lib\index.js:12
export { default as HttpClient } from './httpClient/HttpClient';
^^^^^^
SyntaxError: Unexpected token export
54 |
55 | async postTodo() {
> 56 | const value = await this.addItem(this.state.todo);
57 | const action = postTodoCreator(value);
58 | store.dispatch(action)
59 | }
at ScriptTransformer._transformAndBuildScript (node_modules/jest/node_modules/jest-runtime/build/script_transformer.js:316:17)
at Object.<anonymous> (src/webparts/crud/components/Todolist/Todolist.tsx:56:68)
at Object.<anonymous> (src/webparts/crud/components/Crud.tsx:17:70)
console.log src\webparts\crud\components\Store\reducers.ts:27
action type @@redux/INITb.1.9.m.y.8 is not found
Handlebars: Access has been denied to resolve the property "statements" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
Handlebars: Access has been denied to resolve the property "branches" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
Handlebars: Access has been denied to resolve the property "functions" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
Handlebars: Access has been denied to resolve the property "lines" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | Unknown | Unknown | Unknown | Unknown | |
----------|----------|----------|----------|----------|-------------------|
Jest: Coverage data for global was not found.
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 8.522s
Ran all test suites.
testResultsProcessor support is deprecated. Please use jest reporter. See https://github.com/jest-community/jest-junit#usage:
{
"reporters": [
"jest-junit"
]
}
npm ERR! Test failed. See above for more details.
This is strange, because after doing some research I changed my config:
"transformIgnorePatterns": [
"/node_modules/(?!@microsoft/sp-core-library|sp-dialog|sp-http)"
],
Yet this little fix doesn't seem to cut it even though this seems to be what people did to fix similar issues. Is this a Typescript problem or is it something else? And how do I make sure the Typescript compiler does its job?
解决方案
就我而言,我的配置忽略package.json
了jest
所有这些:
"transformIgnorePatterns": [ "node_modules/(?!(@microsoft/sp-dialog|@microsoft/office-ui-fabric-react-bundle|@microsoft/sp-diagnostics|@microsoft/sp-core-library|@microsoft/sp-http|@microsoft/sp-page-context|@microsoft/sp-dynamic-data|@pnp/sp|@pnp/common|@pnp/odata|@pnp))" ],
推荐阅读
- linden-scripting-language - 如何描述通过 LSL 同步两个不同模式数据流的机制?
- firebase - 在多对多关系上使用 Firebase 对 SaaS 应用建模的最佳做法是什么
- r - R ggplot2 ggrepel 标记位置
- sql - 在 POSTGRESQL 中编写一个 Select 查询以将 null 替换为当前 datetimestamp,计算两列之间的差异并将具有相同 id 的列相加
- python - np.array 没有大小
- tensorflow2.0 - TypeError 拟合 Beta 二项式混合密度网络
- node.js - 使用 Pug 访问数组的特定索引
- javascript - JQuery Datatables Plugin 销毁/检索方法的行为不像记录的那样
- javascript - 将相机重新定位到对象和lookAt()(反应三纤维)
- github - cypress 上传到 github 需要 node_modules 吗?