test: limit information stored in context
Store only objects set in `beforeEach` used in `test`. Avoid logging useless info on test failure.
This commit is contained in:
		
							parent
							
								
									1b8aa95a6e
								
							
						
					
					
						commit
						8942093c18
					
				| @ -12,18 +12,19 @@ import { | |||||||
|   gitDetachedHead, |   gitDetachedHead, | ||||||
| } from './helpers/git-utils'; | } from './helpers/git-utils'; | ||||||
| 
 | 
 | ||||||
| test.beforeEach(t => { |  | ||||||
| // Save the current working diretory
 | // Save the current working diretory
 | ||||||
|   t.context.cwd = process.cwd(); | const cwd = process.cwd(); | ||||||
|  | 
 | ||||||
|  | test.beforeEach(t => { | ||||||
|   // Stub the logger functions
 |   // Stub the logger functions
 | ||||||
|   t.context.log = stub(); |   t.context.log = stub(); | ||||||
|   t.context.error = stub(); |   t.context.error = stub(); | ||||||
|   t.context.logger = {log: t.context.log, error: t.context.error}; |   t.context.logger = {log: t.context.log, error: t.context.error}; | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.afterEach.always(t => { | test.afterEach.always(() => { | ||||||
|   // Restore the current working directory
 |   // Restore the current working directory
 | ||||||
|   process.chdir(t.context.cwd); |   process.chdir(cwd); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Get all commits when there is no last release', async t => { | test.serial('Get all commits when there is no last release', async t => { | ||||||
| @ -411,7 +412,7 @@ test.serial('Throws ENOGITHEAD error if the gitHead of the last release cannot b | |||||||
|   t.is(error.name, '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.args[0][0], | ||||||
|     /The commit the last release of this package was derived from cannot be determined from the release metadata nor from the repository tags/ |     /The commit the last release of this package was derived from cannot be determined from the release metadata nor from the repository tags/ | ||||||
|   ); |   ); | ||||||
| }); | }); | ||||||
| @ -429,9 +430,9 @@ test.serial('Throws ENOTINHISTORY error if gitHead is not in history', async t = | |||||||
|   t.is(error.code, 'ENOTINHISTORY'); |   t.is(error.code, 'ENOTINHISTORY'); | ||||||
|   t.is(error.name, '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.args[0][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
 | ||||||
|   t.regex(t.context.error.firstCall.args[0], /restoring the commit "notinhistory"/); |   t.regex(t.context.error.args[0][0], /restoring the commit "notinhistory"/); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Throws ENOTINHISTORY error if gitHead is not in branch history but present in others', async t => { | test.serial('Throws ENOTINHISTORY error if gitHead is not in branch history but present in others', async t => { | ||||||
| @ -454,9 +455,9 @@ test.serial('Throws ENOTINHISTORY error if gitHead is not in branch history but | |||||||
|   t.is(error.code, 'ENOTINHISTORY'); |   t.is(error.code, 'ENOTINHISTORY'); | ||||||
|   t.is(error.name, '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.args[0][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
 | ||||||
|   t.regex(t.context.error.firstCall.args[0], new RegExp(`restoring the commit "${commitsBranch[0].hash}"`)); |   t.regex(t.context.error.args[0][0], new RegExp(`restoring the commit "${commitsBranch[0].hash}"`)); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Throws ENOTINHISTORY error if gitHead is not in detached head but present in other branch', async t => { | test.serial('Throws ENOTINHISTORY error if gitHead is not in detached head but present in other branch', async t => { | ||||||
| @ -483,9 +484,9 @@ test.serial('Throws ENOTINHISTORY error if gitHead is not in detached head but p | |||||||
|   t.is(error.code, 'ENOTINHISTORY'); |   t.is(error.code, 'ENOTINHISTORY'); | ||||||
|   t.is(error.name, '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.args[0][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
 | ||||||
|   t.regex(t.context.error.firstCall.args[0], new RegExp(`restoring the commit "${commitsBranch[0].hash}"`)); |   t.regex(t.context.error.args[0][0], new RegExp(`restoring the commit "${commitsBranch[0].hash}"`)); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Throws ENOTINHISTORY error when a tag is not in branch history but present in others', async t => { | test.serial('Throws ENOTINHISTORY error when a tag is not in branch history but present in others', async t => { | ||||||
| @ -509,7 +510,7 @@ test.serial('Throws ENOTINHISTORY error when a tag is not in branch history but | |||||||
|   t.is(error.code, 'ENOTINHISTORY'); |   t.is(error.code, 'ENOTINHISTORY'); | ||||||
|   t.is(error.name, '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.args[0][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
 | ||||||
|   t.regex(t.context.error.firstCall.args[0], new RegExp(`restoring the commit "${shaTag}"`)); |   t.regex(t.context.error.args[0][0], new RegExp(`restoring the commit "${shaTag}"`)); | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -5,20 +5,21 @@ import {stub} from 'sinon'; | |||||||
| import yaml from 'js-yaml'; | import yaml from 'js-yaml'; | ||||||
| import {gitRepo, gitCommits, gitShallowClone, gitAddConfig} from './helpers/git-utils'; | import {gitRepo, gitCommits, gitShallowClone, gitAddConfig} from './helpers/git-utils'; | ||||||
| 
 | 
 | ||||||
| test.beforeEach(t => { |  | ||||||
| // Save the current process.env
 | // Save the current process.env
 | ||||||
|   t.context.env = Object.assign({}, process.env); | const envBackup = Object.assign({}, process.env); | ||||||
| // Save the current working diretory
 | // Save the current working diretory
 | ||||||
|   t.context.cwd = process.cwd(); | const cwd = process.cwd(); | ||||||
|  | 
 | ||||||
|  | test.beforeEach(t => { | ||||||
|   t.context.plugins = stub().returns({}); |   t.context.plugins = stub().returns({}); | ||||||
|   t.context.getConfig = proxyquire('../lib/get-config', {'./plugins': t.context.plugins}); |   t.context.getConfig = proxyquire('../lib/get-config', {'./plugins': t.context.plugins}); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.afterEach.always(t => { | test.afterEach.always(() => { | ||||||
|   // Restore the current working directory
 |  | ||||||
|   process.chdir(t.context.cwd); |  | ||||||
|   // Restore process.env
 |   // Restore process.env
 | ||||||
|   process.env = Object.assign({}, t.context.env); |   process.env = envBackup; | ||||||
|  |   // Restore the current working directory
 | ||||||
|  |   process.chdir(cwd); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Default values, reading repositoryUrl from package.json', async t => { | test.serial('Default values, reading repositoryUrl from package.json', async t => { | ||||||
| @ -84,7 +85,7 @@ test.serial('Read options from package.json', async t => { | |||||||
|   // Verify the options contains the plugin config from package.json
 |   // Verify the options contains the plugin config from package.json
 | ||||||
|   t.deepEqual(options, release); |   t.deepEqual(options, release); | ||||||
|   // Verify the plugins module is called with the plugin options from package.json
 |   // Verify the plugins module is called with the plugin options from package.json
 | ||||||
|   t.deepEqual(t.context.plugins.firstCall.args[0], release); |   t.deepEqual(t.context.plugins.args[0][0], release); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Read options from .releaserc.yml', async t => { | test.serial('Read options from .releaserc.yml', async t => { | ||||||
| @ -104,7 +105,7 @@ test.serial('Read options from .releaserc.yml', async t => { | |||||||
|   // Verify the options contains the plugin config from package.json
 |   // Verify the options contains the plugin config from package.json
 | ||||||
|   t.deepEqual(options, release); |   t.deepEqual(options, release); | ||||||
|   // Verify the plugins module is called with the plugin options from package.json
 |   // Verify the plugins module is called with the plugin options from package.json
 | ||||||
|   t.deepEqual(t.context.plugins.firstCall.args[0], release); |   t.deepEqual(t.context.plugins.args[0][0], release); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Read options from .releaserc.json', async t => { | test.serial('Read options from .releaserc.json', async t => { | ||||||
| @ -124,7 +125,7 @@ test.serial('Read options from .releaserc.json', async t => { | |||||||
|   // Verify the options contains the plugin config from package.json
 |   // Verify the options contains the plugin config from package.json
 | ||||||
|   t.deepEqual(options, release); |   t.deepEqual(options, release); | ||||||
|   // Verify the plugins module is called with the plugin options from package.json
 |   // Verify the plugins module is called with the plugin options from package.json
 | ||||||
|   t.deepEqual(t.context.plugins.firstCall.args[0], release); |   t.deepEqual(t.context.plugins.args[0][0], release); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Read options from .releaserc.js', async t => { | test.serial('Read options from .releaserc.js', async t => { | ||||||
| @ -144,7 +145,7 @@ test.serial('Read options from .releaserc.js', async t => { | |||||||
|   // Verify the options contains the plugin config from package.json
 |   // Verify the options contains the plugin config from package.json
 | ||||||
|   t.deepEqual(options, release); |   t.deepEqual(options, release); | ||||||
|   // Verify the plugins module is called with the plugin options from package.json
 |   // Verify the plugins module is called with the plugin options from package.json
 | ||||||
|   t.deepEqual(t.context.plugins.firstCall.args[0], release); |   t.deepEqual(t.context.plugins.args[0][0], release); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Read options from release.config.js', async t => { | test.serial('Read options from release.config.js', async t => { | ||||||
| @ -164,7 +165,7 @@ test.serial('Read options from release.config.js', async t => { | |||||||
|   // Verify the options contains the plugin config from package.json
 |   // Verify the options contains the plugin config from package.json
 | ||||||
|   t.deepEqual(options, release); |   t.deepEqual(options, release); | ||||||
|   // Verify the plugins module is called with the plugin options from package.json
 |   // Verify the plugins module is called with the plugin options from package.json
 | ||||||
|   t.deepEqual(t.context.plugins.firstCall.args[0], release); |   t.deepEqual(t.context.plugins.args[0][0], release); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Prioritise cli parameters over file configuration and git repo', async t => { | test.serial('Prioritise cli parameters over file configuration and git repo', async t => { | ||||||
| @ -191,5 +192,5 @@ test.serial('Prioritise cli parameters over file configuration and git repo', as | |||||||
|   // Verify the options contains the plugin config from cli
 |   // Verify the options contains the plugin config from cli
 | ||||||
|   t.deepEqual(result.options, options); |   t.deepEqual(result.options, options); | ||||||
|   // Verify the plugins module is called with the plugin options from cli
 |   // Verify the plugins module is called with the plugin options from cli
 | ||||||
|   t.deepEqual(t.context.plugins.firstCall.args[0], options); |   t.deepEqual(t.context.plugins.args[0][0], options); | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -11,14 +11,12 @@ import { | |||||||
|   gitAddConfig, |   gitAddConfig, | ||||||
| } from './helpers/git-utils'; | } from './helpers/git-utils'; | ||||||
| 
 | 
 | ||||||
| test.beforeEach(t => { |  | ||||||
| // Save the current working diretory
 | // Save the current working diretory
 | ||||||
|   t.context.cwd = process.cwd(); | const cwd = process.cwd(); | ||||||
| }); |  | ||||||
| 
 | 
 | ||||||
| test.afterEach.always(t => { | test.afterEach.always(() => { | ||||||
|   // Restore the current working directory
 |   // Restore the current working directory
 | ||||||
|   process.chdir(t.context.cwd); |   process.chdir(cwd); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Get the last commit sha', async t => { | test.serial('Get the last commit sha', async t => { | ||||||
|  | |||||||
| @ -6,29 +6,27 @@ 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'; | ||||||
| 
 | 
 | ||||||
| test.beforeEach(t => { |  | ||||||
| // Save the current process.env
 | // Save the current process.env
 | ||||||
|   t.context.env = Object.assign({}, process.env); | const envBackup = Object.assign({}, process.env); | ||||||
| // Save the current working diretory
 | // Save the current working diretory
 | ||||||
|   t.context.cwd = process.cwd(); | const cwd = process.cwd(); | ||||||
|  | 
 | ||||||
|  | stub(process.stdout, 'write'); | ||||||
|  | stub(process.stderr, 'write'); | ||||||
|  | 
 | ||||||
|  | test.beforeEach(t => { | ||||||
|   // Stub the logger functions
 |   // Stub the logger functions
 | ||||||
|   t.context.log = stub(); |   t.context.log = stub(); | ||||||
|   t.context.error = stub(); |   t.context.error = stub(); | ||||||
|   t.context.logger = {log: t.context.log, error: t.context.error}; |   t.context.logger = {log: t.context.log, error: t.context.error}; | ||||||
|   t.context.semanticRelease = proxyquire('../index', {'./lib/logger': t.context.logger}); |   t.context.semanticRelease = proxyquire('../index', {'./lib/logger': t.context.logger}); | ||||||
| 
 |  | ||||||
|   t.context.stdout = stub(process.stdout, 'write'); |  | ||||||
|   t.context.stderr = stub(process.stderr, 'write'); |  | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.afterEach.always(t => { | test.afterEach.always(() => { | ||||||
|   // Restore process.env
 |   // Restore process.env
 | ||||||
|   process.env = Object.assign({}, t.context.env); |   process.env = envBackup; | ||||||
|   // Restore the current working directory
 |   // Restore the current working directory
 | ||||||
|   process.chdir(t.context.cwd); |   process.chdir(cwd); | ||||||
| 
 |  | ||||||
|   t.context.stdout.restore(); |  | ||||||
|   t.context.stderr.restore(); |  | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Plugins are called with expected values', async t => { | test.serial('Plugins are called with expected values', async t => { | ||||||
| @ -65,44 +63,44 @@ test.serial('Plugins are called with expected values', async t => { | |||||||
| 
 | 
 | ||||||
|   await t.context.semanticRelease(options); |   await t.context.semanticRelease(options); | ||||||
| 
 | 
 | ||||||
|   t.true(verifyConditions1.calledOnce); |   t.is(verifyConditions1.callCount, 1); | ||||||
|   t.deepEqual(verifyConditions1.firstCall.args[1], {options, logger: t.context.logger}); |   t.deepEqual(verifyConditions1.args[0][1], {options, logger: t.context.logger}); | ||||||
|   t.true(verifyConditions2.calledOnce); |   t.is(verifyConditions2.callCount, 1); | ||||||
|   t.deepEqual(verifyConditions2.firstCall.args[1], {options, logger: t.context.logger}); |   t.deepEqual(verifyConditions2.args[0][1], {options, logger: t.context.logger}); | ||||||
| 
 | 
 | ||||||
|   t.true(getLastRelease.calledOnce); |   t.is(getLastRelease.callCount, 1); | ||||||
|   t.deepEqual(getLastRelease.firstCall.args[1], {options, logger: t.context.logger}); |   t.deepEqual(getLastRelease.args[0][1], {options, logger: t.context.logger}); | ||||||
| 
 | 
 | ||||||
|   t.true(analyzeCommits.calledOnce); |   t.is(analyzeCommits.callCount, 1); | ||||||
|   t.deepEqual(analyzeCommits.firstCall.args[1].options, options); |   t.deepEqual(analyzeCommits.args[0][1].options, options); | ||||||
|   t.deepEqual(analyzeCommits.firstCall.args[1].logger, t.context.logger); |   t.deepEqual(analyzeCommits.args[0][1].logger, t.context.logger); | ||||||
|   t.deepEqual(analyzeCommits.firstCall.args[1].lastRelease, lastRelease); |   t.deepEqual(analyzeCommits.args[0][1].lastRelease, lastRelease); | ||||||
|   t.deepEqual(analyzeCommits.firstCall.args[1].commits[0].hash.substring(0, 7), commits[0].hash); |   t.deepEqual(analyzeCommits.args[0][1].commits[0].hash.substring(0, 7), commits[0].hash); | ||||||
|   t.deepEqual(analyzeCommits.firstCall.args[1].commits[0].message, commits[0].message); |   t.deepEqual(analyzeCommits.args[0][1].commits[0].message, commits[0].message); | ||||||
| 
 | 
 | ||||||
|   t.true(verifyRelease.calledOnce); |   t.is(verifyRelease.callCount, 1); | ||||||
|   t.deepEqual(verifyRelease.firstCall.args[1].options, options); |   t.deepEqual(verifyRelease.args[0][1].options, options); | ||||||
|   t.deepEqual(verifyRelease.firstCall.args[1].logger, t.context.logger); |   t.deepEqual(verifyRelease.args[0][1].logger, t.context.logger); | ||||||
|   t.deepEqual(verifyRelease.firstCall.args[1].lastRelease, lastRelease); |   t.deepEqual(verifyRelease.args[0][1].lastRelease, lastRelease); | ||||||
|   t.deepEqual(verifyRelease.firstCall.args[1].commits[0].hash.substring(0, 7), commits[0].hash); |   t.deepEqual(verifyRelease.args[0][1].commits[0].hash.substring(0, 7), commits[0].hash); | ||||||
|   t.deepEqual(verifyRelease.firstCall.args[1].commits[0].message, commits[0].message); |   t.deepEqual(verifyRelease.args[0][1].commits[0].message, commits[0].message); | ||||||
|   t.deepEqual(verifyRelease.firstCall.args[1].nextRelease, nextRelease); |   t.deepEqual(verifyRelease.args[0][1].nextRelease, nextRelease); | ||||||
| 
 | 
 | ||||||
|   t.true(generateNotes.calledOnce); |   t.is(generateNotes.callCount, 1); | ||||||
|   t.deepEqual(generateNotes.firstCall.args[1].options, options); |   t.deepEqual(generateNotes.args[0][1].options, options); | ||||||
|   t.deepEqual(generateNotes.firstCall.args[1].logger, t.context.logger); |   t.deepEqual(generateNotes.args[0][1].logger, t.context.logger); | ||||||
|   t.deepEqual(generateNotes.firstCall.args[1].lastRelease, lastRelease); |   t.deepEqual(generateNotes.args[0][1].lastRelease, lastRelease); | ||||||
|   t.deepEqual(generateNotes.firstCall.args[1].commits[0].hash.substring(0, 7), commits[0].hash); |   t.deepEqual(generateNotes.args[0][1].commits[0].hash.substring(0, 7), commits[0].hash); | ||||||
|   t.deepEqual(generateNotes.firstCall.args[1].commits[0].message, commits[0].message); |   t.deepEqual(generateNotes.args[0][1].commits[0].message, commits[0].message); | ||||||
|   t.deepEqual(generateNotes.firstCall.args[1].nextRelease, nextRelease); |   t.deepEqual(generateNotes.args[0][1].nextRelease, nextRelease); | ||||||
| 
 | 
 | ||||||
|   t.true(publish.calledOnce); |   t.is(publish.callCount, 1); | ||||||
|   t.deepEqual(publish.firstCall.args[1].options, options); |   t.deepEqual(publish.args[0][1].options, options); | ||||||
|   t.deepEqual(publish.firstCall.args[1].logger, t.context.logger); |   t.deepEqual(publish.args[0][1].logger, t.context.logger); | ||||||
|   t.deepEqual(publish.firstCall.args[1].lastRelease, lastRelease); |   t.deepEqual(publish.args[0][1].lastRelease, lastRelease); | ||||||
|   t.deepEqual(publish.firstCall.args[1].commits[0].hash.substring(0, 7), commits[0].hash); |   t.deepEqual(publish.args[0][1].commits[0].hash.substring(0, 7), commits[0].hash); | ||||||
|   t.deepEqual(publish.firstCall.args[1].commits[0].message, commits[0].message); |   t.deepEqual(publish.args[0][1].commits[0].message, commits[0].message); | ||||||
|   t.deepEqual(publish.firstCall.args[1].nextRelease, Object.assign({}, nextRelease, {notes})); |   t.deepEqual(publish.args[0][1].nextRelease, Object.assign({}, nextRelease, {notes})); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Use new gitHead, and recreate release notes if a publish plugin create a commit', async t => { | test.serial('Use new gitHead, and recreate release notes if a publish plugin create a commit', async t => { | ||||||
| @ -138,16 +136,16 @@ test.serial('Use new gitHead, and recreate release notes if a publish plugin cre | |||||||
| 
 | 
 | ||||||
|   await t.context.semanticRelease(options); |   await t.context.semanticRelease(options); | ||||||
| 
 | 
 | ||||||
|   t.true(generateNotes.calledTwice); |   t.is(generateNotes.callCount, 2); | ||||||
|   t.deepEqual(generateNotes.firstCall.args[1].nextRelease, nextRelease); |   t.deepEqual(generateNotes.args[0][1].nextRelease, nextRelease); | ||||||
|   t.true(publish1.calledOnce); |   t.is(publish1.callCount, 1); | ||||||
|   t.deepEqual(publish1.firstCall.args[1].nextRelease, Object.assign({}, nextRelease, {notes})); |   t.deepEqual(publish1.args[0][1].nextRelease, Object.assign({}, nextRelease, {notes})); | ||||||
| 
 | 
 | ||||||
|   nextRelease.gitHead = await getGitHead(); |   nextRelease.gitHead = await getGitHead(); | ||||||
| 
 | 
 | ||||||
|   t.deepEqual(generateNotes.secondCall.args[1].nextRelease, Object.assign({}, nextRelease, {notes})); |   t.deepEqual(generateNotes.secondCall.args[1].nextRelease, Object.assign({}, nextRelease, {notes})); | ||||||
|   t.true(publish2.calledOnce); |   t.is(publish2.callCount, 1); | ||||||
|   t.deepEqual(publish2.firstCall.args[1].nextRelease, Object.assign({}, nextRelease, {notes})); |   t.deepEqual(publish2.args[0][1].nextRelease, Object.assign({}, nextRelease, {notes})); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Dry-run skips verifyConditions and publish', async t => { | test.serial('Dry-run skips verifyConditions and publish', async t => { | ||||||
| @ -185,12 +183,12 @@ test.serial('Dry-run skips verifyConditions and publish', async t => { | |||||||
| 
 | 
 | ||||||
|   await t.context.semanticRelease(options); |   await t.context.semanticRelease(options); | ||||||
| 
 | 
 | ||||||
|   t.true(verifyConditions.notCalled); |   t.is(verifyConditions.callCount, 0); | ||||||
|   t.true(getLastRelease.calledOnce); |   t.is(getLastRelease.callCount, 1); | ||||||
|   t.true(analyzeCommits.calledOnce); |   t.is(analyzeCommits.callCount, 1); | ||||||
|   t.true(verifyRelease.calledOnce); |   t.is(verifyRelease.callCount, 1); | ||||||
|   t.true(generateNotes.calledOnce); |   t.is(generateNotes.callCount, 1); | ||||||
|   t.true(publish.notCalled); |   t.is(publish.callCount, 0); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Accept "undefined" values for the "getLastRelease" and "generateNotes" plugins', async t => { | test.serial('Accept "undefined" values for the "getLastRelease" and "generateNotes" plugins', async t => { | ||||||
| @ -225,20 +223,20 @@ test.serial('Accept "undefined" values for the "getLastRelease" and "generateNot | |||||||
| 
 | 
 | ||||||
|   await t.context.semanticRelease(options); |   await t.context.semanticRelease(options); | ||||||
| 
 | 
 | ||||||
|   t.true(getLastRelease.calledOnce); |   t.is(getLastRelease.callCount, 1); | ||||||
| 
 | 
 | ||||||
|   t.true(analyzeCommits.calledOnce); |   t.is(analyzeCommits.callCount, 1); | ||||||
|   t.deepEqual(analyzeCommits.firstCall.args[1].lastRelease, lastRelease); |   t.deepEqual(analyzeCommits.args[0][1].lastRelease, lastRelease); | ||||||
| 
 | 
 | ||||||
|   t.true(verifyRelease.calledOnce); |   t.is(verifyRelease.callCount, 1); | ||||||
|   t.deepEqual(verifyRelease.firstCall.args[1].lastRelease, lastRelease); |   t.deepEqual(verifyRelease.args[0][1].lastRelease, lastRelease); | ||||||
| 
 | 
 | ||||||
|   t.true(generateNotes.calledOnce); |   t.is(generateNotes.callCount, 1); | ||||||
|   t.deepEqual(generateNotes.firstCall.args[1].lastRelease, lastRelease); |   t.deepEqual(generateNotes.args[0][1].lastRelease, lastRelease); | ||||||
| 
 | 
 | ||||||
|   t.true(publish.calledOnce); |   t.is(publish.callCount, 1); | ||||||
|   t.deepEqual(publish.firstCall.args[1].lastRelease, lastRelease); |   t.deepEqual(publish.args[0][1].lastRelease, lastRelease); | ||||||
|   t.falsy(publish.firstCall.args[1].nextRelease.notes); |   t.falsy(publish.args[0][1].nextRelease.notes); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Throw SemanticReleaseError if not running from a git repository', async t => { | test.serial('Throw SemanticReleaseError if not running from a git repository', async t => { | ||||||
|  | |||||||
| @ -23,9 +23,16 @@ const testEnv = Object.assign({}, process.env, { | |||||||
|   NPM_EMAIL: 'integration@test.com', |   NPM_EMAIL: 'integration@test.com', | ||||||
|   LEGACY_TOKEN: Buffer.from(`${process.env.NPM_USERNAME}:${process.env.NPM_PASSWORD}`, 'utf8').toString('base64'), |   LEGACY_TOKEN: Buffer.from(`${process.env.NPM_USERNAME}:${process.env.NPM_PASSWORD}`, 'utf8').toString('base64'), | ||||||
| }); | }); | ||||||
|  | // Save the current process.env
 | ||||||
|  | const envBackup = Object.assign({}, process.env); | ||||||
| const cli = require.resolve('../bin/semantic-release'); | const cli = require.resolve('../bin/semantic-release'); | ||||||
| const pluginError = require.resolve('./fixtures/plugin-error'); | const pluginError = require.resolve('./fixtures/plugin-error'); | ||||||
| const pluginInheritedError = require.resolve('./fixtures/plugin-error-inherited'); | const pluginInheritedError = require.resolve('./fixtures/plugin-error-inherited'); | ||||||
|  | // Save the current working diretory
 | ||||||
|  | const cwd = process.cwd(); | ||||||
|  | // Disable logs during tests
 | ||||||
|  | stub(process.stdout, 'write'); | ||||||
|  | stub(process.stderr, 'write'); | ||||||
| 
 | 
 | ||||||
| test.before(async () => { | test.before(async () => { | ||||||
|   // Start the local NPM registry
 |   // Start the local NPM registry
 | ||||||
| @ -34,11 +41,7 @@ test.before(async () => { | |||||||
|   await mockServer.start(); |   await mockServer.start(); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.beforeEach(t => { | test.beforeEach(() => { | ||||||
|   // Save the current process.env
 |  | ||||||
|   t.context.env = Object.assign({}, process.env); |  | ||||||
|   // Save the current working diretory
 |  | ||||||
|   t.context.cwd = process.cwd(); |  | ||||||
|   // Delete env paramaters that could have been set on the machine running the tests
 |   // Delete env paramaters that could have been set on the machine running the tests
 | ||||||
|   delete process.env.NPM_TOKEN; |   delete process.env.NPM_TOKEN; | ||||||
|   delete process.env.NPM_USERNAME; |   delete process.env.NPM_USERNAME; | ||||||
| @ -56,23 +59,13 @@ test.beforeEach(t => { | |||||||
|       delete process.env[keys[i]]; |       delete process.env[keys[i]]; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   // Disable logs during tests
 |  | ||||||
|   t.context.log = stub(console, 'log'); |  | ||||||
|   t.context.error = stub(console, 'error'); |  | ||||||
|   t.context.stdout = stub(process.stdout, 'write'); |  | ||||||
|   t.context.stderr = stub(process.stderr, 'write'); |  | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.afterEach.always(t => { | test.afterEach.always(() => { | ||||||
|   // Restore process.env
 |   // Restore process.env
 | ||||||
|   process.env = Object.assign({}, t.context.env); |   process.env = envBackup; | ||||||
|   // Restore the current working directory
 |   // Restore the current working directory
 | ||||||
|   process.chdir(t.context.cwd); |   process.chdir(cwd); | ||||||
|   // Restore the logs
 |  | ||||||
|   t.context.log.restore(); |  | ||||||
|   t.context.error.restore(); |  | ||||||
|   t.context.stdout.restore(); |  | ||||||
|   t.context.stderr.restore(); |  | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.after.always(async () => { | test.after.always(async () => { | ||||||
| @ -653,9 +646,6 @@ test.serial('Run via JS API', async t => { | |||||||
|     debug: true, |     debug: true, | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   t.true(t.context.log.calledWithMatch(/Published Github release: /, new RegExp(`release-url/${version}`))); |  | ||||||
|   t.true(t.context.log.calledWithMatch(/Publishing version .* to npm registry/, version)); |  | ||||||
| 
 |  | ||||||
|   // Verify package.json and has been updated
 |   // Verify package.json and has been updated
 | ||||||
|   t.is((await readJson('./package.json')).version, version); |   t.is((await readJson('./package.json')).version, version); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,5 +1,5 @@ | |||||||
| import test from 'ava'; | import test from 'ava'; | ||||||
| import {stub, match} from 'sinon'; | import {stub} from 'sinon'; | ||||||
| import logger from '../lib/logger'; | import logger from '../lib/logger'; | ||||||
| 
 | 
 | ||||||
| test.beforeEach(t => { | test.beforeEach(t => { | ||||||
| @ -16,8 +16,8 @@ test.serial('Basic log', t => { | |||||||
|   logger.log('test log'); |   logger.log('test log'); | ||||||
|   logger.error('test error'); |   logger.error('test error'); | ||||||
| 
 | 
 | ||||||
|   t.true(t.context.log.calledWithMatch(/.*test log/)); |   t.regex(t.context.log.args[0][0], /.*test log/); | ||||||
|   t.true(t.context.error.calledWithMatch(/.*test error/)); |   t.regex(t.context.error.args[0][0], /.*test error/); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Log object', t => { | test.serial('Log object', t => { | ||||||
| @ -25,16 +25,18 @@ test.serial('Log object', t => { | |||||||
|   logger.log(obj); |   logger.log(obj); | ||||||
|   logger.error(obj); |   logger.error(obj); | ||||||
| 
 | 
 | ||||||
|   t.true(t.context.log.calledWithMatch(match.string, obj)); |   t.is(t.context.log.args[0][1], obj); | ||||||
|   t.true(t.context.error.calledWithMatch(match.string, obj)); |   t.is(t.context.error.args[0][1], obj); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Log with string formatting', t => { | test.serial('Log with string formatting', t => { | ||||||
|   logger.log('test log %s', 'log value'); |   logger.log('test log %s', 'log value'); | ||||||
|   logger.error('test error %s', 'error value'); |   logger.error('test error %s', 'error value'); | ||||||
| 
 | 
 | ||||||
|   t.true(t.context.log.calledWithMatch(/.*test log/, 'log value')); |   t.regex(t.context.log.args[0][0], /.*test log/); | ||||||
|   t.true(t.context.error.calledWithMatch(/.*test error/, 'error value')); |   t.regex(t.context.error.args[0][0], /.*test error/); | ||||||
|  |   t.is(t.context.log.args[0][1], 'log value'); | ||||||
|  |   t.is(t.context.error.args[0][1], 'error value'); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Log with error stacktrace and properties', t => { | test.serial('Log with error stacktrace and properties', t => { | ||||||
| @ -43,6 +45,7 @@ test.serial('Log with error stacktrace and properties', t => { | |||||||
|   const otherError = new Error('other error message'); |   const otherError = new Error('other error message'); | ||||||
|   logger.error('test error %O', otherError); |   logger.error('test error %O', otherError); | ||||||
| 
 | 
 | ||||||
|   t.true(t.context.error.calledWithMatch(match.string, error)); |   t.is(t.context.error.args[0][1], error); | ||||||
|   t.true(t.context.error.calledWithMatch(/.*test error/, otherError)); |   t.regex(t.context.error.args[1][0], /.*test error/); | ||||||
|  |   t.is(t.context.error.args[1][1], otherError); | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| import test from 'ava'; | import test from 'ava'; | ||||||
| import {noop} from 'lodash'; | import {noop} from 'lodash'; | ||||||
| import {stub, match} from 'sinon'; | import {stub} from 'sinon'; | ||||||
| import normalize from '../../lib/plugins/normalize'; | import normalize from '../../lib/plugins/normalize'; | ||||||
| 
 | 
 | ||||||
| test.beforeEach(t => { | test.beforeEach(t => { | ||||||
| @ -13,14 +13,14 @@ test('Normalize and load plugin from string', t => { | |||||||
|   const plugin = normalize('verifyConditions', './test/fixtures/plugin-noop', t.context.logger); |   const plugin = normalize('verifyConditions', './test/fixtures/plugin-noop', t.context.logger); | ||||||
| 
 | 
 | ||||||
|   t.is(typeof plugin, 'function'); |   t.is(typeof plugin, 'function'); | ||||||
|   t.true(t.context.log.calledWith(match.string, 'verifyConditions', './test/fixtures/plugin-noop')); |   t.deepEqual(t.context.log.args[0], ['Load plugin %s from %s', 'verifyConditions', './test/fixtures/plugin-noop']); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test('Normalize and load plugin from object', t => { | test('Normalize and load plugin from object', t => { | ||||||
|   const plugin = normalize('publish', {path: './test/fixtures/plugin-noop'}, t.context.logger); |   const plugin = normalize('publish', {path: './test/fixtures/plugin-noop'}, t.context.logger); | ||||||
| 
 | 
 | ||||||
|   t.is(typeof plugin, 'function'); |   t.is(typeof plugin, 'function'); | ||||||
|   t.true(t.context.log.calledWith(match.string, 'publish', './test/fixtures/plugin-noop')); |   t.deepEqual(t.context.log.args[0], ['Load plugin %s from %s', 'publish', './test/fixtures/plugin-noop']); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test('Normalize and load plugin from function', t => { | test('Normalize and load plugin from function', t => { | ||||||
| @ -33,7 +33,7 @@ test('Normalize and load plugin that retuns multiple functions', t => { | |||||||
|   const plugin = normalize('verifyConditions', './test/fixtures/multi-plugin', t.context.logger); |   const plugin = normalize('verifyConditions', './test/fixtures/multi-plugin', t.context.logger); | ||||||
| 
 | 
 | ||||||
|   t.is(typeof plugin, 'function'); |   t.is(typeof plugin, 'function'); | ||||||
|   t.true(t.context.log.calledWith(match.string, 'verifyConditions', './test/fixtures/multi-plugin')); |   t.deepEqual(t.context.log.args[0], ['Load plugin %s from %s', 'verifyConditions', './test/fixtures/multi-plugin']); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test('Wrap plugin in a function that validate the output of the plugin', async t => { | test('Wrap plugin in a function that validate the output of the plugin', async t => { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user