'use strict';
const path = require('path');
+const { name: packageName, version: packageVersion } = require('../package');
+
+const libraryIdentifier = `${packageName}@${packageVersion}`;
/**
* Return a function which combines a part of the filename with a scope, for use in logging.
* @param {string} filename
*/
const fileScope = (filename) => {
- let fScope = path.basename(filename, '.js');
- if (fScope === 'index') {
- fScope = path.basename(path.dirname(filename));
- }
- return (scope) => `${fScope}:${scope}`;
+ const shortFilename = path.basename(filename, '.js');
+ const fScope = (shortFilename === 'index') ? path.basename(path.dirname(filename)) : shortFilename;
+ return (scope) => [libraryIdentifier, fScope, scope].join(':');
}
it('names a file path', function () {
const filename = 'lib/foo/bar.js';
const result = common.fileScope(filename)('baz');
- assert.strictEqual(result, 'bar:baz');
+ assert(result.endsWith(':bar:baz'));
});
it('names an index path', function () {
const filename = 'lib/foo/index.js';
const result = common.fileScope(filename)('baz');
- assert.strictEqual(result, 'foo:baz');
+ assert(result.endsWith(':foo:baz'));
});
}); // fileScope