小编Nat*_*orn的帖子

为 Jest 的每个测试文件指定 window.location

我正在升级到 Jest 22,但在模拟方面遇到了一些问题window.location。过去,此方法工作正常,但升级后不起作用。

Object.defineProperty(window.location, 'href', {
    writable: true,
    value: 'https://example.com/abc',
});
Run Code Online (Sandbox Code Playgroud)

我已阅读过玩笑文档,有嘲笑的方式window.location在package.json为这样的配置。

"jest": {
    "testURL": "https://example.com/home"
}
Run Code Online (Sandbox Code Playgroud)

如果所有测试都使用相同的 URL,这可以正常工作。

有什么办法可以window.location.href在测试文件中模拟。

我正在使用

"@types/jest": "^22.2.3",
"jest": "^22.4.3",
"@types/enzyme": "^3.1.10",
"enzyme": "^3.3.0",
Run Code Online (Sandbox Code Playgroud)

更新

这是window.location我的组件内部的用法

const currentPage = window.location.href.match(/([^\/]*)\/*$/)[1];
Run Code Online (Sandbox Code Playgroud)

javascript reactjs jestjs

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

AWS Lambda上的PhantomJS始终超时

我尝试在AWS Lambda上创建一个任务,从PhantomJS创建PDF文件,然后再将其上传到AWS S3.

现在,我尝试在Lambda上运行它,但它始终是Timeout.

我的Lambda有128mb的ram.运行时是node.js 4.4.3.

这是我从Lambda得到的错误

"errorMessage": "2017-03-01T08:05:56.255Z dfd4cfe8-fe55-11e6-bf24-e7edf412e037 Task timed out after 10.00 seconds"
Run Code Online (Sandbox Code Playgroud)

这些也是日志输出

REPORT RequestId: dfd4cfe8-fe55-11e6-bf24-e7edf412e037  Duration: 10000.08 ms   Billed Duration: 10000 ms   Memory Size: 128 MB Max Memory Used: 29 MB


2017-03-01T08:05:56.255Z dfd4cfe8-fe55-11e6-bf24-e7edf412e037 Task timed out after 10.00 seconds
Run Code Online (Sandbox Code Playgroud)

这是我的代码.

Index.js

var childProcess = require('child_process');
var path = require('path');

exports.handler = function(event, context, callback) {

     // Set the path as described here: https://aws.amazon.com/blogs/compute/running-executables-in-aws-lambda/
process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT'];

     // Set the path to …
Run Code Online (Sandbox Code Playgroud)

lambda amazon-web-services node.js phantomjs

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