Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use aot-test-generators to generate test files #23

Merged
merged 1 commit into from
Oct 23, 2017
Merged
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
4 changes: 3 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Default: **false**

---

`options.testGenerator` *{Function}*
`options.testGenerator` *{Function|String}*

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

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

You can also provide a string to use one of the predefined test generators. Currently `qunit` and `mocha` are supported.

Default generates QUnit style tests.

---
Expand Down
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var path = require('path');
var Linter = require('tslint').Linter;
var Configuration = require('tslint').Configuration;
var fs = require('fs');
var testGenerators = require('aot-test-generators');

function TSLint(inputNode, options) {
if (!(this instanceof TSLint)) {
Expand Down Expand Up @@ -120,15 +121,14 @@ TSLint.prototype.testGenerator = function(relativePath, passed, errors) {
errors = '';
}

if (this.options.testGenerator) {
if (typeof this.options.testGenerator === 'function') {
return this.options.testGenerator.call(this, relativePath, passed, errors);
} else {
return "" +
"QUnit.module('TSLint - " + path.dirname(relativePath) + "');\n" +
"QUnit.test('" + relativePath + " should pass tslint', function(assert) { \n" +
" assert.expect(1);\n" +
" assert.ok(" + !!passed + ", '" + relativePath + " should pass tslint." + errors + "'); \n" +
"});\n";
var generatorName = this.options.testGenerator || 'qunit';
var output = testGenerators[generatorName].suiteHeader('TSLint - ' + path.dirname(relativePath));
output += testGenerators[generatorName].test(relativePath + ' should pass tslint', !!passed, relativePath + ' should pass tslint.' + errors);

return output;
}
};

Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"homepage": "https://github.com/kratiahuja/broccoli-tslinter#readme",
"dependencies": {
"aot-test-generators": "^0.1.0",
"broccoli-persistent-filter": "^1.2.0",
"chalk": "^2.0.1",
"exists-sync": "0.0.4"
Expand All @@ -32,11 +33,11 @@
"broccoli": "1.1.3",
"chai": "^4.0.2",
"mocha": "^4.0.0",
"typescript": "^2.1.0",
"tslint": "^5.0.0"
"tslint": "^5.0.0",
"typescript": "^2.1.0"
},
"peerDependencies": {
"typescript": "^2.1.0",
"tslint": "^5.0.0"
"tslint": "^5.0.0",
"typescript": "^2.1.0"
}
}
16 changes: 16 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ describe('broccoli-tslinter', function() {
});
});

it('mocha tests should be generated when mocha is provided as the testGenerator', function() {
var node = new TSLint('./tests/fixtures/errorFiles', {
logError: function(message) {
loggerOutput.push(message);
},
testGenerator: 'mocha'
});
builder = new broccoli.Builder(node);
return builder.build().then(function() {
var dir = builder.outputPath;
var testGenerated = readFile(dir + '/errorFile1.lint-test.js');
assert.notEqual(testGenerated.indexOf("it('errorFile1.ts should pass tslint', function() {"), -1, 'Mocha test should be generated');
assert.notEqual(loggerOutput.length, 0, 'Errors should be seen for linted files');
});
});

it('tests should not be generated when disableTestGenerator is true', function() {
var node = new TSLint('./tests/fixtures/errorFiles', {
logError: function(message) {
Expand Down