Skip to content

Commit b3f7960

Browse files
committed
feat: throw when no package.json in path
1 parent ceb1f05 commit b3f7960

File tree

6 files changed

+25
-8
lines changed

6 files changed

+25
-8
lines changed

lib/loader.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ internals.createPathLoader = async (path) => {
6262
throw new Error(`${path} is not a git repository`);
6363
}
6464

65+
if (!Fs.existsSync(Path.join(path, 'package.json'))) {
66+
throw new Error(`${path} does not contain a package.json`);
67+
}
68+
6569
return {
6670
getCommit: () => {
6771

File renamed without changes.
File renamed without changes.

test/index.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ internals.prepareFixture = async ({ travisYml, packageJson, git = true } = {}) =
3030
Fs.copyFileSync(Path.join(__dirname, 'fixtures', travisYml), Path.join(tmpObj.name, '.travis.yml'));
3131
}
3232

33-
Fs.writeFileSync(Path.join(tmpObj.name, 'package.json'), JSON.stringify(packageJson || {
34-
name: 'test-module',
35-
version: '0.0.0-development'
36-
}));
33+
if (packageJson !== false) {
34+
Fs.writeFileSync(Path.join(tmpObj.name, 'package.json'), JSON.stringify(packageJson || {
35+
name: 'test-module',
36+
version: '0.0.0-development'
37+
}));
38+
}
3739

3840
if (git) {
3941
const simpleGit = SimpleGit(tmpObj.name);
@@ -125,7 +127,7 @@ describe('node-support', () => {
125127
it('returns the single node version', async () => {
126128

127129
const path = await internals.prepareFixture({
128-
travisYml: '_single-version.yml'
130+
travisYml: 'testing-single-version.yml'
129131
});
130132

131133
const result = await NodeSupport.detect({ path });
@@ -145,7 +147,7 @@ describe('node-support', () => {
145147
it('returns default node version', async () => {
146148

147149
const path = await internals.prepareFixture({
148-
travisYml: '_minimal.yml'
150+
travisYml: 'testing-minimal.yml'
149151
});
150152

151153
const result = await NodeSupport.detect({ path });
@@ -165,7 +167,7 @@ describe('node-support', () => {
165167
it('returns empty array when no node detected', async () => {
166168

167169
const path = await internals.prepareFixture({
168-
travisYml: '_no-node.yml'
170+
travisYml: 'testing-no-node.yml'
169171
});
170172

171173
const result = await NodeSupport.detect({ path });
@@ -325,7 +327,7 @@ describe('node-support', () => {
325327
it('handles missing env.matrix', async () => {
326328

327329
const path = await internals.prepareFixture({
328-
travisYml: '_no-env-matrix.yml'
330+
travisYml: 'testing-no-env-matrix.yml'
329331
});
330332

331333
const result = await NodeSupport.detect({ path });
@@ -349,6 +351,17 @@ describe('node-support', () => {
349351
await expect(NodeSupport.detect({ path }))
350352
.to.reject(`${path} is not a git repository`);
351353
});
354+
355+
it('throws when path does not have a package.json', async () => {
356+
357+
const path = await internals.prepareFixture({
358+
travisYml: 'testing-no-node.yml',
359+
packageJson: false
360+
});
361+
362+
await expect(NodeSupport.detect({ path }))
363+
.to.reject(`${path} does not contain a package.json`);
364+
});
352365
});
353366

354367
describe('repository', () => {

0 commit comments

Comments
 (0)