Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Commit

Permalink
Merge dabe58f into 5f42912
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedseyfi committed Jan 9, 2019
2 parents 5f42912 + dabe58f commit 2dacd2f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/hooks.js
Expand Up @@ -72,7 +72,9 @@ exports.chpwd = function(/*dir, [versionFile], [options]*/) {

return Promise.bind({})
.then(function() { return fs.readFile(path.join(dir, file), 'utf8'); })
.then(function(version) { this.version = version.trim(); })
.then(function(fileContent) {
this.version = fileContent.split('\n')[0].trim();
})
.then(function() { return match(this.version); })
.then(function(result) {
process.stdout.write(fmt.success(this.version, result, via));
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/multiline-version/.node-version
@@ -0,0 +1,2 @@
0.11.13
# SOME COMMENT
11 changes: 11 additions & 0 deletions test/hooks.js
Expand Up @@ -80,6 +80,17 @@ describe('avn', function() {
});
});

it('reads only the first line of version file', function() {
var std = capture();
setupExample('multiline-version');
return avn.hooks.chpwd(cwd, '.node-version').finally(std.restore).then(function() {
expect(plugin.match).to.have.been.calledWith('0.11.13');
expect(std.err).to.be.empty;
expect(std.out).to.eql('avn activated 0.11.13 (test v0.11.13)\n');
expect(std.cmd).to.eql('node-version-tool activate 0.11.13\n');
});
});

it('fails if plugin returns undefined', function() {
var std = capture();
plugin = { name: 'test', match: function() {} };
Expand Down

0 comments on commit 2dacd2f

Please sign in to comment.