Angular2测试和RESOURCE_CACHE_PROVIDER全局 [英] Angular2 tests and RESOURCE_CACHE_PROVIDER global

查看:102
本文介绍了Angular2测试和RESOURCE_CACHE_PROVIDER全局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在karma-test-shim.src.js

我们无法修改单个测试,因为我们还在dist文件夹中使用了它们,其中templateUrlgulp-inline-ng2-template替换为gulp-inline-ng2-template

We cannot modify single test because we use them also on dist folder where templateUrl is replace with template by gulp-inline-ng2-template

我们已经进行了一些测试,但没有成功:

Here some tests we have already run without success:

Promise.all([
    System.import("@angular/core/testing"),
    System.import("@angular/platform-browser-dynamic"),
    System.import("@angular/platform-browser-dynamic/testing")
]).then(function ([testing, browserDynamic, testingBrowserDynamic]) {
       testing.TestBed.initTestEnvironment(
          [testingBrowserDynamic.BrowserDynamicTestingModule],
          testingBrowserDynamic.platformBrowserDynamicTesting()
        );

      // First approach (it doesn't work)
      testing.TestBed.overrideProvider(browserDynamic.RESOURCE_CACHE_PROVIDER);

      // Second approach (it doesn't work)
      testing.TestBed.configureCompiler({
        providers: [ 
            browserDynamic.RESOURCE_CACHE_PROVIDER
        ]
    })

推荐答案

我们找到了一个解决方案,但不是基于Angular提供程序的.

We have found a solution but not based on Angular provider.

我们开发了一个简单的业力预处理器,用于测试:

We developed a simple karma preprocessor just for test as:

  preprocessors: {
            "**/*.component.js": ["generic"]
        },

然后预处理器仅使用gulp-inline-ng2-template解析器

Then preprocessor just uses gulp-inline-ng2-template parser

genericPreprocessor: {
            rules: [{
                process: function (content, file, done, log) {
                    // Prepare content for parser
                    file.contents = new Buffer(content);
                    // Every file has a parser
                    var parse = require('gulp-inline-ng2-template/parser')(file, { base: "packages/", useRelativePaths: false });
                    // Call real parse function
                    parse(function (err, contents) {
                        // Callback with content with template and style inline
                        done(contents);
                    });
                }
            }]
        },

这篇关于Angular2测试和RESOURCE_CACHE_PROVIDER全局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