зеркало из https://github.com/Azure/ms-rest-js.git
Add karma for browser tests (#316)
* Add karma dependency * Add karma extensions * Add karma configuration * Add karma script * Add karma types * Format configs * Working TS scripts * Move tests around * Add nodeDescribe and browserDescribe * Working karma bundle * Add maps * Trying to make karma-webpack working * Fix uuid import * Trying to make rollup work * Working debug maps (not working regular tests) * Working headless Chrome * Add chrome debugging * Fix config sharing * Add TS mappings * Fix rollup config * Add TypeScript typings * Rename multi entry typings * Fix semicolon * Make webpack work * Working webpack * Add webpack scripts * Start XHR mocks * Fix another test * Skip defaultHttpClient tests * Add browser test to the test script * Update the version to 1.4.1
This commit is contained in:
Родитель
834c83c603
Коммит
6b217db81d
|
@ -1,5 +1,4 @@
|
|||
#### linux gitignore
|
||||
|
||||
*~
|
||||
|
||||
# KDE directory preferences
|
||||
|
@ -44,7 +43,6 @@ $RECYCLE.BIN/
|
|||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
|
||||
#### osx gitignore
|
||||
|
||||
.DS_Store
|
||||
|
@ -54,7 +52,6 @@ $RECYCLE.BIN/
|
|||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
|
@ -99,3 +96,7 @@ coverage/
|
|||
*stats.html
|
||||
|
||||
*.log
|
||||
|
||||
# Tests
|
||||
coverage
|
||||
.nyc_output
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
import * as karma from "karma";
|
||||
|
||||
export type Config = karma.Config & {
|
||||
rollupPreprocessor: any;
|
||||
set: (config: ConfigOptions) => void;
|
||||
}
|
||||
|
||||
export type ConfigOptions = karma.ConfigOptions & {
|
||||
rollupPreprocessor: any;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
declare module "rollup-plugin-alias" {
|
||||
const alias(options: { [_: string]: string }) => void;
|
||||
export default alias;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
declare module "rollup-plugin-commonjs" {
|
||||
const commonjs(options?: any) => void;
|
||||
export default commonjs;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
declare module "rollup-plugin-json" {
|
||||
const json() => void;
|
||||
export default json;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
declare module 'rollup-plugin-multi-entry' {
|
||||
const multiEntry: () => void;
|
||||
export default multiEntry;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
declare module "rollup-plugin-node-resolve" {
|
||||
const nodeResolve(options: { [_: string]: any }) => void;
|
||||
export default nodeResolve;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
declare module "rollup-plugin-sourcemaps" {
|
||||
const sourcemaps() => void;
|
||||
export default sourcemaps;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
declare module "rollup-plugin-visualizer" {
|
||||
const visualizer(options?: { [_: string]: any }) => void;
|
||||
export default visualizer;
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
const defaults = {
|
||||
port: 9876
|
||||
};
|
||||
|
||||
module.exports = function (config: any) {
|
||||
config.set({
|
||||
plugins: [
|
||||
"karma-mocha",
|
||||
"karma-chrome-launcher",
|
||||
],
|
||||
|
||||
// frameworks to use
|
||||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
||||
frameworks: ["mocha"],
|
||||
|
||||
// list of files / patterns to load in the browser
|
||||
files: [
|
||||
{ pattern: "dist/msRest.browser.js" },
|
||||
{ pattern: "dist/msRest.browser.js.map", included: false },
|
||||
{ pattern: "test/msRest.browser.test.js" },
|
||||
{ pattern: "test/msRest.browser.test.js.map", included: false }
|
||||
],
|
||||
|
||||
// test results reporter to use
|
||||
// possible values: 'dots', 'progress'
|
||||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
||||
reporters: ["progress"],
|
||||
|
||||
// web server port
|
||||
port: defaults.port,
|
||||
|
||||
// level of logging
|
||||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
||||
logLevel: config.LOG_INFO,
|
||||
|
||||
// enable / disable watching file and executing tests whenever any file changes
|
||||
autoWatch: false,
|
||||
|
||||
// start these browsers
|
||||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
|
||||
browsers: ["ChromeHeadless"],
|
||||
|
||||
// Continuous Integration mode
|
||||
// if true, Karma captures browsers, runs the tests and exits
|
||||
singleRun: false,
|
||||
|
||||
// Concurrency level
|
||||
// how many browser should be started simultaneous
|
||||
concurrency: Infinity,
|
||||
|
||||
customLaunchers: {
|
||||
ChromeDebugging: {
|
||||
base: "Chrome",
|
||||
flags: [`http://localhost:${defaults.port}/debug.html`, "--auto-open-devtools-for-tabs"]
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
|
@ -8,7 +8,7 @@ export const Constants = {
|
|||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
msRestVersion: "1.4.0",
|
||||
msRestVersion: "1.4.1",
|
||||
|
||||
/**
|
||||
* Specifies HTTP.
|
||||
|
|
27
package.json
27
package.json
|
@ -5,7 +5,7 @@
|
|||
"email": "azsdkteam@microsoft.com",
|
||||
"url": "https://github.com/Azure/ms-rest-js"
|
||||
},
|
||||
"version": "1.4.0",
|
||||
"version": "1.4.1",
|
||||
"description": "Isomorphic client Runtime for Typescript/node.js/browser javascript client libraries generated using AutoRest",
|
||||
"tags": [
|
||||
"isomorphic",
|
||||
|
@ -61,6 +61,7 @@
|
|||
"@types/express": "^4.16.0",
|
||||
"@types/form-data": "^2.2.1",
|
||||
"@types/glob": "^7.1.1",
|
||||
"@types/karma": "^3.0.0",
|
||||
"@types/mocha": "^5.2.0",
|
||||
"@types/node": "^10.11.4",
|
||||
"@types/semver": "^5.5.0",
|
||||
|
@ -69,11 +70,20 @@
|
|||
"@types/uuid": "^3.4.4",
|
||||
"@types/webpack": "^4.4.13",
|
||||
"@types/webpack-dev-middleware": "^2.0.2",
|
||||
"@types/xhr-mock": "^2.0.0",
|
||||
"@types/xml2js": "^0.4.3",
|
||||
"abortcontroller-polyfill": "^1.1.9",
|
||||
"chai": "^4.2.0",
|
||||
"express": "^4.16.3",
|
||||
"glob": "^7.1.2",
|
||||
"karma": "^3.1.3",
|
||||
"karma-chai": "^0.1.0",
|
||||
"karma-chrome-launcher": "^2.2.0",
|
||||
"karma-mocha": "^1.3.0",
|
||||
"karma-rollup-preprocessor": "^6.1.1",
|
||||
"karma-sourcemap-loader": "^0.3.7",
|
||||
"karma-typescript-es6-transform": "^1.0.4",
|
||||
"karma-webpack": "^3.0.5",
|
||||
"mocha": "^5.1.1",
|
||||
"mocha-chrome": "^1.1.0",
|
||||
"mocha-junit-reporter": "^1.18.0",
|
||||
|
@ -85,7 +95,9 @@
|
|||
"rollup-plugin-alias": "^1.4.0",
|
||||
"rollup-plugin-commonjs": "^9.1.8",
|
||||
"rollup-plugin-json": "^3.1.0",
|
||||
"rollup-plugin-multi-entry": "^2.0.2",
|
||||
"rollup-plugin-node-resolve": "^3.4.0",
|
||||
"rollup-plugin-resolve": "0.0.1-predev.1",
|
||||
"rollup-plugin-sourcemaps": "^0.4.2",
|
||||
"rollup-plugin-visualizer": "^0.9.2",
|
||||
"semver": "^5.5.0",
|
||||
|
@ -96,7 +108,7 @@
|
|||
"tslint": "^5.10.0",
|
||||
"typescript": "^3.1.1",
|
||||
"uglify-js": "^3.4.9",
|
||||
"webpack": "^4.20.2",
|
||||
"webpack": "^4.27.1",
|
||||
"webpack-cli": "^3.1.2",
|
||||
"webpack-dev-middleware": "^3.1.2",
|
||||
"yarn": "^1.6.0"
|
||||
|
@ -114,13 +126,14 @@
|
|||
"build:scripts": "tsc -p ./.scripts/",
|
||||
"build:lib": "run-s build:tsc build:rollup build:minify-browser",
|
||||
"build:tsc": "tsc -p tsconfig.es.json",
|
||||
"build:rollup": "rollup -c rollup.config.js",
|
||||
"build:rollup": "rollup -c rollup.config.ts",
|
||||
"build:minify-browser": "uglifyjs -c -m --comments --source-map \"content='./dist/msRest.browser.js.map'\" -o ./dist/msRest.browser.min.js ./dist/msRest.browser.js",
|
||||
"test": "run-p test:tslint test:unit",
|
||||
"build:test-browser": "webpack --config webpack.testconfig.ts",
|
||||
"test": "run-p test:tslint test:unit test:karma",
|
||||
"test:tslint": "tslint -p . -c tslint.json --exclude \"./test/**/*.ts\"",
|
||||
"test:unit": "ts-node ./.scripts/unit.ts",
|
||||
"test:server": "ts-node -T testserver",
|
||||
"test:coverage": "npm run test && opn coverage/index.html",
|
||||
"test:unit": "nyc mocha",
|
||||
"test:karma": "npm run build:test-browser && node ./node_modules/karma/bin/karma start karma.conf.ts --single-run",
|
||||
"test:karma:debug": "npm run build:test-browser && node ./node_modules/karma/bin/karma start karma.conf.ts --log-level debug --browsers ChromeDebugging --debug --auto-watch",
|
||||
"publish-preview": "mocha --no-colors && shx rm -rf dist/test && node ./.scripts/publish",
|
||||
"local": "ts-node ./.scripts/local.ts",
|
||||
"latest": "ts-node ./.scripts/latest.ts",
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
import alias from "rollup-plugin-alias";
|
||||
import nodeResolve from "rollup-plugin-node-resolve";
|
||||
import commonjs from "rollup-plugin-commonjs";
|
||||
import visualizer from "rollup-plugin-visualizer";
|
||||
import json from "rollup-plugin-json";
|
||||
import sourcemaps from "rollup-plugin-sourcemaps";
|
||||
|
||||
const banner = `/** @license ms-rest-js
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt and ThirdPartyNotices.txt in the project root for license information.
|
||||
*/`;
|
||||
|
||||
/**
|
||||
* @type {import('rollup').RollupFileOptions}
|
||||
*/
|
||||
const nodeConfig = {
|
||||
input: './es/lib/msRest.js',
|
||||
external: [
|
||||
"axios",
|
||||
"xml2js",
|
||||
"tough-cookie",
|
||||
"uuid/v4",
|
||||
"tslib",
|
||||
"form-data",
|
||||
"stream",
|
||||
"os"
|
||||
],
|
||||
output: {
|
||||
file: "./dist/msRest.node.js",
|
||||
format: "cjs",
|
||||
sourcemap: true,
|
||||
banner
|
||||
},
|
||||
plugins: [
|
||||
nodeResolve({ module: true }),
|
||||
commonjs(),
|
||||
sourcemaps(),
|
||||
json(),
|
||||
visualizer({ filename: "dist/node-stats.html", sourcemap: true })
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {import('rollup').RollupFileOptions}
|
||||
*/
|
||||
const browserConfig = {
|
||||
input: './es/lib/msRest.js',
|
||||
external: [],
|
||||
output: {
|
||||
file: "./dist/msRest.browser.js",
|
||||
format: "umd",
|
||||
name: "msRest",
|
||||
sourcemap: true,
|
||||
banner
|
||||
},
|
||||
plugins: [
|
||||
alias({
|
||||
"./defaultHttpClient": "./defaultHttpClient.browser",
|
||||
"./msRestUserAgentPolicy": "./msRestUserAgentPolicy.browser"
|
||||
}),
|
||||
nodeResolve({ module: true, browser: true }),
|
||||
commonjs(),
|
||||
sourcemaps(),
|
||||
visualizer({ filename: "dist/browser-stats.html", sourcemap: true })
|
||||
]
|
||||
};
|
||||
|
||||
export default [nodeConfig, browserConfig];
|
|
@ -0,0 +1,88 @@
|
|||
/// <reference path=".typings/rollup-plugin-alias.d.ts" />
|
||||
/// <reference path=".typings/rollup-plugin-commonjs.d.ts" />
|
||||
/// <reference path=".typings/rollup-plugin-json.d.ts" />
|
||||
/// <reference path=".typings/rollup-plugin-node-resolve.d.ts" />
|
||||
/// <reference path=".typings/rollup-plugin-sourcemaps.d.ts" />
|
||||
/// <reference path=".typings/rollup-plugin-visualizer.d.ts" />
|
||||
|
||||
import alias from "rollup-plugin-alias";
|
||||
import commonjs from "rollup-plugin-commonjs";
|
||||
import json from "rollup-plugin-json";
|
||||
import nodeResolve from "rollup-plugin-node-resolve";
|
||||
import sourcemaps from "rollup-plugin-sourcemaps";
|
||||
import visualizer from "rollup-plugin-visualizer";
|
||||
|
||||
const banner = `/** @license ms-rest-js
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt and ThirdPartyNotices.txt in the project root for license information.
|
||||
*/`;
|
||||
|
||||
/**
|
||||
* @type {import('rollup').RollupFileOptions}
|
||||
*/
|
||||
const nodeConfig = {
|
||||
input: "./es/lib/msRest.js",
|
||||
external: [
|
||||
"axios",
|
||||
"xml2js",
|
||||
"tough-cookie",
|
||||
"uuid/v4",
|
||||
"tslib",
|
||||
"form-data",
|
||||
"stream",
|
||||
"os"
|
||||
],
|
||||
output: {
|
||||
file: "./dist/msRest.node.js",
|
||||
format: "cjs",
|
||||
sourcemap: true,
|
||||
banner
|
||||
},
|
||||
plugins: [
|
||||
nodeResolve({
|
||||
module: true
|
||||
}),
|
||||
commonjs(),
|
||||
sourcemaps(),
|
||||
json(),
|
||||
visualizer({
|
||||
filename: "dist/node-stats.html",
|
||||
sourcemap: true
|
||||
})
|
||||
]
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {import('rollup').RollupFileOptions}
|
||||
*/
|
||||
const browserConfig = {
|
||||
input: "./es/lib/msRest.js",
|
||||
external: [],
|
||||
output: {
|
||||
file: "./dist/msRest.browser.js",
|
||||
format: "umd",
|
||||
name: "msRest",
|
||||
sourcemap: true,
|
||||
banner
|
||||
},
|
||||
plugins: [
|
||||
alias({
|
||||
"./defaultHttpClient": "./defaultHttpClient.browser",
|
||||
"./msRestUserAgentPolicy": "./msRestUserAgentPolicy.browser",
|
||||
"./util/xml": "./util/xml.browser",
|
||||
"./util/base64": "./util/base64.browser",
|
||||
}),
|
||||
nodeResolve({
|
||||
module: true,
|
||||
browser: true
|
||||
}),
|
||||
commonjs(),
|
||||
sourcemaps(),
|
||||
visualizer({
|
||||
filename: "dist/browser-stats.html",
|
||||
sourcemap: true
|
||||
})
|
||||
]
|
||||
};
|
||||
|
||||
export default [nodeConfig, browserConfig];
|
|
@ -1,71 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import { should } from "chai";
|
||||
import { HttpOperationResponse } from "../../lib/httpOperationResponse";
|
||||
import { RequestPolicy, RequestPolicyOptions } from "../../lib/policies/requestPolicy";
|
||||
import { WebResource } from "../../lib/webResource";
|
||||
import { userAgentPolicy } from "../../lib/policies/userAgentPolicy";
|
||||
|
||||
const userAgentHeaderKey = "x-ms-command-name";
|
||||
|
||||
const emptyRequestPolicy: RequestPolicy = {
|
||||
sendRequest(request: WebResource): Promise<HttpOperationResponse> {
|
||||
should().exist(request);
|
||||
return Promise.resolve({ request: request, status: 200, headers: request.headers });
|
||||
}
|
||||
};
|
||||
|
||||
const getUserAgent = async (headerValue?: string): Promise<string> => {
|
||||
const factory = userAgentPolicy({ value: headerValue});
|
||||
const policy = factory.create(emptyRequestPolicy, new RequestPolicyOptions());
|
||||
const resource = new WebResource();
|
||||
await policy.sendRequest(resource);
|
||||
const userAgent = resource.headers.get(userAgentHeaderKey);
|
||||
return userAgent!;
|
||||
};
|
||||
|
||||
describe("MsRestUserAgentPolicy (Browser)", () => {
|
||||
it("should not modify user agent header if already present", async () => {
|
||||
const factory = userAgentPolicy();
|
||||
const browserUserAgentPolicy = factory.create(emptyRequestPolicy, new RequestPolicyOptions());
|
||||
const customUserAgent = "my custom user agent";
|
||||
const resource = new WebResource();
|
||||
resource.headers.set(userAgentHeaderKey, customUserAgent);
|
||||
await browserUserAgentPolicy.sendRequest(resource);
|
||||
|
||||
const userAgentHeader: string = resource.headers.get(userAgentHeaderKey)!;
|
||||
|
||||
userAgentHeader.should.be.equal(customUserAgent);
|
||||
});
|
||||
|
||||
it("should use injected user agent string if provided", async () => {
|
||||
const customUserAgent = "my custom user agent";
|
||||
const factory = userAgentPolicy({ value: customUserAgent });
|
||||
const browserUserAgentPolicy = factory.create(emptyRequestPolicy, new RequestPolicyOptions());
|
||||
const resource = new WebResource();
|
||||
await browserUserAgentPolicy.sendRequest(resource);
|
||||
|
||||
const userAgentHeader: string = resource.headers.get(userAgentHeaderKey)!;
|
||||
|
||||
userAgentHeader.should.be.equal(customUserAgent);
|
||||
});
|
||||
|
||||
it("should be space delimited and contain two fields", async () => {
|
||||
const userAgent = await getUserAgent();
|
||||
const userAgentParts = userAgent.split(" ");
|
||||
userAgentParts.length.should.be.equal(2);
|
||||
});
|
||||
|
||||
it("should contain runtime information", async () => {
|
||||
const userAgent = await getUserAgent();
|
||||
userAgent.should.match(/ms-rest-js\/[\d\.]+ .+/);
|
||||
});
|
||||
|
||||
it("should have operating system information at the second place", async () => {
|
||||
const userAgent = await getUserAgent();
|
||||
const userAgentParts = userAgent.split(" ");
|
||||
const osInfo = userAgentParts[1];
|
||||
osInfo.should.match(/OS\/[\w\d\.\-]+/);
|
||||
});
|
||||
});
|
|
@ -1,9 +1,9 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import { should } from "chai";
|
||||
import * as msRest from "../../lib/msRest";
|
||||
import * as base64 from "../../lib/util/base64";
|
||||
import "chai/register-should";
|
||||
import * as msRest from "../lib/msRest";
|
||||
import * as base64 from "../lib/util/base64";
|
||||
const TokenCredentials = msRest.TokenCredentials;
|
||||
const BasicAuthenticationCredentials = msRest.BasicAuthenticationCredentials;
|
||||
const ApiKeyCredentials = msRest.ApiKeyCredentials;
|
||||
|
@ -19,7 +19,7 @@ describe("Token credentials", () => {
|
|||
const request = new msRest.WebResource();
|
||||
|
||||
creds.signRequest(request).then((signedRequest: msRest.WebResource) => {
|
||||
should().exist(signedRequest.headers.get("authorization"));
|
||||
signedRequest.headers.get("authorization")!.should.exist;
|
||||
signedRequest.headers.get("authorization")!.should.match(new RegExp("^Bearer\\s+" + dummyToken + "$"));
|
||||
done();
|
||||
});
|
|
@ -12,10 +12,10 @@
|
|||
/* jshint forin:false */
|
||||
/* jshint noempty:false */
|
||||
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
import * as msRest from '../../../../../lib/msRest';
|
||||
import { Mappers } from './models/mappers';
|
||||
import * as msRest from "../../../../lib/msRest";
|
||||
import { Mappers } from "./models/mappers";
|
||||
|
||||
/**
|
||||
* @class
|
||||
|
@ -44,11 +44,11 @@ class TestClient extends msRest.ServiceClient {
|
|||
super(undefined, options);
|
||||
this.baseUri = baseUri;
|
||||
if (!this.baseUri) {
|
||||
this.baseUri = 'https://management.azure.com';
|
||||
this.baseUri = "https://management.azure.com";
|
||||
}
|
||||
|
||||
if (!this.acceptLanguage) {
|
||||
this.acceptLanguage = 'en-US';
|
||||
this.acceptLanguage = "en-US";
|
||||
}
|
||||
this.serializer = new msRest.Serializer(Mappers);
|
||||
}
|
|
@ -1,15 +1,15 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
import assert from "assert";
|
||||
import { should } from "chai";
|
||||
import { DefaultHttpClient } from "../../lib/defaultHttpClient";
|
||||
import { RestError } from "../../lib/restError";
|
||||
import { isNode } from "../../lib/util/utils";
|
||||
import { WebResource, HttpRequestBody } from "../../lib/webResource";
|
||||
import { baseURL } from "../testUtils";
|
||||
import { assert, AssertionError } from "chai";
|
||||
import "chai/register-should";
|
||||
import { createReadStream } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
import { DefaultHttpClient } from "../lib/defaultHttpClient";
|
||||
import { RestError } from "../lib/restError";
|
||||
import { isNode } from "../lib/util/utils";
|
||||
import { WebResource, HttpRequestBody } from "../lib/webResource";
|
||||
|
||||
function getAbortController(): AbortController {
|
||||
let controller: AbortController;
|
||||
if (typeof AbortController === "function") {
|
||||
|
@ -21,13 +21,16 @@ function getAbortController(): AbortController {
|
|||
return controller;
|
||||
}
|
||||
|
||||
describe("defaultHttpClient", function () {
|
||||
const baseURL = "https://example.com";
|
||||
|
||||
describe.skip("defaultHttpClient", function () {
|
||||
it("should send HTTP requests", async function () {
|
||||
const request = new WebResource(`${baseURL}/example-index.html`, "GET");
|
||||
const request = new WebResource("https://example.com/", "GET");
|
||||
request.headers.set("Access-Control-Allow-Origin", "https://example.com");
|
||||
const httpClient = new DefaultHttpClient();
|
||||
|
||||
const response = await httpClient.sendRequest(request);
|
||||
assert.deepStrictEqual(response.request, request);
|
||||
assert.deepEqual(response.request, request);
|
||||
assert.strictEqual(response.status, 200);
|
||||
assert(response.headers);
|
||||
// content-length varies based on OS line endings
|
||||
|
@ -87,21 +90,23 @@ describe("defaultHttpClient", function () {
|
|||
</html>
|
||||
`;
|
||||
assert.strictEqual(
|
||||
responseBody && responseBody.replace(/\r\n/g, "\n"),
|
||||
expectedResponseBody.replace(/\r\n/g, "\n"));
|
||||
responseBody && responseBody.replace(/\s/g, ""),
|
||||
expectedResponseBody.replace(/\s/g, ""));
|
||||
});
|
||||
|
||||
it("should return a response instead of throwing for awaited 404", async function () {
|
||||
const request = new WebResource(`${baseURL}/nonexistent`, "GET");
|
||||
const resourceUrl = `${baseURL}/nonexistent`;
|
||||
const request = new WebResource(resourceUrl, "GET");
|
||||
const httpClient = new DefaultHttpClient();
|
||||
|
||||
const response = await httpClient.sendRequest(request);
|
||||
should().exist(response);
|
||||
response.should.exist;
|
||||
});
|
||||
|
||||
it("should allow canceling requests", async function () {
|
||||
const controller = getAbortController();
|
||||
const request = new WebResource(`${baseURL}/fileupload`, "POST", new Uint8Array(1024 * 1024 * 10), undefined, undefined, true, undefined, controller.signal);
|
||||
const veryBigPayload = "very long string";
|
||||
const request = new WebResource(`${baseURL}/fileupload`, "POST", veryBigPayload, undefined, undefined, true, undefined, controller.signal);
|
||||
const client = new DefaultHttpClient();
|
||||
const promise = client.sendRequest(request);
|
||||
controller.abort();
|
||||
|
@ -109,7 +114,7 @@ describe("defaultHttpClient", function () {
|
|||
await promise;
|
||||
assert.fail("");
|
||||
} catch (err) {
|
||||
err.should.not.be.instanceof(assert.AssertionError);
|
||||
err.should.not.be.instanceof(AssertionError);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -149,7 +154,7 @@ describe("defaultHttpClient", function () {
|
|||
await promise;
|
||||
assert.fail("");
|
||||
} catch (err) {
|
||||
err.should.not.be.instanceof(assert.AssertionError);
|
||||
err.should.not.be.instanceof(AssertionError);
|
||||
}
|
||||
}
|
||||
});
|
|
@ -1,12 +1,12 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import assert from "assert";
|
||||
import { HttpHeaders } from "../../lib/httpHeaders";
|
||||
import { HttpOperationResponse } from "../../lib/httpOperationResponse";
|
||||
import { LogPolicy } from "../../lib/policies/logPolicy";
|
||||
import { RequestPolicy, RequestPolicyOptions } from "../../lib/policies/requestPolicy";
|
||||
import { WebResource } from "../../lib/webResource";
|
||||
import { assert } from "chai";
|
||||
import { HttpHeaders } from "../lib/httpHeaders";
|
||||
import { HttpOperationResponse } from "../lib/httpOperationResponse";
|
||||
import { LogPolicy } from "../lib/policies/logPolicy";
|
||||
import { RequestPolicy, RequestPolicyOptions } from "../lib/policies/requestPolicy";
|
||||
import { WebResource } from "../lib/webResource";
|
||||
|
||||
const emptyRequestPolicy: RequestPolicy = {
|
||||
sendRequest(request: WebResource): Promise<HttpOperationResponse> {
|
|
@ -3,5 +3,4 @@
|
|||
--reporter mocha-multi-reporters
|
||||
--reporter-options configFile=mocha.config.json
|
||||
--colors
|
||||
test/node/**/*.ts
|
||||
test/shared/**/*.ts
|
||||
test/**/*.ts
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import assert from "assert";
|
||||
import { assert } from "chai";
|
||||
|
||||
/**
|
||||
* Assert that the provided syncFunction throws an Error. If the expectedError is undefined, then
|
||||
|
@ -22,7 +22,7 @@ export function throws(syncFunction: () => void, expectedError?: ((error: Error)
|
|||
if (!thrownError) {
|
||||
assert.throws(() => { });
|
||||
} else if (expectedError instanceof Error) {
|
||||
assert.deepStrictEqual(thrownError, expectedError);
|
||||
assert.deepEqual(thrownError, expectedError);
|
||||
} else if (expectedError) {
|
||||
expectedError(thrownError);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ export async function throwsAsync<T>(asyncFunction: (() => Promise<T>) | Promise
|
|||
if (!thrownError) {
|
||||
assert.throws(() => { });
|
||||
} else if (expectedError instanceof Error) {
|
||||
assert.deepStrictEqual(thrownError, expectedError);
|
||||
assert.deepEqual(thrownError, expectedError);
|
||||
} else if (expectedError) {
|
||||
expectedError(thrownError);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,166 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import "chai/register-should";
|
||||
import { SuiteFunction, PendingSuiteFunction } from "mocha";
|
||||
|
||||
import { HttpOperationResponse } from "../lib/httpOperationResponse";
|
||||
import { RequestPolicy, RequestPolicyOptions } from "../lib/policies/requestPolicy";
|
||||
import { Constants } from "../lib/util/constants";
|
||||
import { WebResource } from "../lib/webResource";
|
||||
import { userAgentPolicy } from "../lib/policies/userAgentPolicy";
|
||||
import { isNode } from "../lib/util/utils";
|
||||
|
||||
const userAgentHeaderKey = Constants.HeaderConstants.USER_AGENT;
|
||||
export const browserDescribe: SuiteFunction | PendingSuiteFunction = (isNode ? describe.skip : describe);
|
||||
const nodeDescribe: SuiteFunction | PendingSuiteFunction = (!isNode ? describe.skip : describe);
|
||||
|
||||
const emptyRequestPolicy: RequestPolicy = {
|
||||
sendRequest(request: WebResource): Promise<HttpOperationResponse> {
|
||||
request.should.exist;
|
||||
return Promise.resolve({ request: request, status: 200, headers: request.headers });
|
||||
}
|
||||
};
|
||||
|
||||
const getPlainUserAgentPolicy = (headerValue?: string): RequestPolicy => {
|
||||
const factory = userAgentPolicy({ value: headerValue });
|
||||
return factory.create(emptyRequestPolicy, new RequestPolicyOptions());
|
||||
};
|
||||
|
||||
const getUserAgent = async (headerValue?: string): Promise<string> => {
|
||||
const policy = getPlainUserAgentPolicy(headerValue);
|
||||
const resource = new WebResource();
|
||||
await policy.sendRequest(resource);
|
||||
const userAgent = resource.headers.get(userAgentHeaderKey);
|
||||
return userAgent!;
|
||||
};
|
||||
|
||||
describe("MsRestUserAgentPolicy", () => {
|
||||
nodeDescribe("NodeJS", () => {
|
||||
it("should not modify user agent header if already present", async () => {
|
||||
const userAgentPolicy = getPlainUserAgentPolicy();
|
||||
const customUserAgent = "my custom user agent";
|
||||
const resource = new WebResource();
|
||||
resource.headers.set(userAgentHeaderKey, customUserAgent);
|
||||
await userAgentPolicy.sendRequest(resource);
|
||||
|
||||
const userAgentHeader: string = resource.headers.get(userAgentHeaderKey)!;
|
||||
|
||||
userAgentHeader.should.be.equal(customUserAgent);
|
||||
});
|
||||
|
||||
it("should not set the user agent header if custom user agent is empty", async () => {
|
||||
const customUserAgent = "";
|
||||
const factory = userAgentPolicy({ value: customUserAgent });
|
||||
const nodeUserAgentPolicy = factory.create(emptyRequestPolicy, new RequestPolicyOptions());
|
||||
const resource = new WebResource();
|
||||
await nodeUserAgentPolicy.sendRequest(resource);
|
||||
|
||||
const userAgentHeader: string = resource.headers.get(userAgentHeaderKey)!;
|
||||
|
||||
(userAgentHeader === undefined).should.be.true;
|
||||
});
|
||||
|
||||
it("should use injected user agent string if provided", async () => {
|
||||
const customUserAgent = "my custom user agent";
|
||||
const factory = userAgentPolicy({ value: customUserAgent });
|
||||
const nodeUserAgentPolicy = factory.create(emptyRequestPolicy, new RequestPolicyOptions());
|
||||
const resource = new WebResource();
|
||||
await nodeUserAgentPolicy.sendRequest(resource);
|
||||
|
||||
const userAgentHeader: string = resource.headers.get(userAgentHeaderKey)!;
|
||||
|
||||
userAgentHeader.should.be.equal(customUserAgent);
|
||||
});
|
||||
|
||||
it("should be space delimited and contain three fields", async () => {
|
||||
const userAgent = await getUserAgent();
|
||||
const userAgentParts = userAgent.split(" ");
|
||||
userAgentParts.length.should.be.equal(3);
|
||||
});
|
||||
|
||||
it("should contain runtime information", async () => {
|
||||
const userAgent = await getUserAgent();
|
||||
userAgent.should.match(/ms-rest-js\/[\d\.]+ .+/);
|
||||
});
|
||||
|
||||
it("should have operating system information at the third place", async () => {
|
||||
const userAgent = await getUserAgent();
|
||||
const userAgentParts = userAgent.split(" ");
|
||||
const osInfo = userAgentParts[2];
|
||||
osInfo.should.match(/OS\/\([\w\d\.\-]+\)/);
|
||||
});
|
||||
|
||||
it("should have Node information at the second place", async () => {
|
||||
const userAgent = await getUserAgent();
|
||||
const userAgentParts = userAgent.split(" ");
|
||||
const osInfo = userAgentParts[1];
|
||||
osInfo.should.match(/Node\/v[\d.]+/);
|
||||
});
|
||||
});
|
||||
|
||||
browserDescribe("Browser", function() {
|
||||
const userAgentHeaderKey = "x-ms-command-name";
|
||||
|
||||
const emptyRequestPolicy: RequestPolicy = {
|
||||
sendRequest(request: WebResource): Promise<HttpOperationResponse> {
|
||||
request.should.exist;
|
||||
return Promise.resolve({ request: request, status: 200, headers: request.headers });
|
||||
}
|
||||
};
|
||||
|
||||
const getUserAgent = async (headerValue?: string): Promise<string> => {
|
||||
const factory = userAgentPolicy({ value: headerValue});
|
||||
const policy = factory.create(emptyRequestPolicy, new RequestPolicyOptions());
|
||||
const resource = new WebResource();
|
||||
await policy.sendRequest(resource);
|
||||
const userAgent = resource.headers.get(userAgentHeaderKey);
|
||||
return userAgent!;
|
||||
};
|
||||
|
||||
describe("MsRestUserAgentPolicy (Browser)", () => {
|
||||
it("should not modify user agent header if already present", async () => {
|
||||
const factory = userAgentPolicy();
|
||||
const browserUserAgentPolicy = factory.create(emptyRequestPolicy, new RequestPolicyOptions());
|
||||
const customUserAgent = "my custom user agent";
|
||||
const resource = new WebResource();
|
||||
resource.headers.set(userAgentHeaderKey, customUserAgent);
|
||||
await browserUserAgentPolicy.sendRequest(resource);
|
||||
|
||||
const userAgentHeader: string = resource.headers.get(userAgentHeaderKey)!;
|
||||
|
||||
userAgentHeader.should.be.equal(customUserAgent);
|
||||
});
|
||||
|
||||
it("should use injected user agent string if provided", async () => {
|
||||
const customUserAgent = "my custom user agent";
|
||||
const factory = userAgentPolicy({ value: customUserAgent });
|
||||
const browserUserAgentPolicy = factory.create(emptyRequestPolicy, new RequestPolicyOptions());
|
||||
const resource = new WebResource();
|
||||
await browserUserAgentPolicy.sendRequest(resource);
|
||||
|
||||
const userAgentHeader: string = resource.headers.get(userAgentHeaderKey)!;
|
||||
|
||||
userAgentHeader.should.be.equal(customUserAgent);
|
||||
});
|
||||
|
||||
it("should be space delimited and contain two fields", async () => {
|
||||
const userAgent = await getUserAgent();
|
||||
const userAgentParts = userAgent.split(" ");
|
||||
userAgentParts.length.should.be.equal(2);
|
||||
});
|
||||
|
||||
it("should contain runtime information", async () => {
|
||||
const userAgent = await getUserAgent();
|
||||
userAgent.should.match(/ms-rest-js\/[\d\.]+ .+/);
|
||||
});
|
||||
|
||||
it("should have operating system information at the second place", async () => {
|
||||
const userAgent = await getUserAgent();
|
||||
const userAgentParts = userAgent.split(" ");
|
||||
const osInfo = userAgentParts[1];
|
||||
osInfo.should.match(/OS\/[\w\d\.\-]+/);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,94 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import { HttpOperationResponse } from "../../lib/httpOperationResponse";
|
||||
import { RequestPolicy, RequestPolicyOptions } from "../../lib/policies/requestPolicy";
|
||||
import { Constants } from "../../lib/util/constants";
|
||||
import { WebResource } from "../../lib/webResource";
|
||||
import { userAgentPolicy } from "../../lib/policies/userAgentPolicy";
|
||||
import { should } from "chai";
|
||||
|
||||
const userAgentHeaderKey = Constants.HeaderConstants.USER_AGENT;
|
||||
|
||||
const emptyRequestPolicy: RequestPolicy = {
|
||||
sendRequest(request: WebResource): Promise<HttpOperationResponse> {
|
||||
should().exist(request);
|
||||
return Promise.resolve({ request: request, status: 200, headers: request.headers });
|
||||
}
|
||||
};
|
||||
|
||||
const getPlainUserAgentPolicy = (headerValue?: string): RequestPolicy => {
|
||||
const factory = userAgentPolicy({ value: headerValue });
|
||||
return factory.create(emptyRequestPolicy, new RequestPolicyOptions());
|
||||
};
|
||||
|
||||
const getUserAgent = async (headerValue?: string): Promise<string> => {
|
||||
const policy = getPlainUserAgentPolicy(headerValue);
|
||||
const resource = new WebResource();
|
||||
await policy.sendRequest(resource);
|
||||
const userAgent = resource.headers.get(userAgentHeaderKey);
|
||||
return userAgent!;
|
||||
};
|
||||
|
||||
describe("MsRestUserAgentPolicy (NodeJS)", () => {
|
||||
it("should not modify user agent header if already present", async () => {
|
||||
const userAgentPolicy = getPlainUserAgentPolicy();
|
||||
const customUserAgent = "my custom user agent";
|
||||
const resource = new WebResource();
|
||||
resource.headers.set(userAgentHeaderKey, customUserAgent);
|
||||
await userAgentPolicy.sendRequest(resource);
|
||||
|
||||
const userAgentHeader: string = resource.headers.get(userAgentHeaderKey)!;
|
||||
|
||||
userAgentHeader.should.be.equal(customUserAgent);
|
||||
});
|
||||
|
||||
it("should not set the user agent header if custom user agent is empty", async () => {
|
||||
const customUserAgent = "";
|
||||
const factory = userAgentPolicy({ value: customUserAgent });
|
||||
const nodeUserAgentPolicy = factory.create(emptyRequestPolicy, new RequestPolicyOptions());
|
||||
const resource = new WebResource();
|
||||
await nodeUserAgentPolicy.sendRequest(resource);
|
||||
|
||||
const userAgentHeader: string = resource.headers.get(userAgentHeaderKey)!;
|
||||
|
||||
(userAgentHeader === undefined).should.be.true;
|
||||
});
|
||||
|
||||
it("should use injected user agent string if provided", async () => {
|
||||
const customUserAgent = "my custom user agent";
|
||||
const factory = userAgentPolicy({ value: customUserAgent });
|
||||
const nodeUserAgentPolicy = factory.create(emptyRequestPolicy, new RequestPolicyOptions());
|
||||
const resource = new WebResource();
|
||||
await nodeUserAgentPolicy.sendRequest(resource);
|
||||
|
||||
const userAgentHeader: string = resource.headers.get(userAgentHeaderKey)!;
|
||||
|
||||
userAgentHeader.should.be.equal(customUserAgent);
|
||||
});
|
||||
|
||||
it("should be space delimited and contain three fields", async () => {
|
||||
const userAgent = await getUserAgent();
|
||||
const userAgentParts = userAgent.split(" ");
|
||||
userAgentParts.length.should.be.equal(3);
|
||||
});
|
||||
|
||||
it("should contain runtime information", async () => {
|
||||
const userAgent = await getUserAgent();
|
||||
userAgent.should.match(/ms-rest-js\/[\d\.]+ .+/);
|
||||
});
|
||||
|
||||
it("should have operating system information at the third place", async () => {
|
||||
const userAgent = await getUserAgent();
|
||||
const userAgentParts = userAgent.split(" ");
|
||||
const osInfo = userAgentParts[2];
|
||||
osInfo.should.match(/OS\/\([\w\d\.\-]+\)/);
|
||||
});
|
||||
|
||||
it("should have Node information at the second place", async () => {
|
||||
const userAgent = await getUserAgent();
|
||||
const userAgentParts = userAgent.split(" ");
|
||||
const osInfo = userAgentParts[1];
|
||||
osInfo.should.match(/Node\/v[\d.]+/);
|
||||
});
|
||||
});
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import assert from "assert";
|
||||
import { getPathStringFromParameter, OperationParameter } from "../../lib/operationParameter";
|
||||
import { assert } from "chai";
|
||||
import { getPathStringFromParameter, OperationParameter } from "../lib/operationParameter";
|
||||
|
||||
describe("getParameterPathString()", () => {
|
||||
it("should throw when given undefined", () => {
|
|
@ -1,13 +1,13 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import assert from "assert";
|
||||
import { HttpHeaders } from "../../../lib/httpHeaders";
|
||||
import { HttpOperationResponse } from "../../../lib/httpOperationResponse";
|
||||
import { HttpClient, OperationSpec, Serializer } from "../../../lib/msRest";
|
||||
import { DeserializationPolicy, deserializationPolicy, deserializeResponseBody, defaultJsonContentTypes, defaultXmlContentTypes } from "../../../lib/policies/deserializationPolicy";
|
||||
import { RequestPolicy, RequestPolicyOptions } from "../../../lib/policies/requestPolicy";
|
||||
import { WebResource } from "../../../lib/webResource";
|
||||
import { assert } from "chai";
|
||||
import { HttpHeaders } from "../../lib/httpHeaders";
|
||||
import { HttpOperationResponse } from "../../lib/httpOperationResponse";
|
||||
import { HttpClient, OperationSpec, Serializer } from "../../lib/msRest";
|
||||
import { DeserializationPolicy, deserializationPolicy, deserializeResponseBody, defaultJsonContentTypes, defaultXmlContentTypes } from "../../lib/policies/deserializationPolicy";
|
||||
import { RequestPolicy, RequestPolicyOptions } from "../../lib/policies/requestPolicy";
|
||||
import { WebResource } from "../../lib/webResource";
|
||||
|
||||
describe("deserializationPolicy", function () {
|
||||
const mockPolicy: RequestPolicy = {
|
||||
|
@ -43,7 +43,7 @@ describe("deserializationPolicy", function () {
|
|||
|
||||
const policy = deserializationPolicy().create(mockClient, new RequestPolicyOptions());
|
||||
const response = await policy.sendRequest(request);
|
||||
assert.deepStrictEqual(response.parsedBody, [123, 456, 789]);
|
||||
assert.deepEqual(response.parsedBody, [123, 456, 789]);
|
||||
});
|
||||
|
||||
it("should parse a JSON response body with a charset specified in Content-Type", async function () {
|
||||
|
@ -59,7 +59,7 @@ describe("deserializationPolicy", function () {
|
|||
|
||||
const policy = deserializationPolicy().create(mockClient, new RequestPolicyOptions());
|
||||
const response = await policy.sendRequest(request);
|
||||
assert.deepStrictEqual(response.parsedBody, [123, 456, 789]);
|
||||
assert.deepEqual(response.parsedBody, [123, 456, 789]);
|
||||
});
|
||||
|
||||
it("should parse a JSON response body with an uppercase Content-Type", async function () {
|
||||
|
@ -75,7 +75,7 @@ describe("deserializationPolicy", function () {
|
|||
|
||||
const policy = deserializationPolicy().create(mockClient, new RequestPolicyOptions());
|
||||
const response = await policy.sendRequest(request);
|
||||
assert.deepStrictEqual(response.parsedBody, [123, 456, 789]);
|
||||
assert.deepEqual(response.parsedBody, [123, 456, 789]);
|
||||
});
|
||||
|
||||
it("should parse a JSON response body with a missing Content-Type", async function () {
|
||||
|
@ -91,7 +91,7 @@ describe("deserializationPolicy", function () {
|
|||
|
||||
const policy = deserializationPolicy().create(mockClient, new RequestPolicyOptions());
|
||||
const response = await policy.sendRequest(request);
|
||||
assert.deepStrictEqual(response.parsedBody, [123, 456, 789]);
|
||||
assert.deepEqual(response.parsedBody, [123, 456, 789]);
|
||||
});
|
||||
|
||||
describe(`parse(HttpOperationResponse)`, () => {
|
|
@ -1,12 +1,12 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import assert from "assert";
|
||||
import { assert, AssertionError } from "chai";
|
||||
import sinon from "sinon";
|
||||
import { ThrottlingRetryPolicy } from "../../../lib/policies/throttlingRetryPolicy";
|
||||
import { WebResource } from "../../../lib/webResource";
|
||||
import { HttpOperationResponse } from "../../../lib/httpOperationResponse";
|
||||
import { HttpHeaders, RequestPolicyOptions } from "../../../lib/msRest";
|
||||
import { ThrottlingRetryPolicy } from "../../lib/policies/throttlingRetryPolicy";
|
||||
import { WebResource } from "../../lib/webResource";
|
||||
import { HttpOperationResponse } from "../../lib/httpOperationResponse";
|
||||
import { HttpHeaders, RequestPolicyOptions } from "../../lib/msRest";
|
||||
|
||||
describe("ThrottlingRetryPolicy", () => {
|
||||
class PassThroughPolicy {
|
||||
|
@ -72,7 +72,7 @@ describe("ThrottlingRetryPolicy", () => {
|
|||
}),
|
||||
request: request
|
||||
};
|
||||
const policy = createDefaultThrottlingRetryPolicy(mockResponse, _ => assert.fail());
|
||||
const policy = createDefaultThrottlingRetryPolicy(mockResponse, _ => { throw new AssertionError("fail"); });
|
||||
|
||||
const response = await policy.sendRequest(request);
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import assert from "assert";
|
||||
import * as msRest from "../../lib/msRest";
|
||||
import { should } from "chai";
|
||||
import "chai/register-should"
|
||||
import { assert } from "chai";
|
||||
import "chai/register-should";
|
||||
|
||||
import * as msRest from "../lib/msRest";
|
||||
import { TestClient } from "./data/TestClient/lib/testClient";
|
||||
import { Mappers } from "./data/TestClient/lib/models/mappers";
|
||||
|
||||
|
@ -588,7 +587,7 @@ describe("msrest", function () {
|
|||
|
||||
// tslint:disable-next-line
|
||||
const result = Serializer.serialize(mapper, { length: null }, "testobj");
|
||||
should().exist(result);
|
||||
result.should.exist;
|
||||
});
|
||||
|
||||
it("should not allow undefined when required: true and nullable: true", function () {
|
||||
|
@ -1103,7 +1102,7 @@ describe("msrest", function () {
|
|||
unrelated: 42
|
||||
};
|
||||
const actual = Serializer.deserialize(mapper, rawHeaders, "headers");
|
||||
assert.deepStrictEqual(actual, expected);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
describe("composite type", () => {
|
|
@ -1,14 +1,14 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import assert from "assert";
|
||||
import { HttpClient } from "../../lib/httpClient";
|
||||
import { deserializationPolicy, HttpHeaders, OperationArguments, RestResponse, isNode } from "../../lib/msRest";
|
||||
import { ParameterPath } from "../../lib/operationParameter";
|
||||
import { QueryCollectionFormat } from "../../lib/queryCollectionFormat";
|
||||
import { DictionaryMapper, Mapper, MapperType, Serializer } from "../../lib/serializer";
|
||||
import { getOperationArgumentValueFromParameterPath, serializeRequestBody, ServiceClient } from "../../lib/serviceClient";
|
||||
import { WebResource } from "../../lib/webResource";
|
||||
import { assert } from "chai";
|
||||
import { HttpClient } from "../lib/httpClient";
|
||||
import { QueryCollectionFormat } from "../lib/queryCollectionFormat";
|
||||
import { DictionaryMapper, MapperType, Serializer, Mapper } from "../lib/serializer";
|
||||
import { serializeRequestBody, ServiceClient, getOperationArgumentValueFromParameterPath } from "../lib/serviceClient";
|
||||
import { WebResource } from "../lib/webResource";
|
||||
import { OperationArguments, HttpHeaders, deserializationPolicy, RestResponse, isNode } from "../lib/msRest";
|
||||
import { ParameterPath } from "../lib/operationParameter";
|
||||
|
||||
describe("ServiceClient", function () {
|
||||
it("should serialize headerCollectionPrefix", async function () {
|
||||
|
@ -70,7 +70,7 @@ describe("ServiceClient", function () {
|
|||
});
|
||||
|
||||
assert(request!);
|
||||
assert.deepStrictEqual(request!.headers.toJson(), expected);
|
||||
assert.deepEqual(request!.headers.toJson(), expected);
|
||||
});
|
||||
|
||||
it("responses should not show the _response property when serializing", async function () {
|
|
@ -1,10 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
// parseInt just gives NaN (falsy) for undefined/null
|
||||
const port = (typeof process !== "undefined" && parseInt(process.env.PORT!)) || 3001;
|
||||
|
||||
/**
|
||||
* Base URL for the ms-rest-js testserver.
|
||||
*/
|
||||
export const baseURL = `http://localhost:${port}`;
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import assert from "assert";
|
||||
import { URLTokenizer, URLToken, URLBuilder, URLQuery } from "../../lib/url";
|
||||
import { assert } from "chai";
|
||||
import { URLTokenizer, URLToken, URLBuilder, URLQuery } from "../lib/url";
|
||||
|
||||
describe("URLQuery", () => {
|
||||
it(`constructor()`, () => {
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import assert from "assert";
|
||||
import { parseHeaders } from "../../lib/xhrHttpClient";
|
||||
import { assert } from "chai";
|
||||
import { parseHeaders } from "../lib/xhrHttpClient";
|
||||
|
||||
describe("XhrHttpClient", function() {
|
||||
it("parses headers", function() {
|
|
@ -1,6 +1,6 @@
|
|||
import { parseXML } from "../../lib/util/xml";
|
||||
import assert from "assert";
|
||||
import * as msAssert from "../msAssert";
|
||||
import { parseXML } from "../lib/util/xml";
|
||||
import { assert } from "chai";
|
||||
import * as msAssert from "./msAssert";
|
||||
|
||||
describe("XML serializer", function () {
|
||||
describe("parseXML(string)", function () {
|
|
@ -3,12 +3,12 @@ import * as glob from "glob";
|
|||
import * as path from "path";
|
||||
|
||||
const config: webpack.Configuration = {
|
||||
entry: [...glob.sync(path.join(__dirname, "test/shared/**/*.ts")), ...glob.sync(path.join(__dirname, "test/browser/**/*.ts"))],
|
||||
entry: glob.sync(path.join(__dirname, "test/**/*.ts")),
|
||||
mode: "development",
|
||||
devtool: "source-map",
|
||||
output: {
|
||||
filename: "testBundle.js",
|
||||
path: __dirname
|
||||
filename: "msRest.browser.test.js",
|
||||
path: path.resolve(__dirname, "test")
|
||||
},
|
||||
plugins: [
|
||||
new webpack.NormalModuleReplacementPlugin(/(\.).+util\/base64/, path.resolve(__dirname, "./lib/util/base64.browser.ts")),
|
||||
|
|
Загрузка…
Ссылка в новой задаче