Gulp 加载本地保存的 qunit
Gulp load locally saved qunit
我有以下树结构:
- 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 进行测试?
只需包含以下文件:
../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>
我有以下树结构:
- 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 进行测试?
只需包含以下文件:
../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>