Tone.js/test/karma.conf.js

171 lines
4.4 KiB
JavaScript
Raw Normal View History

2019-09-20 14:09:44 +00:00
/* eslint-disable no-console, @typescript-eslint/no-var-requires */
2016-03-04 21:25:44 +00:00
// Karma configuration
2019-04-12 14:37:47 +00:00
const path = require("path");
const argv = require("yargs")
.alias("i", "file")
.alias("d", "dir")
.argv;
2016-03-04 21:25:44 +00:00
2019-04-12 14:37:47 +00:00
let BROWSERS = ["HeadlessChrome", "HeadlessFirefox", "Safari"];
2018-01-16 16:04:47 +00:00
// get the entry point files
let entryPoints = undefined;
2019-09-20 14:09:44 +00:00
if (typeof argv.file === "string") {
entryPoints = RegExp(`.*\\/${argv.file}\\.test\\.ts$`);
2019-09-20 14:09:44 +00:00
console.log(`testing file "${argv.file}"`);
} else if (typeof argv.dir === "string") {
entryPoints = RegExp(`.*${argv.dir}.*\\/.*\\.test\\.ts$`);
2019-09-20 14:09:44 +00:00
console.log(`testing directory "${argv.dir}"`);
}
2019-04-12 14:37:47 +00:00
if (process.env.BROWSER === "chrome") {
2018-01-16 16:04:47 +00:00
BROWSERS = ["HeadlessChrome"];
2019-04-12 14:37:47 +00:00
} else if (process.env.BROWSER === "firefox") {
2018-01-16 16:04:47 +00:00
BROWSERS = ["HeadlessFirefox"];
2019-04-12 14:37:47 +00:00
} else if (process.env.BROWSER === "safari") {
2018-01-16 16:04:47 +00:00
BROWSERS = ["Safari"];
2018-05-18 16:12:50 +00:00
} else {
2018-05-28 22:02:04 +00:00
BROWSERS = ["HeadlessChrome", "HeadlessFirefox"];
}
2019-04-12 14:37:47 +00:00
module.exports = function(config) {
const configuration = {
2016-03-04 21:25:44 +00:00
2017-03-26 18:51:25 +00:00
// base path that will be used to resolve all patterns (eg. files, exclude)
2019-09-20 14:09:44 +00:00
basePath: "../",
2016-03-04 21:25:44 +00:00
2017-03-26 18:51:25 +00:00
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
2019-09-20 14:09:44 +00:00
frameworks: ["mocha", "karma-typescript"],
2016-03-04 21:25:44 +00:00
2017-03-26 18:51:25 +00:00
// list of files / patterns to load in the browser
2019-09-20 14:09:44 +00:00
files: [
2019-04-12 14:37:47 +00:00
"test/**/*.ts",
"Tone/**/*.ts",
2019-09-20 14:09:44 +00:00
{ pattern: "test/audio/**", included: false },
{ pattern: "test/html/**", included: false },
2018-01-16 16:04:47 +00:00
],
2016-03-04 21:25:44 +00:00
2019-04-12 14:37:47 +00:00
// Karma Typescript compiler options
karmaTypescriptConfig: {
2019-09-20 14:09:44 +00:00
compilerOptions: {
target: "es6",
2019-07-25 18:54:02 +00:00
module: "commonjs",
2019-04-12 14:37:47 +00:00
},
bundlerOptions: {
resolve: {
directories: ["Tone", "node_modules", "test"],
},
2019-09-20 14:09:44 +00:00
entrypoints: entryPoints
2019-04-12 14:37:47 +00:00
},
2019-09-20 14:09:44 +00:00
coverageOptions: {
2019-08-02 20:40:50 +00:00
exclude: /(.*\.test\.ts|test\/.*\.ts)$/i,
2019-04-12 14:37:47 +00:00
},
reports: {
html: path.resolve(__dirname, "../coverage"),
2019-06-19 22:06:42 +00:00
lcovonly: {
2019-09-20 14:09:44 +00:00
directory: path.resolve(__dirname, "../coverage"),
2019-06-19 22:06:42 +00:00
filename: "coverage.lcov",
},
2019-04-12 14:37:47 +00:00
},
tsconfig: "./tsconfig.json",
},
2017-03-26 18:51:25 +00:00
// list of files to exclude
2019-09-20 14:09:44 +00:00
exclude: [
2019-04-12 14:37:47 +00:00
"node_modules/*",
],
2016-03-04 21:25:44 +00:00
2017-03-26 18:51:25 +00:00
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
2019-04-12 14:37:47 +00:00
preprocessors: {
"**/*.ts": "karma-typescript",
// "Tone/**/*.ts": "coverage",
2017-04-30 17:02:35 +00:00
},
2016-03-04 21:25:44 +00:00
2017-03-26 18:51:25 +00:00
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
2019-09-20 14:09:44 +00:00
reporters: ["dots", "karma-typescript"],
2017-04-30 17:02:35 +00:00
2019-04-12 14:37:47 +00:00
// coverageReporter : {
// type : "lcov",
// dir: path.resolve(__dirname, "../coverage"),
// },
2016-03-04 21:25:44 +00:00
2019-09-20 14:09:44 +00:00
// plugins
plugins: [
2019-04-12 14:37:47 +00:00
"karma-typescript",
// "karma-coverage",
2018-01-16 16:04:47 +00:00
"karma-mocha",
"karma-chrome-launcher",
"karma-firefox-launcher",
"karma-safari-launcher",
2019-04-12 14:37:47 +00:00
// "karma-sourcemap-loader",
2017-03-26 18:51:25 +00:00
],
2016-03-04 21:25:44 +00:00
2019-09-20 14:09:44 +00:00
client: {
mocha: {
reporter: "html",
timeout: 10000,
retries: 2,
2019-09-20 14:09:44 +00:00
ui: "bdd",
},
},
2017-03-26 18:51:25 +00:00
// web server port
2019-09-20 14:09:44 +00:00
port: 9876,
2016-03-04 21:25:44 +00:00
2017-03-26 18:51:25 +00:00
// enable / disable colors in the output (reporters and logs)
2019-09-20 14:09:44 +00:00
colors: true,
2016-03-04 21:25:44 +00:00
// set the inactivity level to longer
2019-09-20 14:09:44 +00:00
browserNoActivityTimeout: 40000,
2017-03-26 18:51:25 +00:00
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
2019-04-12 14:37:47 +00:00
logLevel: config.LOG_ERROR,
2016-03-04 21:25:44 +00:00
2017-03-26 18:51:25 +00:00
// enable / disable watching file and executing tests whenever any file changes
2019-09-20 14:09:44 +00:00
autoWatch: false,
2018-05-28 22:02:04 +00:00
// restartOnFileChange : true,
2016-03-04 21:25:44 +00:00
2017-03-26 18:51:25 +00:00
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
2019-09-20 14:09:44 +00:00
browsers: BROWSERS,
2016-03-04 21:25:44 +00:00
2017-03-26 18:51:25 +00:00
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
2019-09-20 14:09:44 +00:00
singleRun: false,
2016-03-04 21:25:44 +00:00
2017-03-26 18:51:25 +00:00
// Concurrency level
// how many browser should be started simultaneous
2017-11-29 21:14:53 +00:00
// concurrency: process.env.TRAVIS ? 1 : Infinity,
2019-09-20 14:09:44 +00:00
concurrency: Infinity,
// custom launcher for travis
customLaunchers: {
HeadlessChrome: {
base: "ChromeHeadless",
flags: ["--no-sandbox", "--use-fake-ui-for-media-stream", "--use-fake-device-for-media-stream",
"--autoplay-policy=no-user-gesture-required"],
2017-10-26 18:11:47 +00:00
},
2019-09-20 14:09:44 +00:00
HeadlessFirefox: {
base: "Firefox",
flags: ["-headless"],
prefs: {
"focusmanager.testmode": true,
"media.navigator.permission.disabled": true,
2019-04-12 14:37:47 +00:00
},
},
OnlineChrome: {
base: "Chrome",
flags: ["--no-sandbox", "--use-fake-ui-for-media-stream", "--use-fake-device-for-media-stream",
"--autoplay-policy=no-user-gesture-required"],
},
2019-04-12 14:37:47 +00:00
},
2017-03-26 18:51:25 +00:00
};
config.set(configuration);
2016-03-04 21:25:44 +00:00
};