小编Bil*_*ill的帖子

获取预转换源代码的Karma代码覆盖率

我正在使用Karma来运行测试,使用webpack来捆绑文件,并使用babel来进行es6 - > es5 transpilation.我已经运行了测试并生成了代码覆盖率,但代码覆盖率数字是在转换后的源文件.反正有没有获得原始源文件的代码覆盖率?

我尝试使用sourcemap预处理器,但似乎没有做任何事情.我是否需要将其添加到某个地方的webpack配置中?

karma.conf.js

config.set({
    browsers: ['Chrome'], //run in Chrome

    files: [
        'src/**/*-test.js'
    ],

    frameworks: ['mocha'], //use the mocha test framework

    plugins: [
        'karma-chrome-launcher',
        'karma-mocha',
        'karma-sourcemap-loader',
        'karma-webpack',
        'karma-coverage',
    ],

    preprocessors: {
        'src/**/*-test.js': ['webpack']
    },

    reporters: ['dots', 'coverage'], //report results in this format

    coverageReporter: {
        reporters: [{
            type: 'text-summary',
        }, {
            type: 'html',
            dir: 'build/reports/coverage'
        }]
    },

    singleRun: true, //just run once by default

    webpack: {
        node: {
            fs: 'empty'
        },

        // Instrument code that isn't …
Run Code Online (Sandbox Code Playgroud)

javascript karma-runner webpack karma-coverage babeljs

8
推荐指数
1
解决办法
6167
查看次数

使用mongoose.js跟踪对字段的更改

我正在尝试找出使用mongoose.js时跟踪字段更改的最佳方法.例如,每次name设置对象上的字段时,我都想在该对象的历史记录中添加一个新条目(作为嵌入文档){ field: 'name', previous: 'foo', current: 'bar', date: '3/06/2012 9:06 am' }.

我开始尝试使用一个挂钩的插件.pre('save')但我无法弄清楚哪些字段已被修改而没有从数据库中获取旧值并自己比较它们.然后我想我可以使用自定义setter,但我遇到了同样的问题 - 我不知道哪个字段被修改了.目前我还做了类似这样的事情,将字段名称硬编码到setter中:

var comment = new Schema({
  name : { type: String, set: trackName },
  history : [Change]
});

var trackName = function(val) {
  var change = new Change;
  change.field = 'name';
  change.previous = this.name;
  change.current = val;
  change.date = Date.now();
  this.history.push(change);
  return val;
}
Run Code Online (Sandbox Code Playgroud)

但这意味着我需要为每个要跟踪的字段名称设置自定义设置器.我猜想必须有更好的方法来实现这一目标.

mongoose node.js

6
推荐指数
1
解决办法
3914
查看次数

平滑的Javascript mousemove类似于Cubism.js

我很好奇迈克博斯托克是如何能够以如此平滑的方式创建一条跟随鼠标光标的垂直线.如果你看这里http://square.github.com/cubism/,你可以看到我在说什么.

看看我刚刚在这里做的一个简单例子:http://jsfiddle.net/zbfUq/

有很多次我的例子中的线条实际上消失了.他是否正在进行某种位置插值,以便在两个未被记录的点之间创建平滑的平移?如果是这样,任何人都知道如何做这样的事情?

javascript jquery d3.js cubism.js

6
推荐指数
1
解决办法
3995
查看次数

使用AngularJS在Firefox中使用SVG符号

我正在尝试将Angularjs的SVG图标html5Mode设置为true.要使用html5mode网址,您需要basePath在html文档的头部设置.

<base href="/">
Run Code Online (Sandbox Code Playgroud)

然后我将所有svg图标作为符号加载到index.html页面中.

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" style="display:none">
    <symbol id="user" viewBox="0 0 64 64">
        <path d="...">
    </symbol>
</svg>
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚如何在Firefox中始终如一地工作.在Chrome和IE中,我总是可以将svg usehref 设置为svg符号的id.

<svg ng-class="type" class="main-nav-icon">
   <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#user"></use>
</svg>
Run Code Online (Sandbox Code Playgroud)

但是,Firefox中没有显示任何图标.从前一个问题来看,我被告知这是因为base标签.所以我尝试将base标记设置为绝对网址

<base href="http://localhost:5080/">
Run Code Online (Sandbox Code Playgroud)

然后尝试use标记的每个URL组合.如果我使用基于index.html页面下载的原始路径的绝对URL,我终于可以使用了.

例如,如果页面已加载,http://localhost:5080/user那么设置use标签,如下所示将显示图标:

<svg ng-class="type" class="main-nav-icon">
   <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost:5080/user#user"></use>
</svg>
Run Code Online (Sandbox Code Playgroud)

当用户点击应用程序时,这可以正常工作.但是,如果用户然后刷新页面上的http://localhost:5080/photos所有图标再次被破坏,因为href现在是不正确的.然后我开始缓存index.html页面加载的原始URL并使用它.但是,即使在某些页面上刷新,也会再次打破所有图标.

使用html5modeAngularJS,设置base标记的正确方法是什么,将use标记href 设置为什么才能使图标显示在IE,Chrome和Firefox中?

html javascript firefox svg angularjs

6
推荐指数
1
解决办法
2036
查看次数

使用Express.js通过gm上传的流文件,以消除双重写入

我正在使用Express.js并有一个上传图像的路线,然后我需要调整大小.目前我只是Express将文件写入磁盘(我认为node-formidable在封面下使用)然后使用gm(http://aheckmann.github.com/gm/)调整大小,将第二个版本写入磁盘.

gm(path)
  .resize(540,404)
  .write(dest, function (err) { ... });
Run Code Online (Sandbox Code Playgroud)

我已经读过你可以在将node-formidable文件流写入磁盘之前获取文件流,并且因为gm可以接受流而不仅仅是路径,所以我应该能够通过消除双重写入磁盘来传递这一点.

我想我需要覆盖,form.onPart但我不确定在哪里(它应该作为Express中间件做什么?)而且我不确定如何获取form或者与该如何做什么part.这是我在几个地方看到的代码框架:

form.onPart = function(part) {
    if (!part.filename) { form.handlePart(part); return; }

    part.on('data', function(buffer) {

    });
    part.on('end', function() {

    }
}
Run Code Online (Sandbox Code Playgroud)

有人可以帮我把这两件放在一起吗?谢谢!

javascript node.js graphicsmagick express

5
推荐指数
1
解决办法
3156
查看次数

React-Native 0.52:Metro Bundler遇到内部错误

我将项目从0.51.0和16.0升级到React-Native 0.52.0和React 16.2,现在当我尝试使用XCode(或通过CLI)运行它时,我收到以下错误:

在此输入图像描述

终端输出:

2018-01-20 06:19:16.972 [info][tid:main][RCTCxxBridge.mm:210] Initializing <RCTCxxBridge: 0x6000001c2850> (parent: <RCTBridge: 0x6040000c7620>, executor: (null))
2018-01-20 06:19:16.975378-0800 LevelStory[67373:2037856] Initializing <RCTCxxBridge: 0x6000001c2850> (parent: <RCTBridge: 0x6040000c7620>, executor: (null))
2018-01-20 06:19:17.158 [warn][tid:main][RCTBridge.m:120] Class RCTCxxModule was not exported. Did you forget to use RCT_EXPORT_MODULE()?
2018-01-20 06:19:17.158401-0800 LevelStory[67373:2037856] Class RCTCxxModule was not exported. Did you forget to use RCT_EXPORT_MODULE()?
2018-01-20 06:19:17.215 [warn][tid:main][RCTModuleData.mm:69] Module RCTImageLoader requires main queue setup since it overrides `init` but doesn't implement `requiresMainQueueSetup`. In a future release React Native will default to …
Run Code Online (Sandbox Code Playgroud)

reactjs react-native

5
推荐指数
1
解决办法
4350
查看次数

将 Vercel/Nextjs 项目安装为不同 Vercel/Nextjs 项目的子目录时出现问题

我有一个包含两个项目的 monorepo -webdocs. 其中每个都是自己的 Vercel 项目,该web项目安装在https://example.comdocs安装在https://docs.example.com。所有这一切都按预期进行。

我现在希望该项目可以在https://example.com/docsdocs上使用。在项目中,我在文件中设置了以下重写。webvercel.json

{
  "rewrites": [
    {
      "source": "/docs/:match*",
      "destination": "https://docs.example.com/:match*"
    },
    { "source": "/(.*)", "destination": "/" }
  ]
}
Run Code Online (Sandbox Code Playgroud)

这适用于主索引文件,但所有相应的 css 和 js 文件都会导致 404。浏览器正在https://example.com/_next查找这些文件,这是不正确的,它应该查看https://docs.example.com/_next

我该如何进行这项工作?

url-rewriting next.js vercel

5
推荐指数
2
解决办法
2055
查看次数

基于外键增加PostgreSQL中的序列

我想使用序列为我的数据库中的某些对象创建友好的ID.我的问题是我不希望序列对表是全局的,而是我想基于外键增加值.

例如,我的表定义为:

CREATE TABLE foo (id numeric PRIMARY KEY, friendly_id SERIAL, bar_id numeric NOT NULL)
Run Code Online (Sandbox Code Playgroud)

我想friendly_id分别为每个增加bar_id以下声明:

INSERT INTO foo (123, DEFAULT, 345)
INSERT INTO foo (124, DEFAULT, 345)
INSERT INTO foo (125, DEFAULT, 346)
INSERT INTO foo (126, DEFAULT, 345)
Run Code Online (Sandbox Code Playgroud)

会导致(期望的行为):

id         | friendly_id      | bar_id
-----------+------------------+-----------------
123        | 1                | 345
124        | 2                | 345
125        | 1                | 346
126        | 3                | 345
Run Code Online (Sandbox Code Playgroud)

而不是(当前行为):

id         | friendly_id      | bar_id
-----------+------------------+-----------------
123        | …
Run Code Online (Sandbox Code Playgroud)

postgresql

4
推荐指数
1
解决办法
884
查看次数

将响应图像添加到Bootstrap列中固定div的位置

我有两列布局,一列是文档内容,另一列是导航.我使用Bootstrap行设置了这个,一列是8个单位宽,另一个是3个单位宽,偏移量是1个单位.我已将导航内容设置为固定,以便它保留在页面上.

在某些页面上,我希望在导航栏的顶部有一个图像.我希望这个图像能够响应并保持在3个单位列中,并与导航一起修复.但是,当您将内容设置为固定时,图像不再受限于3单位列.

我在http://jsfiddle.net/yKUZW/3/上设置了问题的一个小问题.

这是示例html:

<div class="container">
    <div class="row">
        <div class="col-xs-8 content">Content goes here...</div>
        <div class="col-xs-3 col-xs-offset-1">
            <div class="fixed">
                <img class="img-responsive" src="http://placekitten.com/300/200">
                Some links go here.
            </div>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

和相关的CSS:

.fixed {
    position: fixed;
    top: 150px;
}
Run Code Online (Sandbox Code Playgroud)

请注意,当页面水平调整大小时,图像会拉伸到浅灰色容器区域之外.我想要的是图像的右侧始终与容器的右手边精确对齐,根据需要调整图像大小.

我将如何实现这一目标?

html css twitter-bootstrap

2
推荐指数
1
解决办法
1万
查看次数

Neo4j 正则表达式字符串匹配未返回预期结果

我正在尝试在 Cypher 中使用 Neo4j 2.1.5 正则表达式匹配并遇到问题。

我需要对用户有权访问的特定字段实施全文搜索。访问要求是关键,它阻止我将所有内容转储到 Lucene 实例中并以这种方式进行查询。访问系统是动态的,因此我需要查询特定用户有权访问的节点集,然后在这些节点内执行搜索。我真的很想将节点集与 Lucene 查询进行匹配,但我不知道如何做到这一点,所以我现在只使用基本的正则表达式匹配。我的问题是 Neo4j 并不总是返回预期的结果。

例如,我有大约 200 个节点,其中之一如下:

( i:node {name: "Linear Glass Mosaic Tiles", description: "Introducing our new Rip Curl linear glass mosaic tiles. This Caribbean color combination of greens and blues brings a warm inviting feeling to a kitchen backsplash or bathroom. The colors work very well with white cabinetry or larger tiles. We also carry this product in a small subway mosaic to give you some options! SOLD OUT: …
Run Code Online (Sandbox Code Playgroud)

regex neo4j cypher

2
推荐指数
1
解决办法
2133
查看次数