|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT license. |
| 3 | + |
| 4 | +// https://github.com/karma-runner/karma-chrome-launcher |
| 5 | +process.env.CHROME_BIN = require("puppeteer").executablePath(); |
| 6 | +require("dotenv").config(); |
| 7 | +const { relativeRecordingsPath } = require("@azure-tools/test-recorder"); |
| 8 | +process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath(); |
| 9 | + |
| 10 | +module.exports = function (config) { |
| 11 | + config.set({ |
| 12 | + // base path that will be used to resolve all patterns (eg. files, exclude) |
| 13 | + basePath: "./", |
| 14 | + |
| 15 | + // frameworks to use |
| 16 | + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter |
| 17 | + frameworks: ["source-map-support", "mocha"], |
| 18 | + |
| 19 | + plugins: [ |
| 20 | + "karma-mocha", |
| 21 | + "karma-mocha-reporter", |
| 22 | + "karma-chrome-launcher", |
| 23 | + "karma-edge-launcher", |
| 24 | + "karma-firefox-launcher", |
| 25 | + "karma-ie-launcher", |
| 26 | + "karma-env-preprocessor", |
| 27 | + "karma-coverage", |
| 28 | + "karma-sourcemap-loader", |
| 29 | + "karma-junit-reporter", |
| 30 | + "karma-source-map-support", |
| 31 | + ], |
| 32 | + |
| 33 | + // list of files / patterns to load in the browser |
| 34 | + files: [ |
| 35 | + "dist-test/index.browser.js", |
| 36 | + { |
| 37 | + pattern: "dist-test/index.browser.js.map", |
| 38 | + type: "html", |
| 39 | + included: false, |
| 40 | + served: true, |
| 41 | + }, |
| 42 | + ], |
| 43 | + |
| 44 | + // list of files / patterns to exclude |
| 45 | + exclude: [], |
| 46 | + |
| 47 | + // preprocess matching files before serving them to the browser |
| 48 | + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor |
| 49 | + preprocessors: { |
| 50 | + "**/*.js": ["sourcemap", "env"], |
| 51 | + // IMPORTANT: COMMENT following line if you want to debug in your browsers!! |
| 52 | + // Preprocess source file to calculate code coverage, however this will make source file unreadable |
| 53 | + // "dist-test/index.js": ["coverage"] |
| 54 | + }, |
| 55 | + |
| 56 | + envPreprocessor: [ |
| 57 | + "RECORDINGS_RELATIVE_PATH", |
| 58 | + "TEST_MODE", |
| 59 | + "ENDPOINT", |
| 60 | + "AZURE_CLIENT_SECRET", |
| 61 | + "AZURE_CLIENT_ID", |
| 62 | + "AZURE_TENANT_ID", |
| 63 | + "SUBSCRIPTION_ID", |
| 64 | + ], |
| 65 | + |
| 66 | + // test results reporter to use |
| 67 | + // possible values: 'dots', 'progress' |
| 68 | + // available reporters: https://npmjs.org/browse/keyword/karma-reporter |
| 69 | + reporters: ["mocha", "coverage", "junit"], |
| 70 | + |
| 71 | + coverageReporter: { |
| 72 | + // specify a common output directory |
| 73 | + dir: "coverage-browser/", |
| 74 | + reporters: [ |
| 75 | + { type: "json", subdir: ".", file: "coverage.json" }, |
| 76 | + { type: "lcovonly", subdir: ".", file: "lcov.info" }, |
| 77 | + { type: "html", subdir: "html" }, |
| 78 | + { type: "cobertura", subdir: ".", file: "cobertura-coverage.xml" }, |
| 79 | + ], |
| 80 | + }, |
| 81 | + |
| 82 | + junitReporter: { |
| 83 | + outputDir: "", // results will be saved as $outputDir/$browserName.xml |
| 84 | + outputFile: "test-results.browser.xml", // if included, results will be saved as $outputDir/$browserName/$outputFile |
| 85 | + suite: "", // suite will become the package name attribute in xml testsuite element |
| 86 | + useBrowserName: false, // add browser name to report and classes names |
| 87 | + nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element |
| 88 | + classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element |
| 89 | + properties: {}, // key value pair of properties to add to the <properties> section of the report |
| 90 | + }, |
| 91 | + |
| 92 | + // web server port |
| 93 | + port: 9876, |
| 94 | + |
| 95 | + // enable / disable colors in the output (reporters and logs) |
| 96 | + colors: true, |
| 97 | + |
| 98 | + // level of logging |
| 99 | + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG |
| 100 | + logLevel: config.LOG_INFO, |
| 101 | + |
| 102 | + // enable / disable watching file and executing tests whenever any file changes |
| 103 | + autoWatch: false, |
| 104 | + |
| 105 | + // --no-sandbox allows our tests to run in Linux without having to change the system. |
| 106 | + // --disable-web-security allows us to authenticate from the browser without having to write tests using interactive auth, which would be far more complex. |
| 107 | + browsers: ["ChromeHeadlessNoSandbox"], |
| 108 | + customLaunchers: { |
| 109 | + ChromeHeadlessNoSandbox: { |
| 110 | + base: "ChromeHeadless", |
| 111 | + flags: ["--no-sandbox", "--disable-web-security"], |
| 112 | + }, |
| 113 | + }, |
| 114 | + |
| 115 | + // Continuous Integration mode |
| 116 | + // if true, Karma captures browsers, runs the tests and exits |
| 117 | + singleRun: false, |
| 118 | + |
| 119 | + // Concurrency level |
| 120 | + // how many browser should be started simultaneous |
| 121 | + concurrency: 1, |
| 122 | + |
| 123 | + browserNoActivityTimeout: 60000000, |
| 124 | + browserDisconnectTimeout: 10000, |
| 125 | + browserDisconnectTolerance: 3, |
| 126 | + |
| 127 | + client: { |
| 128 | + mocha: { |
| 129 | + // change Karma's debug.html to the mocha web reporter |
| 130 | + reporter: "html", |
| 131 | + timeout: "600000", |
| 132 | + }, |
| 133 | + }, |
| 134 | + }); |
| 135 | +}; |
0 commit comments