Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
feat: Add test filename to html report's metaInfo section
Browse files Browse the repository at this point in the history
  • Loading branch information
up73k committed Dec 29, 2016
1 parent fefd44f commit 0311f6d
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 100 deletions.
1 change: 1 addition & 0 deletions lib/reporters/html/view-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ module.exports = class ViewModel {
const suite = result.suite;
const metaInfo = suite ? suite.metaInfo : {};
metaInfo.sessionId = result.sessionId || 'unknown session id';
metaInfo.file = suite.file;

const testResult = _.assign({
suiteUrl: rootUrl + suite.url,
Expand Down
1 change: 1 addition & 0 deletions lib/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = class Suite {
this.afterActions = [];
this.browsers = [];
this.context = {};
this.file = null;
definePrivate(this);
}

Expand Down
17 changes: 10 additions & 7 deletions lib/test-reader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const _ = require('lodash');
const path = require('path');
const SetsBuilder = require('gemini-core').SetsBuilder;
const Suite = require('./suite');
const Events = require('./constants/events');
Expand All @@ -9,15 +10,17 @@ const utils = require('./utils');

const DEFAULT_DIR = require('../package').name;

const loadSuites = (sets, emitter) => {
const loadSuites = (sets, emitter, projectRoot) => {
const rootSuite = Suite.create('');

_.forEach(sets.groupByFile(), (browsers, path) => {
global.gemini = testsApi(rootSuite, browsers);
_.forEach(sets.groupByFile(), (browsers, filePath) => {
const relativeFilePath = path.relative(projectRoot, filePath);

emitter.emit(Events.BEFORE_FILE_READ, path);
utils.requireWithNoCache(path);
emitter.emit(Events.AFTER_FILE_READ, path);
global.gemini = testsApi(rootSuite, browsers, relativeFilePath);

emitter.emit(Events.BEFORE_FILE_READ, filePath);
utils.requireWithNoCache(filePath);
emitter.emit(Events.AFTER_FILE_READ, filePath);

delete global.gemini;
});
Expand All @@ -32,5 +35,5 @@ module.exports = (emitter, config, opts) => {
.useFiles(opts.paths)
.useBrowsers(opts.browsers)
.build(config.system.projectRoot, {ignore: config.system.exclude})
.then((setCollection) => loadSuites(setCollection, emitter));
.then((setCollection) => loadSuites(setCollection, emitter, config.system.projectRoot));
};
14 changes: 11 additions & 3 deletions lib/tests-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Suite = require('../suite');
const SuiteBuilder = require('./suite-builder');
const keysCodes = require('./keys-codes');

module.exports = (suite, browsers) => {
module.exports = (suite, browsers, file) => {
let suiteId = 1;
const testsAPI = keysCodes;

Expand All @@ -25,9 +25,17 @@ module.exports = (suite, browsers) => {
suite = Suite.create(name, parent);
parent.addChild(suite);
suite.id = suiteId++;
if (browsers && suite.parent.isRoot) {
suite.browsers = browsers;

if (suite.parent.isRoot) {
if (browsers) {
suite.browsers = browsers;
}

if (file) {
suite.file = file;
}
}

callback(new SuiteBuilder(suite));
if (suite.hasStates) {
if (!suite.url) {
Expand Down
38 changes: 38 additions & 0 deletions test/unit/reporters/html/view-model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

const _ = require('lodash');

const ViewModel = require('lib/reporters/html/view-model');

describe('ViewModel', () => {
const sandbox = sinon.sandbox.create();
const stubTest_ = (opts) => {
opts = opts || {};

return _.defaultsDeep(opts, {
state: {name: 'name-default'},
suite: {
path: ['suite'],
metaInfo: {sessionId: 'sessionId-default'},
file: 'default/path/file.js'
}
});
};
const getResult_ = (model) => model.getResult().suites[0].children[0].browsers[0].result;
const createViewModel_ = () =>{
const config = {forBrowser: sandbox.stub().returns({})};
return new ViewModel(config);
};

it('should contain "file" in "metaInfo"', () => {
const model = createViewModel_();

model.addSuccess(stubTest_({
suite: {file: '/path/file.js'}
}));

const metaInfo = JSON.parse(getResult_(model).metaInfo);

assert.equal(metaInfo.file, '/path/file.js');
});
});
13 changes: 13 additions & 0 deletions test/unit/test-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ describe('test-reader', () => {
);
});
});

it('should call "testsApi" with relative file path', () => {
const groupByFile = () => ({'/project/root/path/file1.js': []});

const config = mkConfigStub({
system: {projectRoot: '/project/root'}
});

SetsBuilder.prototype.build.returns(Promise.resolve({groupByFile}));

return readTests_({config})
.then(() => assert.calledWith(testsApi, sinon.match.any, sinon.match.any, 'path/file1.js'));
});
});

describe('global "gemini" variable', () => {
Expand Down
Loading

0 comments on commit 0311f6d

Please sign in to comment.