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Q,CAAC;YACtC,IAAM,SAAS,GAAG,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YAC9C,SAAS,CAAC,gBAAgB,CAAC,MAAM,EAAE;gBACjC,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC,CAAC;YACH,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,UAAC,KAAK;gBACxC,OAAO,CAAC,KAAK,CAAC,mBAAiB,IAAI,MAAG,EAAE,KAAK,CAAC,CAAC;gBAC/C,MAAM,CAAC,IAAI,KAAK,CAAC,oBAAkB,IAAM,CAAC,CAAC,CAAC;YAC9C,CAAC,CAAC,CAAC;YACH,IAAI,KAAK,EAAE;gBACT,SAAS,CAAC,IAAI,GAAG,QAAQ,CAAC;aAC3B;YACD,SAAS,CAAC,GAAG,GAAG,IAAI,CAAC;YACrB,SAAS,CAAC,KAAK,GAAG,IAAI,CAAC;YACvB,IAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,CAAC;YACpD,YAAY,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACL,CAAC","sourcesContent":["import { Minimatch } from 'minimatch';\nimport { request, Task, CancellablePromise, global } from '@theintern/common';\n\nimport * as console from '../common/console';\nimport Executor, { Config, Events, Plugins } from './Executor';\nimport { dirname, join, normalizePathEnding } from '../common/path';\nimport { getDefaultBasePath } from '../browser/util';\nimport { RuntimeEnvironment } from '../types';\n\n// Reporters\nimport Html from '../reporters/Html';\nimport Dom from '../reporters/Dom';\nimport ConsoleReporter from '../reporters/Console';\n\n/**\n * A Browser executor is used to run unit tests in a browser.\n */\nexport default class Browser extends Executor<Events, Config, Plugins> {\n constructor(options?: { [key in keyof Config]?: any }) {\n super(<Config>{\n basePath: '',\n internPath: '',\n });\n\n // Report uncaught errors\n global.addEventListener(\n 'unhandledRejection',\n (event: PromiseRejectionEvent) => {\n console.warn('Unhandled rejection:', event);\n const { warnOnUnhandledRejection } = this.config;\n if (\n warnOnUnhandledRejection &&\n (warnOnUnhandledRejection === true ||\n warnOnUnhandledRejection.test(`${event.reason}`))\n ) {\n this.emit('warning', `${event.reason}`);\n } else {\n this.emit('error', event.reason);\n }\n }\n );\n\n global.addEventListener('error', (event: ErrorEvent) => {\n console.warn('Unhandled error:', event);\n const error = new Error(event.message);\n if (\n this.config.warnOnUncaughtException &&\n (this.config.warnOnUncaughtException === true ||\n this.config.warnOnUncaughtException.test(`${error}`))\n ) {\n this.emit('warning', `${error}`);\n } else {\n error.stack = `${event.filename}:${event.lineno}:${event.colno}`;\n this.emit('error', error);\n }\n });\n\n this.registerReporter('html', (options) => new Html(this, options));\n this.registerReporter('dom', (options) => new Dom(this, options));\n this.registerReporter(\n 'console',\n (options) => new ConsoleReporter(this, options)\n );\n\n if (options) {\n this.configure(options);\n }\n }\n\n get environment(): RuntimeEnvironment {\n return 'browser';\n }\n\n /**\n * Load a script or scripts via script injection.\n *\n * @param script a path to a script\n */\n loadScript(\n script: string | string[],\n isEsm = false\n ): CancellablePromise<void> {\n if (typeof script === 'string') {\n script = [script];\n }\n\n return script.reduce((previous, script) => {\n if (script[0] !== '/' && !/https?:\\/\\//.test(script)) {\n script = `${this.config.basePath}${script}`;\n }\n return previous.then(() => injectScript(script, isEsm));\n }, Task.resolve());\n }\n\n protected _resolveConfig() {\n return super._resolveConfig().then(() => {\n const config = this.config;\n // const currentPath = global.location.pathname;\n\n if (!config.internPath) {\n const scripts = document.scripts;\n for (let i = 0; i < scripts.length; i++) {\n const scriptPath = scripts[i].src;\n if (/browser\\/intern.js/.test(scriptPath)) {\n config.internPath = dirname(dirname(scriptPath));\n }\n }\n\n if (!config.internPath) {\n config.internPath = '/';\n }\n }\n\n if (!config.basePath) {\n config.basePath = getDefaultBasePath();\n } else if (/^\\./.test(config.basePath)) {\n // The user provided a relative value for basePath. Resolve it\n // relative to the path to Intern's index.html.\n config.basePath = join(config.internPath, config.basePath);\n }\n\n (['basePath', 'internPath'] as ('basePath' | 'internPath')[]).forEach(\n (property) => {\n config[property] = normalizePathEnding(config[property]);\n }\n );\n\n // Combine suites and browser.suites into browser.suites\n const suites = (config.browser.suites = [\n ...config.suites,\n ...config.browser.suites,\n ]);\n\n // Clear out the suites list after combining the suites\n // @ts-ignore\n delete config.suites;\n\n const hasGlobs = suites.some((pattern) => {\n const matcher = new Minimatch(pattern);\n return matcher.set[0].some((entry) => typeof entry !== 'string');\n });\n\n if (hasGlobs) {\n return request('__resolveSuites__', { query: { suites } })\n .then((response) => response.json<string[]>())\n .catch(() => {\n throw new Error(\n 'The server does not support suite glob resolution'\n );\n })\n .then((data: string[]) => {\n config.browser.suites = data;\n });\n }\n });\n }\n}\n\nexport { Events, Config };\n\nfunction injectScript(path: string, isEsm: boolean): CancellablePromise<void> {\n return new Task<void>((resolve, reject) => {\n const doc: Document = global.document;\n const scriptTag = doc.createElement('script');\n scriptTag.addEventListener('load', () => {\n resolve();\n });\n scriptTag.addEventListener('error', (event) => {\n console.error(`Error loading ${path}:`, event);\n reject(new Error(`Unable to load ${path}`));\n });\n if (isEsm) {\n scriptTag.type = 'module';\n }\n scriptTag.src = path;\n scriptTag.defer = true;\n const scriptTarget = document.head || document.body;\n scriptTarget.appendChild(scriptTag);\n });\n}\n"]} |