代码之家  ›  专栏  ›  技术社区  ›  Dimitrios Desyllas

本地储存的大量货物

  •  0
  • Dimitrios Desyllas  · 技术社区  · 7 年前

    我有以下树结构:

    - tests
    |-- simple_basic.html
    

    我试着这样测试它:

    const qunit = require('node-qunit-phantomjs');
    const fs = require('fs');
    
    gulp.task('test', (done) => {
        fs.readdir('./tests', (err, files) => {
            files.forEach(file => {
              qunit('./tests/'+file);
            });
            done();
        });
    });
    

    但我得到以下错误:

    [23:00:41] Using gulpfile ~/Kwdikas/Javascript/no_url_page/gulpfile.js
    [23:00:41] Starting 'test'...
    Testing file:////home/pcmagas/Kwdikas/Javascript/no_url_page/tests/simple_basic.html
    [23:00:41] Finished 'test' after 16 ms
    ReferenceError: Can't find variable: QUnit
    
      file:////home/pcmagas/Kwdikas/Javascript/no_url_page/tests/simple_basic.html:14 in global code
    ReferenceError: Can't find variable: QUnit
    
      undefined:6
    The `QUnit` object is not present on this page.
    
      phantomjs://code/runner-json.js:78
    

    但是我如何使用本地保存的qunit进行测试呢?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Dimitrios Desyllas    7 年前

    只包括以下文件:

    • ../node_modules/qunit/qunit/qunit.css
    • ../node_modules/qunit/qunit/qunit.js

    到位于 tests 目录。因此 simple_basic.html 将变成(放置虚拟测试):

    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width">
      <title>QUnit Example</title>
      <link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css">
    </head>
    <body>
      <div id="qunit"></div>
      <div id="qunit-fixture"></div>
      <script src="../node_modules/qunit/qunit/qunit.js"></script>
      <script>
          // Replace the test with the one you really need
          QUnit.test( "a basic test example", function( assert ) {
            var value = "hello";
            assert.equal( value, "hello", "We expect value to be hello" );
          });
      </script>
    </body>
    </html>