Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions sdk/identity/identity/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
// https://github.com/karma-runner/karma-chrome-launcher
process.env.CHROME_BIN = require("puppeteer").executablePath();
require("dotenv").config({ path: "../.env" });

module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: "./",

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ["mocha"],

plugins: [
"karma-mocha",
"karma-mocha-reporter",
"karma-chrome-launcher",
"karma-edge-launcher",
"karma-firefox-launcher",
"karma-ie-launcher",
"karma-env-preprocessor",
"karma-coverage",
"karma-remap-coverage",
"karma-junit-reporter",
"karma-json-to-file-reporter",
"karma-json-preprocessor"
],

// list of files / patterns to load in the browser
files: [
// polyfill service supporting IE11 missing features
// Promise,String.prototype.startsWith,String.prototype.endsWith,String.prototype.repeat,String.prototype.includes,Array.prototype.includes,Object.keys
"https://cdn.polyfill.io/v2/polyfill.js?features=Symbol,Promise,String.prototype.startsWith,String.prototype.endsWith,String.prototype.repeat,String.prototype.includes,Array.prototype.includes,Object.keys|always",
"test-browser/index.js",
"recordings/browsers/**/*.json"
],

// list of files / patterns to exclude
exclude: [],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
"**/*.js": ["env"],
// IMPORTANT: COMMENT following line if you want to debug in your browsers!!
// Preprocess source file to calculate code coverage, however this will make source file unreadable
"test-browser/index.js": ["coverage"],
"recordings/browsers/**/*.json": ["json"]
},

// inject following environment values into browser testing with window.__env__
// environment values MUST be exported or set with same console running "karma start"
// https://www.npmjs.com/package/karma-env-preprocessor
envPreprocessor: ["ACCOUNT_NAME", "ACCOUNT_SAS", "TEST_MODE"],

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ["mocha", "coverage", "remap-coverage", "junit", "json-to-file"],

coverageReporter: { type: "in-memory" },

// Coverage report settings
remapCoverageReporter: {
"text-summary": null, // to show summary in console
html: "./coverage-browser",
cobertura: "./coverage-browser/cobertura-coverage.xml"
},

// Exclude coverage calculation for following files
remapOptions: {
exclude: /node_modules|test/g
},

junitReporter: {
outputDir: "", // results will be saved as $outputDir/$browserName.xml
outputFile: "test-results.browser.xml", // if included, results will be saved as $outputDir/$browserName/$outputFile
suite: "", // suite will become the package name attribute in xml testsuite element
useBrowserName: false, // add browser name to report and classes names
nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
properties: {} // key value pair of properties to add to the <properties> section of the report
},

jsonToFileReporter: {
filter: function(obj) {
if (obj.writeFile) {
const fs = require("fs-extra");
// Create the directories recursively incase they don't exist
try {
// Stripping away the filename from the file path and retaining the directory structure
fs.ensureDirSync(obj.path.substring(0, obj.path.lastIndexOf("/") + 1));
} catch (err) {
if (err.code !== "EEXIST") throw err;
}
fs.writeFile(obj.path, JSON.stringify(obj.content, null, " "), (err) => {
if (err) {
throw err;
}
});
}
return false;
},
outputPath: "."
},

// web server port
port: 9876,

// enable / disable colors in the output (reporters and logs)
colors: true,

// 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
// 'ChromeHeadless', 'Chrome', 'Firefox', 'Edge', 'IE'
browsers: ["ChromeHeadless"],
Comment thread
daviwil marked this conversation as resolved.

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,

// Concurrency level
// how many browser should be started simultaneous
concurrency: 1,

browserNoActivityTimeout: 600000,
browserDisconnectTimeout: 10000,
browserDisconnectTolerance: 3,
browserConsoleLogOptions: {
// IMPORTANT: COMMENT the following line if you want to print debug logs in your browsers in record mode!!
terminal: process.env.TEST_MODE !== "record"
},

