diff --git a/package.json b/package.json index d2296f4c..69c25d22 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,6 @@ "ava": { "files": [ "test/**/*.test.js" - ], - "helpers": [ - "test/helpers/**/*" ] }, "bugs": { @@ -29,7 +26,7 @@ "p-reduce": "^2.0.0" }, "devDependencies": { - "ava": "^2.0.0", + "ava": "^3.1.0", "clear-module": "^4.0.0", "codecov": "^3.0.0", "file-url": "^3.0.0", diff --git a/test/git.test.js b/test/git.test.js index 1fff3ea0..ada4e6d8 100644 --- a/test/git.test.js +++ b/test/git.test.js @@ -1,8 +1,8 @@ -import path from 'path'; -import test from 'ava'; -import {outputFile, appendFile} from 'fs-extra'; -import {add, getModifiedFiles, commit, gitHead, push} from '../lib/git'; -import {gitRepo, gitCommits, gitGetCommits, gitStaged, gitRemoteHead} from './helpers/git-utils'; +const path = require('path'); +const test = require('ava'); +const {outputFile, appendFile} = require('fs-extra'); +const {add, getModifiedFiles, commit, gitHead, push} = require('../lib/git'); +const {gitRepo, gitCommits, gitGetCommits, gitStaged, gitRemoteHead} = require('./helpers/git-utils'); test('Add file to index', async t => { // Create a git repository, set the current working directory at the root of the repo diff --git a/test/helpers/git-utils.js b/test/helpers/git-utils.js index c4ace2d3..7137c2aa 100644 --- a/test/helpers/git-utils.js +++ b/test/helpers/git-utils.js @@ -1,9 +1,9 @@ -import tempy from 'tempy'; -import execa from 'execa'; -import fileUrl from 'file-url'; -import pReduce from 'p-reduce'; -import gitLogParser from 'git-log-parser'; -import getStream from 'get-stream'; +const tempy = require('tempy'); +const execa = require('execa'); +const fileUrl = require('file-url'); +const pReduce = require('p-reduce'); +const gitLogParser = require('git-log-parser'); +const getStream = require('get-stream'); /** * Create a temporary git repository. @@ -14,7 +14,7 @@ import getStream from 'get-stream'; * @param {String} [branch='master'] The branch to initialize. * @return {String} The path of the clone if `withRemote` is `true`, the path of the repository otherwise. */ -export async function gitRepo(withRemote, branch = 'master') { +async function gitRepo(withRemote, branch = 'master') { let cwd = tempy.directory(); await execa('git', ['init'].concat(withRemote ? ['--bare'] : []), {cwd}); @@ -43,7 +43,7 @@ export async function gitRepo(withRemote, branch = 'master') { * @param {String} repositoryUrl The URL of the bare repository. * @param {String} [branch='master'] the branch to initialize. */ -export async function initBareRepo(repositoryUrl, branch = 'master') { +async function initBareRepo(repositoryUrl, branch = 'master') { const cwd = tempy.directory(); await execa('git', ['clone', '--no-hardlinks', repositoryUrl, cwd], {cwd}); await gitCheckout(branch, true, {cwd}); @@ -59,7 +59,7 @@ export async function initBareRepo(repositoryUrl, branch = 'master') { * * @returns {Array} The created commits, in reverse order (to match `git log` order). */ -export async function gitCommits(messages, execaOpts) { +async function gitCommits(messages, execaOpts) { await pReduce( messages, async (_, message) => @@ -76,7 +76,7 @@ export async function gitCommits(messages, execaOpts) { * * @return {Array} The list of parsed commits. */ -export async function gitGetCommits(from, execaOpts) { +async function gitGetCommits(from, execaOpts) { Object.assign(gitLogParser.fields, {hash: 'H', message: 'B', gitTags: 'd', committerDate: {key: 'ci', type: Date}}); return ( await getStream.array( @@ -96,7 +96,7 @@ export async function gitGetCommits(from, execaOpts) { * @param {Boolean} create to create the branch, `false` to checkout an existing branch. * @param {Object} [execaOpts] Options to pass to `execa`. */ -export async function gitCheckout(branch, create, execaOpts) { +async function gitCheckout(branch, create, execaOpts) { await execa('git', create ? ['checkout', '-b', branch] : ['checkout', branch], execaOpts); } @@ -107,7 +107,7 @@ export async function gitCheckout(branch, create, execaOpts) { * @param {String} [sha] The commit on which to create the tag. If undefined the tag is created on the last commit. * @param {Object} [execaOpts] Options to pass to `execa`. */ -export async function gitTagVersion(tagName, sha, execaOpts) { +async function gitTagVersion(tagName, sha, execaOpts) { await execa('git', sha ? ['tag', '-f', tagName, sha] : ['tag', tagName], execaOpts); } @@ -120,7 +120,7 @@ export async function gitTagVersion(tagName, sha, execaOpts) { * @param {Number} [depth=1] The number of commit to clone. * @return {String} The path of the cloned repository. */ -export async function gitShallowClone(repositoryUrl, branch = 'master', depth = 1) { +async function gitShallowClone(repositoryUrl, branch = 'master', depth = 1) { const cwd = tempy.directory(); await execa('git', ['clone', '--no-hardlinks', '--no-tags', '-b', branch, '--depth', depth, repositoryUrl, cwd], { @@ -136,7 +136,7 @@ export async function gitShallowClone(repositoryUrl, branch = 'master', depth = * @param {Number} head A commit sha of the remote repo that will become the detached head of the new one. * @return {String} The path of the new repository. */ -export async function gitDetachedHead(repositoryUrl, head) { +async function gitDetachedHead(repositoryUrl, head) { const cwd = tempy.directory(); await execa('git', ['init'], {cwd}); @@ -154,7 +154,7 @@ export async function gitDetachedHead(repositoryUrl, head) { * * @return {String} The HEAD sha of the remote repository. */ -export async function gitRemoteHead(repositoryUrl, execaOpts) { +async function gitRemoteHead(repositoryUrl, execaOpts) { return (await execa('git', ['ls-remote', repositoryUrl, 'HEAD'], execaOpts)).stdout .split('\n') .filter(head => Boolean(head)) @@ -168,7 +168,7 @@ export async function gitRemoteHead(repositoryUrl, execaOpts) { * * @return {Array} Array of staged files path. */ -export async function gitStaged(execaOpts) { +async function gitStaged(execaOpts) { return (await execa('git', ['status', '--porcelain'], execaOpts)).stdout .split('\n') .filter(status => status.startsWith('A ')) @@ -183,7 +183,7 @@ export async function gitStaged(execaOpts) { * * @return {Array} The list of files path included in the commit. */ -export async function gitCommitedFiles(ref, execaOpts) { +async function gitCommitedFiles(ref, execaOpts) { return (await execa('git', ['diff-tree', '-r', '--name-only', '--no-commit-id', '-r', ref], execaOpts)).stdout .split('\n') .filter(file => Boolean(file)); @@ -195,7 +195,7 @@ export async function gitCommitedFiles(ref, execaOpts) { * @param {Array} files Array of files path to add to the index. * @param {Object} [execaOpts] Options to pass to `execa`. */ -export async function gitAdd(files, execaOpts) { +async function gitAdd(files, execaOpts) { await execa('git', ['add', '--force', '--ignore-errors', ...files], {...execaOpts}); } @@ -206,6 +206,22 @@ export async function gitAdd(files, execaOpts) { * @param {String} branch The branch to push. * @param {Object} [execaOpts] Options to pass to `execa`. */ -export async function gitPush(repositoryUrl, branch, execaOpts) { +async function gitPush(repositoryUrl, branch, execaOpts) { await execa('git', ['push', '--tags', repositoryUrl, `HEAD:${branch}`], execaOpts); } + +module.exports = { + gitRepo, + initBareRepo, + gitCommits, + gitGetCommits, + gitCheckout, + gitTagVersion, + gitShallowClone, + gitDetachedHead, + gitRemoteHead, + gitStaged, + gitCommitedFiles, + gitAdd, + gitPush, +}; diff --git a/test/integration.test.js b/test/integration.test.js index 64caae6c..09a33336 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -1,10 +1,10 @@ -import path from 'path'; -import test from 'ava'; -import {outputFile} from 'fs-extra'; -import {stub} from 'sinon'; -import clearModule from 'clear-module'; -import {push, add} from '../lib/git'; -import { +const path = require('path'); +const test = require('ava'); +const {outputFile} = require('fs-extra'); +const {stub} = require('sinon'); +const clearModule = require('clear-module'); +const {push, add} = require('../lib/git'); +const { gitRepo, gitCommits, gitShallowClone, @@ -12,7 +12,7 @@ import { gitCommitedFiles, gitGetCommits, gitTagVersion, -} from './helpers/git-utils'; +} = require('./helpers/git-utils'); test.beforeEach(t => { // Clear npm cache to refresh the module state diff --git a/test/prepare.test.js b/test/prepare.test.js index b1df0791..f72397f5 100644 --- a/test/prepare.test.js +++ b/test/prepare.test.js @@ -1,9 +1,9 @@ -import path from 'path'; -import test from 'ava'; -import {outputFile, remove} from 'fs-extra'; -import {stub} from 'sinon'; -import prepare from '../lib/prepare'; -import {gitRepo, gitGetCommits, gitCommitedFiles, gitAdd, gitCommits, gitPush} from './helpers/git-utils'; +const path = require('path'); +const test = require('ava'); +const {outputFile, remove} = require('fs-extra'); +const {stub} = require('sinon'); +const prepare = require('../lib/prepare'); +const {gitRepo, gitGetCommits, gitCommitedFiles, gitAdd, gitCommits, gitPush} = require('./helpers/git-utils'); test.beforeEach(t => { // Stub the logger functions diff --git a/test/verify.test.js b/test/verify.test.js index add0e8d9..4fe12603 100644 --- a/test/verify.test.js +++ b/test/verify.test.js @@ -1,5 +1,5 @@ -import test from 'ava'; -import verify from '../lib/verify'; +const test = require('ava'); +const verify = require('../lib/verify'); test('Throw SemanticReleaseError if "assets" option is not a String or false or an Array of Objects', t => { const assets = true;