>
如果您还不知道媒体,那么这是SASS中非常轻巧但功能强大的断点经理。>提供的公共API是单个Mixin,Media(..)(因此是库的名称),但是整个事情都经过了足够的思考,因此您实际上可以为此做奇迹。入门之前的一个简短示例:
<span>.my-component { </span><span> <span>width: 100%;</span> </span> <span>// On screens larger or equal to *small* breakpoint, </span> <span>// make the component floated and half the size </span><span> <span>@include media('≥small') {</span> </span><span> <span>float: left;</span> </span><span> <span>width: 50%;</span> </span> <span>} </span><span>}</span>
无论如何,
,所以我们想出了一个我想与你们分享的一些测试系统。当然,如果您想测试一个完整的框架,则可能需要从Eric Suzanne中使用True,而Eric Suzanne则是用Sass编写的完整吹制测试框架,并在最近的SitePoint上的一篇文章中被David介绍和解释。有什么想法?
的事情)。 实现类似的事情最终变得非常容易:我们在任何提交之前设置了a
> gitgit挂钩,以在libsass和ruby sass中进行测试。如果测试失败,我们会杀死该过程。
有不同的方法来运行Sass和Libsass。您可以使用二进制文件,也可以使用包装纸。在我们的情况下,我们选择了一个很小的散装工作流程,使我们很容易运行Ruby Sass和Libsass。
编译SASS测试时,如果GULP任务遇到了SASS错误,则在投掷错误本身时退出该过程,该错误本身会弹出前签名的挂钩并最终中止了提交。
如果我们总结一下,那就这样:
>设置测试体系结构
架构>单词使它听起来很大,而它实际上非常简单。这是该项目的外观:
<span>.my-component { </span><span> <span>width: 100%;</span> </span> <span>// On screens larger or equal to *small* breakpoint, </span> <span>// make the component floated and half the size </span><span> <span>@include media('≥small') {</span> </span><span> <span>float: left;</span> </span><span> <span>width: 50%;</span> </span> <span>} </span><span>}</span>
dist/ <span>| </span><span>|- my-sass-library.scss </span><span>| </span>tests/ <span>| </span><span>|- helpers/ </span><span>| |- _SassyTester.scss </span><span>| |- _custom-formatter.scss </span><span>| </span><span>|- function-1.scss </span><span>|- function-2.scss </span><span>|- ...</span>
>中
<span>// Import the library to test (or only the function if you can) </span><span><span>@import '../dist/my-sass-library';</span> </span> <span>// Import the tester </span><span><span>@import 'helpers/SassyTester';</span> </span> <span>// Import the custom formatter </span><span><span>@import 'helpers/custom-formatter';</span> </span> <span>// Write the tests </span><span>// See my previous article to know more about this: </span><span>// http://... </span><span><span>$tests-function-1: ( ... );</span> </span> <span>// Run the tests </span><span><span>@include run(test('function-1', $tests-function-1));</span></span>
Gulp Workflow
一个可以在测试文件夹上运行libsass(使用Gulp-sass)
> 一个可以在测试文件夹上运行Ruby Sass(使用Gulp-ruby-sass)<span>// We overwrite the `run(..)` mixin from SassyTester to make it throw </span><span>// an `@error` only if a test fails. The only argument needed by the </span><span>// `run(..)` mixin is the return of `test(..)` function from SassyTester. </span><span>// You can check what `$data` looks like in SassyTester documentation: </span><span>// http://kittygiraudel.com/SassyTester/#function-test </span><span><span>@mixin run($data) {</span> </span><span> <span>$tests: map-get($data, 'tests');</span> </span> <span> <span>@each $test in $tests {</span> </span><span> <span>@if map-get($test, 'fail') {</span> </span><span> <span>@error 'Failing test!</span> </span><span> <span>Expected : #{map-get($test, 'expected')}</span> </span><span> <span>Actual : #{map-get($test, 'actual')}';</span> </span> <span>} </span> <span>} </span><span>}</span>
>有大量的库可以设置前签名的挂钩。我个人喜欢预先提交的,但您基本上可以选择自己喜欢的东西,因为它们都做或多或少。>
>要在我们的项目中添加预订挂钩,我们需要在包装中创建一个预命令密钥。该键映射到 就是这样,我们已经完成了。 最终想法
如您所见,此示例非常简单,但是它可以完成工作,并且做得很好。这是它的外观:
>你怎么看?您可能会考虑将其添加到您的库或框架中吗?
提交时,预先承诺的挂钩会发射并尝试执行测试NPM脚本。该脚本运行以下命令:Gulp Test,该脚本将Gulp插入测试。
<span>var gulp = require('gulp');
</span><span>var sass = require('gulp-sass');
</span><span>var rubySass = require('gulp-ruby-sass');
</span>
<span>// Run LibSass on the tests folder
</span><span>// Gulp automatically exits process in case of Sass error
</span>gulp<span>.task('test:libsass', function () {
</span> <span>return gulp.src('./tests/*.scss')
</span> <span>.pipe(plugins.sass());
</span><span>});
</span>
<span>// Run Ruby Sass on the tests folder
</span><span>// Gulp manually exits process in case of Sass error
</span>gulp<span>.task('test:ruby-sass', function () {
</span> <span>return rubySass('./tests')
</span> <span>.on('error', function (err) {
</span> process<span>.exit(1);
</span> <span>});
</span><span>});
</span>
gulp<span>.task('test', ['test:libsass', 'test:ruby-sass']);</span>
以上是测试SASS库的详细内容。更多信息请关注PHP中文网其他相关文章!