如何使用Rollup.js捆绑使用Sinon.js的testing?

我使用Rollup.js和插件rollup-plugin-node-resolverollup-plugin-commonjs来捆绑我使用Sinon.js的testing。 当我尝试运行捆绑文件时,出现以下错误:

错误:rollup-plugin-commonjs当前不支持dynamic需求

有没有任何解决这个错误,或者我必须使用一些其他工具,如Webpack?

在Sinon.js GitHub仓库上的README.md说:

Sinon.JS v1.x作为源代码不适用于AMD加载器/ RequireJS / Webpack / Browserify。 为此,您将不得不使用预先构build的版本。

这已经在Sinon v2.x中解决了; 请不要将此报告为错误。

所以将Sinon与Rollup.js和Webpack都捆绑在一起是不可能的。 我认为最好的select是使用Sinon v2.x. 您可以使用以下命令安装它:

 npm install sinon@next 

但是,一些Sinon插件可能不适用于Sinon v2.x; 例如sinon-chai要求sinon-chai >=1.4.0 <2