Skip to content

Commit 638d53d

Browse files
authored
Merge pull request #23 from t-sauer/aot-test-generators
Use `aot-test-generators` to generate test files
2 parents e315ba6 + 8e576e3 commit 638d53d

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

README.MD

+3-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Default: **false**
5858

5959
---
6060

61-
`options.testGenerator` *{Function}*
61+
`options.testGenerator` *{Function|String}*
6262

6363
The function used to generate test modules. You can provide a custom function for your client side testing framework of choice.
6464

@@ -68,6 +68,8 @@ The function receives the following arguments:
6868
* `passed` - If the linting passed (true/false)
6969
* `errors` - A generated string of errors found.
7070

71+
You can also provide a string to use one of the predefined test generators. Currently `qunit` and `mocha` are supported.
72+
7173
Default generates QUnit style tests.
7274

7375
---

index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var path = require('path');
55
var Linter = require('tslint').Linter;
66
var Configuration = require('tslint').Configuration;
77
var fs = require('fs');
8+
var testGenerators = require('aot-test-generators');
89

910
function TSLint(inputNode, options) {
1011
if (!(this instanceof TSLint)) {
@@ -120,15 +121,14 @@ TSLint.prototype.testGenerator = function(relativePath, passed, errors) {
120121
errors = '';
121122
}
122123

123-
if (this.options.testGenerator) {
124+
if (typeof this.options.testGenerator === 'function') {
124125
return this.options.testGenerator.call(this, relativePath, passed, errors);
125126
} else {
126-
return "" +
127-
"QUnit.module('TSLint - " + path.dirname(relativePath) + "');\n" +
128-
"QUnit.test('" + relativePath + " should pass tslint', function(assert) { \n" +
129-
" assert.expect(1);\n" +
130-
" assert.ok(" + !!passed + ", '" + relativePath + " should pass tslint." + errors + "'); \n" +
131-
"});\n";
127+
var generatorName = this.options.testGenerator || 'qunit';
128+
var output = testGenerators[generatorName].suiteHeader('TSLint - ' + path.dirname(relativePath));
129+
output += testGenerators[generatorName].test(relativePath + ' should pass tslint', !!passed, relativePath + ' should pass tslint.' + errors);
130+
131+
return output;
132132
}
133133
};
134134

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
},
2525
"homepage": "https://github.com/kratiahuja/broccoli-tslinter#readme",
2626
"dependencies": {
27+
"aot-test-generators": "^0.1.0",
2728
"broccoli-persistent-filter": "^1.2.0",
2829
"chalk": "^2.0.1",
2930
"exists-sync": "0.0.4"
@@ -32,11 +33,11 @@
3233
"broccoli": "1.1.3",
3334
"chai": "^4.0.2",
3435
"mocha": "^4.0.0",
35-
"typescript": "^2.1.0",
36-
"tslint": "^5.0.0"
36+
"tslint": "^5.0.0",
37+
"typescript": "^2.1.0"
3738
},
3839
"peerDependencies": {
39-
"typescript": "^2.1.0",
40-
"tslint": "^5.0.0"
40+
"tslint": "^5.0.0",
41+
"typescript": "^2.1.0"
4142
}
4243
}

tests/index.js

+16
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,22 @@ describe('broccoli-tslinter', function() {
108108
});
109109
});
110110

111+
it('mocha tests should be generated when mocha is provided as the testGenerator', function() {
112+
var node = new TSLint('./tests/fixtures/errorFiles', {
113+
logError: function(message) {
114+
loggerOutput.push(message);
115+
},
116+
testGenerator: 'mocha'
117+
});
118+
builder = new broccoli.Builder(node);
119+
return builder.build().then(function() {
120+
var dir = builder.outputPath;
121+
var testGenerated = readFile(dir + '/errorFile1.lint-test.js');
122+
assert.notEqual(testGenerated.indexOf("it('errorFile1.ts should pass tslint', function() {"), -1, 'Mocha test should be generated');
123+
assert.notEqual(loggerOutput.length, 0, 'Errors should be seen for linted files');
124+
});
125+
});
126+
111127
it('tests should not be generated when disableTestGenerator is true', function() {
112128
var node = new TSLint('./tests/fixtures/errorFiles', {
113129
logError: function(message) {

0 commit comments

Comments
 (0)