-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(best): Add IE11 runner and configuration
- Loading branch information
Dinko
committed
May 22, 2018
1 parent
0d7d022
commit 7d6f124
Showing
6 changed files
with
223 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module.exports = { | ||
projectName: 'simple-benchmark-ie11', | ||
plugins: ['rollup-plugin-compat'], | ||
benchmarkOnClient: true, | ||
benchmarkMinIterations: 10, | ||
useMacroTaskAfterBenchmark: false, | ||
"runnerConfig": [ | ||
{ | ||
"runner": "@best/runner-ie11", | ||
"name": "default", | ||
"config": { | ||
"host": 'localhost', | ||
"port": '4444' | ||
} | ||
}, | ||
{ | ||
"runner": '@best/runner-remote', | ||
"name": "remote", | ||
"config": { | ||
"host": "http://localhost:5000", | ||
"options": { path: '/best' }, | ||
"remoteRunner": "@best/runner-ie11" | ||
} | ||
} | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module.exports = { | ||
projectName: 'lwc-examples-ie11', | ||
plugins: [ | ||
'<rootDir>/custom-rollup-transformer/empty-example.js', | ||
['rollup-plugin-lwc-compiler', { | ||
rootDir: '<rootDir>/src/', | ||
mode: 'compat', // We don't really need prod here since this is for test best itself | ||
}] | ||
], | ||
benchmarkMinIterations: 10, | ||
benchmarkOnClient: false, | ||
"runnerConfig": [ | ||
{ | ||
"runner": "@best/runner-ie11", | ||
"name": "default", | ||
"config": { | ||
"host": 'localhost', | ||
"port": '4444' | ||
} | ||
}, | ||
{ | ||
"runner": '@best/runner-remote', | ||
"name": "remote", | ||
"config": { | ||
"host": "http://localhost:5000", | ||
"options": { path: '/best' }, | ||
"remoteRunner": "@best/runner-ie11" | ||
} | ||
} | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "@best/runner-ie11", | ||
"version": "0.5.1", | ||
"description": "Best Runner for IE 11", | ||
"keywords": [ | ||
"Best", | ||
"Runner", | ||
"IE11", | ||
"Internet Explorer 11", | ||
"LWC" | ||
], | ||
"main": "build/index.js", | ||
"module": "src/index.js", | ||
"dependencies": { | ||
"webdriverio": "4.12.0", | ||
"@best/utils": "0.5.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import { getSystemInfo } from '@best/utils'; | ||
const webdriverio = require('webdriverio'); | ||
|
||
const UPDATE_INTERVAL = 500; | ||
const BROWSER_OPTIONS = { | ||
desiredCapabilities: { | ||
platform: 'WINDOWS', | ||
browserName: 'internet explorer', | ||
version: '11', | ||
ignoreZoomSetting: true, | ||
initialBrowserUrl: 'about:blank', | ||
nativeEvents: false | ||
}, | ||
host: 'localhost', | ||
port: 4444 | ||
} | ||
|
||
function normalizeRuntimeOptions(projectConfig) { | ||
const { benchmarkIterations, benchmarkOnClient } = projectConfig; | ||
const definedIterations = Number.isInteger(benchmarkIterations); | ||
// For benchmarking on the client or a defined number of iterations duration is irrelevant | ||
const maxDuration = definedIterations ? 1 : projectConfig.benchmarkMaxDuration; | ||
const minSampleCount = definedIterations ? benchmarkIterations : projectConfig.benchmarkMinIterations; | ||
|
||
return { | ||
maxDuration, | ||
minSampleCount, | ||
iterations: benchmarkIterations, | ||
iterateOnClient: benchmarkOnClient, | ||
}; | ||
} | ||
|
||
function initializeBenchmarkState(opts) { | ||
return { | ||
executedTime: 0, | ||
executedIterations: 0, | ||
results: [], | ||
iterateOnClient: opts.iterateOnClient, | ||
}; | ||
} | ||
|
||
async function normalizeEnvironment(browser, projectConfig, globalConfig) { | ||
const { | ||
benchmarkOnClient, | ||
benchmarkRunner, | ||
benchmarkEnvironment, | ||
benchmarkIterations, | ||
projectName, | ||
} = projectConfig; | ||
const { system, cpu, os, load } = await getSystemInfo(); | ||
const version = `${browser.desiredCapabilities.browserName} ${browser.desiredCapabilities.version}`; | ||
return { | ||
hardware: { system, cpu, os }, | ||
runtime: { load }, | ||
browser: { version, options: BROWSER_OPTIONS }, | ||
configuration: { | ||
project: { | ||
projectName, | ||
benchmarkOnClient, | ||
benchmarkRunner, | ||
benchmarkEnvironment, | ||
benchmarkIterations, | ||
}, | ||
global: { | ||
gitCommitHash: globalConfig.gitCommit, | ||
gitHasLocalChanges: globalConfig.gitLocalChanges, | ||
gitBranch: globalConfig.gitBranch, | ||
gitRepository: globalConfig.gitRepository, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
function runIteration(page, state, opts) { | ||
// eslint-disable-next-line no-undef | ||
return page.executeAsync(function(o, done) { | ||
BEST.runBenchmark(o) | ||
.then(function(data) { | ||
done(data); | ||
}) | ||
.catch(function(e) { | ||
done(e); | ||
}); | ||
}, opts); | ||
} | ||
|
||
async function runIterations(page, state, opts, messager) { | ||
// Run an iteration to estimate the time it will take | ||
const result = await runIteration(page, state, { iterations: 1 }); | ||
const testResult = result.value; | ||
const estimatedIterationTime = testResult.executedTime; | ||
|
||
const start = Date.now(); | ||
// eslint-disable-next-line lwc/no-set-interval | ||
const intervalId = setInterval(() => { | ||
const executing = Date.now() - start; | ||
state.executedTime = executing; | ||
state.executedIterations = Math.round(executing / estimatedIterationTime); | ||
messager.updateBenchmarkProgress(state, opts); | ||
}, UPDATE_INTERVAL); | ||
|
||
await page.refresh(); | ||
|
||
const clientRawResults = await runIteration(page, state, opts); | ||
clearInterval(intervalId); | ||
|
||
const results = clientRawResults.value.results; | ||
state.results.push(...results); | ||
|
||
return state; | ||
} | ||
|
||
export async function run({ benchmarkName, benchmarkEntry }, projectConfig, globalConfig, messager) { | ||
const opts = normalizeRuntimeOptions(projectConfig); | ||
const state = initializeBenchmarkState(opts); | ||
const { projectName } = projectConfig; | ||
const browserOptions = Object.assign({}, BROWSER_OPTIONS, projectConfig.benchmarkRunnerConfig); | ||
|
||
let browser; | ||
try { | ||
browser = webdriverio.remote(browserOptions); | ||
const environment = await normalizeEnvironment(browser, projectConfig, globalConfig); | ||
|
||
messager.onBenchmarkStart(benchmarkName, projectName); | ||
|
||
const url = 'file:///' + benchmarkEntry; | ||
const page = browser.init().url(url); | ||
|
||
const { results } = await runIterations(page, state, opts, messager); | ||
return { results, environment }; | ||
} catch (e) { | ||
messager.onBenchmarkError(benchmarkName, projectName); | ||
throw e; | ||
} finally { | ||
messager.onBenchmarkEnd(benchmarkName, projectName); | ||
|
||
if (browser) { | ||
await browser.end(); | ||
} | ||
} | ||
} |