配置phantomjs以使用webpack和karma nwb(Configure phantomjs to work with webpack and karma nwb)
我正在使用nwb配置反应应用程序,我会用
chai
和enzyme
来设置我的测试环境。 我做了以下更改来完成此操作,我创建了一个tests.webpack.js
文件:import chai from 'chai'; import chaiEnzyme from 'chai-enzyme'; import chaiAsPromised from 'chai-as-promised'; import sinonChai from 'sinon-chai'; chai.use(chaiEnzyme()); chai.use(chaiAsPromised); chai.use(sinonChai); const context = require.context('./src', true, /\.spec\.js/); context.keys.forEach(context);
我还修改了
nwb.config.js
的karma配置:const karmaChaiPlugins = require('karma-chai-plugins'); module.exports = { type: 'react-component', npm: { esModules: true, umd: { global: 'ReactMg', externals: { react: 'React', }, }, }, karma: { testContext: 'tests.webpack.js', plugins: [ karmaChaiPlugins, ], frameworks: ['mocha', 'chai', 'chai-as-promised'], }, webpack: { compat: { enzyme: true, sinon: true, }, }, };
在
src
定义index.spec.js
后运行nwb test
时出错:PhantomJS 2.1.1 (Linux 0.0.0) ERROR TypeError: undefined is not a function (evaluating 'context.keys.forEach(context)') at tests.webpack.js:73 PhantomJS 2.1.1 (Linux 0.0.0): Executed 0 of 0 ERROR (0.375 secs / 0 secs) Karma exit code was 1
I am using nwb to configure a react app, I would use like to
chai
andenzyme
to set up my testing environment. I have made the following changes to accomplish this, I created atests.webpack.js
file:import chai from 'chai'; import chaiEnzyme from 'chai-enzyme'; import chaiAsPromised from 'chai-as-promised'; import sinonChai from 'sinon-chai'; chai.use(chaiEnzyme()); chai.use(chaiAsPromised); chai.use(sinonChai); const context = require.context('./src', true, /\.spec\.js/); context.keys.forEach(context);
I also modified the karma config in
nwb.config.js
:const karmaChaiPlugins = require('karma-chai-plugins'); module.exports = { type: 'react-component', npm: { esModules: true, umd: { global: 'ReactMg', externals: { react: 'React', }, }, }, karma: { testContext: 'tests.webpack.js', plugins: [ karmaChaiPlugins, ], frameworks: ['mocha', 'chai', 'chai-as-promised'], }, webpack: { compat: { enzyme: true, sinon: true, }, }, };
I get an error when running
nwb test
after definingindex.spec.js
insrc
:PhantomJS 2.1.1 (Linux 0.0.0) ERROR TypeError: undefined is not a function (evaluating 'context.keys.forEach(context)') at tests.webpack.js:73 PhantomJS 2.1.1 (Linux 0.0.0): Executed 0 of 0 ERROR (0.375 secs / 0 secs) Karma exit code was 1
原文:https://stackoverflow.com/questions/41210882
最满意答案
我注意到生成的图形总是只有一个接收器顶点,这是第一个顶点。 您可以反转所有边的方向以获得具有单个源顶点的图形。
I noticed that the generated graphs have always exactly one sink vertex which is the first vertex. You can reverse direction of all edges to get a graph with single source vertex.
相关问答
更多-
这是我的未来! 以下是如何解决您的问题: 最近blob添加是在Caffe中实现的Python。 这是一个执行该操作的示例图层: class Param(caffe.Layer): def setup(self, bottom, top): self.blobs.add_blob(1,2,3) self.blobs[0].data[...] = 0 def reshape(self, bottom, top): top[0].reshape(1 ...
-
你可以使用bfs进行一些修改:维护一个deque而不是一个队列,并且如果使用0 edge,则向deque的前面添加一个顶点,否则添加一个顶点到deque的前面(我的意思是0-1的情况) You can use bfs with some modifications: maintain a deque instead of a queue and add a vertex to the front of the deque if 0 edge is used and to the back of the de ...
-
您建议的算法将确实在该图中找到最短路径,但并不是所有图形一般。 例如,考虑这个图表: 假设边缘是从左到右的,如你的例子所示, 您的算法将工作如下: 首先,将d(A)设置zero ,将其他距离设置为infinity 。 然后展开节点A ,将d(B)设置为1 ,将d(C)设置zero ,将d(D)为99 。 接下来,展开C ,没有任何变化。 然后你展开B ,这没有任何效果。 最后,您展开D ,将d(B)更改为-201 。 请注意,尽管如此, d(C)仍然为0 , 尽管到C的最短路径的长度为-200 。 因此,在 ...
-
对于非加权图,假设边存储在列表中,您可以简单地生成1到n之间的均匀随机整数。 大多数库(在任何编程语言中)将具有0和1 u = U(0,1)之间的均匀随机数生成器。 现在将(0,1)间隔均匀地划分为n个子间隔。 对于'k',范围从1 to n-1检查其间隔(k/n, (k+1)/n)是否下降。 k是你的随机边缘。 对于加权图,如果目标是基于其权重随机选择边(更高的权重意味着更可能选择),则使用与上述相同的方法。 但是根据它们的权重将(0,1)间隔分成子间隔。 最后生成u并选择k 。 例如:如果有3条边具有权 ...
-
如果您担心生成随机游走的性能,则可以使用别名方法构建适合您选择随机出局边缘的要求的数据结构。 开销只是你必须为每个有向边指定一个概率权重和一个所谓的别名边。 因此,对于每个音符,您都有一个向外边缘矢量以及重量和别名边缘。 然后你可以选择在不变的时间内的随机边缘(只有edata结构的产生是关于边缘总数或节点边缘数的线性时间)。 在这个例子中,边由->[NODE] ,节点v对应于上面给出的例子: Node v ->a (p=1, alias= ...) ->b (p=3/4, alias= ...
-
在R中生成随机有向无环图显示循环和双向图(Generating a random directed acyclic graph in R is showing loops and bidirections)[2023-10-03]
要生成随机DAG,您可以使用pcalg库 library(pcalg) set.seed(101) myDAG <- randomDAG(n = 20, prob= 0.2, lB = 0.1, uB = 1) plot(myDAG) To generate a random DAG you can use the pcalg library library(pcalg) set.seed(101) myDAG <- randomDAG(n = 20, prob= 0.2, lB = 0.1, uB = ... -
使用具有负边缘权重的Bellman-Ford追踪最长路径(Tracing the longest path using Bellman-Ford with negative edge weights)[2023-10-17]
您需要稍微修改您在Bellman Ford实施中所执行的操作: ... int[] lastNode = new int[nnodes]; lastNode[source] = source; for (int i = 0; i < nnodes; ++i) for (int j = 0; j < edges.size(); ++j) { if (distance[edges.get(j).source] == INF) continue; int newDistan ... -
我注意到生成的图形总是只有一个接收器顶点,这是第一个顶点。 您可以反转所有边的方向以获得具有单个源顶点的图形。 I noticed that the generated graphs have always exactly one sink vertex which is the first vertex. You can reverse direction of all edges to get a graph with single source vertex.
-
网络图与Plotly(Network Graphs with Plotly)[2023-01-11]
由于nx.random_geometric_graph编号节点从0开始,而你的edge_list (显然)编号节点从1开始,你有一个“off-by-one”错误。 例如, In [80]: G = nx.random_geometric_graph(3, 1) In [81]: G.nodes() Out[81]: [0, 1, 2] 到现在为止还挺好。 每个节点都有一个pos : In [82]: G.nodes(data=True) Out[82]: [(0, {'pos': [0.3530839 ... -
如何使用OGDF库在非循环有向图中找到最长路径?(How to find the longest path in an acyclic directed graph using OGDF library?)[2022-07-24]
在OGDF中,您可以使用ShortestPathWithBFM找到节点s和其他节点之间的最短路径。 应使用EdgeArray将边的长度(权重)传递给函数。 以下是源代码中的类定义: namespace ogdf { class OGDF_EXPORT ShortestPathWithBFM : public ShortestPathModule { public: ShortestPathWithBFM() { } // computes shortest paths // Precon ...