test: Verify Error instance type and SemanticReleaseError name
				
					
				
			This commit is contained in:
		
							parent
							
								
									2491032a99
								
							
						
					
					
						commit
						8371a03da0
					
				| @ -1,6 +1,5 @@ | |||||||
| import test from 'ava'; | import test from 'ava'; | ||||||
| import {stub} from 'sinon'; | import {stub} from 'sinon'; | ||||||
| import SemanticReleaseError from '@semantic-release/error'; |  | ||||||
| import getCommits from '../lib/get-commits'; | import getCommits from '../lib/get-commits'; | ||||||
| import { | import { | ||||||
|   gitRepo, |   gitRepo, | ||||||
| @ -409,7 +408,7 @@ test.serial('Throws ENOGITHEAD error if the gitHead of the last release cannot b | |||||||
| 
 | 
 | ||||||
|   // Verify error code and type
 |   // Verify error code and type
 | ||||||
|   t.is(error.code, 'ENOGITHEAD'); |   t.is(error.code, 'ENOGITHEAD'); | ||||||
|   t.true(error instanceof SemanticReleaseError); |   t.is(error.name, 'SemanticReleaseError'); | ||||||
|   // Verify the log function has been called with a message explaining the error
 |   // Verify the log function has been called with a message explaining the error
 | ||||||
|   t.regex( |   t.regex( | ||||||
|     t.context.error.firstCall.args[0], |     t.context.error.firstCall.args[0], | ||||||
| @ -428,7 +427,7 @@ test.serial('Throws ENOTINHISTORY error if gitHead is not in history', async t = | |||||||
| 
 | 
 | ||||||
|   // Verify error code and type
 |   // Verify error code and type
 | ||||||
|   t.is(error.code, 'ENOTINHISTORY'); |   t.is(error.code, 'ENOTINHISTORY'); | ||||||
|   t.true(error instanceof SemanticReleaseError); |   t.is(error.name, 'SemanticReleaseError'); | ||||||
|   // Verify the log function has been called with a message mentionning the branch
 |   // Verify the log function has been called with a message mentionning the branch
 | ||||||
|   t.regex(t.context.error.firstCall.args[0], /history of the "master" branch/); |   t.regex(t.context.error.firstCall.args[0], /history of the "master" branch/); | ||||||
|   // Verify the log function has been called with a message mentionning the missing gitHead
 |   // Verify the log function has been called with a message mentionning the missing gitHead
 | ||||||
| @ -453,7 +452,7 @@ test.serial('Throws ENOTINHISTORY error if gitHead is not in branch history but | |||||||
| 
 | 
 | ||||||
|   // Verify error code and type
 |   // Verify error code and type
 | ||||||
|   t.is(error.code, 'ENOTINHISTORY'); |   t.is(error.code, 'ENOTINHISTORY'); | ||||||
|   t.true(error instanceof SemanticReleaseError); |   t.is(error.name, 'SemanticReleaseError'); | ||||||
|   // Verify the log function has been called with a message mentionning the branch
 |   // Verify the log function has been called with a message mentionning the branch
 | ||||||
|   t.regex(t.context.error.firstCall.args[0], /history of the "master" branch/); |   t.regex(t.context.error.firstCall.args[0], /history of the "master" branch/); | ||||||
|   // Verify the log function has been called with a message mentionning the missing gitHead
 |   // Verify the log function has been called with a message mentionning the missing gitHead
 | ||||||
| @ -482,7 +481,7 @@ test.serial('Throws ENOTINHISTORY error if gitHead is not in detached head but p | |||||||
| 
 | 
 | ||||||
|   // Verify error code and type
 |   // Verify error code and type
 | ||||||
|   t.is(error.code, 'ENOTINHISTORY'); |   t.is(error.code, 'ENOTINHISTORY'); | ||||||
|   t.true(error instanceof SemanticReleaseError); |   t.is(error.name, 'SemanticReleaseError'); | ||||||
|   // Verify the log function has been called with a message mentionning the branch
 |   // Verify the log function has been called with a message mentionning the branch
 | ||||||
|   t.regex(t.context.error.firstCall.args[0], /history of the "master" branch/); |   t.regex(t.context.error.firstCall.args[0], /history of the "master" branch/); | ||||||
|   // Verify the log function has been called with a message mentionning the missing gitHead
 |   // Verify the log function has been called with a message mentionning the missing gitHead
 | ||||||
| @ -508,7 +507,7 @@ test.serial('Throws ENOTINHISTORY error when a tag is not in branch history but | |||||||
|   const error = await t.throws(getCommits({version: '1.0.0'}, 'master', t.context.logger)); |   const error = await t.throws(getCommits({version: '1.0.0'}, 'master', t.context.logger)); | ||||||
|   // Verify error code and type
 |   // Verify error code and type
 | ||||||
|   t.is(error.code, 'ENOTINHISTORY'); |   t.is(error.code, 'ENOTINHISTORY'); | ||||||
|   t.true(error instanceof SemanticReleaseError); |   t.is(error.name, 'SemanticReleaseError'); | ||||||
|   // Verify the log function has been called with a message mentionning the branch
 |   // Verify the log function has been called with a message mentionning the branch
 | ||||||
|   t.regex(t.context.error.firstCall.args[0], /history of the "master" branch/); |   t.regex(t.context.error.firstCall.args[0], /history of the "master" branch/); | ||||||
|   // Verify the log function has been called with a message mentionning the missing gitHead
 |   // Verify the log function has been called with a message mentionning the missing gitHead
 | ||||||
|  | |||||||
| @ -36,7 +36,7 @@ test.serial('Throw error if the last commit sha cannot be found', async t => { | |||||||
|   // Create a git repository, set the current working directory at the root of the repo
 |   // Create a git repository, set the current working directory at the root of the repo
 | ||||||
|   await gitRepo(); |   await gitRepo(); | ||||||
| 
 | 
 | ||||||
|   await t.throws(gitHead()); |   await t.throws(gitHead(), Error); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Unshallow repository', async t => { | test.serial('Unshallow repository', async t => { | ||||||
|  | |||||||
| @ -2,7 +2,6 @@ import test from 'ava'; | |||||||
| import proxyquire from 'proxyquire'; | import proxyquire from 'proxyquire'; | ||||||
| import {stub} from 'sinon'; | import {stub} from 'sinon'; | ||||||
| import tempy from 'tempy'; | import tempy from 'tempy'; | ||||||
| import SemanticReleaseError from '@semantic-release/error'; |  | ||||||
| import DEFINITIONS from '../lib/plugins/definitions'; | import DEFINITIONS from '../lib/plugins/definitions'; | ||||||
| import {gitHead as getGitHead} from '../lib/git'; | import {gitHead as getGitHead} from '../lib/git'; | ||||||
| import {gitRepo, gitCommits, gitTagVersion} from './helpers/git-utils'; | import {gitRepo, gitCommits, gitTagVersion} from './helpers/git-utils'; | ||||||
| @ -250,10 +249,10 @@ test.serial('Throw SemanticReleaseError if not running from a git repository', a | |||||||
| 
 | 
 | ||||||
|   // Verify error code and type
 |   // Verify error code and type
 | ||||||
|   t.is(error.code, 'ENOGITREPO'); |   t.is(error.code, 'ENOGITREPO'); | ||||||
|   t.true(error instanceof SemanticReleaseError); |   t.is(error.name, 'SemanticReleaseError'); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Throw SemanticReleaseError if repositoryUrl is not set and canot be found', async t => { | test.serial('Throw SemanticReleaseError if repositoryUrl is not set and cannot be found', async t => { | ||||||
|   // Create a git repository, set the current working directory at the root of the repo
 |   // Create a git repository, set the current working directory at the root of the repo
 | ||||||
|   await gitRepo(); |   await gitRepo(); | ||||||
| 
 | 
 | ||||||
| @ -261,7 +260,8 @@ test.serial('Throw SemanticReleaseError if repositoryUrl is not set and canot be | |||||||
| 
 | 
 | ||||||
|   // Verify error code and type
 |   // Verify error code and type
 | ||||||
|   t.is(error.code, 'ENOREPOURL'); |   t.is(error.code, 'ENOREPOURL'); | ||||||
|   t.true(error instanceof SemanticReleaseError); |   t.is(error.name, 'SemanticReleaseError'); | ||||||
|  | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Throw an Error if returns an unexpected value', async t => { | test.serial('Throw an Error if returns an unexpected value', async t => { | ||||||
|   // Create a git repository, set the current working directory at the root of the repo
 |   // Create a git repository, set the current working directory at the root of the repo
 | ||||||
|  | |||||||
| @ -46,7 +46,7 @@ test('Wrap plugin in a function that validate the output of the plugin', async t | |||||||
|   await t.notThrows(plugin()); |   await t.notThrows(plugin()); | ||||||
| 
 | 
 | ||||||
|   pluginFunction.resolves(2); |   pluginFunction.resolves(2); | ||||||
|   const error = await t.throws(plugin()); |   const error = await t.throws(plugin(), Error); | ||||||
|   t.is(error.message, 'The output must be 1. Received: 2'); |   t.is(error.message, 'The output must be 1. Received: 2'); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| @ -104,7 +104,7 @@ test('Always pass a defined "pluginConfig" for plugin defined with path', async | |||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test('Throws an error if the plugin return an object without the expected plugin function', t => { | test('Throws an error if the plugin return an object without the expected plugin function', t => { | ||||||
|   const error = t.throws(() => normalize('inexistantPlugin', './test/fixtures/multi-plugin', t.context.logger)); |   const error = t.throws(() => normalize('inexistantPlugin', './test/fixtures/multi-plugin', t.context.logger), Error); | ||||||
| 
 | 
 | ||||||
|   t.is( |   t.is( | ||||||
|     error.message, |     error.message, | ||||||
|  | |||||||
| @ -32,7 +32,7 @@ test('Stop execution and throw error is a step rejects', async t => { | |||||||
|   const step2 = stub().throws(new Error('test error')); |   const step2 = stub().throws(new Error('test error')); | ||||||
|   const step3 = stub().resolves(3); |   const step3 = stub().resolves(3); | ||||||
| 
 | 
 | ||||||
|   const error = await t.throws(pipeline([step1, step2, step3])(0)); |   const error = await t.throws(pipeline([step1, step2, step3])(0), Error); | ||||||
|   t.is(error.message, 'test error'); |   t.is(error.message, 'test error'); | ||||||
|   t.true(step1.calledWith(0)); |   t.true(step1.calledWith(0)); | ||||||
|   t.true(step2.calledWith(0)); |   t.true(step2.calledWith(0)); | ||||||
|  | |||||||
| @ -49,7 +49,7 @@ test('Use default when only options are passed for a single plugin', t => { | |||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test('Throw an error if plugin configuration is missing a path for plugin pipeline', t => { | test('Throw an error if plugin configuration is missing a path for plugin pipeline', t => { | ||||||
|   const error = t.throws(() => getPlugins({verifyConditions: {}}, t.context.logger)); |   const error = t.throws(() => getPlugins({verifyConditions: {}}, t.context.logger), Error); | ||||||
| 
 | 
 | ||||||
|   t.is( |   t.is( | ||||||
|     error.message, |     error.message, | ||||||
| @ -58,7 +58,10 @@ test('Throw an error if plugin configuration is missing a path for plugin pipeli | |||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test('Throw an error if an array of plugin configuration is missing a path for plugin pipeline', t => { | test('Throw an error if an array of plugin configuration is missing a path for plugin pipeline', t => { | ||||||
|   const error = t.throws(() => getPlugins({verifyConditions: [{path: '@semantic-release/npm'}, {}]}, t.context.logger)); |   const error = t.throws( | ||||||
|  |     () => getPlugins({verifyConditions: [{path: '@semantic-release/npm'}, {}]}, t.context.logger), | ||||||
|  |     Error | ||||||
|  |   ); | ||||||
| 
 | 
 | ||||||
|   t.is( |   t.is( | ||||||
|     error.message, |     error.message, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user