Skip to content

Commit

Permalink
feat: remove Gemini support
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
Migrate your Gemini test to Hermine or use html-reporter@4.
  • Loading branch information
CatWithApple committed Oct 8, 2019
1 parent e96a8c0 commit 90e88eb
Show file tree
Hide file tree
Showing 50 changed files with 786 additions and 1,877 deletions.
40 changes: 5 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# html-reporter

Plugin for [gemini](https://github.com/gemini-testing/gemini) and [hermione](https://github.com/gemini-testing/hermione) which is intended to aggregate the results of tests running into html report.
Plugin for [hermione](https://github.com/gemini-testing/hermione) which is intended to aggregate the results of tests running into html report.

You can read more about gemini plugins [here](https://github.com/gemini-testing/gemini/blob/master/doc/plugins.md) and about hermione plugins [here](https://github.com/gemini-testing/hermione#plugins).
You can read more about hermione plugins [here](https://github.com/gemini-testing/hermione#plugins).

## Installation

Expand All @@ -18,7 +18,7 @@ Plugin has following configuration:

* **enabled** (optional) `Boolean` – enable/disable the plugin; by default plugin is enabled
* **path** (optional) `String` - path to directory for saving html report file; by
default html report will be saved into `gemini-report/index.html` inside current work
default html report will be saved into `hermione-report/index.html` inside current work
directory.
* **saveErrorDetails** (optional) `Boolean` – save/don't save error details to json-files (to error-details folder); `false` by default.

Expand Down Expand Up @@ -48,40 +48,10 @@ Use `html_reporter_` prefix for the environment variables and `--html-reporter-`

For example you can override `path` option like so:
```bash
$ html_reporter_path=custom/dir gemini test
$ gemini test --html-reporter-path custom/dir
$ html_reporter_path=custom/dir hermione test
$ hermione test --html-reporter-path custom/dir
```

### Gemini Usage

Add plugin to your `gemini` config file:

```js
module.exports = {
// ...
system: {
plugins: {
'html-reporter/gemini': {
enabled: true,
path: 'my/gemini-reports',
defaultView: 'all',
baseHost: 'test.com',
errorPatterns: [
'Parameter .* must be a string',
{
name: 'Cannot read property of undefined',
pattern: 'Cannot read property .* of undefined'
}
]
}
}
},
//...
}
```

### Hermione Usage

Add plugin to your `hermione` config file:

```js
Expand Down
77 changes: 2 additions & 75 deletions gemini.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,5 @@
'use strict';

const Promise = require('bluebird');
const PluginAdapter = require('./lib/plugin-adapter');
const utils = require('./lib/server-utils');

module.exports = (gemini, opts) => {
const plugin = PluginAdapter.create(gemini, opts, 'gemini');

if (!plugin.isEnabled()) {
return;
}

plugin
.addApi()
.addCliCommands()
.init(prepareData, prepareImages);
module.exports = () => {
throw new Error('html-reporter: Gemini support is removed. Migrate your Gemini test to Hermione (https://github.com/gemini-testing/hermione) or use html-reporter@4');
};

function prepareData(gemini, reportBuilder) {
return new Promise((resolve) => {
gemini.on(gemini.events.SKIP_STATE, (result) => reportBuilder.addSkipped(result));

gemini.on(gemini.events.TEST_RESULT, (result) => {
return result.equal ? reportBuilder.addSuccess(result) : reportBuilder.addFail(result);
});

gemini.on(gemini.events.UPDATE_RESULT, (result) => reportBuilder.addSuccess(result));

gemini.on(gemini.events.RETRY, (result) => reportBuilder.addRetry(result));

gemini.on(gemini.events.ERROR, (result) => reportBuilder.addError(result));

gemini.on(gemini.events.END, (stats) => resolve(
reportBuilder
.setStats(stats)
.setApiValues(gemini.htmlReporter.values)
));
});
}

function prepareImages(gemini, reportBuilder, pluginConfig) {
const {path: reportPath} = pluginConfig;

function handleErrorEvent(result) {
const src = result.getCurrImg().path || result.getErrImg().path;

return src && utils.copyImageAsync(src, utils.getCurrentAbsolutePath(result, reportPath));
}

return new Promise((resolve, reject) => {
let queue = Promise.resolve();

gemini.on(gemini.events.ERROR, (testResult) => {
queue = queue.then(() => handleErrorEvent(reportBuilder.format(testResult)));
});

gemini.on(gemini.events.RETRY, (testResult) => {
const formattedResult = reportBuilder.format(testResult);

queue = queue.then(() => {
return formattedResult.hasDiff()
? formattedResult.saveTestImages(reportPath)
: handleErrorEvent(formattedResult);
});
});

gemini.on(gemini.events.TEST_RESULT, (testResult) => {
queue = queue.then(() => reportBuilder.format(testResult).saveTestImages(reportPath));
});

gemini.on(gemini.events.UPDATE_RESULT, (testResult) => {
queue = queue.then(() => reportBuilder.format(testResult).saveTestImages(reportPath));
});

gemini.on(gemini.events.END, () => queue.then(resolve, reject));
});
}
6 changes: 3 additions & 3 deletions hermione.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const os = require('os');
const PQueue = require('p-queue');

const PluginAdapter = require('./lib/plugin-adapter');
const createHermioneWorkers = require('./lib/workers/create-hermione-workers');
const createWorkers = require('./lib/workers/create-workers');

let workers;

module.exports = (hermione, opts) => {
const plugin = PluginAdapter.create(hermione, opts, 'hermione');
const plugin = PluginAdapter.create(hermione, opts);

if (!plugin.isEnabled()) {
return;
Expand All @@ -21,7 +21,7 @@ module.exports = (hermione, opts) => {
.init(prepare);

hermione.on(hermione.events.RUNNER_START, (runner) => {
workers = createHermioneWorkers(runner);
workers = createWorkers(runner);
});
};

Expand Down
6 changes: 3 additions & 3 deletions lib/cli-commands/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const runGui = require('../gui');
const Api = require('../gui/api');
const {GUI: commandName} = require('./');

module.exports = (program, pluginConfig, tool) => {
module.exports = (program, pluginConfig, hermione) => {
// must be executed here because it adds `gui` field in `gemini` and `hermione tool`,
// which is available to other plugins and is an API for interacting with the current plugin
const guiApi = Api.create(tool);
const guiApi = Api.create(hermione);

program
.command(`${commandName} [paths...]`)
Expand All @@ -18,6 +18,6 @@ module.exports = (program, pluginConfig, tool) => {
.option('-a, --auto-run', 'auto run immediately')
.option('-O, --no-open', 'not to open a browser window after starting the server')
.action((paths, options) => {
runGui({paths, tool, guiApi, configs: {options, program, pluginConfig}});
runGui({paths, hermione, guiApi, configs: {options, program, pluginConfig}});
});
};
8 changes: 4 additions & 4 deletions lib/gui/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
const ApiFacade = require('./facade');

module.exports = class Api {
static create(tool) {
return new Api(tool);
static create(hermione) {
return new Api(hermione);
}

constructor(tool) {
this._gui = tool.gui = ApiFacade.create();
constructor(hermione) {
this._gui = hermione.gui = ApiFacade.create();
}

initServer(server) {
Expand Down
30 changes: 15 additions & 15 deletions lib/gui/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path');
const _ = require('lodash');
const looksSame = require('looks-same');
const Promise = require('bluebird');
const ToolRunnerFactory = require('./tool-runner-factory');
const ToolRunner = require('./tool-runner');

const lookSameAsync = (img1, img2, opts) => {
return new Promise((resolve, reject) => {
Expand All @@ -15,55 +15,55 @@ const lookSameAsync = (img1, img2, opts) => {
};

module.exports = class App {
static create(paths, tool, configs) {
return new this(paths, tool, configs);
static create(paths, hermione, configs) {
return new this(paths, hermione, configs);
}

constructor(paths, tool, configs) {
const {program, pluginConfig} = configs;
constructor(paths, hermione, configs) {
const {pluginConfig} = configs;

this._tool = ToolRunnerFactory.create(program.name(), paths, tool, configs);
this._toolRunner = ToolRunner.create(paths, hermione, configs);
this._pluginConfig = pluginConfig;

this._browserConfigs = [];
this._retryCache = {};
}

initialize() {
return this._tool.initialize();
return this._toolRunner.initialize();
}

finalize() {
this._tool.finalize();
this._toolRunner.finalize();
}

run(tests) {
return _.isEmpty(tests)
? this._tool.run()
? this._toolRunner.run()
: this._runWithoutRetries(tests);
}

_runWithoutRetries(tests) {
if (_.isEmpty(this._browserConfigs)) {
this._browserConfigs = _.map(this._tool.config.getBrowserIds(), (id) => this._tool.config.forBrowser(id));
this._browserConfigs = _.map(this._toolRunner.config.getBrowserIds(), (id) => this._toolRunner.config.forBrowser(id));
}

this._disableRetries();

return this._tool.run(tests)
return this._toolRunner.run(tests)
.finally(() => this._restoreRetries());
}

updateReferenceImage(failedTests = []) {
return this._tool.updateReferenceImage(failedTests);
return this._toolRunner.updateReferenceImage(failedTests);
}

_resolveImgPath(imgPath) {
return path.resolve(process.cwd(), this._pluginConfig.path, imgPath);
}

_getCompareOpts() {
const {tolerance, antialiasingTolerance} = this._tool.config;
const {tolerance, antialiasingTolerance} = this._toolRunner.config;

return {tolerance, antialiasingTolerance, stopOnFirstFail: true, shouldCluster: false};
}
Expand Down Expand Up @@ -104,11 +104,11 @@ module.exports = class App {
}

addClient(connection) {
this._tool.addClient(connection);
this._toolRunner.addClient(connection);
}

get data() {
return this._tool.tree;
return this._toolRunner.tree;
}

_disableRetries() {
Expand Down
4 changes: 2 additions & 2 deletions lib/gui/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const {MAX_REQUEST_SIZE, KEEP_ALIVE_TIMEOUT, HEADERS_TIMEOUT} = require('./const
const {IMAGES_PATH, ERROR_DETAILS_PATH} = require('../constants/paths');
const {logger} = require('../server-utils');

exports.start = ({paths, tool, guiApi, configs}) => {
exports.start = ({paths, hermione, guiApi, configs}) => {
const {options, pluginConfig} = configs;
const app = App.create(paths, tool, configs);
const app = App.create(paths, hermione, configs);
const server = express();

server.use(bodyParser.json({limit: MAX_REQUEST_SIZE}));
Expand Down
Loading

0 comments on commit 90e88eb

Please sign in to comment.