webpack-dev-server + protractor - 主机头无效

时间:2017-06-11 19:08:25

标签: webpack protractor webpack-dev-server

  • OS:macOS Sierra 10.12.4
  • 节点:v7.9.0
  • Npm:5.0.3
  • Cucumber-js:2.3.0
  • 量角器:4.0.14
  • TypeScript:2.2.2
  • webpack-dev-server:2.4.5

您好

我在版本>中使用webpack-dev-server运行量角器测试时遇到问题2.4.3。当我运行测试时,浏览器显示消息:'无效的主机标题'并且测试失败。如果我将webpack-dev-server的版本更改为2.4.2,一切正常。我知道选项' public'在webpack但我不知道我应该把什么主机或IP放到量角器工作。我想我尝试了一切。这是我的webpack.config:

'use strict';

const HtmlWebpack = require('html-webpack-plugin');
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const extractPlugin = new ExtractTextPlugin({
   filename: 'main.css'
});
const CleanWebpack = require('clean-webpack-plugin');

const rootDir = path.resolve(__dirname);

module.exports = {
    devServer: {
        contentBase: path.resolve(rootDir, 'dist'),
        port: 3000,
        host: '0.0.0.0',
        disableHostCheck: false,
        public: '172.23.0.1'
    },
    watchOptions: {
        poll: true
    },
    devtool: 'source-map',
    entry: {
        "bundle": "./src/webpack.main.js",
        "plugins": "./src/plugins.js"
    },
    output: {
        path: path.resolve(__dirname, "dist"),
        filename: "[name].js",
        sourceMapFilename: '[file].map'
        // publicPath: "/dist"
    },
    resolve: {
        extensions: [ '.js', '.ts' ]
    },
    module: {
        exprContextCritical: false,
        rules: [
            {
                test: /\.html$/,
                use: [
                    {
                        loader: 'file-loader',
                        options: {
                            name: '[name].[ext]'
                        },
                    },
                    { loader: 'extract-loader' },
                    { loader: 'html-loader' }
                ],
                exclude: path.resolve(__dirname, 'src/index.html')
            },
            {
                test: /\index.html$/,
                loader: ['html-loader']
            },
            {
                test: /\.ts$/,
                loader: 'ts-loader',
                exclude: /node_modules/
            },
            {
                test: /\.(scss|css)$/,
                use: extractPlugin.extract({
                    use: ['css-loader', 'sass-loader']
                })
            },
            {
                test: /\.(jpg|png|gif|eot|ttf|svg|woff|woff2)$/,
                use: [{
                    loader: 'file-loader',
                    options: {
                        name: '[name].[ext]',
                        outputPath: 'img/',
                        publicPath: 'img/'
                    }
                }]
            },
        ],
    },
    plugins: [
        new CleanWebpack(['dist']),
        extractPlugin,
        new HtmlWebpack({
            template: 'src/index.html'
        }),
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery",
            "window.jQuery": "jquery",
            "Tether": 'tether'
        }),
        new HtmlWebpackPlugin({
            template: './src/index.html',
            filename: 'index.html',
            inject: 'body'
        }),
    ],
};

我将公共选项设置为:172.23.0.1所以我可以在浏览器中打开dockerized app(172.23.0.1是我在docker网络中的主机ip)。

这是我的protractor.config:

// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts

var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var webpackConfig = require('./webpack.config');
var deasync = require('deasync');
var server;

exports.config = {
    // seleniumAddress: 'http://selenium-standalone-chrome:4444/wd/hub',
    baseUrl: 'http://0.0.0.0:3000',
    useAllAngular2AppRoots: true,
    directConnect: true,
    beforeLaunch: () => {

        var isServerReady = false;
        var isBundleReady = false;
        var compiler = webpack(webpackConfig, () => {
            isBundleReady = true;
            console.log('Dumpstere bundled...');
        });

        server = new WebpackDevServer(compiler, {});

        server.listen(3000, () => {
            isServerReady = true;
            console.log('Dumpstere started...');
        });

        deasync.loopWhile(() => !isServerReady || !isBundleReady);
    },
    afterLaunch: () => {
        server.close();
    },
    capabilities: {
        browserName:'chrome'
    },

    framework: 'custom',

    frameworkPath: require.resolve('protractor-cucumber-framework'),
    specs: [
        './features/*.feature'
    ],
    cucumberOpts: {
        require: ['./features/step_definitions/*.ts'],
        tags: [],
        strict: false,
        format: ["pretty", "json:report/json/cucumber_report.json"],
        dryRun: false,
        compiler: ["ts:ts-node/register"]
    },

    onPrepare: function () {
        browser.ignoreSynchronization = true;
        browser.manage().window().maximize();
    }
};

0 个答案:

没有答案