Skip to content

Commit

Permalink
增加测试用例覆盖率统计
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Feb 2, 2021
1 parent 92c4ae1 commit dbf44a4
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 39 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.idea
.vscode
.nyc_output
coverage
node_modules
package-lock.json
.vscode
2 changes: 1 addition & 1 deletion dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -2132,7 +2132,7 @@ base.init(COS, task);
advance.init(COS, task);

COS.getAuthorization = util.getAuth;
COS.version = '1.1.9';
COS.version = '1.1.11';

module.exports = COS;

Expand Down
2 changes: 1 addition & 1 deletion dist/cos-js-sdk-v5.min.js

Large diffs are not rendered by default.

34 changes: 22 additions & 12 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ declare namespace COS {
/** 获取签名的回调方法,如果没有 SecretId、SecretKey 时,必选 */
getAuthorization?: (
options: GetAuthorizationOptions,
/** 获取完签名或临时密钥后,回传给 SDK 的方法 */
/** callback 获取完签名或临时密钥后,回传给 SDK 的方法 */
callback: (
/** 回传给 SDK 的签名或获取临时密钥 */
/** params 回传给 SDK 的签名或获取临时密钥 */
params: GetAuthorizationCallbackParams
) => void
) => void,
Expand All @@ -182,12 +182,16 @@ declare namespace COS {
Method?: Method,
/** 请求路径,最前面带 /,例如 /images/1.jpg,可选 */
Pathname?: Pathname,
/** 请求的对象键,最前面不带 /,例如 images/1.jpg,可选 */
Key?: Key,
/** 要参与签名计算的 Url Query 参数,可选 */
Query?: Query,
/** 要参与签名计算的 Header 参数,可选 */
Headers?: Headers,
/** 校正时间的偏移值,单位 ms(毫秒),计算签名时会用设备当前时间戳加上该偏移值,在设备时间有误时可用于校正签名用的时间参数。 */
SystemClockOffset?: number,
/** 签名有效时间戳区间,如果传入了该参数,会赋值给在签名里的 q-key-time 和 q-sign-time 字段,格式如:1611915436;1611916336 */
KeyTime: string,
}
/** 计算签名或获取临时密钥可能需要的参数列表 */
interface GetAuthorizationOptions {
Expand All @@ -210,6 +214,7 @@ declare namespace COS {
/** 校正时间的偏移值,单位 ms(毫秒),计算签名时会用设备当前时间戳加上该偏移值,在设备时间有误时可用于校正签名用的时间参数。 */
SystemClockOffset: number,
}
/** 请求凭证,包含临时密钥信息 */
interface Credentials {
/** 临时密钥 tmpSecretId */
TmpSecretId: string,
Expand All @@ -229,22 +234,27 @@ declare namespace COS {
type Authorization = string;
/** SDK 用于请求的凭证,可以是签名,也可以是临时密钥信息 */
type GetAuthorizationCallbackParams = Authorization | Credentials;
/** 错误格式,其中服务端返回错误码可查看 @see https://cloud.tencent.com/document/product/436/7730 */
type CosError = null | {
/** 请求返回的 HTTP 状态码 */
statusCode?: number,
/** 请求返回的 header 字段 */
headers?: Headers,
/** 错误信息,可能是参数错误、客户端出错、或服务端返回的错误 */
error: string | Error | { Code: string, Message: string }
}
/** 一般接口的返回结果 */
interface GeneralResult {
/** 请求返回的 HTTP 状态码 */
statusCode?: number,
/** 请求返回的 header 字段 */
headers?: Headers,
/** 请求的唯一标识 */
RequestId?: string,
}
/** SDK 的错误格式,其中服务端返回错误码可查看 @see https://cloud.tencent.com/document/product/436/7730 */
interface CosSdkError extends GeneralResult {
/** 错误码 */
code: string,
/** 错误信息 */
message: string,
/** 错误信息,可能是参数错误、客户端出错、或服务端返回的错误 */
error: string | Error | { Code: string, Message: string },
}
/** 回调的错误格式,其中服务端返回错误码可查看 @see https://cloud.tencent.com/document/product/436/7730 */
type CosError = null | CosSdkError;
/** 存储桶操作接口的公共参数 */
interface BucketParams {
/** 存储桶的名称,格式为<bucketname-appid>,例如examplebucket-1250000000 */
Bucket: Bucket,
Expand All @@ -253,6 +263,7 @@ declare namespace COS {
/** 请求时带上的 Header 字段 */
Headers?: Headers,
}
/** 对象操作接口的公共参数 */
interface ObjectParams {
/** 存储桶的名称,格式为<bucketname-appid>,例如examplebucket-1250000000 */
Bucket: Bucket,
Expand Down Expand Up @@ -2085,7 +2096,6 @@ declare class COS {

/** 获取文件下载链接 @see https://cloud.tencent.com/document/product/436/35651 */
getObjectUrl(params: COS.GetObjectUrlParams, callback: (err: COS.CosError, data: COS.GetObjectUrlResult) => void): string;
getObjectUrl(params: COS.GetObjectUrlParams): Promise<COS.GetObjectUrlResult>;

/** 获取 COS JSON API (v4) 签名 @see https://cloud.tencent.com/document/product/436/6054 */
getV4Auth(params: COS.GetV4AuthParams): COS.Authorization;
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "cos-js-sdk-v5",
"version": "1.1.10",
"version": "1.1.11",
"description": "JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)",
"main": "index.js",
"types": "types",
"scripts": {
"server": "node server/sts.js",
"dev": "cross-env NODE_ENV=development webpack -w",
"build": "cross-env NODE_ENV=production webpack",
"cos-auth.min.js": "uglifyjs ./demo/common/cos-auth.js -o ./demo/common/cos-auth.min.js -c -m"
"cos-auth.min.js": "uglifyjs ./demo/common/cos-auth.js -o ./demo/common/cos-auth.min.js -c -m",
"nyc": "node test/watcher.js && nyc report --reporter=clover --reporter=cobertura"
},
"repository": {
"type": "git",
Expand All @@ -30,9 +31,10 @@
"body-parser": "^1.18.3",
"cross-env": "^5.2.0",
"express": "^4.16.4",
"puppeteer": "^5.3.1",
"puppeteer-to-istanbul": "^1.4.0",
"qcloud-cos-sts": "^3.0.2",
"request": "^2.87.0",
"webpack": "^3.12.0",
"puppeteer": "^5.3.1"
"webpack": "^3.12.0"
}
}
2 changes: 1 addition & 1 deletion src/cos.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ base.init(COS, task);
advance.init(COS, task);

COS.getAuthorization = util.getAuth;
COS.version = '1.1.9';
COS.version = '1.1.11';

module.exports = COS;
2 changes: 1 addition & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ <h2 id="qunit-banner"></h2>
<script src="./test.js"></script>

</body>
</html>
</html>
29 changes: 12 additions & 17 deletions test/watcher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const pti = require('puppeteer-to-istanbul')
const puppeteer = require('puppeteer');

var path = require('path');
var fs = require('fs');
var util = require('util');

Expand All @@ -13,29 +15,22 @@ console.log = function () {
}
console.error = console.log;

puppeteer.launch({
args: [
'--no-proxy-server',
'--no-sandbox',
'--disable-setuid-sandbox'
]
}).then(function (browser) {
browser.newPage().then(function (page) {
page.on('console', function (msg) {
(async () => {
const browser = await puppeteer.launch({args: ['--no-proxy-server', '--no-sandbox', '--disable-setuid-sandbox']});
const page = await browser.newPage();
page.on('console', async function (msg) {
var text = msg.text();
var type = msg.type();
if (text.startsWith('[test-result]')) {
console.log('==[TESTING-ENDS]==')

const details = JSON.parse(text.replace('[test-result]', ''))
console.log(details)

browser.close()
const jsCoverage = await page.coverage.stopJSCoverage();
pti.write(jsCoverage, { includeHostname: true , storagePath: './.nyc_output' })
await browser.close()
} else {
console.log(msg.text())
}

});
page.goto(`http://127.0.0.1:3000/test`);
})
});
await page.coverage.startJSCoverage();
await page.goto('http://127.0.0.1:3000/test');
})()
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ if (process.env.NODE_ENV === 'production') {
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
sourceMap: false,
output: {
ascii_only: true,
},
Expand Down

0 comments on commit dbf44a4

Please sign in to comment.