Skip to content

Commit

Permalink
lib: log correct version and sha for -c option (#1026)
Browse files Browse the repository at this point in the history
When using the -c option to supply a specific sha to test CITGM will
erroneously log the latest version of the module. This commit overrides
the incorrect value with the one that is in the downloaded package.json.
Additionally, when supplying -c CITGM will now output the sha for easier
debugging.
  • Loading branch information
BethGriggs committed Nov 14, 2023
1 parent 9c19fe2 commit 18cf7df
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
3 changes: 3 additions & 0 deletions lib/citgm.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ export class Tester extends EventEmitter {
flaky: this.module.flaky,
expectFail: this.module.expectFail
};

if (this.options.sha) payload.sha = this.module.sha;

if (err) {
if (!payload.expectFail) {
this.emit('fail', err);
Expand Down
13 changes: 5 additions & 8 deletions lib/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ export function lookup(context) {
context.module.ref = ref;
} else {
const gitHead = rep.head || rep.ignoreGitHead ? null : meta.gitHead;
const sha = context.options.sha || rep.sha || gitHead;
const url = makeUrl(
getRepo(rep.repo, meta),
rep.head ? null : detail.fetchSpec,
meta['dist-tags'],
rep.head ? null : rep.prefix,
context.options.sha || rep.sha || gitHead
sha
);
context.emit(
'data',
Expand Down Expand Up @@ -197,16 +198,12 @@ export function lookup(context) {
: defaultMatcher.isMatch(rep.expectFail);
} else {
context.emit('data', 'info', 'lookup-notfound', detail.name);
const sha = context.options.sha || meta.gitHead;
if (meta.gitHead) {
const url = makeUrl(
getRepo(null, meta),
null,
null,
null,
context.options.sha || meta.gitHead
);
const url = makeUrl(getRepo(null, meta), null, null, null, sha);
context.emit('data', 'info', 'lookup-githead', url);
context.module.raw = url;
context.module.sha = sha;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/package-manager/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export async function test(packageManager, context) {
let data;
try {
data = await readPackage(join(wd, 'package.json'), false);
// Explicitly set the version to the value in the downloaded package.json.
context.module.version = data.version;
} catch (err) {
throw new Error('Package.json Could not be found');
}
Expand Down
2 changes: 2 additions & 0 deletions lib/reporter/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ function logModule(log, logType, module) {
log[logType](chalk.yellow('module name:'), module.name);
if (!module.skipped) {
log[logType](chalk.yellow('version:'), module.version);

if (module.sha) log[logType](chalk.yellow('sha:'), module.sha);
}
if (module.error) {
if (!module.testOutput) module.testOutput = '';
Expand Down

0 comments on commit 18cf7df

Please sign in to comment.