首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无头JS站点测试和每个页面的测试

无头JS站点测试和每个页面的测试
EN

Stack Overflow用户
提问于 2014-01-31 23:17:08
回答 2查看 95关注 0票数 1

我试图用CoffeeScript/Javascript为我的站点上的每个页面编写无头集成测试,并在一个命令中运行它们。我尝试过使用casperjs,但是当我试图在一个请求循环中运行多个测试套件时,我一直会遇到问题

理想情况下,我想做这样的事情:

代码语言:javascript
复制
for page in ['/products','/about', '/contact']
   open(page, ->
       require("tests/#{page}/test.coffee").execute()

其中的测试文件看起来类似于:

代码语言:javascript
复制
exports.execute ->
    test.assert(pageTitleIs('about us'))

这样我就可以将每个页面的测试保存在单独的文件中,但是只需使用一个命令就可以随意运行它们。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-02-05 18:50:33

代码语言:javascript
复制
casper.thenOpen( url, ->
  @CurrentUrl = url
  @currentRoute = route
  @test.currentSuite = @test.running = @test.started = false # Hack. If we don't do this and a test fails, no tests after it will be executed
  @test.info("Testing #{urlPath}");
  path = currentDirectory+'/root'+route;
  if(fs.isDirectory(path))
    for file in fs.list(path)
      if(file.indexOf('.spec')!=-1)
        @echo 'executing file: ' + path + '/'+ file
        @test.exec(path + '/'+ file);
  @test.exec currentDirectory+"/smoke.test.js"
  @waitFor ->
    if test_done #Hack. If we don't do this, new tests will start before old ones finished.
      return true
    test_done = false
)

这是我想出的解决方案,每个页面都要执行smoke.test.js。这很麻烦,我遇到了许多与测试范围有关的问题,但是它是有效的。

票数 1
EN

Stack Overflow用户

发布于 2014-02-01 12:54:57

字符串插值不适用于单引号。你得用双引号。见不同之处:

代码语言:javascript
复制
require('tests/#{page}/test.coffee').execute()
# becomes: require('tests/#{page}/test.coffee').execute();

require("tests/#{page}/test.coffee").execute()
# becomes: require("tests/" + page + "/test.coffee").execute();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21491845

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档