Skip to content

Commit 9eba295

Browse files
committed
--verbose flag to print configuration debugging info
Fixes #211.
1 parent 75fd5bb commit 9eba295

File tree

5 files changed

+78
-14
lines changed

5 files changed

+78
-14
lines changed

lib/command.js

+19-13
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,20 @@ function isFileArg(arg) {
7979
}
8080

8181
function parseOptions(argv, isWindows) {
82-
let files = [],
83-
helpers = [],
84-
requires = [],
85-
unknownOptions = [],
86-
usageErrors = [],
87-
color = process.stdout.isTTY || false,
88-
reporter,
89-
configPath,
90-
filter,
91-
failFast,
92-
random,
93-
seed,
94-
numWorkers = 1;
82+
let files = [];
83+
let helpers = [];
84+
let requires = [];
85+
let unknownOptions = [];
86+
let usageErrors = [];
87+
let color = process.stdout.isTTY || false;
88+
let reporter;
89+
let configPath;
90+
let filter;
91+
let failFast;
92+
let random;
93+
let seed;
94+
let numWorkers = 1;
95+
let verbose = false;
9596

9697
for (const arg of argv) {
9798
if (arg === '--no-color') {
@@ -125,6 +126,8 @@ function parseOptions(argv, isWindows) {
125126
usageErrors.push('Argument to --parallel= must be an integer greater than 1');
126127
}
127128
}
129+
} else if (arg === '--verbose') {
130+
verbose = true;
128131
} else if (arg === '--') {
129132
break;
130133
} else if (isFileArg(arg)) {
@@ -150,6 +153,7 @@ function parseOptions(argv, isWindows) {
150153
random,
151154
seed,
152155
numWorkers,
156+
verbose,
153157
usageErrors
154158
};
155159
}
@@ -168,6 +172,7 @@ async function runJasmine(Jasmine, ParallelRunner, projectBaseDir, options) {
168172
});
169173
}
170174

175+
runner.verbose(options.verbose);
171176
await runner.loadConfigFile(options.configPath || process.env.JASMINE_CONFIG_PATH);
172177

