From 66f2aa6a3da83ed970194fca2e40fadfed278911 Mon Sep 17 00:00:00 2001 From: egavr Date: Fri, 20 Jan 2017 17:33:52 +0300 Subject: [PATCH] feat: add method 'gemini.ctx' to tests API Method returns the context which is defined in 'ctx' field of the system settings in the config --- lib/config/options.js | 14 +++++++------- lib/test-reader.js | 9 +++------ lib/tests-api/index.js | 8 ++++++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/config/options.js b/lib/config/options.js index 56a4d0864..889062f7d 100644 --- a/lib/config/options.js +++ b/lib/config/options.js @@ -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({ @@ -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'); } @@ -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'); } @@ -88,7 +86,7 @@ module.exports = root( exclude: option({ defaultValue: [], - validate: function(value) { + validate: (value) => { if (_.isString(value)) { return; } @@ -98,7 +96,9 @@ module.exports = root( } }, map: (value) => [].concat(value) - }) + }), + + ctx: anyObject() }), sets: coreOptions.sets, diff --git a/lib/test-reader.js b/lib/test-reader.js index ddeba9f59..8e8a933a5 100644 --- a/lib/test-reader.js +++ b/lib/test-reader.js @@ -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'); @@ -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); @@ -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)); }; diff --git a/lib/tests-api/index.js b/lib/tests-api/index.js index c8b59b539..302b8beb7 100644 --- a/lib/tests-api/index.js +++ b/lib/tests-api/index.js @@ -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; @@ -32,7 +34,7 @@ module.exports = (suite, browsers, file) => { } if (file) { - suite.file = file; + suite.file = path.relative(config.system.projectRoot, file); } } @@ -53,5 +55,7 @@ module.exports = (suite, browsers, file) => { suite = suite.parent; }; + testsAPI.ctx = _.clone(config.system.ctx); + return testsAPI; };