首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用serverless-bundle,我如何对使用sharp包的代码运行测试?

使用serverless-bundle,我如何对使用sharp包的代码运行测试?
EN

Stack Overflow用户
提问于 2020-02-16 10:15:08
回答 1查看 186关注 0票数 0

我在一个serverless-framework项目中同时使用sharp包和serverless-bundle。使用这个custom.bundle.packagerOptions.scripts脚本:rm -rf node_modules/sharp && npm install --arch=x64 --platform=linux --target=10.15.0 sharp,我可以很好地运行和部署代码。

当我尝试对触及sharp包的代码运行测试时,我得到以下错误:'linux-x64' binaries cannot be used on the 'darwin-x64' platform. Please remove the 'node_modules/sharp/vendor' directory and run 'npm install'.

我不打算测试sharp的实现,而是模拟导入它的JavaScript文件。下面是我遇到这个问题的测试文件:https://github.com/groffcole/art-center-service/blob/master/ports/GalleriesHttpPort.test.js

我做错了什么?

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2020-02-17 04:44:45

我只是偶然解决了这个问题。我删除了整个node_modules目录并运行了npm install。我相信,因为我使用的是serverless-bundle包,所以出现了问题。现在,我可以使用serverless-bundle test命令成功运行测试。

以下是我在serverless.yml文件中的自定义serverless-bundle设置,以供参考:

代码语言:javascript
复制
custom:
  bundle:
    caching: false
    packagerOptions:
      scripts:
        - rm -rf node_modules/sharp && npm install --arch=x64 --platform=linux --target=10.15.0 sharp
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60244846

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档