173178
if (options.failFast !== undefined) {
@@ -307,6 +312,7 @@ function help(options) {
307312
print('%s\tstop Jasmine execution on spec failure', lPad('--fail-fast', 18));
308313
print('%s\tpath to your optional jasmine.json', lPad('--config=', 18));
309314
print('%s\tpath to reporter to use instead of the default Jasmine reporter', lPad('--reporter=', 18));
315+
print('%s\tprint information that may be useful for debugging configuration', lPad('--verbose', 18));
310316
print('%s\tmarker to signal the end of options meant for Jasmine', lPad('--', 18));
311317
print('');
312318
print('The given arguments take precedence over options in your jasmine.json');

lib/jasmine.js

+4
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ class Jasmine extends RunnerBase {
205205
}
206206

207207
if (files && files.length > 0) {
208+
if (this.isVerbose_) {
209+
console.log('Overriding previous specDir and specFiles because a list of spec files was provided on the command line or as an argument to Jasmine#execute');
210+
}
211+
208212
this.specDir = '';
209213
this.specFiles = [];
210214
this.addMatchingSpecFiles(files);

lib/parallel_runner.js

+7
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ class ParallelRunner extends RunnerBase {
120120
* @return {Promise<JasmineDoneInfo>} Promise that is resolved when the suite completes.
121121
*/
122122
async execute(files, filterString) {
123+
if (this.isVerbose_) {
124+
console.log(`Running in parallel with ${this.numWorkers_} workers`);
125+
}
123126
if (this.startedExecuting_) {
124127
throw new Error('Parallel runner instance can only be executed once');
125128
}
@@ -148,6 +151,10 @@ class ParallelRunner extends RunnerBase {
148151
}
149152

150153
if (files && files.length > 0) {
154+
if (this.isVerbose_) {
155+
console.log('Overriding previous specDir and specFiles because a list of spec files was provided on the command line or as an argument to ParallelRunner#execute');
156+
}
157+
151158
this.specDir = '';
152159
this.specFiles = [];
153160
this.addMatchingSpecFiles(files);

lib/runner_base.js

+35-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ class RunnerBase {
5454
this.showingColors = value;
5555
}
5656

57+
/**
58+
* Sets whether to run in verbose mode, which prints information that may
59+
* be useful for debugging configuration problems.
60+
* @function
61+
* @name Runner#verbose
62+
* @param {boolean} value Whether to run in verbose mode
63+
*/
64+
verbose(isVerbose) {
65+
this.isVerbose_ = isVerbose;
66+
}
67+
5768
/**
5869
* Sets whether the console reporter should list pending specs even when there
5970
* are failures.
@@ -79,21 +90,34 @@ class RunnerBase {
7990
* @return Promise
8091
*/
8192
async loadConfigFile(configFilePath) {
93+
if (this.isVerbose_) {
94+
console.log(`Project base dir: ${this.projectBaseDir}`);
95+
}
96+
8297
if (configFilePath) {
98+
if (this.isVerbose_) {
99+
console.log(`Loading config file ${configFilePath} because it was explicitly specified`);
100+
}
83101
await this.loadSpecificConfigFile_(configFilePath);
84102
} else {
85103
let numFound = 0;
86104

87105
for (const ext of ['json', 'js']) {
106+
const candidate = `spec/support/jasmine.${ext}`;
107+
88108
try {
89-
await this.loadSpecificConfigFile_(`spec/support/jasmine.${ext}`);
109+
await this.loadSpecificConfigFile_(candidate);
90110
numFound++;
91111
} catch (e) {
92112
if (e.code !== 'MODULE_NOT_FOUND' // CommonJS
93113
&& e.code !== 'ERR_MODULE_NOT_FOUND' // ESM
94114
&& e.code !== 'ENOENT') { // Testdouble.js, maybe other ESM loaders too
95115
throw e;
96116
}
117+
118+
if (this.isVerbose_) {
119+
console.log(`Tried to load config file ${candidate} but it does not exist (${e.code})`);
120+
}
97121
}
98122
}
99123

@@ -104,13 +128,18 @@ class RunnerBase {
104128
'config files. In a future version, only the first file found ' +
105129
'will be loaded.'
106130
);
131+
} else if (numFound === 0 && this.isVerbose_) {
132+
console.log('Did not find any config files.');
107133
}
108134
}
109135
}
110136

111137
async loadSpecificConfigFile_(relativePath) {
112138
const absolutePath = path.resolve(this.projectBaseDir, relativePath);
113139
const config = await this.loader.load(absolutePath);
140+
if (this.isVerbose_) {
141+
console.log(`Loaded config file ${absolutePath}`);
142+
}
114143
this.loadConfig(config);
115144
}
116145

@@ -510,6 +539,11 @@ function addFiles(kind) {
510539
fileArr.push(filePath);
511540
});
512541
});
542+
543+
if (this.isVerbose_) {
544+
console.log(`File glob for ${kind}: ${files}`);
545+
console.log(`Resulting ${kind}: [${fileArr}]`);
546+
}
513547
};
514548
}
515549

spec/command_spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ describe('command', function() {
5656
'loadConfigFile',
5757
'execute',
5858
'showColors',
59+
'verbose',
5960
'coreVersion',
6061
'clearReporters',
6162
'addReporter',
@@ -266,6 +267,18 @@ describe('command', function() {
266267
}.bind(this));
267268
});
268269

270+
it('does not enable verbose mode by default', async function() {
271+
await this.run(['node', 'bin/jasmine.js']);
272+
expect(this.runner.verbose).toHaveBeenCalledWith(false);
273+
expect(this.runner.verbose).toHaveBeenCalledBefore(this.runner.loadConfigFile);
274+
});
275+
276+
it('can enable verbose mode', async function() {
277+
await this.run(['node', 'bin/jasmine.js', '--verbose']);
278+
expect(this.runner.verbose).toHaveBeenCalledWith(true);
279+
expect(this.runner.verbose).toHaveBeenCalledBefore(this.runner.loadConfigFile);
280+
});
281+
269282
it('should execute the jasmine suite', async function () {
270283
await this.run(['node', 'bin/jasmine.js']);
271284
expect(this.runner.execute).toHaveBeenCalled();

0 commit comments

Comments
 (0)