简体   繁体   English

如何删除index.html和karma中加载的脚本文件中的重复项?

[英]How to remove duplication in the script files loaded in index.html and karma?

I have a project that was initially created using the yeoman angularjs generator . 我有一个最初使用yeoman angularjs generator创建的项目。 I run my unit-tests using karma and currently whenever I add a new script to the index.html I also need to add it to the karma.conf.js file so it is accessible for me to test. 我使用业力运行单元测试,目前,每当我将新脚本添加到index.html时,我还需要将其添加到业力karma.conf.js文件中,以便我进行测试。 I don't like this duplication, it slows me down and it is error prone (eg I can add it to index.html and forget to add it to karma.conf.js). 我不喜欢这种重复,它会使我放慢速度,而且容易出错(例如,我可以将其添加到index.html中,而忘记将其添加到karma.conf.js中)。

The example projects that I see do something like this in the karma.conf.js: 我看到的示例项目在karma.conf.js中执行以下操作:

files: [
    'app/bower_components/jquery/jquery.js',
    'app/bower_components/lodash/dist/lodash.js',
    'app/scripts/**/*.js',
    'test/spec/**/*.js'
]

That is fine for test specs but not for actual application scripts because the order matters there. 这对于测试规范来说是很好的,但对于实际的应用程序脚本而言则不是,因为顺序在那里很重要。 Also they have to specifically specify each bower component because the order also matters there 他们还必须具体指定每个凉亭组件,因为顺序也很重要

I thought about creating a task that copies the file paths from index.js and modifies and adds it to karma.conf.js before I run the unit-tests, but before I do that I thought I would ask if anyone knows a better way to remove/manage this duplication. 我考虑过创建一个任务,该任务在运行单元测试之前从index.js复制文件路径并将其修改并将其添加到karma.conf.js,但是在我这样做之前,我想我想问问是否有人知道更好的方法删除/管理此重复项。

I know if I was using a file and module loader I would not have this issue, but I don't intend to use that at least for now. 我知道如果我使用的是文件和模块加载器,就不会有这个问题,但至少现在不打算使用它。

There's a partial solution which works at least for the Bower dependencies. 有一个部分解决方案至少对Bower依赖项有效。 You can use grunt-wiredep to update your Karma configuration with the Bower dependencies, so you don't have to do that manually. 您可以使用grunt-wiredep通过Bower依赖来更新Karma配置,因此您不必手动执行此操作。

There are a couple of configuration examples here . 有一对夫妇的配置实例这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM