如何在 Web Component Tester 中更换服务器 [英] How can I replace the server in Web Component Tester

查看:52
本文介绍了如何在 Web Component Tester 中更换服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于 Polymer Starter Kit 的项目,其中包括 Web-Component-Tester

I have a project set up based around the Polymer Starter Kit, which includes Web-Component-Tester

这个项目包括 php 服务器代码,我也想通过编写测试来测试它在浏览器中运行,浏览器将通过 Ajax 调用利用 PHP 服务器代码.

This project includes php server code which I would also like to test by writing tests to run in the browser which will utilise the PHP server code through Ajax Calls.

这意味着替换 Web Component Tester 仅在测试服务器端代码时使用的服务器.我希望为此做一个单独的 gulp 任务.

This implies replacing the server that Web Component Tester is using ONLY when testing server side code. I hope to make a separate gulp task for this.

不幸的是,我不了解 WCT、Selenium 和当前运行的任何服务器之间的关系.我可以看到 WCT 命令启动 Selenium,但我无法找出 Web 服务器是什么以及它是如何启动的.我怀疑它是 WCT,因为有目录到 url 的映射的配置,但除此之外我没有任何线索,尽管试图阅读代码.

Unfortunately, I don't understand the relationship between WCT, Selenium and what ever server is run currently. I can see that WCT command starts Selenium, but I can't find out what the web server is and how that is started. I suspect it is WCT, because there is configuration of the mapping of directories to urls, but other than that I haven't a clue, despite trying to read the code.

有人可以解释我如何在测试客户端时让它运行自己的服务器,但在运行服务器时依赖已经设置的 Web 服务器 (nginx).我可以将 nginx 设置为从本地主机或其他域运行,如果这是选择不同配置的一种方式.

Can someone explain how I go about making it run its own server when testing the client, but relying on an already set up web server (nginx) when running the server. I can set nginx to run from local host, or an other domain if that is a way to choose a different configuration.

我现在发现 runner/webserver.js 启动了一个快速服务器,并且 url 被映射,因此测试运行器的基本目录和 bower_components 目录都被映射到/components url.

I have now found that runner/webserver.js starts an express server, and that urls get mapped so the base directory for the test runner and the bower_components directory both get mapped to the /components url.

目前让我感到困惑的是它在什么情况下运行.似乎加载插件以某种方式做到了这一点,但我从阅读代码中的理解是脆弱的.

What is currently confusing me is in what circumstances this gets run. It appears that loading plugins somehow does it, but my understanding from reading the code for this is tenuous.

推荐答案

答案是 Web 组件测试员本身在 runner/config.js 文件中有注释.

The answer is that web component tester itself has a comment in the runner/config.js file.

wct-conf.js 中,您可以使用 registerHooks 键进入返回的对象以添加执行

In wct-conf.js, you can use registerHooks key into the Object that gets returned to add a function that does

  registerHooks: function(wct) {
    wct.hook('prepare:webserver', function(app, done) {
      var proxy = require('express-http-proxy');
      app.use('/api',
        proxy('pas.dev', {
          forwardPath: function(req, res) {
            return require('url').parse(req.url).path;
          }
        })
      );
      done();
    });

这个注册钩子函数允许你提供一个路由(在我的例子中是/api),它代理到一个可以运行 php 脚本的服务器.

This register hook function allows you to provide a route (/api in my case) which this proxies to a server which can run the php scripts.

这篇关于如何在 Web Component Tester 中更换服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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