From c56b8b2045f096505a5b1917ca08406984bc6014 Mon Sep 17 00:00:00 2001 From: Mater Date: Tue, 18 Jul 2023 17:21:59 +0800 Subject: [PATCH 1/3] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ad276ac4..ba1e2cf6 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ npm i @mpxjs/cli -g ``` +> 如果插件版本是2.x以上,需要前往https://github.com/mpx-ecology/mpx-cli/tree/next 查看文档 + ## 使用 ```sh From e419a7927bc6e05dbd1807972e002447fadd6636 Mon Sep 17 00:00:00 2001 From: yaojianxin Date: Wed, 19 Jul 2023 11:33:03 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E5=8D=95=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/mpx-cli/__tests__/preset.spec.js | 118 +++++++++++++++- .../__tests__/preset.spec.js | 128 ++++++++++++++++++ 2 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 packages/vue-cli-plugin-mpx/__tests__/preset.spec.js diff --git a/packages/mpx-cli/__tests__/preset.spec.js b/packages/mpx-cli/__tests__/preset.spec.js index 8fb67e6b..324711d8 100644 --- a/packages/mpx-cli/__tests__/preset.spec.js +++ b/packages/mpx-cli/__tests__/preset.spec.js @@ -23,7 +23,6 @@ test('normal', async () => { useConfigFiles: true } ) - const pkg = require(path.resolve(cwd, name, 'package.json')) expect(pkg.devDependencies).toHaveProperty('@mpxjs/vue-cli-plugin-mpx') }) @@ -228,3 +227,120 @@ test('test-e2e', async () => { const pkg = require(path.resolve(cwd, name, 'package.json')) expect(pkg.devDependencies).toHaveProperty('@mpxjs/vue-cli-plugin-mpx-e2e-test') }) + +// 测试一下 test-yao-1.0.0 这个项目,有没有 @mpxjs/babel-plugin-inject-page-events 这个依赖 +test('test-yao-1.0.0', async () => { + const cwd = path.resolve(__dirname, '../../test') + const name = 'test-yao-1.0.0' + await create( + name, + { + force: true, + git: false, + cwd + }, + { + srcMode: 'wx', + appid: 'test-yao-1.0.0', + description: 'test', + cross: true, + needE2ETest: true, + plugins: {}, + useConfigFiles: true + // srcMode: 'wx' 表示小程序的类型是微信小程序 + // appid: 'test-yao-1.0.0' 表示小程序的appid + // description: 'test' 表示小程序的描述 + // cross: true 表示是否跨平台 + // needE2ETest: true 表示是否需要e2e测试 + // plugins: {} 表示插件 + // useConfigFiles: true 表示是否使用配置文件 + } + ) + + const pkg = require(path.resolve(cwd, name, 'package.json')) + expect(pkg.devDependencies).toHaveProperty('@mpxjs/babel-plugin-inject-page-events') +}) + +// 将srcMode改成ali,测试一下 test-yao-1.0.1 这个项目生成的static/ali目录是否存在,还是否存在wx目录 +test('test-yao-1.0.1', async () => { + const cwd = path.resolve(__dirname, '../../test') + const name = 'test-yao-1.0.1' + await create( + name, + { + force: true, + git: false, + cwd + }, + { + srcMode: 'ali', + appid: 'test-yao-1.0.1', + description: 'test', + cross: true, + needE2ETest: true, + plugins: {}, + useConfigFiles: true + } + ) + + const staticWxDir = fs.existsSync(path.resolve(cwd, name, 'static/wx')) + const staticAliDir = fs.existsSync(path.resolve(cwd, name, 'static/ali')) + expect(staticWxDir).toBe(false) + expect(staticAliDir).toBe(true) + // a: 1. fs.existsSync(path.resolve(cwd, name, 'static/wx')) 判断static/wx目录是否存在,如果存在返回true,不存在返回false + // a: 2. fs.existsSync(path.resolve(cwd, name, 'static/ali')) 判断static/ali目录是否存在,如果存在返回true,不存在返回false + // a: 3. expect(staticWxDir).toBe(false) 判断staticWxDir是否为false,如果为false则测试通过,如果为true则测试失败 + // a: 4. expect(staticAliDir).toBe(true) 判断staticAliDir是否为true,如果为true则测试通过,如果为false则测试失败 +}) + +// 测试一下 test-yao-1.0.0 这个项目,有没有 @mpxjs/babel-plugin-inject-page-events 这个依赖 +test('test-yao-vue-1.0.0', async () => { + const cwd = path.resolve(__dirname, '../../test') + const name = 'test-yao-vue-1.0.0' + await create( + name, + { + force: true, + git: false, + cwd + }, + { + srcMode: 'wx', + appid: 'test-yao-vue-1.0.0', + description: 'test', + cross: true, + needE2ETest: true, + plugins: {}, + useConfigFiles: true + } + ) + + const pkg = require(path.resolve(cwd, name, 'package.json')) + expect(pkg.devDependencies).toHaveProperty('@mpxjs/babel-plugin-inject-page-events') +}) + +// 将srcMode改成ali,测试一下 test-yao-1.0.1 这个项目生成的static/ali目录是否存在,还是否存在wx目录,是否还有 @mpxjs/babel-plugin-inject-page-events 这个依赖 +test('test-yao-vue-1.0.1', async () => { + const cwd = path.resolve(__dirname, '../../test') + const name = 'test-yao-vue-1.0.1' + await create( + name, + { + force: true, + git: false, + cwd + }, + { + srcMode: 'ali', + appid: 'test-yao-vue-1.0.1', + description: 'test', + cross: true, + needE2ETest: true, + plugins: {}, + useConfigFiles: true + } + ) + + const pkg = require(path.resolve(cwd, name, 'package.json')) + expect(pkg.devDependencies).toHaveProperty('@mpxjs/babel-plugin-inject-page-events') +}) diff --git a/packages/vue-cli-plugin-mpx/__tests__/preset.spec.js b/packages/vue-cli-plugin-mpx/__tests__/preset.spec.js new file mode 100644 index 00000000..29c8bba3 --- /dev/null +++ b/packages/vue-cli-plugin-mpx/__tests__/preset.spec.js @@ -0,0 +1,128 @@ +jest.mock('inquirer') + +const path = require('path') +const fs = require('fs') +const create = require('@mpxjs/cli/lib/create') + +// intersection +// 引入本脚手架的utils/index.js里面的intersection方法,用来比较两个数组的交集,测试一下这个方法 +const { intersection } = require('../utils/index.js') +test('intersection', () => { + expect(intersection([1, 2, 3], [2, 3, 4])).toEqual([2, 3]) +}) + +// removeArgv +// 引入本脚手架的utils/index.js里面的removeArgv方法,用来移除argv里面的某个参数,测试一下这个方法 +const { removeArgv } = require('../utils/index.js') +test('removeArgv', () => { + expect(removeArgv(['--name'], '--name')).toEqual([]) +}) + +// makeMap +// 引入本脚手架的utils/index.js里面的makeMap方法 +// makeMap函数的作用是将给定的数组转换为一个键值对形式的对象(Map),其中数组的元素作为对象的键,值为true。它适用于需要快速判断某个元素是否在给定数组中的情况。 +const { makeMap } = require('../utils/index.js') +test('makeMap', () => { + // 测试空数组的情况 + expect(makeMap([])).toEqual({}) + + // 测试只有一个元素的数组的情况 + expect(makeMap(['a'])).toEqual({ a: true }) + + // 测试多个元素的数组的情况 + expect(makeMap(['a', 'b', 'c'])).toEqual({ a: true, b: true, c: true }) + + // 测试数组中包含重复元素的情况 + expect(makeMap(['a', 'b', 'a'])).toEqual({ a: true, b: true }) +}) + +// getMpxPluginOptions +const { getMpxPluginOptions } = require('../utils/index.js') +test('getMpxPluginOptions', () => { + // 测试没有传入参数的情况 + expect(getMpxPluginOptions()).toEqual({}) + + // 测试传入参数为空对象的情况 + expect(getMpxPluginOptions({})).toEqual({}) + + // 测试传入参数包含pluginOptions字段但没有mpx字段的情况 + expect(getMpxPluginOptions({ pluginOptions: {} })).toEqual({}) + + // 测试传入参数包含pluginOptions和mpx字段的情况 + expect(getMpxPluginOptions({ pluginOptions: { mpx: { mode: 'wx' } } })).toEqual({ mode: 'wx' }) +}) + +// getTargets +const { getTargets } = require('../utils/index.js') +test('getTargets', () => { + // 测试没有传入 targets 和 options 参数的情况 + // 预期结果:返回包含默认目标的数组 [{ mode: 'wx' }] + expect(getTargets({}, {})).toEqual([{ mode: 'wx' }]) + + // 测试传入 targets 参数为字符串的情况 + // 预期结果:返回包含根据 targets 解析得到的目标的数组 + expect(getTargets({ targets: 'wx,ali' }, {})).toEqual([{ mode: 'wx' }, { mode: 'ali' }]) + + // 测试传入 targets 参数为逗号分隔的字符串的情况 + // 预期结果:返回包含根据 targets 解析得到的目标的数组 + expect(getTargets({ targets: 'wx,ali,swan' }, {})).toEqual([ + { mode: 'wx' }, + { mode: 'ali' }, + { mode: 'swan' } + ]) + + // 测试传入 targets 参数为其他非空值的情况 + // 预期结果:返回默认目标 [{ mode: 'wx' }] + expect(getTargets({ targets: 'xyz' }, {})).toEqual([{ mode: 'wx' }]) + + // 测试传入 options 参数包含 mpx 字段的情况 + // 预期结果:返回根据 options.mpx.srcMode 解析的目标数组 + expect(getTargets({}, { pluginOptions: { mpx: { srcMode: 'ali' } } })).toEqual([{ mode: 'ali' }]) +}) + +// getCurrentTarget +const { getCurrentTarget } = require('../utils/index.js') +test('getCurrentTarget', () => { + // 测试默认情况下获取当前目标对象 + // 预期结果:返回包含 mode 和 env 字段的当前目标对象 + expect(getCurrentTarget()).toEqual({ + mode: process.env.MPX_CURRENT_TARGET_MODE, + env: process.env.MPX_CURRENT_TARGET_ENV + }) +}) + +// parseTarget +const { parseTarget } = require('../utils/index.js') +test('parseTarget', () => { + // 测试没有传入 target 和 options 参数的情况 + // 预期结果:返回包含默认目标的对象 { mode: 'wx', env: undefined } + expect(parseTarget()).toEqual({ mode: 'wx', env: undefined }) + + // 测试传入不包含环境的目标字符串的情况 + // 预期结果:返回包含根据 target 解析得到的目标对象 { mode: 'wx', env: undefined } + expect(parseTarget('wx')).toEqual({ mode: 'wx', env: undefined }) + + // 测试传入包含环境的目标字符串的情况 + // 预期结果:返回包含根据 target 解析得到的目标对象 { mode: 'wx', env: 'dev' } + expect(parseTarget('wx:dev')).toEqual({ mode: 'wx', env: 'dev' }) + + // 测试没有传入模式的情况,且根据 options 获取默认模式的情况 + // 预期结果:返回包含默认模式和环境的目标对象 { mode: 'ali', env: undefined } + expect(parseTarget('', { pluginOptions: { mpx: { srcMode: 'ali' } } })).toEqual({ mode: 'ali', env: undefined }) +}) + +// runServiceCommand +const { runServiceCommand } = require('../utils/index.js') +const execa = require('execa') +jest.mock('execa') +test('runServiceCommand', () => { + // 测试执行命令并传入命令行参数的情况 + // 预期结果:返回 Promise 对象,执行命令并将命令行参数传递给该命令 + execa.node.mockResolvedValue() + expect(runServiceCommand('build', ['--watch'], { cwd: '/path/to/project' })).resolves.toBeUndefined() + + // 测试执行命令不传入命令行参数的情况 + // 预期结果:返回 Promise 对象,仅执行命令而不传递命令行参数 + execa.node.mockResolvedValue() + expect(runServiceCommand('lint', [], { cwd: '/path/to/project' })).resolves.toBeUndefined() +}) From e4182b4b46686f8d660728f9b4ae235313c7527c Mon Sep 17 00:00:00 2001 From: yaojianxin Date: Wed, 2 Aug 2023 10:05:28 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E5=8D=95=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__snapshots__/preset.spec.js.snap | 98 ++++++++ packages/mpx-cli/__tests__/preset.spec.js | 223 +++++++++++------- 2 files changed, 231 insertions(+), 90 deletions(-) create mode 100644 packages/mpx-cli/__tests__/__snapshots__/preset.spec.js.snap diff --git a/packages/mpx-cli/__tests__/__snapshots__/preset.spec.js.snap b/packages/mpx-cli/__tests__/__snapshots__/preset.spec.js.snap new file mode 100644 index 00000000..7ba2d862 --- /dev/null +++ b/packages/mpx-cli/__tests__/__snapshots__/preset.spec.js.snap @@ -0,0 +1,98 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`test-ali 1`] = ` +Object { + "staticAliDir": Array [ + "/Users/didi/Desktop/work/mpx-cli/packages/test/test-ali/static/ali", + ], + "staticWxDir": Array [], +} +`; + +exports[`test-plugin-combine 1`] = ` +Object { + "dependencies": Object { + "@mpxjs/api-proxy": "^2.8.0", + "@mpxjs/core": "^2.8.0", + "@mpxjs/fetch": "^2.8.0", + "@mpxjs/pinia": "^2.8.0", + "@mpxjs/store": "^2.8.0", + "@mpxjs/utils": "^2.8.0", + "pinia": "^2.0.14", + "vue": "^2.6.14", + "vue-demi": "^0.13.11", + "vue-i18n": "^8.27.2", + "vue-i18n-bridge": "^9.2.2", + "vue-router": "^3.1.3", + }, + "devDependencies": Object { + "@babel/core": "^7.10.4", + "@babel/plugin-transform-runtime": "^7.10.4", + "@babel/preset-env": "^7.10.4", + "@babel/runtime-corejs3": "^7.10.4", + "@mpxjs/babel-plugin-inject-page-events": "^2.8.0", + "@mpxjs/eslint-config": "^1.0.5", + "@mpxjs/miniprogram-simulate": "^1.4.17", + "@mpxjs/mpx-cli-service": "^2.0.0", + "@mpxjs/mpx-jest": "^0.0.24", + "@mpxjs/size-report": "^2.8.0", + "@mpxjs/vue-cli-plugin-mpx": "^2.0.0", + "@mpxjs/vue-cli-plugin-mpx-e2e-test": "^2.0.0", + "@mpxjs/vue-cli-plugin-mpx-eslint": "^2.0.0", + "@mpxjs/vue-cli-plugin-mpx-typescript": "^2.0.0", + "@mpxjs/vue-cli-plugin-mpx-unit-test": "^2.0.0", + "@mpxjs/webpack-plugin": "^2.8.0", + "@vue/cli-service": "latest", + "autoprefixer": "^10.2.4", + "babel-jest": "^27.4.5", + "eslint": "^7.0.0", + "jest": "^27.4.5", + "postcss": "^8.2.6", + "stylus": "^0.55.0", + "stylus-loader": "^6.1.0", + "typescript": "^4.1.3", + "vue-template-compiler": "^2.6.14", + "webpack": "^5.43.0", + }, + "name": "test-plugin-combine", + "private": true, + "scripts": Object { + "build": "mpx-cli-service build", + "build:e2e": "npm run build && npm run test:e2e", + "lint": "eslint --ext .js,.ts,.mpx src/", + "serve": "mpx-cli-service serve", + "test": "jest test/components", + "test:e2e": "npx e2e-runner j---config=./jest-e2e.config.js", + }, + "version": "0.1.0", +} +`; + +exports[`test-wx 1`] = ` +Object { + "staticAliDir": true, + "staticDdDir": true, + "staticQqDir": false, + "staticSwanDir": true, + "staticTtDir": true, + "staticWxDir": true, +} +`; + +exports[`test-wx 2`] = ` +Object { + "appid": "test-plugin-have-appid", + "condition": Object {}, + "description": "test-plugin-have-description", + "projectname": "test-wx", + "setting": Object { + "autoAudits": false, + "checkSiteMap": false, + "es6": false, + "minified": false, + "newFeature": true, + "postcss": true, + "urlCheck": true, + }, +} +`; diff --git a/packages/mpx-cli/__tests__/preset.spec.js b/packages/mpx-cli/__tests__/preset.spec.js index 324711d8..8f75ebe7 100644 --- a/packages/mpx-cli/__tests__/preset.spec.js +++ b/packages/mpx-cli/__tests__/preset.spec.js @@ -1,5 +1,5 @@ jest.mock('inquirer') - +const glob = require('glob') const path = require('path') const fs = require('fs') const create = require('@mpxjs/cli/lib/create') @@ -228,10 +228,9 @@ test('test-e2e', async () => { expect(pkg.devDependencies).toHaveProperty('@mpxjs/vue-cli-plugin-mpx-e2e-test') }) -// 测试一下 test-yao-1.0.0 这个项目,有没有 @mpxjs/babel-plugin-inject-page-events 这个依赖 -test('test-yao-1.0.0', async () => { +// 封装一个方法,用来生成项目,然后将配置项作为参数传入 +const createProject = async (name, options) => { const cwd = path.resolve(__dirname, '../../test') - const name = 'test-yao-1.0.0' await create( name, { @@ -239,108 +238,152 @@ test('test-yao-1.0.0', async () => { git: false, cwd }, - { - srcMode: 'wx', - appid: 'test-yao-1.0.0', - description: 'test', - cross: true, - needE2ETest: true, - plugins: {}, - useConfigFiles: true - // srcMode: 'wx' 表示小程序的类型是微信小程序 - // appid: 'test-yao-1.0.0' 表示小程序的appid - // description: 'test' 表示小程序的描述 - // cross: true 表示是否跨平台 - // needE2ETest: true 表示是否需要e2e测试 - // plugins: {} 表示插件 - // useConfigFiles: true 表示是否使用配置文件 - } + options + // srcMode: 'wx' 表示小程序的类型是微信小程序 + // appid: 'test-yao-1.0.0' 表示小程序的appid + // description: 'test' 表示小程序的描述 + // cross: true 表示是否跨平台 + // needE2ETest: true 表示是否需要e2e测试 + // plugins: {} 表示插件 + // useConfigFiles: true 表示是否使用配置文件 ) +} - const pkg = require(path.resolve(cwd, name, 'package.json')) - expect(pkg.devDependencies).toHaveProperty('@mpxjs/babel-plugin-inject-page-events') -}) - -// 将srcMode改成ali,测试一下 test-yao-1.0.1 这个项目生成的static/ali目录是否存在,还是否存在wx目录 -test('test-yao-1.0.1', async () => { +// wx模式 +test('test-wx', async () => { const cwd = path.resolve(__dirname, '../../test') - const name = 'test-yao-1.0.1' - await create( - name, - { - force: true, - git: false, - cwd - }, - { - srcMode: 'ali', - appid: 'test-yao-1.0.1', - description: 'test', - cross: true, - needE2ETest: true, - plugins: {}, - useConfigFiles: true - } - ) - + const name = 'test-wx' + await createProject(name, { + srcMode: 'wx', + appid: 'test-plugin-have-appid', + description: 'test-plugin-have-description', + cross: true, + needE2ETest: true, + plugins: {}, + useConfigFiles: true + }) + // 生成的目录下是否包含了wx目录,ali目录,swan目录,tt目录,dd目录 const staticWxDir = fs.existsSync(path.resolve(cwd, name, 'static/wx')) const staticAliDir = fs.existsSync(path.resolve(cwd, name, 'static/ali')) - expect(staticWxDir).toBe(false) + const staticSwanDir = fs.existsSync(path.resolve(cwd, name, 'static/swan')) + const staticQqDir = fs.existsSync(path.resolve(cwd, name, 'static/qq')) + const staticDdDir = fs.existsSync(path.resolve(cwd, name, 'static/dd')) + const staticTtDir = fs.existsSync(path.resolve(cwd, name, 'static/tt')) + expect(staticWxDir).toBe(true) expect(staticAliDir).toBe(true) - // a: 1. fs.existsSync(path.resolve(cwd, name, 'static/wx')) 判断static/wx目录是否存在,如果存在返回true,不存在返回false - // a: 2. fs.existsSync(path.resolve(cwd, name, 'static/ali')) 判断static/ali目录是否存在,如果存在返回true,不存在返回false - // a: 3. expect(staticWxDir).toBe(false) 判断staticWxDir是否为false,如果为false则测试通过,如果为true则测试失败 - // a: 4. expect(staticAliDir).toBe(true) 判断staticAliDir是否为true,如果为true则测试通过,如果为false则测试失败 + expect(staticSwanDir).toBe(true) + expect(staticQqDir).toBe(false) + expect(staticDdDir).toBe(true) + expect(staticTtDir).toBeTruthy() + + // 生成的appid是否是test-plugin-have-appid + const projectConfig = require(path.resolve(cwd, name, 'static/wx/project.config.json')) + expect(projectConfig.appid).toBe('test-plugin-have-appid') + + // 生成的description是否是test-plugin-have-description + expect(projectConfig.description).toBe('test-plugin-have-description') + + // 保存快照 + // 检查生成的目录是否和预期的目录一致 + expect({ + staticWxDir, + staticAliDir, + staticSwanDir, + staticQqDir, + staticDdDir, + staticTtDir + }).toMatchSnapshot() + + // 检查生成的目录下的project.config.json文件是否和预期的一致 + expect(projectConfig).toMatchSnapshot() }) -// 测试一下 test-yao-1.0.0 这个项目,有没有 @mpxjs/babel-plugin-inject-page-events 这个依赖 -test('test-yao-vue-1.0.0', async () => { +// 测试插件是否存在,wx模式 +test('test-plugin-have', async () => { const cwd = path.resolve(__dirname, '../../test') - const name = 'test-yao-vue-1.0.0' - await create( - name, - { - force: true, - git: false, - cwd - }, - { - srcMode: 'wx', - appid: 'test-yao-vue-1.0.0', - description: 'test', - cross: true, - needE2ETest: true, - plugins: {}, - useConfigFiles: true - } - ) + const name = 'test-plugin-have' + await createProject(name, { + srcMode: 'wx', + appid: 'test-plugin-have-appid', + description: 'test-plugin-have-description', + cross: true, + needE2ETest: true, + plugins: {}, + useConfigFiles: true + }) + // 有没有 @mpxjs/babel-plugin-inject-page-events 这个依赖 const pkg = require(path.resolve(cwd, name, 'package.json')) expect(pkg.devDependencies).toHaveProperty('@mpxjs/babel-plugin-inject-page-events') }) -// 将srcMode改成ali,测试一下 test-yao-1.0.1 这个项目生成的static/ali目录是否存在,还是否存在wx目录,是否还有 @mpxjs/babel-plugin-inject-page-events 这个依赖 -test('test-yao-vue-1.0.1', async () => { +// 将srcMode改成ali,生成的static/ali目录是否存在,还是否存在wx目录 +test('test-ali', async () => { const cwd = path.resolve(__dirname, '../../test') - const name = 'test-yao-vue-1.0.1' - await create( - name, - { - force: true, - git: false, - cwd + const name = 'test-ali' + await createProject(name, { + srcMode: 'ali', + appid: 'test-ali-appid', + description: 'test-ali-description', + cross: true, + needE2ETest: true, + plugins: {}, + useConfigFiles: true + }) + + const staticWxDir = glob.sync(path.resolve(cwd, name, 'static/wx')) + const staticAliDir = glob.sync(path.resolve(cwd, name, 'static/ali')) + expect(staticWxDir.length).toBe(0) // 确保 static/wx 目录不存在 + expect(staticAliDir.length).toBeGreaterThan(0) // 确保 static/ali 目录存在 + + // 保存快照 + // 检查生成的目录是否和预期的目录一致 + expect({ + staticWxDir, + staticAliDir + }).toMatchSnapshot() +}) + +// 插件组合测试 +test('test-plugin-combine', async () => { + const cwd = path.resolve(__dirname, '../../test') + const name = 'test-plugin-combine' + await createProject(name, { + srcMode: 'wx', + appid: 'test-plugin-combine-appid', + description: 'test-plugin-combine-description', + cross: true, + needE2ETest: true, + plugins: { + '@mpxjs/vue-cli-plugin-mpx': { + version: '^2.0.0' + }, + '@mpxjs/vue-cli-plugin-mpx-typescript': { + version: '^2.0.0' + }, + '@mpxjs/vue-cli-plugin-mpx-unit-test': { + version: '^2.0.0' + }, + '@mpxjs/vue-cli-plugin-mpx-e2e-test': { + version: '^2.0.0' + } }, - { - srcMode: 'ali', - appid: 'test-yao-vue-1.0.1', - description: 'test', - cross: true, - needE2ETest: true, - plugins: {}, - useConfigFiles: true - } - ) + useConfigFiles: true + }) const pkg = require(path.resolve(cwd, name, 'package.json')) - expect(pkg.devDependencies).toHaveProperty('@mpxjs/babel-plugin-inject-page-events') + expect(pkg.devDependencies).toHaveProperty('@mpxjs/vue-cli-plugin-mpx') + expect(pkg.devDependencies).toHaveProperty('@mpxjs/vue-cli-plugin-mpx-typescript') + expect(pkg.devDependencies).toHaveProperty('@mpxjs/vue-cli-plugin-mpx-unit-test') + expect(pkg.devDependencies).toHaveProperty('@mpxjs/vue-cli-plugin-mpx-e2e-test') + + // 查看上面五个插件的版本是否正确 + expect(pkg.devDependencies['@mpxjs/vue-cli-plugin-mpx']).toBe('^2.0.0') + expect(pkg.devDependencies['@mpxjs/vue-cli-plugin-mpx-typescript']).toBe('^2.0.0') + expect(pkg.devDependencies['@mpxjs/vue-cli-plugin-mpx-unit-test']).toBe('^2.0.0') + expect(pkg.devDependencies['@mpxjs/vue-cli-plugin-mpx-e2e-test']).toBe('^2.0.0') + + // 保存快照 + // 检查生成的文件是否和预期的一致 + expect(pkg).toMatchSnapshot() })