From 311ff27ba6fc2e791a64c7c6f49daeec934e100e Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 17 Dec 2019 10:59:12 +0100 Subject: [PATCH] test: mock semver/functions/satisfies --- packages/builder/test/builder.build.test.js | 22 +++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/builder/test/builder.build.test.js b/packages/builder/test/builder.build.test.js index 4c84248dd7..b5caf80ba4 100644 --- a/packages/builder/test/builder.build.test.js +++ b/packages/builder/test/builder.build.test.js @@ -1,6 +1,7 @@ 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' @@ -8,7 +9,7 @@ import Builder from '../src/builder' import { createNuxt } from './__utils__' jest.mock('fs-extra') -// jest.mock('semver') +jest.mock('semver/functions/satisfies') jest.mock('hash-sum', () => src => `hash(${src})`) jest.mock('@nuxt/utils') jest.mock('../src/ignore') @@ -235,9 +236,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' }) @@ -247,9 +248,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', () => { @@ -261,7 +262,8 @@ 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) @@ -274,7 +276,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') }) })