Skip to content

Commit eb3f60b

Browse files
committed
test: add test case
1 parent e31a2fd commit eb3f60b

File tree

10 files changed

+103
-16
lines changed

10 files changed

+103
-16
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"lerna": "^4.0.0",
1919
"lint-staged": "^11.1.1",
2020
"mwts": "^1.2.2",
21+
"ts-jest": "^27.0.5",
2122
"typescript": "^4.3.5"
2223
},
2324
"config": {
@@ -53,4 +54,4 @@
5354
"node": ">=10"
5455
},
5556
"license": "MIT"
56-
}
57+
}

packages/cli-plugin-deploy/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"main": "dist/index",
55
"typings": "dist/index.d.ts",
66
"scripts": {
7-
"build": "tsc --build"
7+
"build": "tsc --build",
8+
"test": "../../node_modules/.bin/jest"
89
},
910
"engines": {
1011
"node": ">= 10"

packages/cli-plugin-deploy/src/index.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class DeployPlugin {
4646
// 压缩包
4747
const zipStream = await this.zipProject()
4848
// 获取项目名称
49-
const projectName = this.getProjectName()
49+
const projectName = this.getProjectName(process.cwd())
5050
// 上传压缩包
5151
const rules = await this.uploadZipProject(zipStream, projectName)
5252
// 验证代理工具
@@ -106,10 +106,9 @@ export class DeployPlugin {
106106
}
107107
}
108108

109-
getProjectName(): string {
109+
getProjectName(cwd: string): string {
110110
const spinner = ora('get project name').start()
111111
try {
112-
const cwd = process.cwd()
113112
// vue.config.js publicPath
114113
const configUrl = `${cwd}/vue.config.js`
115114
if (fs.existsSync(configUrl)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "proxy"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
publicPath: '/proxy/'
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as path from "path"
2+
import { DeployPlugin } from "../src"
3+
4+
describe("/cli/test/index.test.ts", () => {
5+
6+
it("getProjectName", async () => {
7+
const deployInstance = new DeployPlugin(null)
8+
const cwd = path.resolve(__dirname, './fixtures')
9+
const res = deployInstance.getProjectName(cwd)
10+
expect(res).toBe('proxy')
11+
})
12+
13+
})

packages/cli/jest.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('../../jest.config')({ })

packages/cli/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"wp": "bin/winex-proxy-cli.js"
88
},
99
"scripts": {
10-
"build": "tsc --build"
10+
"build": "tsc --build",
11+
"test": "../../node_modules/.bin/jest"
1112
},
1213
"keywords": [
1314
"bin"
@@ -43,4 +44,4 @@
4344
"@types/semver": "^7.3.8",
4445
"typescript": "^4.3.5"
4546
}
46-
}
47+
}

packages/cli/test/index.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { CLI } from "../src"
2+
3+
describe("/cli/test/index.test.ts", () => {
4+
5+
it("checkUpdate", async () => {
6+
const cliInstance = new CLI()
7+
const res = await cliInstance.checkUpdate()
8+
expect(res).toBeUndefined()
9+
});
10+
11+
it("handleVersion", () => {
12+
const cliInstance = new CLI()
13+
expect(cliInstance.handleVersion()).toBeUndefined()
14+
})
15+
16+
})

yarn.lock

+58-9
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,17 @@
677677
"@types/yargs" "^16.0.0"
678678
chalk "^4.0.0"
679679

680+
"@jest/types@^27.1.0":
681+
version "27.1.0"
682+
resolved "https://registry.yarnpkg.com/@jest/types/-/types-27.1.0.tgz#674a40325eab23c857ebc0689e7e191a3c5b10cc"
683+
integrity sha512-pRP5cLIzN7I7Vp6mHKRSaZD7YpBTK7hawx5si8trMKqk4+WOdK8NEKOTO2G8PKWD1HbKMVckVB6/XHh/olhf2g==
684+
dependencies:
685+
"@types/istanbul-lib-coverage" "^2.0.0"
686+
"@types/istanbul-reports" "^3.0.0"
687+
"@types/node" "*"
688+
"@types/yargs" "^16.0.0"
689+
chalk "^4.0.0"
690+
680691
681692
version "4.0.0"
682693
resolved "https://registry.yarnpkg.com/@lerna/add/-/add-4.0.0.tgz#c36f57d132502a57b9e7058d1548b7a565ef183f"
@@ -2140,6 +2151,13 @@ browserslist@^4.16.6:
21402151
escalade "^3.1.1"
21412152
node-releases "^1.1.71"
21422153

2154+
2155+
version "0.2.6"
2156+
resolved "https://registry.yarnpkg.com/bs-logger/-/bs-logger-0.2.6.tgz#eb7d365307a72cf974cc6cda76b68354ad336bd8"
2157+
integrity sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==
2158+
dependencies:
2159+
fast-json-stable-stringify "2.x"
2160+
21432161
21442162
version "2.1.1"
21452163
resolved "https://registry.yarnpkg.com/bser/-/bser-2.1.1.tgz#e6787da20ece9d07998533cfd9de6f5c38f4bc05"
@@ -3381,7 +3399,7 @@ fast-glob@^3.1.1:
33813399
merge2 "^1.3.0"
33823400
micromatch "^4.0.4"
33833401

3384-
fast-json-stable-stringify@^2.0.0:
3402+
fast-json-stable-stringify@2.x, fast-json-stable-stringify@^2.0.0:
33853403
version "2.1.0"
33863404
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633"
33873405
integrity sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==
@@ -4775,6 +4793,18 @@ jest-snapshot@^27.0.6:
47754793
pretty-format "^27.0.6"
47764794
semver "^7.3.2"
47774795

4796+
jest-util@^27.0.0:
4797+
version "27.1.0"
4798+
resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-27.1.0.tgz#06a53777a8cb7e4940ca8e20bf9c67dd65d9bd68"
4799+
integrity sha512-edSLD2OneYDKC6gZM1yc+wY/877s/fuJNoM1k3sOEpzFyeptSmke3SLnk1dDHk9CgTA+58mnfx3ew3J11Kes/w==
4800+
dependencies:
4801+
"@jest/types" "^27.1.0"
4802+
"@types/node" "*"
4803+
chalk "^4.0.0"
4804+
graceful-fs "^4.2.4"
4805+
is-ci "^3.0.0"
4806+
picomatch "^2.2.3"
4807+
47784808
jest-util@^27.0.6:
47794809
version "27.0.6"
47804810
resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-27.0.6.tgz#e8e04eec159de2f4d5f57f795df9cdc091e50297"
@@ -4926,7 +4956,7 @@ json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1:
49264956
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
49274957
integrity sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=
49284958

4929-
json5@^2.1.2, json5@^2.1.3:
4959+
json5@2.x, json5@^2.1.2, json5@^2.1.3:
49304960
version "2.2.0"
49314961
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.0.tgz#2dfefe720c6ba525d9ebd909950f0515316c89a3"
49324962
integrity sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==
@@ -5180,7 +5210,7 @@ lodash.truncate@^4.4.2:
51805210
resolved "https://registry.yarnpkg.com/lodash.truncate/-/lodash.truncate-4.4.2.tgz#5a350da0b1113b837ecfffd5812cbe58d6eae193"
51815211
integrity sha1-WjUNoLERO4N+z//VgSy+WNbq4ZM=
51825212

5183-
lodash@^4.17.12, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.7.0:
5213+
lodash@4.x, lodash@^4.17.12, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.7.0:
51845214
version "4.17.21"
51855215
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
51865216
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
@@ -5240,6 +5270,11 @@ make-dir@^3.0.0:
52405270
dependencies:
52415271
semver "^6.0.0"
52425272

5273+
5274+
version "1.3.6"
5275+
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
5276+
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
5277+
52435278
make-fetch-happen@^8.0.9:
52445279
version "8.0.14"
52455280
resolved "https://registry.yarnpkg.com/make-fetch-happen/-/make-fetch-happen-8.0.14.tgz#aaba73ae0ab5586ad8eaa68bd83332669393e222"
@@ -6710,7 +6745,7 @@ semver-diff@^3.1.1:
67106745
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
67116746
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==
67126747

6713-
[email protected], semver@^7.1.1, semver@^7.1.3, semver@^7.2.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5:
6748+
[email protected], semver@7.x, semver@^7.1.1, semver@^7.1.3, semver@^7.2.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5:
67146749
version "7.3.5"
67156750
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7"
67166751
integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==
@@ -7312,6 +7347,20 @@ trim-off-newlines@^1.0.0:
73127347
resolved "https://registry.yarnpkg.com/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz#9f9ba9d9efa8764c387698bcbfeb2c848f11adb3"
73137348
integrity sha1-n5up2e+odkw4dpi8v+sshI8RrbM=
73147349

7350+
ts-jest@^27.0.5:
7351+
version "27.0.5"
7352+
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-27.0.5.tgz#0b0604e2271167ec43c12a69770f0bb65ad1b750"
7353+
integrity sha512-lIJApzfTaSSbtlksfFNHkWOzLJuuSm4faFAfo5kvzOiRAuoN4/eKxVJ2zEAho8aecE04qX6K1pAzfH5QHL1/8w==
7354+
dependencies:
7355+
bs-logger "0.x"
7356+
fast-json-stable-stringify "2.x"
7357+
jest-util "^27.0.0"
7358+
json5 "2.x"
7359+
lodash "4.x"
7360+
make-error "1.x"
7361+
semver "7.x"
7362+
yargs-parser "20.x"
7363+
73157364
tslib@^1.8.1, tslib@^1.9.0:
73167365
version "1.14.1"
73177366
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
@@ -7795,6 +7844,11 @@ [email protected]:
77957844
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.4.tgz#b42890f14566796f85ae8e3a25290d205f154a54"
77967845
integrity sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==
77977846

7847+
[email protected], yargs-parser@^20.2.2, yargs-parser@^20.2.3:
7848+
version "20.2.9"
7849+
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee"
7850+
integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==
7851+
77987852
yargs-parser@^18.1.3:
77997853
version "18.1.3"
78007854
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-18.1.3.tgz#be68c4975c6b2abf469236b0c870362fab09a7b0"
@@ -7803,11 +7857,6 @@ yargs-parser@^18.1.3:
78037857
camelcase "^5.0.0"
78047858
decamelize "^1.2.0"
78057859

7806-
yargs-parser@^20.2.2, yargs-parser@^20.2.3:
7807-
version "20.2.9"
7808-
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee"
7809-
integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==
7810-
78117860
yargs@^16.0.3, yargs@^16.2.0:
78127861
version "16.2.0"
78137862
resolved "https://registry.yarnpkg.com/yargs/-/yargs-16.2.0.tgz#1c82bf0f6b6a66eafce7ef30e376f49a12477f66"

0 commit comments

Comments
 (0)