我正在研究一个用CommonJS语法编写的角度应用程序,并使用grunt-contrib-requirejs任务的grunt任务将源文件转换为AMD格式并将其编译成一个输出文件.我的目标是使Karma与RequireJS一起工作,并将我的源文件和spec文件保存在CommonJS语法中.
我已经能够通过以下文件结构以AMD格式传递一个简单的测试:
-- karma-test
|-- spec
| `-- exampleSpec.js
|-- src
| `-- example.js
|-- karma.conf.js
`-- test-main.js
Run Code Online (Sandbox Code Playgroud)
和以下文件:
karma.conf.js
// base path, that will be used to resolve files and exclude
basePath = '';
// list of files / patterns to load in the browser
files = [
JASMINE,
JASMINE_ADAPTER,
REQUIRE,
REQUIRE_ADAPTER,
'test-main.js',
{pattern: 'src/*.js', included: false},
{pattern: 'spec/*.js', included: false}
];
// list of files to exclude
exclude = [];
// test results reporter to use
// possible …
Run Code Online (Sandbox Code Playgroud)