Skip to content

Commit 0cf79dc

Browse files
authored
Merge pull request #18 from pkgjs/fix-16
Return results when no .travis.yml in the repo
2 parents 747adfe + 61282ae commit 0cf79dc

File tree

3 files changed

+81
-8
lines changed

3 files changed

+81
-8
lines changed

lib/loader.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ internals.createRepositoryLoader = (repository) => {
9494
catch (err) {
9595

9696
if (err.output && err.output.statusCode === 404) {
97-
throw new Error(`${repository} does not contain a ${filename}`);
97+
const error = new Error(`${repository} does not contain a ${filename}`);
98+
error.code = 'ENOENT';
99+
throw error;
98100
}
99101

100102
throw err;
@@ -126,10 +128,6 @@ internals.createPathLoader = async (path) => {
126128

127129
const fullPath = Path.join(path, filename);
128130

129-
if (!Fs.existsSync(fullPath)) {
130-
return;
131-
}
132-
133131
const buffer = Fs.readFileSync(fullPath);
134132

135133
if (options.json) {

lib/travis.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,16 @@ internals.scan = async (travisYaml) => {
7878

7979
exports.detect = async ({ loadFile }) => {
8080

81-
const buffer = await loadFile('.travis.yml');
81+
try {
82+
var buffer = await loadFile('.travis.yml');
83+
}
84+
catch (err) {
85+
86+
if (err.code === 'ENOENT') {
87+
return;
88+
}
8289

83-
if (buffer === undefined) {
84-
return;
90+
throw err;
8591
}
8692

8793
const travisYaml = Yaml.safeLoad(buffer, { schema: Yaml.FAILSAFE_SCHEMA });

test/index.js

+69
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,46 @@ describe('detect-node-support', () => {
500500
});
501501
});
502502

503+
it('leaves out `travis` when no `.travis.yml` present', async () => {
504+
505+
listRemoteStub
506+
.returns('9cef39d21ad229dea4b10295f55b0d9a83800b23\tHEAD\n');
507+
508+
Nock('https://raw.githubusercontent.com')
509+
.get('/pkgjs/detect-node-support/HEAD/package.json')
510+
.reply(200, Fs.readFileSync(Path.join(__dirname, '..', 'package.json')))
511+
.get('/pkgjs/detect-node-support/HEAD/.travis.yml')
512+
.reply(404);
513+
514+
const result = await NodeSupport.detect({ repository: 'git+https://github.com/pkgjs/detect-node-support.git' });
515+
516+
expect(listRemoteStub.callCount).to.equal(1);
517+
expect(listRemoteStub.args[0]).to.equal([['http://github.com/pkgjs/detect-node-support.git', 'HEAD']]);
518+
519+
expect(result).to.equal({
520+
name: 'detect-node-support',
521+
version: '0.0.0-development',
522+
commit: '9cef39d21ad229dea4b10295f55b0d9a83800b23',
523+
timestamp: 1580673602000,
524+
engines: '>=10'
525+
});
526+
});
527+
528+
it('throws when loading `.travis.yml` fails', async () => {
529+
530+
listRemoteStub
531+
.returns('9cef39d21ad229dea4b10295f55b0d9a83800b23\tHEAD\n');
532+
533+
Nock('https://raw.githubusercontent.com')
534+
.get('/pkgjs/detect-node-support/HEAD/package.json')
535+
.reply(200, Fs.readFileSync(Path.join(__dirname, '..', 'package.json')))
536+
.get('/pkgjs/detect-node-support/HEAD/.travis.yml')
537+
.reply(500);
538+
539+
await expect(NodeSupport.detect({ repository: 'git+https://github.com/pkgjs/detect-node-support.git' }))
540+
.to.reject('Response Error: 500 null'); // the null is a Nock/Wreck implementation detail
541+
});
542+
503543
it('throws when repository does not have a package.json', async () => {
504544

505545
listRemoteStub
@@ -583,6 +623,35 @@ describe('detect-node-support', () => {
583623
});
584624
});
585625

626+
it('leaves out `travis` when no `.travis.yml` present', async () => {
627+
628+
listRemoteStub
629+
.returns('9cef39d21ad229dea4b10295f55b0d9a83800b23\tHEAD\n');
630+
631+
Nock('https://raw.githubusercontent.com')
632+
.get('/pkgjs/detect-node-support/HEAD/package.json')
633+
.reply(200, Fs.readFileSync(Path.join(__dirname, '..', 'package.json')))
634+
.get('/pkgjs/detect-node-support/HEAD/.travis.yml')
635+
.reply(404);
636+
637+
Nock('https://registry.npmjs.org')
638+
.get('/detect-node-support')
639+
.reply(200, Fs.readFileSync(Path.join(__dirname, '..', 'package.json')));
640+
641+
const result = await NodeSupport.detect({ packageName: 'detect-node-support' });
642+
643+
expect(listRemoteStub.callCount).to.equal(1);
644+
expect(listRemoteStub.args[0]).to.equal([['http://github.com/pkgjs/detect-node-support.git', 'HEAD']]);
645+
646+
expect(result).to.equal({
647+
name: 'detect-node-support',
648+
version: '0.0.0-development',
649+
commit: '9cef39d21ad229dea4b10295f55b0d9a83800b23',
650+
timestamp: 1580673602000,
651+
engines: '>=10'
652+
});
653+
});
654+
586655
it('throws when package does not exist in the registry', async () => {
587656

588657
Nock('https://registry.npmjs.org')

0 commit comments

Comments
 (0)