client: {
mocha: {
// change Karma's debug.html to the mocha web reporter
reporter: "html",
timeout: "600000"
}
}
});
};
22 changes: 18 additions & 4 deletions sdk/identity/identity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"types": "dist-esm/src/index.d.ts",
"browser": {
"stream": "./node_modules/stream-browserify/index.js",
"./dist-esm/src/credentials/environmentCredential.js": "./dist-esm/src/credentials/environmentCredential.browser.js",
"./dist-esm/src/credentials/managedIdentityCredential.js": "./dist-esm/src/credentials/managedIdentityCredential.browser.js",
"./dist-esm/src/credentials/clientCertificateCredential.js": "./dist-esm/src/credentials/clientCertificateCredential.browser.js",
"./dist/index.js": "./browser/index.js"
},
"scripts": {
Expand All @@ -17,8 +20,8 @@
"build:samples": "cd samples && tsc -p .",
"build:test:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c rollup.test.config.js 2>&1",
"build:test:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c rollup.test.config.js 2>&1",
"build:test": "npm run build:test:node",
"build": "npm run build:node",
"build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1",
"build": "tsc -p . && rollup -c 2>&1",
"check-format": "prettier --list-different --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"clean": "rimraf dist dist-esm test-dist typings *.tgz *.log",
"format": "prettier --write --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
Expand All @@ -32,7 +35,7 @@
"test:browser": "npm run build:test && npm run unit-test:browser && npm run integration-test:browser",
"test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
"test": "npm run build:test && npm run unit-test && npm run integration-test",
"unit-test:browser": "echo skipped",
"unit-test:browser": "karma start",
"unit-test:node": "mocha test-dist/**/*.js --reporter mocha-multi --reporter-options spec=-,mocha-junit-reporter=-",
"unit-test": "npm run unit-test:node && npm run unit-test:browser"
},
Expand Down Expand Up @@ -84,10 +87,21 @@
"cross-env": "^5.2.0",
"eslint": "^5.16.0",
"inherits": "^2.0.3",
"karma": "^4.0.1",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.2",
"karma-env-preprocessor": "^0.1.1",
"karma-json-preprocessor": "^0.3.3",
"karma-json-to-file-reporter": "^1.0.1",
"karma-junit-reporter": "^1.2.0",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.5",
"karma-remap-coverage": "^0.1.5",
"mocha": "^5.2.0",
"mocha-junit-reporter": "^1.18.0",
"mocha-multi": "^1.0.1",
"prettier": "^1.16.4",
"puppeteer": "^1.11.0",
"rimraf": "^2.6.2",
"rollup": "~1.13.1",
"rollup-plugin-commonjs": "^10.0.0",
Expand All @@ -96,7 +110,7 @@
"rollup-plugin-node-resolve": "^5.0.2",
"rollup-plugin-replace": "^2.1.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-uglify": "^6.0.0",
"rollup-plugin-terser": "^4.0.4",
"rollup-plugin-visualizer": "^1.0.0",
"typescript": "^3.2.2",
"util": "^0.11.1"
Expand Down
15 changes: 7 additions & 8 deletions sdk/identity/identity/rollup.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import nodeResolve from "rollup-plugin-node-resolve";
import multiEntry from "rollup-plugin-multi-entry";
import cjs from "rollup-plugin-commonjs";
import replace from "rollup-plugin-replace";
import { uglify } from "rollup-plugin-uglify";
import { terser } from "rollup-plugin-terser";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change required for the other sdks?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably so, I'll open a separate PR to make that change everywhere then we can decide whether to merge it.

import sourcemaps from "rollup-plugin-sourcemaps";
import viz from "rollup-plugin-visualizer";

Expand Down Expand Up @@ -36,6 +36,7 @@ export function nodeConfig(test = false) {
if (test) {
// entry point is every test file
baseConfig.input = "dist-esm/test/**/*.spec.js";
baseConfig.input = ["dist-esm/test/*.spec.js", "dist-esm/test/node/*.spec.js"];
baseConfig.plugins.unshift(multiEntry({ exports: false }));

// different output file
Expand All @@ -49,7 +50,7 @@ export function nodeConfig(test = false) {
// applies to test code, which causes all tests to be removed by tree-shaking.
baseConfig.treeshake = false;
} else if (production) {
baseConfig.plugins.push(uglify());
baseConfig.plugins.push(terser());
}

return baseConfig;
Expand All @@ -58,13 +59,11 @@ export function nodeConfig(test = false) {
export function browserConfig(test = false, production = false) {
const baseConfig = {
input: input,
external: ["@azure/ms-rest-js"],
output: {
file: "browser/identity.js",
format: "umd",
name: "ExampleClient",
sourcemap: true,
globals: { "@azure/ms-rest-js": "msRest" }
name: "Azure.Identity",
sourcemap: true
},
preserveSymlinks: false,
plugins: [
Expand Down Expand Up @@ -93,7 +92,7 @@ export function browserConfig(test = false, production = false) {
};

if (test) {
baseConfig.input = "dist-esm/test/**/*.spec.js";
baseConfig.input = "dist-esm/test/*.spec.js";
Comment thread
daviwil marked this conversation as resolved.
baseConfig.plugins.unshift(multiEntry({ exports: false }));
baseConfig.output.file = "test-browser/index.js";

Expand All @@ -103,7 +102,7 @@ export function browserConfig(test = false, production = false) {
baseConfig.treeshake = false;
} else if (production) {
baseConfig.output.file = "browser/identity.min.js";
baseConfig.plugins.push(uglify());
baseConfig.plugins.push(terser());
}

return baseConfig;
Expand Down
Loading