Skip to content

Commit

Permalink
feat(best): Add IE11 runner and configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinko committed May 22, 2018
1 parent 0d7d022 commit 7d6f124
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 1 deletion.
26 changes: 26 additions & 0 deletions examples/simple_benchmark/best.ie11.config.js
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"
}
}
],
};
31 changes: 31 additions & 0 deletions examples/simple_lwc_benchmark/best.ie11.config.js
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"
}
}
],
};
7 changes: 6 additions & 1 deletion packages/best-build/src/html-templating.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const REGEX_BRACKETS = /{{([\w]+)}}/g;

// The '<!-- saved from ... -->' syntax is required to let IE know that this content is safe to execute.
// Full details are here: https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/compatibility/ms537628(v=vs.85)
// Also, note that the line endings have to be <CR><LF> for Internet Explorer to correctly recognize the mark.
// Default line endings on mac and linux have just <LF>
const DEFAULT_HTML = `<!DOCTYPE html>
<!-- saved from url=(0016)http://localhost -->
<html>
<head>
<meta charset="UTF-8">
Expand All @@ -11,7 +16,7 @@ const DEFAULT_HTML = `<!DOCTYPE html>
<script src="{{benchmarkJS}}" type="text/javascript"></script>
</body>
</html>
`;
`.replace(/(\r\n|\r|\n)/g, '\r\n');

export function generateParametrizedHTML(html, options) {
return html.replace(REGEX_BRACKETS, (m, p) => options[p] || `{{undefined_${p}}}`);
Expand Down
1 change: 1 addition & 0 deletions packages/best-runner-ie11/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src
18 changes: 18 additions & 0 deletions packages/best-runner-ie11/package.json
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"
}
}
141 changes: 141 additions & 0 deletions packages/best-runner-ie11/src/index.js
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();
}
}
}

0 comments on commit 7d6f124

Please sign in to comment.