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

Commit

Permalink
feat: add method 'gemini.ctx' to tests API
Browse files Browse the repository at this point in the history
Method returns the context which is defined in 'ctx' field of the system settings in the config
  • Loading branch information
eGavr committed Jan 20, 2017
1 parent 13a57eb commit 66f2aa6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
14 changes: 7 additions & 7 deletions lib/config/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ module.exports = root(
sourceRoot: option({
validate: is('string'),
map: resolveWithProjectRoot,
defaultValue: function(config) {
return config.system.projectRoot;
}
defaultValue: (config) => config.system.projectRoot
}),

tempDir: option({
Expand All @@ -48,7 +46,7 @@ module.exports = root(

diffColor: option({
defaultValue: '#ff00ff',
validate: function(value) {
validate: (value) => {
if (typeof value !== 'string') {
throw new GeminiError('Field "diffColor" must be string');
}
Expand All @@ -73,7 +71,7 @@ module.exports = root(
}),
exclude: option({
defaultValue: [],
validate: function(value) {
validate: (value) => {
if (!_.isArray(value)) {
throw new GeminiError('"coverage.exclude" must be an array');
}
Expand All @@ -88,7 +86,7 @@ module.exports = root(

exclude: option({
defaultValue: [],
validate: function(value) {
validate: (value) => {
if (_.isString(value)) {
return;
}
Expand All @@ -98,7 +96,9 @@ module.exports = root(
}
},
map: (value) => [].concat(value)
})
}),

ctx: anyObject()
}),

sets: coreOptions.sets,
Expand Down
9 changes: 3 additions & 6 deletions lib/test-reader.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'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 @@ -10,13 +9,11 @@ const utils = require('./utils');

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

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

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

global.gemini = testsApi(rootSuite, browsers, relativeFilePath);
global.gemini = testsApi(rootSuite, browsers, filePath, config);

emitter.emit(Events.BEFORE_FILE_READ, filePath);
utils.requireWithNoCache(filePath);
Expand All @@ -35,5 +32,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, config.system.projectRoot));
.then((setCollection) => loadSuites(setCollection, emitter, config));
};
8 changes: 6 additions & 2 deletions lib/tests-api/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
'use strict';

const path = require('path');
const _ = require('lodash');
const Suite = require('../suite');
const SuiteBuilder = require('./suite-builder');
const keysCodes = require('./keys-codes');

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

Expand Down Expand Up @@ -32,7 +34,7 @@ module.exports = (suite, browsers, file) => {
}

if (file) {
suite.file = file;
suite.file = path.relative(config.system.projectRoot, file);
}
}

Expand All @@ -53,5 +55,7 @@ module.exports = (suite, browsers, file) => {
suite = suite.parent;
};

testsAPI.ctx = _.clone(config.system.ctx);

return testsAPI;
};

0 comments on commit 66f2aa6

Please sign in to comment.