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

Commit 66f2aa6

Browse files
committed
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
1 parent 13a57eb commit 66f2aa6

3 files changed

Lines changed: 16 additions & 15 deletions

File tree

lib/config/options.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ module.exports = root(
3030
sourceRoot: option({
3131
validate: is('string'),
3232
map: resolveWithProjectRoot,
33-
defaultValue: function(config) {
34-
return config.system.projectRoot;
35-
}
33+
defaultValue: (config) => config.system.projectRoot
3634
}),
3735

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

4947
diffColor: option({
5048
defaultValue: '#ff00ff',
51-
validate: function(value) {
49+
validate: (value) => {
5250
if (typeof value !== 'string') {
5351
throw new GeminiError('Field "diffColor" must be string');
5452
}
@@ -73,7 +71,7 @@ module.exports = root(
7371
}),
7472
exclude: option({
7573
defaultValue: [],
76-
validate: function(value) {
74+
validate: (value) => {
7775
if (!_.isArray(value)) {
7876
throw new GeminiError('"coverage.exclude" must be an array');
7977
}
@@ -88,7 +86,7 @@ module.exports = root(
8886

8987
exclude: option({
9088
defaultValue: [],
91-
validate: function(value) {
89+
validate: (value) => {
9290
if (_.isString(value)) {
9391
return;
9492
}
@@ -98,7 +96,9 @@ module.exports = root(
9896
}
9997
},
10098
map: (value) => [].concat(value)
101-
})
99+
}),
100+
101+
ctx: anyObject()
102102
}),
103103

104104
sets: coreOptions.sets,

lib/test-reader.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const _ = require('lodash');
4-
const path = require('path');
54
const SetsBuilder = require('gemini-core').SetsBuilder;
65
const Suite = require('./suite');
76
const Events = require('./constants/events');
@@ -10,13 +9,11 @@ const utils = require('./utils');
109

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

13-
const loadSuites = (sets, emitter, projectRoot) => {
12+
const loadSuites = (sets, emitter, config) => {
1413
const rootSuite = Suite.create('');
1514

1615
_.forEach(sets.groupByFile(), (browsers, filePath) => {
17-
const relativeFilePath = path.relative(projectRoot, filePath);
18-
19-
global.gemini = testsApi(rootSuite, browsers, relativeFilePath);
16+
global.gemini = testsApi(rootSuite, browsers, filePath, config);
2017

2118
emitter.emit(Events.BEFORE_FILE_READ, filePath);
2219
utils.requireWithNoCache(filePath);
@@ -35,5 +32,5 @@ module.exports = (emitter, config, opts) => {
3532
.useFiles(opts.paths)
3633
.useBrowsers(opts.browsers)
3734
.build(config.system.projectRoot, {ignore: config.system.exclude})
38-
.then((setCollection) => loadSuites(setCollection, emitter, config.system.projectRoot));
35+
.then((setCollection) => loadSuites(setCollection, emitter, config));
3936
};

lib/tests-api/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
'use strict';
22

3+
const path = require('path');
4+
const _ = require('lodash');
35
const Suite = require('../suite');
46
const SuiteBuilder = require('./suite-builder');
57
const keysCodes = require('./keys-codes');
68

7-
module.exports = (suite, browsers, file) => {
9+
module.exports = (suite, browsers, file, config) => {
810
let suiteId = 1;
911
const testsAPI = keysCodes;
1012

@@ -32,7 +34,7 @@ module.exports = (suite, browsers, file) => {
3234
}
3335

3436
if (file) {
35-
suite.file = file;
37+
suite.file = path.relative(config.system.projectRoot, file);
3638
}
3739
}
3840

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

58+
testsAPI.ctx = _.clone(config.system.ctx);
59+
5660
return testsAPI;
5761
};

0 commit comments

Comments
 (0)