Skip to content

Commit

Permalink
test: semver is not mockable
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Dec 16, 2019
1 parent bb5f84c commit 4669b6b
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions packages/builder/test/builder.build.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import path from 'path'
import consola from 'consola'
import fsExtra from 'fs-extra'
import semver from 'semver'
import { r, waitFor } from '@nuxt/utils'
import { BundleBuilder } from '@nuxt/webpack'

import Builder from '../src/builder'
import { createNuxt } from './__utils__'

jest.mock('fs-extra')
jest.mock('semver')
// jest.mock('semver')
jest.mock('hash-sum', () => src => `hash(${src})`)
jest.mock('@nuxt/utils')
jest.mock('../src/ignore')
Expand Down Expand Up @@ -236,9 +235,9 @@ describe('builder: builder build', () => {
}
}
const builder = new Builder(nuxt, BundleBuilder)
semver.satisfies
.mockReturnValueOnce(true)
.mockReturnValueOnce(true)
// semver.satisfies
// .mockReturnValueOnce(true)
// .mockReturnValueOnce(true)
nuxt.resolver.requireModule
.mockReturnValueOnce({ version: 'alpha' })
.mockReturnValueOnce({ version: 'beta' })
Expand All @@ -248,9 +247,9 @@ describe('builder: builder build', () => {
expect(nuxt.resolver.requireModule).toBeCalledTimes(2)
expect(nuxt.resolver.requireModule).nthCalledWith(1, 'join(vue, package.json)')
expect(nuxt.resolver.requireModule).nthCalledWith(2, 'join(nuxt, package.json)')
expect(semver.satisfies).toBeCalledTimes(2)
expect(semver.satisfies).nthCalledWith(1, 'alpha', 'latest')
expect(semver.satisfies).nthCalledWith(2, 'beta', 'edge')
// expect(semver.satisfies).toBeCalledTimes(2)
// expect(semver.satisfies).nthCalledWith(1, 'alpha', 'latest')
// expect(semver.satisfies).nthCalledWith(2, 'beta', 'edge')
})

test('should warn and throw error if dependencies is not installed', () => {
Expand All @@ -262,8 +261,7 @@ describe('builder: builder build', () => {
}
}
const builder = new Builder(nuxt, BundleBuilder)
semver.satisfies
.mockReturnValueOnce(false)
// semver.satisfies.mockReturnValueOnce(false)
nuxt.resolver.requireModule
.mockReturnValueOnce({ version: 'alpha' })
.mockReturnValueOnce(undefined)
Expand All @@ -276,7 +274,7 @@ describe('builder: builder build', () => {
expect(consola.warn).toBeCalledTimes(2)
expect(consola.warn).nthCalledWith(1, 'vue@latest is recommended but vue@alpha is installed!')
expect(consola.warn).nthCalledWith(2, 'nuxt@edge is required but not installed!')
expect(semver.satisfies).toBeCalledTimes(1)
expect(semver.satisfies).nthCalledWith(1, 'alpha', 'latest')
// expect(semver.satisfies).toBeCalledTimes(1)
// expect(semver.satisfies).nthCalledWith(1, 'alpha', 'latest')
})
})

0 comments on commit 4669b6b

Please sign in to comment.