Skip to content

Commit

Permalink
test: changelog: get rid of some mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Feb 13, 2024
1 parent 4155974 commit c3e8626
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
6 changes: 3 additions & 3 deletions lib/changelog.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {execSync} from 'node:child_process';
import {execSync as _execSync} from 'node:child_process';
import tryCatch from 'try-catch';
import shortdate from 'shortdate';
import _shortdate from 'shortdate';
import {readPackageUpSync} from 'read-package-up';
import buildCommand from './build-command.js';

export default (versionNew) => {
export default (versionNew, {shortdate = _shortdate, execSync = _execSync} = {}) => {
const [error, {packageJson} = {}] = tryCatch(readPackageUpSync);

if (error)
Expand Down
12 changes: 4 additions & 8 deletions lib/changelog.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
stub,
} from 'supertape';
import montag from 'montag';
import changelog from './changelog.js';

const {
mockImport,
Expand Down Expand Up @@ -169,17 +170,12 @@ test('changelog: read package: error', async (t) => {
test('changelog: no fix, no feature', async (t) => {
const execSync = stub().returns('');
const shortdate = stub().returns('2021.08.25');
const version = '1.0.0';

mockImport('node:child_process', {
const [error] = tryCatch(changelog, version, {
execSync,
shortdate,
});
mockImport('shortdate', shortdate);

const changelog = await reImportDefault('./changelog');
const version = '1.0.0';
const [error] = tryCatch(changelog, version);

stopAll();

t.match(error.message, `No new 'feature' and 'fix' commits from v`);
t.end();
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
"type": "git",
"url": "git://github.com/coderaiser/changelog-io.git"
},
"keywords": [
"changelog"
],
"keywords": ["changelog"],
"scripts": {
"test": "madrun test",
"coverage": "madrun coverage",
Expand Down

0 comments on commit c3e8626

Please sign in to comment.