This repository has been archived by the owner on Aug 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Add test module grouping by default #243
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
453e2b1
tests/broccoli: Remove unnecessary generateTestFile() options
Turbo87 5aa8d93
tests/broccoli: Adjust test names
Turbo87 056acd1
Pass autodetected "testGenerator" option to Broccoli plugin
Turbo87 ef588d7
Use "aot-test-generators" for test generation
Turbo87 89ed353
Add factory method and new "group" option
Turbo87 eacfa50
broccoli-template-linter: Rename "group" option to "groupName"
Turbo87 48bffaa
broccoli-template-linter: Strip "groupName" from suite name if eq "te…
Turbo87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,12 @@ const Filter = require('broccoli-persistent-filter'); | |
const md5Hex = require('md5-hex'); | ||
const stringify = require('json-stable-stringify'); | ||
const chalk = require('chalk'); | ||
const jsStringEscape = require('js-string-escape'); | ||
const Linter = require('ember-template-lint'); | ||
const debug = require('debug')('template-lint:broccoli'); | ||
const projectLocalizationAddon = require('./lib/utils/project-localization-framework'); | ||
const testGenerators = require('aot-test-generators'); | ||
const testGeneratorNames = Object.keys(testGenerators); | ||
const concat = require('broccoli-concat'); | ||
|
||
function TemplateLinter(inputNode, _options) { | ||
if (!(this instanceof TemplateLinter)) { return new TemplateLinter(inputNode, _options); } | ||
|
@@ -28,9 +30,16 @@ function TemplateLinter(inputNode, _options) { | |
this.options = options; | ||
this._console = this.options.console || console; | ||
this._templatercConfig = undefined; | ||
this._generateTestFile = this.options.generateTestFile || function() { | ||
return ''; | ||
}; | ||
|
||
if (this.options.testGenerator) { | ||
let testGenerator = testGenerators[this.options.testGenerator]; | ||
if (!testGenerator) { | ||
throw new Error(`No test generator found for "testGenerator: ${this.options.testGenerator}"`); | ||
} | ||
|
||
this._testGenerator = testGenerator; | ||
} | ||
|
||
this.linter = new Linter(options); | ||
|
||
debug('Linter config: %s', JSON.stringify(this.linter.config)); | ||
|
@@ -51,7 +60,8 @@ TemplateLinter.prototype.baseDir = function() { | |
TemplateLinter.prototype.cacheKeyProcessString = function(string, relativePath) { | ||
return md5Hex([ | ||
stringify(this.linter.config), | ||
this._generateTestFile.toString(), | ||
this.options.testGenerator || '', | ||
this.options.groupName || '', | ||
string, | ||
relativePath | ||
]); | ||
|
@@ -101,15 +111,21 @@ TemplateLinter.prototype.processString = function(contents, relativePath) { | |
}, this) | ||
.join('\n'); | ||
|
||
|
||
let output = this._generateTestFile( | ||
'TemplateLint - ' + relativePath, | ||
[{ | ||
name: 'should pass TemplateLint', | ||
passed: passed, | ||
errorMessage: jsStringEscape(relativePath + ' should pass TemplateLint.\n' + errorDisplay) | ||
}] | ||
); | ||
let output = ''; | ||
if (this._testGenerator) { | ||
if (this.options.groupName) { | ||
output = this._testGenerator.test(relativePath, passed, | ||
`${relativePath} should pass TemplateLint.\n\n${errorDisplay}`); | ||
|
||
} else { | ||
output = [ | ||
this._testGenerator.suiteHeader(`TemplateLint | ${relativePath}`), | ||
this._testGenerator.test('should pass TemplateLint', passed, | ||
`${relativePath} should pass TemplateLint.\n\n${errorDisplay}`), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, |
||
this._testGenerator.suiteFooter() | ||
].join(''); | ||
} | ||
} | ||
|
||
debug('Found %s errors for %s with \ncontents: \n%s\nerrors: \n%s', errors.length, relativePath, contents, errorDisplay); | ||
|
||
|
@@ -149,4 +165,37 @@ TemplateLinter.prototype.issueLocalizationWarningIfNeeded = function() { | |
} | ||
}; | ||
|
||
TemplateLinter.create = function(inputNode, options) { | ||
options = options || {}; | ||
|
||
if (!options.groupName) { | ||
return new TemplateLinter(inputNode, options); | ||
} | ||
|
||
if (testGeneratorNames.indexOf(options.testGenerator) === -1) { | ||
throw new Error(`The "groupName" options can only be used with a "testGenerator" option of: ${testGeneratorNames}`); | ||
} | ||
|
||
let testGenerator = testGenerators[options.testGenerator]; | ||
|
||
let headerName = 'TemplateLint'; | ||
if (options.groupName !== 'templates') { | ||
headerName += ` | ${options.groupName}`; | ||
} | ||
|
||
let header = testGenerator.suiteHeader(headerName); | ||
let footer = testGenerator.suiteFooter(); | ||
|
||
let lint = new TemplateLinter(inputNode, options); | ||
|
||
return concat(lint, { | ||
outputFile: `/${options.groupName}.template.lint-test.js`, | ||
header, | ||
inputFiles: ['**/*.template.lint-test.js'], | ||
footer, | ||
sourceMapConfig: { enabled: false }, | ||
allowNone: true | ||
}); | ||
}; | ||
|
||
module.exports = TemplateLinter; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we properly support this anyways? If you have a project today without ember-cli-qunit or ember-cli-mocha (prior to this PR) what happens? What happens after this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ember CLI will display a warning that you should install a test framework (for every generated test 😞) and it will generate an empty file
ember-cli-template-lint
will display a warning that it couldn't detect a test framework (once) and it will generate an empty file