Skip to content

Commit

Permalink
chore: replace mocha with jest testing framework
Browse files Browse the repository at this point in the history
  • Loading branch information
henri-hulski committed Jun 4, 2023
1 parent 3668175 commit 67ea44c
Show file tree
Hide file tree
Showing 58 changed files with 5,888 additions and 2,890 deletions.
2 changes: 0 additions & 2 deletions .mocharc.yaml

This file was deleted.

8,259 changes: 5,611 additions & 2,648 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"prepare": "npm run build",
"pretest": "babel-node test/utils/pretest.js",
"release": "npm run build && node ./dist/cli.js --release --no-parallel",
"test": "REPO_COOKER_NPM_OTP= mocha \"src/**/*.test.js\" \"test/integration/*.test.js\"",
"test": "REPO_COOKER_NPM_OTP= jest",
"test:watch": "npm run test -- --watch"
},
"repository": {
Expand Down Expand Up @@ -53,7 +53,7 @@
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-standard": "^4.1.0",
"foo": "1.0.0",
"mocha": "^10.2.0",
"jest": "^29.5.0",
"nyc": "^15.1.0",
"prettier": "^2.8.4",
"simple-mock": "^0.8.0"
Expand Down
4 changes: 2 additions & 2 deletions src/Cooker/providers/GitProvider/getBranches.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env mocha */
import { config } from 'test-utils'
/* eslint-env jest */
import assert from 'test-utils/assert'
import { commits } from 'test-utils/commits'
import { config } from 'test-utils'
import { getBranches } from './getBranches'

it('should return branches information', done => {
Expand Down
6 changes: 3 additions & 3 deletions src/Cooker/providers/GitProvider/getCommit.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-env mocha */
import { config } from 'test-utils'
/* eslint-env jest */
import assert from 'test-utils/assert'
import { commits } from 'test-utils/commits'
import { config } from 'test-utils'
import { getCommit } from './getCommit'
import { runAll } from '../../../helpers/runAll'

it('should get commit data', function (done) {
it('should get commit data', done => {
runAll(commits.map(commit => getCommit(config.path, commit.hash)))
.then(list => list.sort((a, b) => (a.date < b.date ? -1 : 1)))
.then(list => {
Expand Down
4 changes: 2 additions & 2 deletions src/Cooker/providers/GitProvider/getCurrentBranch.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env mocha */
import { config } from 'test-utils'
/* eslint-env jest */
import assert from 'test-utils/assert'
import { commits } from 'test-utils/commits'
import { config } from 'test-utils'
import { getCurrentBranch } from './getCurrentBranch'

it('should return information on current branch', done => {
Expand Down
4 changes: 2 additions & 2 deletions src/Cooker/providers/GitProvider/getHashListFromHash.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env mocha */
import { config } from 'test-utils'
/* eslint-env jest */
import assert from 'test-utils/assert'
import { commits } from 'test-utils/commits'
import { config } from 'test-utils'
import { getHashListFromHash } from './getHashListFromHash'

it('should return hash list up to hash', done => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-env mocha */
import { config } from 'test-utils'
/* eslint-env jest */
import assert from 'test-utils/assert'
import { tags } from 'test-utils/commits'
import { config } from 'test-utils'
import { getLatestTagMatchingName } from './getLatestTagMatchingName'
import { tags } from 'test-utils/commits'

it('should return the latest tag matching given name', done => {
getLatestTagMatchingName(config.path, 'release_').then(tag => {
Expand Down
2 changes: 1 addition & 1 deletion src/Cooker/providers/GitProvider/restoreRepository.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-env mocha */
/* eslint-env jest */
import assert from 'test-utils/assert'
import { config } from 'test-utils'
import fs from 'fs'
Expand Down
14 changes: 7 additions & 7 deletions src/Cooker/providers/GithubProvider/createRelease.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-env mocha */
import request from 'request'
import simple from 'simple-mock'
import { config } from 'test-utils'
/* eslint-env jest */
import assert from 'test-utils/assert'
import { config } from 'test-utils'
import { createRelease } from './createRelease'
import request from 'request'
import simple from 'simple-mock'

describe('createRelease', () => {
const release = {
Expand All @@ -13,7 +13,7 @@ describe('createRelease', () => {
created_at: new Date().toISOString(),
}

before(() => {
beforeAll(() => {
simple.mock(request, 'post').callFn(({ url, body }, callback) => {
const data = JSON.parse(body)
callback(
Expand All @@ -29,9 +29,9 @@ describe('createRelease', () => {
})
})

after(() => simple.restore())
afterAll(() => simple.restore())

it('should publish release to github', function (done) {
it('should publish release to github', done => {
createRelease(config.path, release.name, release.body)
.then(response => {
assert.deepEqual(response, release, done)
Expand Down
28 changes: 16 additions & 12 deletions src/Cooker/providers/NpmProvider/getCurrentPackageVersion.test.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
/* eslint-env mocha */
import simple from 'simple-mock'
import assert from 'test-utils/assert'
/* eslint-env jest */
import { mockNpmRegistry, versions } from 'test-utils/npm'

import assert from 'test-utils/assert'
import { getCurrentPackageVersion } from './getCurrentPackageVersion'
import simple from 'simple-mock'

describe('getCurrentPackageVersion', () => {
before(mockNpmRegistry)
after(() => simple.restore())
beforeAll(mockNpmRegistry)
afterAll(() => simple.restore())

it('should return the "latest" dist-tag version', function (done) {
it('should return the "latest" dist-tag version', done => {
getCurrentPackageVersion('repo-cooker-test').then(version => {
assert.equal(version, versions['repo-cooker-test'], done)
})
})

it('should return null when no version available', function (done) {
it('should return null when no version available', done => {
getCurrentPackageVersion('@repo-cooker-test/sous-chef').then(version => {
assert.equal(version, null, done)
})
})

it('should return null when latest in not a semver version', function (done) {
getCurrentPackageVersion('@repo-cooker-test/poissonier').then(version => {
assert.equal(version, null, done)
})
})
it(
'should return null when latest in not a semver version',
done => {
getCurrentPackageVersion('@repo-cooker-test/poissonier').then(version => {
assert.equal(version, null, done)
})
}
)
})
2 changes: 1 addition & 1 deletion src/Cooker/providers/NpmProvider/publish.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-env mocha */
/* eslint-env jest */
import { config, runCommandMock } from 'test-utils'

import assert from 'test-utils/assert'
Expand Down
2 changes: 1 addition & 1 deletion src/Cooker/providers/NpmProvider/replaceTag.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-env mocha */
/* eslint-env jest */
import { config, runCommandMock } from 'test-utils'

import assert from 'test-utils/assert'
Expand Down
5 changes: 3 additions & 2 deletions src/Cooker/providers/NpmProvider/runScript.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-env mocha */
import assert from 'test-utils/assert'
/* eslint-env jest */
import { config, runCommandMock } from 'test-utils'

import assert from 'test-utils/assert'
import { runScript as runScriptFactory } from './runScript'

it('should execute script in package', done => {
Expand Down
4 changes: 2 additions & 2 deletions src/Cooker/providers/PackageJsonProvider/get.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-env mocha */
/* eslint-env jest */
import assert from 'test-utils/assert'
import { config } from 'test-utils'
import { get } from './get'
import { join } from '../../../helpers/path'
import { readFileSync } from 'fs'

it('should get package info', function (done) {
it('should get package info', done => {
const getInfo = get(config)

const commisInfo = JSON.parse(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-env mocha */
/* eslint-env jest */
import assert from 'test-utils/assert'
import { getDependencies } from './getDependencies'

it('should get package dependencies', function (done) {
it('should get package dependencies', done => {
const getDeps = getDependencies({
packagesPaths: {
tiger: './test/deps-fixtures/tiger',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/* eslint-env mocha */
/* eslint-env jest */
import assert from 'test-utils/assert'
import { config } from 'test-utils'
import { getRelatedPackages as getRelatedPackagesFactory } from './getRelatedPackages'

it('should get related packages by package', function (done) {
it('should get related packages by package', done => {
const getRelatedPackages = getRelatedPackagesFactory(config)

getRelatedPackages('@repo-cooker-test/commis').then(relatedPackages => {
assert.deepEqual(relatedPackages, ['@repo-cooker-test/poissonier'], done)
})
})

it('should not use devDependencies', function (done) {
it('should not use devDependencies', done => {
const getRelatedPackages = getRelatedPackagesFactory(config)

getRelatedPackages('@repo-cooker-test/poissonier').then(relatedPackages => {
assert.deepEqual(relatedPackages, [], done)
})
})

it('should get read peerDependencies', function (done) {
it('should get read peerDependencies', done => {
const getRelatedPackages = getRelatedPackagesFactory(config)

getRelatedPackages('@repo-cooker-test/pastry-chef').then(relatedPackages => {
Expand Down
4 changes: 2 additions & 2 deletions src/Cooker/providers/PackageJsonProvider/write.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-env mocha */
/* eslint-env jest */
import { config, runCommandMock } from 'test-utils'

import assert from 'test-utils/assert'
import { join } from '../../../helpers/path'
import { write as writeFactory } from './write'

it('should write to package.json', function (done) {
it('should write to package.json', done => {
const runCommand = runCommandMock()
const write = writeFactory({
runCommand,
Expand Down
4 changes: 2 additions & 2 deletions src/actions/byBranch.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env mocha */
import { testAction } from 'test-utils'
/* eslint-env jest */
import { byBranch } from './'
import { testAction } from 'test-utils'

it('should go down current branch', done => {
testAction(
Expand Down
4 changes: 2 additions & 2 deletions src/actions/byReleaseTarget.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env mocha */
import { testAction } from 'test-utils'
/* eslint-env jest */
import { byReleaseTarget } from './'
import { testAction } from 'test-utils'

it('should choose branch from argv', done => {
testAction(
Expand Down
5 changes: 3 additions & 2 deletions src/actions/checkDependencies.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-env mocha */
import { testAction } from 'test-utils'
/* eslint-env jest */
import { checkDependencies, getDependencies } from './'

import { testAction } from 'test-utils'

describe('checkDependencies', () => {
it('should check dependencies for conflict', done => {
const checkDeps = {
Expand Down
3 changes: 2 additions & 1 deletion src/actions/createGithubRelease.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-env mocha */
/* eslint-env jest */
import { config, testAction } from 'test-utils'

import { createGithubRelease } from './'

it('should post new release to github', done => {
Expand Down
4 changes: 2 additions & 2 deletions src/actions/createReleaseNotes.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env mocha */
import { testAction } from 'test-utils'
/* eslint-env jest */
import { createReleaseNotes } from './'
import { testAction } from 'test-utils'

const makeCommit = name => {
const [, type, breaks] = name.split('_')
Expand Down
3 changes: 2 additions & 1 deletion src/actions/evaluateNewVersionByPackage.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-env mocha */
/* eslint-env jest */
import { testAction, testActionThrows } from 'test-utils'

import { evaluateNewVersionByPackage } from './'

const relatedPackagesByPackage = {
Expand Down
23 changes: 13 additions & 10 deletions src/actions/evaluateSemverByPackage.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env mocha */
import { testAction } from 'test-utils'
/* eslint-env jest */
import { evaluateSemverByPackage } from './'
import { testAction } from 'test-utils'

const commitsByPackage = {
foo: [{ type: 'fix', breaks: [] }],
Expand All @@ -19,14 +19,17 @@ const semverByPackage = {
baz: 'major',
}

it('should run the grouping function for every commit and group commits', done => {
testAction(
evaluateSemverByPackage,
{ commitsByPackage },
{ semverByPackage },
done
)
})
it(
'should run the grouping function for every commit and group commits',
done => {
testAction(
evaluateSemverByPackage,
{ commitsByPackage },
{ semverByPackage },
done
)
}
)

it('should bump all to major for Big Bang hash', done => {
const semverByPackage = {
Expand Down
4 changes: 2 additions & 2 deletions src/actions/filter.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env mocha */
import { testAction } from 'test-utils'
/* eslint-env jest */
import { filter } from './'
import { testAction } from 'test-utils'

describe('filter', () => {
it('should filter given prop synchronously', done => {
Expand Down
8 changes: 4 additions & 4 deletions src/actions/fixDependencies.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-env mocha */
import { testAction } from 'test-utils'
/* eslint-env jest */
import assert from 'test-utils/assert'
import simple from 'simple-mock'
import { fixDependencies } from './'
import { fs } from './helpers'
import simple from 'simple-mock'
import { testAction } from 'test-utils'

import { fixDependencies } from './'
const toInstallDeps = {
toInstall: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/actions/getBranches.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env mocha */
import { testAction } from 'test-utils'
/* eslint-env jest */
import { commits } from 'test-utils/commits'
import { getBranches } from './'
import { testAction } from 'test-utils'

it('should list branches', done => {
const commit = commits[commits.length - 1]
Expand Down
4 changes: 2 additions & 2 deletions src/actions/getCurrentBranch.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env mocha */
import { testAction } from 'test-utils'
/* eslint-env jest */
import { commits } from 'test-utils/commits'
import { getCurrentBranch } from './'
import { testAction } from 'test-utils'

it('should find the name of the current branch', done => {
const commit = commits[commits.length - 1]
Expand Down
Loading

0 comments on commit 67ea44c

Please sign in to comment.