Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,25 @@ module.exports = function (params) {
return through.obj(function (file, enc, cb) {
var absolutePath = path.resolve(file.path),
isAbsolutePath = absolutePath.indexOf(file.path) >= 0,
queryParams = [],
childArgs = [];

if (options.noGlobals) {
queryParams.push('noglobals');
}

if (options.noTryCatch) {
queryParams.push('notrycatch');
}

if (options['phantomjs-options'] && options['phantomjs-options'].length) {
childArgs.push(options['phantomjs-options']);
}

childArgs.push(
require.resolve('qunit-phantomjs-runner'),
(isAbsolutePath ? 'file:///' + absolutePath.replace(/\\/g, '/') : file.path)
(isAbsolutePath ? 'file:///' + absolutePath.replace(/\\/g, '/') : file.path) +
(queryParams.length ? '?' + queryParams.join('&') : '')
);

if (options.timeout) {
Expand Down
32 changes: 32 additions & 0 deletions test/fixtures/no-globals.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<title>QUnit Test Suite</title>
<link rel="stylesheet" href="../../node_modules/qunitjs/qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="../../node_modules/qunitjs/qunit/qunit.js"></script>
<!-- Your project file goes here -->
<!-- <script type="text/javascript" src="myProject.js"></script> -->
<!-- Your tests file goes here -->
<!-- <script type="text/javascript" src="myTests.js"></script> -->
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>

<script>
// Let's test this function but "accidentally" leak into global scope.
function multiply(a, b) {
res = a * b;
return res;
}

test('multiply()', function() {
ok(multiply(0, 1) === 0, 'Zero times one is zero');
ok(multiply(2, 2) === 4, 'Two times two is four');
ok(multiply(1, 3) === 3, 'One times three is three');
ok(multiply(10, 5) === 50, 'Five times ten is fifty');
ok(multiply(10, 10) === 100, 'Ten times ten is one hundred');
});
</script>
</body>
</html>
23 changes: 23 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,27 @@ describe('gulp-qunit', function() {

stream.end();
});

it('tests should fail', function(done) {
var stream = qunit({ noGlobals: true });

process.stdout.write = function (str) {
out(str);
str = chalk.stripColor(str);
out(str);

if (/Introduced global variable\(s\): res/.test(str)) {
assert(true);
done();
process.stdout.write = out;
}
};

stream.write(new gutil.File({
path: './test/fixtures/no-globals.html',
contents: new Buffer('')
}));

stream.end();
});
});