-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[[FIX]] Emit correct token value from "module" API
* [[TEST]] Re-factor tests for "module" API Separate the project's single unit test for the module API into a standalone file. Beyond improving test discoverability, this organization encapsulates new logic necessary for test hygiene (as described in the in-line documentation). * [[FIX]] Emit correct token value Correct a typo in the source which caused the value `undefined` to be emitted as the `from` property for all Identifier tokens, regardless of the actual character position.
- Loading branch information
1 parent
c3b4d63
commit 4a43fb9
Showing
3 changed files
with
109 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* The JSHint API does not allow for un-registering "modules", and the Nodeunit | ||
* API does not support per-group setup/teardown logic. These deficiencies | ||
* necessitate additional logic in the test suite in order to test the JSHint | ||
* "module" API hygienically: | ||
* | ||
* - Only one JSHint "module" should be added at any time, regardless of the | ||
* number of tests executed | ||
* - No JSHint "module" should run following the completion of this group of | ||
* tests | ||
*/ | ||
"use strict"; | ||
|
||
var JSHINT = require("../..").JSHINT; | ||
var TestRun = require("../helpers/testhelper").setup.testRun; | ||
|
||
var firstRun = true; | ||
var testContext = null; | ||
var suiteSetup = function (done) { | ||
JSHINT.addModule(function (linter) { | ||
if (!testContext) { | ||
return; | ||
} | ||
testContext.onAddModule(linter); | ||
}); | ||
|
||
done(); | ||
}; | ||
exports.setUp = function (done) { | ||
testContext = this; | ||
|
||
if (firstRun) { | ||
firstRun = false; | ||
suiteSetup(done); | ||
return; | ||
} | ||
|
||
done(); | ||
}; | ||
exports.tearDown = function (done) { | ||
testContext = null; | ||
done(); | ||
}; | ||
|
||
exports["test for GH-1103"] = function (test) { | ||
var code = [ "var ohnoes = 42;" ]; | ||
|
||
var run = TestRun(test); | ||
|
||
var patch = true; | ||
|
||
this.onAddModule = function (linter) { | ||
if (!patch) { | ||
return; | ||
} | ||
patch = false; | ||
|
||
var ohnoes = "oh noes"; | ||
Array.prototype.ohnoes = function () { | ||
linter.warn("E024", { line: 1, char: 1, data: [ ohnoes += "!" ] }); | ||
}; | ||
}; | ||
|
||
run.test(code); | ||
|
||
test.done(); | ||
|
||
delete Array.prototype.ohnoes; | ||
}; | ||
|
||
exports.identifiers = function (test) { | ||
var src = [ | ||
"var x = {", | ||
" y: 23,", | ||
" 'z': 45", | ||
"};" | ||
]; | ||
var expected = [ | ||
{ | ||
line: 1, | ||
char: 6, | ||
from: 5, | ||
name: 'x', | ||
raw_name: 'x', | ||
isProperty: false | ||
}, | ||
{ | ||
line: 2, | ||
char: 4, | ||
from: 3, | ||
name: 'y', | ||
raw_name: 'y', | ||
isProperty: false | ||
} | ||
]; | ||
var actual = []; | ||
this.onAddModule = function (linter) { | ||
linter.on("Identifier", function(x) { | ||
actual.push(x); | ||
}); | ||
}; | ||
|
||
JSHINT(src); | ||
|
||
test.deepEqual(actual, expected); | ||
|
||
test.done(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters