Skip to content

Commit

Permalink
Implement generator
Browse files Browse the repository at this point in the history
  • Loading branch information
inikulin committed Dec 9, 2015
1 parent f4d558b commit ed00b42
Show file tree
Hide file tree
Showing 26 changed files with 677 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[{.eslintrc,package.json,.travis.yml}]
[{.eslintrc,*.json,.travis.yml}]
indent_size = 2
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"no-shadow": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-trailing-spaces": 2,
"no-undef-init": 2,
"no-unused-expressions": 2,
"no-with": 2,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
node_modules
test/temp
2 changes: 1 addition & 1 deletion gulpfile.js → Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gulp.task('lint', function () {

gulp.task('test', ['lint'], function () {
return gulp
.src('test.js')
.src('test/test.js')
.pipe(mocha({
ui: 'bdd',
reporter: 'spec',
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

[![Build Status](https://api.travis-ci.org/DevExpress/generator-testcafe-reporter.svg)](https://travis-ci.org/DevExpress/generator-testcafe-reporter)

TestCafe can build test run reports in your own format and style. What you have to do is create a custom reporter plugin.
This Yeoman generator scaffolds out such a plugin, so that you only need to write a few lines of code.

## Installation

Expand All @@ -19,6 +21,6 @@ Then generate your new project:
yo generator-testcafe-reporter
```

#Author
## Author

Developer Express Inc.([http://devexpress.com](http://devexpress.com))
88 changes: 67 additions & 21 deletions generators/app/index.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,85 @@
'use strict';
var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var yosay = require('yosay');
var yeoman = require('yeoman-generator');
var slugify = require('underscore.string').slugify;
var normalizeUrl = require('normalize-url');

function filterProjectName (name) {
return slugify(name.replace(/^testcafe(-|\s)reporter(-|\s)/i, ''));
}

module.exports = yeoman.generators.Base.extend({
prompting: function () {
var done = this.async();
var gen = this;

this.log(yosay(
'Welcome to the astounding ' + chalk.red('generator-testcafe-reporter') + ' generator!'
));

var prompts = [{
type: 'confirm',
name: 'someOption',
message: 'Would you like to enable this option?',
default: true
}];
var prompts = [
{
name: 'reporterName',
message: 'How do you want to name your reporter?',
default: filterProjectName(this.appname),
filter: filterProjectName
},
{
name: 'githubUsername',
message: 'What is your GitHub username?',
store: true,
validate: function (name) {
return name.length ? true : 'You should provide a username';
}
},
{
name: 'website',
message: 'What is the URL of your website?',
store: true,
filter: function (url) {
return url && normalizeUrl(url);
}
},
{
name: 'errorDecorator',
message: 'Do you want to implement custom error decorator?',
type: 'confirm',
default: false
}
];

this.prompt(prompts, function (props) {
this.props = props;
// To access props later use this.props.someOption;
gen.props = props;

done();
}.bind(this));
});
},

writing: function () {
this.fs.copy(
this.templatePath('dummyfile.txt'),
this.destinationPath('dummyfile.txt')
);
var gen = this;

var tmplProps = {
author: this.user.git.name(),
email: this.user.git.email(),
website: this.props.website,
reporterName: this.props.reporterName,
githubUsername: this.props.githubUsername,
errorDecorator: this.props.errorDecorator
};

var unescaped = {
'_.editorconfig': '.editorconfig',
'_.eslintrc': '.eslintrc',
'_.gitignore': '.gitignore',
'test/_.eslintrc': 'test/.eslintrc',
'_.travis.yml': '.travis.yml',
'_package.json': 'package.json'
};

this.fs.copyTpl(this.templatePath() + '/**/!(*.png)', this.destinationPath(), tmplProps);
this.fs.copy(this.templatePath() + '/**/*.png', this.destinationPath());

Object.keys(unescaped).forEach(function (escaped) {
gen.fs.move(gen.destinationPath(escaped), gen.destinationPath(unescaped[escaped]));
});
},

install: function () {
this.installDependencies();
this.installDependencies({ bower: false });
}
});
58 changes: 58 additions & 0 deletions generators/app/templates/Gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var gulp = require('gulp');
var eslint = require('gulp-eslint');
var babel = require('gulp-babel');
var mocha = require('gulp-mocha');
var del = require('del');
var publish = require('publish-please');

gulp.task('clean', function (cb) {
del('lib', cb);
});

gulp.task('lint', function () {
return gulp
.src([
'src/**/*.js',
'test/**/*.js',
'Gulpfile.js'
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

gulp.task('build', ['clean', 'lint'], function () {
return gulp
.src('src/**/*.js')
.pipe(babel())
.pipe(gulp.dest('lib'));
});

gulp.task('test', ['build'], function () {
return gulp
.src('test/**.js')
.pipe(mocha({
ui: 'bdd',
reporter: 'spec',
timeout: typeof v8debug === 'undefined' ? 2000 : Infinity // NOTE: disable timeouts in debug
}));
});

gulp.task('preview', ['build'], function () {
var pluginTestingUtils = require('testcafe').pluginTestingUtils;
var pluginFactory = require('./lib');
var testCalls = require('./test/data/test-calls');
var plugin = pluginTestingUtils.buildReporterPlugin(pluginFactory);

console.log();

testCalls.forEach(function (call) {
plugin[call.method].apply(plugin, call.args);
});

process.exit(0);
});

gulp.task('publish', ['test'], function () {
return publish();
});
21 changes: 21 additions & 0 deletions generators/app/templates/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) <%= author %> <<%= email %>>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
37 changes: 37 additions & 0 deletions generators/app/templates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# testcafe-reporter-<%= reporterName %>
[![Build Status](https://travis-ci.org/<%= githubUsername %>/testcafe-reporter-<%= reporterName %>.svg)](https://travis-ci.org/<%= githubUsername %>/testcafe-reporter-<%= reporterName %>)

This is the **<%= reporterName %>** reporter plugin for [TestCafe](http://devexpress.github.io/testcafe).

<p align="center">
<img src="https://raw.github.com/<%= githubUsername %>/testcafe-reporter-<%= reporterName %>/master/media/preview.png" alt="preview" />
</p>

## Install

```
npm install -g testcafe-reporter-<%= reporterName %>
```

## Usage

When you run tests from the command line, specify the reporter name by using the `--reporter` option:

```
testcafe chrome 'path/to/test/file.js' --reporter <%= reporterName %>
```


When you use API, pass the reporter name to the `reporter()` method:

```js
testCafe
.createRunner()
.src('path/to/test/file.js')
.browsers('chrome')
.reporter('<%= reporterName %>') // <-
.run();
```

## Author
<%= author %> <% if (website) { %>(<%= website %>)<% } %>
15 changes: 15 additions & 0 deletions generators/app/templates/_.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

root = true

[*]
end_of_line = lf
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[{.eslintrc,*.json,.travis.yml}]
indent_size = 2
88 changes: 88 additions & 0 deletions generators/app/templates/_.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"parser": "babel-eslint",
"extends": "eslint:recommended",
"rules": {
"no-alert": 2,
"no-array-constructor": 2,
"no-caller": 2,
"no-catch-shadow": 2,
"no-console": 0,
"no-empty-label": 2,
"no-eval": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-implied-eval": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-loop-func": 2,
"no-multi-str": 2,
"no-native-reassign": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-wrappers": 2,
"no-octal-escape": 2,
"no-proto": 2,
"no-return-assign": 2,
"no-script-url": 2,
"no-sequences": 2,
"no-shadow": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-undef-init": 2,
"no-unused-expressions": 2,
"no-with": 2,
"camelcase": 2,
"comma-spacing": 2,
"consistent-return": 2,
"eqeqeq": 2,
"semi": 2,
"semi-spacing": [2, {"before": false, "after": true}],
"space-infix-ops": 2,
"space-return-throw-case": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"yoda": [2, "never"],
"brace-style": [2, "stroustrup", { "allowSingleLine": false }],
"eol-last": 2,
"indent": 2,
"key-spacing": [2, { "align": "value" }],
"max-nested-callbacks": [2, 3],
"new-parens": 2,
"newline-after-var": [2, "always"],
"no-lonely-if": 2,
"no-multiple-empty-lines": [2, { "max": 2 }],
"no-nested-ternary": 2,
"no-underscore-dangle": 0,
"no-unneeded-ternary": 2,
"object-curly-spacing": [2, "always"],
"operator-assignment": [2, "always"],
"quotes": [2, "single", "avoid-escape"],
"space-after-keywords": [2, "always"],
"space-before-blocks": [2, "always"],
"prefer-const": 2,
"no-path-concat": 2,
"no-undefined": 2,
"strict": 0,
"curly": [2, "multi-or-nest"],
"dot-notation": 0,
"no-else-return": 2,
"one-var": [2, "never"],
"no-multi-spaces": [2, {
"exceptions": {
"VariableDeclarator": true,
"AssignmentExpression": true
}
}],
"radix": 2,
"no-extra-parens": 2,
"new-cap": [2, { "capIsNew": false }],
"space-before-function-paren": [2, "always"],
"no-use-before-define" : [2, "nofunc"],
"handle-callback-err": 0
},
"env": {
"node": true
}
}
2 changes: 2 additions & 0 deletions generators/app/templates/_.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib
node_modules
6 changes: 6 additions & 0 deletions generators/app/templates/_.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: node_js
node_js:
- stable
- v4
- '0.12'
- '0.10'
Loading

0 comments on commit ed00b42

Please sign in to comment.