对于用 ES6/7 编写的库,我想将该库编译(到 ES5)到一个 dist/ 文件夹。我还想为这个库运行测试(用 ES6/7 编写)。
我的开发依赖项如下所示(package.json):
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"@babel/register": "^7.4.4",
"chai": "^4.2.0",
"mocha": "^6.1.4",
"sinon": "^7.3.2"
},
Run Code Online (Sandbox Code Playgroud)
我的构建和测试脚本如下所示 (package.json):
"scripts": {
"test": "mocha --require @babel/register",
"build": "babel src -d dist --presets=@babel/preset-env"
},
Run Code Online (Sandbox Code Playgroud)
跑步npm run build效果很好。dist/ 文件夹中填充了转换后的文件。
跑步npm run test似乎不起作用 - 这是我的问题。
> mocha --require @babel/register
/Users/dro/Repos/lib/node_modules/yargs/yargs.js:1163
else throw err
^
ReferenceError: regeneratorRuntime is not defined
Run Code Online (Sandbox Code Playgroud)
最初我遇到了一个导入错误,通过添加 .babelrc 文件解决了这个错误。
下面是我的 .babelrc 文件内容。
{
"presets": ["@babel/preset-env"]
}
Run Code Online (Sandbox Code Playgroud)
我正在读关于regeneratorRuntime …
当我们创建一个 cookie 时,我们可以通过设置域属性来指定它的使用位置。
Set-Cookie: Foo=bar; Path=/; Secure; Domain=baz.qux.com;
Run Code Online (Sandbox Code Playgroud)
上面的 cookie 将仅与对域的请求一起使用baz.qux.com。
Set-Cookie: Foo=bar; Path=/; Secure; SameSite=strict;
Run Code Online (Sandbox Code Playgroud)
上面的 cookie 省略了domain属性,这意味着将使用设置cookie 的域(不包括子域,IE 例外)。它还具有属性SameSite=strict,这意味着:
SameSite cookie 允许服务器要求 cookie 不应与跨站点(站点由可注册域定义)请求一起发送,这提供了一些针对跨站点请求伪造攻击 (CSRF) 的保护。
来自MDN
如果这两个 cookie 都设置在域上,那么这两个 cookie 之间的行为有何不同baz.qux.com?
该SameSite=strict属性如何防止具有指定域的其他 cookie没有的CSRF?
我有一个带有指令的常规角度应用程序.该指令包含一个带ng-click="clickFunction()"调用的元素.单击该元素时,一切正常.我现在需要为此单击编写一个测试,确保在单击该元素时实际运行此函数 - 这就是我遇到的问题.
这是一个解释我的问题的方法:http://jsfiddle.net/miphe/v0ged3vb/
控制器包含一个clickFunction()应该在单击时调用的函数.单元测试应模仿指令元素的单击,从而触发对该函数的调用.
在clickFunction与sinonjs嘲笑,这样我可以检查是否被调用,还是没有.该测试失败,意味着没有点击.
我在这做错了什么?
我已经看到类似问题的答案,比如使用Sinon测试JavaScript Click事件,但我不想使用完整的jQuery,我相信我正在嘲笑(监视)正确的功能.
这是上面小提琴的js(对于那些喜欢在这里看到它的人):
angular.js,angular-mocks.js也加载.
// App
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', function($scope) {
$scope.person = 'Mr';
$scope.clickFunction = function() {
// Some important functionality
};
});
myApp.directive('pers', function() {
return {
restrict: 'E',
template: '<h2 ng-click="clickFunction()" ng-model="person">Person</h2>',
};
});
// Test suite
describe('Pers directive', function() {
var $scope, $controller, template = '<pers></pers>', compiled;
beforeEach(module('myApp'));
beforeEach(inject(function($rootScope, $controller, $compile) {
$scope …Run Code Online (Sandbox Code Playgroud) 如何confirmPassword使用tcomb-form-native库验证我的字段?
电子邮件和密码字段非常简单,我不知道如何比较模型中另一个字段的现有值.
这是我的代码.
const Email = t.refinement(t.String, (email) => {
const reg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
return reg.test(email);
});
const Password = t.refinement(t.String, (password) => {
const reg = /^(?=\S+$).{8,}$/;
return reg.test(password);
});
const RegistrationData = t.struct({
email: Email,
password: Password,
confirmPassword: t.String // Need some equality check
});
Run Code Online (Sandbox Code Playgroud)
我已经调查了文档https://github.com/gcanti/tcomb-form-native#disable-a-field-based-on-another-fields-value但我无法理解它.
我需要将用户重定向到 React 组件之外,这通常是使用 historyreact-router 完成的。
// history.js
const history = createBrowserHistory();
export default history;
// App, setting up router
import { HashRouter as Router } from 'react-router-dom';
import history from './history';
...
<HashRouter history={history}>...</HashRouter> // problem
// Non-component file
import history from './history';
history.push('/target');
Run Code Online (Sandbox Code Playgroud)
由于HashRouter不接受历史道具,而是在内部处理历史,并指示开发人员使用withRouter以暴露history给组件,因此如何在组件外部进行重定向并不明显。
我正在使用HashRouter ,我需要使用history组件外部(意味着我不能使用withRouter)。
我怎么能做到这一点?
我正在构建我的第一个Spree应用程序和我自己的布局/主题.我需要更改产品的缩略图大小,并且指向不同,大多数情况下它似乎是一个不受欢迎的主题.这是如何工作的,我该如何改变它?
配置/初始化/ spree_config.rb
Spree::Config.set(
attachment_styles: "{
\"mini\":\"48x48>\",
\"small\":\"110x110>\",
\"product\":\"340x340>\",
\"large\":\"650x650>\"
}"
)
Run Code Online (Sandbox Code Playgroud)
这就是我第一次尝试它的方式 - 没有效果.
我试图像这样清除缓存:
rake tmp:clear没有结果.
我试图重新上传一些图片来强制重新生成缩略图,有是结果,但不是所有的大小.例如,似乎很难为"产品"尺寸创建340x340像素图像.
我所追求的是一种根据我自己定义的尺寸重新生成所有缩略图的方法.
ruby 1.9.3p194 | Rails 3.2.8 | Spree 1.2.0
在我的应用程序中,我有一个控制器,其范围有一个模型,用于确定我视图中的条件.非常标准.
调节器
$scope.shouldShow = false;
$scope.seeCoal = true;
Run Code Online (Sandbox Code Playgroud)
视图
<div ng-controller="SomeController" ng-if="shouldShow">
<span id="coal" ng-show="seeCoal"></span>
</div>
Run Code Online (Sandbox Code Playgroud)
很公平.当我把它shouldShow变成真正的东西时,这个div就会呈现出来.
量角器如何解释这个并且它包含标记?如果我的测试没有将shouldShow模型设置为true,那么#coal元素是否会被认为存在element.isPresent()?
此外,如果(在我的测试中)我没有设置shouldShow为truthy(保持为假),并设置seeCoal为false - 我将能够遍历#coal以确认ng-hide该类是否存在,即使它的父级具有ng-if评估为的条件假?
在我正在尝试这个的项目中,我有太多的不确定性,我无法确定量角器在这些情况下应该如何工作.
angularjs ×2
mocha.js ×2
babeljs ×1
cookies ×1
csrf ×1
e-commerce ×1
imagemagick ×1
jqlite ×1
npm ×1
protractor ×1
react-native ×1
react-router ×1
security ×1
spree ×1
thumbnails ×1
transpiler ×1
validation ×1