2015-04-03 22 views
10

kurulum homurtu görevi için. İşte nasıl kurulum için requirejs ve hırıltı-contrib-qunit kullanarak bir QUnit ortamı çalışıyorum requirejs ve qunit

ben ne var.

gruntfile:

qunit: { 
    all: { 
    options: { 
     urls: [ 
     'http://localhost:8000/qunit/qunit-test-suite.html' 
     ] 
    } 
    } 
}, 

connect: { 
    server: { 
    options: { 
     port: 8000, 
     base: '.' 
    } 
    } 
}, 

qunit-test suite.html:

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title>QUnit Tests Suite: travis CI Test</title> 
    <link rel="stylesheet" href="../components/libs/qunit/qunit/qunit.css"> 
</head> 
<body> 

    <div id="qunit"></div> 
    <div id="qunit-fixture"></div> 

    <script src="../components/libs/qunit/qunit/qunit.js"></script> 
    <script> 
    QUnit.config.autoload = false; 
    QUnit.config.autostart = false; 
    </script> 

    <script data-main="qunit" src="../components/libs/requirejs/require.js"></script> 

</body> 
</html> 

qunit.js:

require.config({ 
    baseUrl: "../", 
    paths: { 
     'jquery': 'components/libs/jquery/dist/jquery.min', 

     // Test for Foo 
     'foo': 'components/app/foo/foo', 
     'test-Foo': 'components/app/foo/test-Foo' 
    }, 
    shim: { 
    'QUnit': { 
     exports: 'QUnit', 
     init: function() { 
     QUnit.config.autoload = false; 
     QUnit.config.autostart = false; 
     } 
     } 
    } 
}); 

require(['test-Foo'], function (Foo) { 
    QUnit.load(); 
    QUnit.start(); 
}); 

test Foo.js:

define(['foo'], function(Foo) { 

    'use strict'; 

    module("Foo"); 

    test("Foo return Test", function() { 
    equal(Foo.foo(), "foo", "Function should return 'foo'"); 
    equal(Foo.oof(), "oof", "Function should return 'oof'"); 
    }); 

    test("Bar return Test", function() { 
    equal(Foo.bar(), "barz", "Function should return 'bar'"); 
    }); 

}); 

Sorun, tarayıcımda test-suite.html açtığımda her şeyin iyi çalıştığıdır. Bir kez aşağıdaki hatayı alıyorum PhantomJS gönderilen:

Running "connect:server" (connect) task 
Started connect web server on http://localhost:8000 

Running "qunit:all" (qunit) task 
Testing http://localhost:8000/qunit/qunit-test-suite.html 

>> PhantomJS timed out, possibly due to a missing QUnit start() call. 
Warning: 1/1 assertions failed (0ms) Use --force to continue. 

Aborted due to warnings. 

Tam kurulumu: https://github.com/markusfalk/test-travis

Test Çalışması: herhangi bir yardım :) önceden

+0

brigde mı sorun? Bununla ilgili ne yapılabilir? http://stackoverflow.com/a/18433173/2538388 Ama aslında HTML içinde Qunit yüklüyorsun ve requireJS – Markus

+0

ile yüklenemiyorum Bu [email protected] kullanarak bu kurulumun işe yaradığını öğrendim. Belki de yaptıkları güncellemeyle ilgisi vardır: Q0n0'a iletilen noGlobals seçeneği ekleyin. Hatalara bağlı olarak uygun çıkış kodunu uygun bir şekilde raporlayın. AMD için destek ekleyin. – Markus

+0

Jörn Zaefferer'in önerdiği bir şeyi yeniden kurdum (https://github.com/markusfalk/test-travis/tree/20150411_falk_require-qunit-as-amd/qunit) ama yine de zaman aşımına uğradı (https: // travis -ci.org/markusfalk/test-travis/builds/58909816) – Markus

cevap

4

Jörn yardımı ile bir çalışma kurulumu yaptım. Trick, QUnit yüklemelerinden önce requireJS'yi ayarlamalıdır (config.js için requireJS yapılandırmasını taşıdı ve önce yükledik).

Gereksinimler:

  • hırıltı-contrib-qunit v0.7.0
  • qunit v1.18.0

HTML test paketi:

