Angular 2量角器不能要求.scss文件

时间:2016-05-26 15:05:18

标签: sass angular protractor webpack angularjs-e2e

我正在尝试使用Angular 2和Webpack运行Protractor测试

部分Webpack配置:

    resolve: {
       extensions: ['', '.ts', '.js', '.scss', '.css']
    },
    module: {
    loaders: [
      // TypeScript
      { test: /\.ts$/, loader: 'ts-loader'},

      // SCSS
      { test: /\.scss$/, exclude: /node_modules/, loaders: ['raw-loader', 'sass-loader']}
        ]
     },
     plugins: [
        new webpack.optimize.OccurenceOrderPlugin(true)
      ]

我的home.component.ts

    import { Component, Injectable } from '@angular/core';

    @Component({
      selector: 'home',
      styles: [require('./home.component.scss')],
      template: `<h4 class="page-home">Home</h4>`
   })
   @Injectable()
   export class Home {}

我的home.component.scss

.page-home {
  color: blue;
}

我的E2E:

require('../server');

describe('App', () => {
  beforeEach(() => {
    browser.get('/');
  });


  it('should have a title', (done) => {
    let subject = browser.getTitle();
    subject
      .then((data) => {
        let result = 'test';
        expect(data).toEqual(result);
        done();
      });
  });

  it('should definitely pass', () => {
    expect(true).toEqual(true);
  });

});

我运行服务器,所有内容都按预期启动。当我运行我的E2E测试时,我收到以下错误:

 [14:42:47] I/hosted - Using the selenium server at        http://hub.browserstack.com/wd/hub
    [14:42:47] I/launcher - Running 1 instances of WebDriver
    [14:43:03] E/launcher - Error: /app/src/app/home/home.component.scss:1
    (function (exports, require, module, __filename, __dirname) { .page-home {
                                                              ^
    SyntaxError: Unexpected token .
        at Object.exports.runInThisContext (vm.js:53:16)
        at Module._compile (module.js:513:28)
        at Object.Module._extensions..js (module.js:550:10)
        at Module.load (module.js:458:32)
        at tryModuleLoad (module.js:417:12)
        at Function.Module._load (module.js:409:3)
        at Module.require (module.js:468:17)
        at require (internal/module.js:20:19)
        at home.component.ts:5:12
        at Object.<anonymous> (home.component.ts:9:21)
    [14:43:03] E/launcher - Process exited with error code 100

    npm info lifecycle cnd-app@1.0.0~protractor: Failed to exec protractor   script
    npm ERR! Linux 3.19.0-59-generic
    npm ERR! argv "/usr/local/bin/node" "/app/node_modules/.bin/npm" "run" "protractor"
    npm ERR! node v6.2.0
    npm ERR! npm  v3.9.2
    npm ERR! code ELIFECYCLE
    npm ERR! cnd-app@1.0.0 protractor: `protractor protractor.conf.js`
    npm ERR! Exit status 100

似乎量角器使用require与WebPack处理它的方式不同。是否存在此配置或我缺少的任何内容?

**更新** 我能够解决这个问题。我有一个打字稿寄存器导致protractor.conf.js发生冲突。

0 个答案:

没有答案