<!doctype html> 
<html> 
    <head> 
    <meta charset="utf-8"> 
    <title>QUnit Tests Suite: asdf</title> 
    <link rel="stylesheet" href="../components/libs/qunit/qunit/qunit.css"> 
    </head> 
    <body> 

    <div id="qunit"></div> 
    <div id="qunit-fixture"></div> 

    <script src="config.js"></script> 
    <script data-main="unit" src="../components/libs/requirejs/require.js"></script> 

    </body> 
</html> 

yapılandırma.js

var requirejs = { 
    baseUrl: "../", 
    paths: { 
    //{{app}} 
    'foo': 'components/app/foo/foo', 
    'test-foo': 'components/app/foo/test-foo', 

    //{{libs}} 
    'unit': 'qunit/unit', 
    'qunit': 'components/libs/qunit/qunit/qunit', 
    'jquery.exists': 'libs/jquery.exists/jquery.exists', 
    'jquery': 'components/libs/jquery/dist/jquery.min' 
    }, 
    'shim': { 
    'jquery.exists': ['jquery'] 
    } 
}; 

unit.js

require([ 
    'qunit', 
    'test-foo' 
], 
function(qunit, TestFoo) { 
    TestFoo(); 
    qunit.start(); 
}); 

test foo.js:

define(['jquery', 'qunit', 'foo'], function($, qunit, Foo) { 
    'use strict'; 
    return function() { 
    qunit.module("Foo"); 
    qunit.test("Foo Test", function() { 
     equal(Foo.saySomething(), "Hello", "returns 'Hello'"); 
    }); 
    }; 
}); 

Ve sonunda teste istediğiniz modülü:

define(['jquery'], function($) { 
    'use strict'; 
    var Foo = { 
    saySomething: function() { 
     return "Hello"; 
    } 
    }; 
    return { 
    saySomething: Foo.saySomething 
    }; 
}); 
0

Özür eğer ben için https://travis-ci.org/markusfalk/test-travis

Teşekkür Açıkça belirtmekle birlikte PhantomJS yüklü mü? Paketleri.json dosyasında göremiyorum. Proje kökünüzde npm install phantomjs --save-dev kullanarak yükleyebilirsiniz. Save-dev bunu paketlerinize ekleyecektir. Bu yüzden npm install'u çalıştırdığınızda otomatik olarak yüklenecektir.

+0

phantomjs – Markus

1

Bazı daha ayrıntılı çıktılar elde etmek için -v ve/veya -d işaretleriyle çalışmayı denediniz mi? Travis-ci yapınızda PhantomJS ile ilgili bir şey atlandığını fark ettim.

Writing location.js file

PhantomJS is already installed at /usr/local/phantomjs/bin/phantomjs.

npm WARN excluding symbolic link lib/socket.io-client.js -> io.js

io.js'ye bağımlıysa ve bağlantı yok ise, başarısız olur.

GÜNCELLEME: Sorunu ayrıntılı çıktı kullanarak buldum. Bir dosya adı sorunu nedeniyle testiniz 404'tür.

["phantomjs","onResourceReceived",{"contentType":"text/html; charset=utf-8","headers":[{"name":"X-Content-Type-Options","value":"nosniff"},{"name":"Content-Type","value":"text/html; charset=utf-8"},{"name":"Content-Length","value":"43"},{"name":"Date","value":"Fri, 10 Apr 2015 06:45:47 GMT"},{"name":"Connection","value":"keep-alive"}],"id":6,"redirectURL":null,"stage":"end","status":404,"statusText":"Not Found","time":"2015-04-10T06:45:47.747Z","url":" http://localhost:10000/components/app/foo/test-Foo.js "}]

Dosyayı test Foo.js kullanmaya çalışıyoruz. Dosya, deponuzda test-foo.js olarak adlandırılmıştır. Davanın değiştirilmesi testi düzeltmelidir.

+0

içeren [email protected] yüklü Travis yapısına -vd ekledim ama gerçekten fazla bir anlam ifade edemiyorum – Markus

+0

Cevabı buldum. Yanıtımı, ayrıntılı çıktıda bulduğum şeyi yansıtacak şekilde güncelleştirdim. – voldemortensen

+0

Çabalarınız için teşekkürler ama bu sorun değildi. 404'ü düzeltdim ama yine de aynı sonucu aldım. – Markus