Skip to content

Commit 6e706ed

Browse files
committed
✨ (benchmarks) re-introduce benchmarks frontend with web test runner, configs and new code
1 parent 71993bd commit 6e706ed

12 files changed

+483
-184
lines changed

.tasks/.tests/benchmarks/bundle-benchmarks.task.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async function bundleBenchmarksTask( done ) {
1313

1414
const configs = [
1515
getRollupConfigurationFor( 'benchmarks-backend' ),
16-
getRollupConfigurationFor( 'benchmarks-frontend' )
16+
// getRollupConfigurationFor( 'benchmarks-frontend' )
1717
]
1818

1919
for ( let config of configs ) {

.tasks/.tests/benchmarks/compute-benchmarks.task.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,9 @@ function computeBenchmarksTask( done ) {
139139
}
140140

141141
const template = '' + '\n' +
142-
`import Benchmark from 'benchmark'` + '\n' +
143-
`import { Testing } from 'itee-utils'` + '\n' +
142+
`/* global Benchmark */` + '\n' +
143+
'\n' +
144+
`import { Testing } from 'itee-utils/sources/testings/benchmarks.js'` + '\n' +
144145
`import * as ${ nsName } from '${ importFilePath }'` + '\n' +
145146
'\n' +
146147
`${ benchSuites }` +
@@ -189,7 +190,7 @@ function computeBenchmarksTask( done ) {
189190
`\tsuite.run()` + '\n' +
190191
`}` + '\n'
191192

192-
const benchesFilePath = join( benchesDir, `${ packageName }.benchs.js` )
193+
const benchesFilePath = join( benchesDir, `${ packageName }.benchmarks.js` )
193194

194195
log( green( `Create ${ benchesFilePath }` ) )
195196
writeFileSync( benchesFilePath, benchesTemplate )

.tasks/.tests/benchmarks/run-benchmarks-for-backend.task.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const yellow = colors.yellow
1212

1313
function runBenchmarksForBackendTask( done ) {
1414

15-
const benchesPath = path.join( packageTestsBenchmarksDirectory, `/builds/${ packageName }.benchs.cjs.js` )
15+
const benchesPath = path.join( packageTestsBenchmarksDirectory, `/builds/${ packageName }.benchmarks.cjs.js` )
1616
if ( !existsSync( benchesPath ) ) {
1717
log( yellow( `${ benchesPath } does not exist, skip backend benchmarks...` ) )
1818
done()

.tasks/.tests/benchmarks/run-benchmarks-for-frontend.task.mjs

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,27 @@
1-
import colors from 'ansi-colors'
2-
import log from 'fancy-log'
3-
import { existsSync } from 'fs'
4-
import karma from 'karma'
5-
import path from 'path'
6-
import { packageRootDirectory } from '../../_utils.mjs'
7-
8-
const {
9-
red,
10-
yellow
11-
} = colors
1+
import { startTestRunner } from '@web/test-runner'
2+
import colors from 'ansi-colors'
3+
import { default as config } from '../../configs/benchmarks.conf.mjs'
124

5+
const { red } = colors
136

147
async function runBenchmarksForFrontendTask( done ) {
158

16-
const configFile = path.normalize( `${ packageRootDirectory }/configs/karma.benchs.conf.js` )
17-
if ( !existsSync( configFile ) ) {
18-
log( yellow( `${ configFile } does not exist, skip frontend benchmarks...` ) )
19-
done()
20-
return
21-
}
22-
23-
const karmaConfig = karma.config.parseConfig( configFile )
24-
const karmaServer = new karma.Server( karmaConfig, ( exitCode ) => {
25-
if ( exitCode === 0 ) {
26-
log( `Karma server exit with code ${ exitCode }` )
27-
done()
28-
} else {
29-
done( `Karma server exit with code ${ exitCode }` )
9+
return new Promise( async ( resolve, reject ) => {
10+
11+
const testRunner = await startTestRunner( {
12+
config: config,
13+
readCliArgs: false,
14+
readFileConfig: false,
15+
} )
16+
17+
if ( !testRunner ) {
18+
reject( red( 'Internal test runner error.' ) )
19+
return
3020
}
31-
} )
32-
karmaServer.on( 'browser_error', ( browser, error ) => {
33-
log( red( error.message ) )
34-
} )
3521

36-
await karmaServer.start()
22+
testRunner.on( 'finished', resolve )
23+
24+
} )
3725

3826
}
3927

.tasks/configs/benchmarks.conf.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { playwrightLauncher } from '@web/test-runner-playwright'
2+
import { packageRootDirectory } from '../_utils.mjs'
3+
import { iteeReporter } from '../itee-reporter.mjs'
4+
5+
export default {
6+
files: [
7+
'tests/benchmarks/**/*.bench.js',
8+
],
9+
nodeResolve: true,
10+
browsers: [
11+
playwrightLauncher( { product: 'chromium' } ),
12+
playwrightLauncher( { product: 'webkit' } ),
13+
playwrightLauncher( { product: 'firefox' } ),
14+
],
15+
testFramework: {
16+
path: packageRootDirectory + '/.tasks/itee-benchmarks-framework.js',
17+
config: {
18+
foo: 'bar'
19+
}
20+
},
21+
testRunnerHtml: testFramework => `
22+
<!DOCTYPE html>
23+
<html>
24+
<body>
25+
<script type="module" src="node_modules/lodash/lodash.js"></script>
26+
<script type="module" src="node_modules/platform/platform.js"></script>
27+
<script type="module" src="node_modules/benchmark/benchmark.js"></script>
28+
<script type="module" src="${ testFramework }"></script>
29+
</body>
30+
</html>
31+
`,
32+
reporters: [
33+
iteeReporter()
34+
]
35+
}

.tasks/configs/build.conf.mjs

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,8 @@ const configs = {
342342
}
343343
},
344344
'benchmarks-backend': {
345-
input: `tests/benchmarks/${ packageName }.benchs.js`,
345+
input: `tests/benchmarks/${ packageName }.benchmarks.js`,
346346
external: [
347-
'benchmark',
348347
'fs'
349348
],
350349
plugins: [
@@ -368,16 +367,23 @@ const configs = {
368367
output: {
369368
indent: '\t',
370369
format: 'cjs',
371-
file: `tests/benchmarks/builds/${ packageName }.benchs.cjs.js`
370+
intro: () => "var Benchmark = require('benchmark')",
371+
file: `tests/benchmarks/builds/${ packageName }.benchmarks.cjs.js`
372372
}
373373
},
374374
'benchmarks-frontend': {
375-
input: `tests/benchmarks/${ packageName }.benchs.js`,
375+
input: `tests/benchmarks/${ packageName }.benchmarks.js`,
376376
external: [
377-
'benchmark'
377+
'benchmark',
378+
// 'lodash'
378379
],
379380
plugins: [
380-
nodeResolve(),
381+
nodeResolve( {
382+
preferBuiltins: true
383+
} ),
384+
commonjs( {
385+
include: 'node_modules/**'
386+
} ),
381387
replace( {
382388
// Even this variable are not used in this package, we need it because
383389
// they are used in dependency package itee-utils that use them to focus some build stuff
@@ -424,30 +430,22 @@ const configs = {
424430
'\tisValidPathSuite,': '\t//isValidPathSuite,',
425431
'\tisValidSocketPathSuite,': '\t//isValidSocketPathSuite,',
426432
'\tisValidSymbolicLinkPathSuite,': '\t//isValidSymbolicLinkPathSuite,',
427-
428-
'suite.run()': '//suite.run()'
429433
}
430434
} ),
431435
cleanup( {
432436
comments: 'none'
433437
} )
434438
],
435-
treeshake: {
436-
moduleSideEffects: false,
437-
annotations: true,
438-
correctVarValueBeforeDeclaration: true,
439-
propertyReadSideEffects: false,
440-
tryCatchDeoptimization: true,
441-
unknownGlobalSideEffects: false
442-
},
439+
treeshake: false,
443440
output: {
444441
indent: '\t',
445442
format: 'iife',
446443
name: 'Itee.Benchmarks',
447444
globals: {
448-
'benchmark': 'Benchmark'
445+
'benchmark': 'Benchmark',
446+
// 'lodash': '_'
449447
},
450-
file: `tests/benchmarks/builds/${ packageName }.benchs.iife.js`
448+
file: `tests/benchmarks/builds/${ packageName }.benchmarks.iife.js`
451449
}
452450
},
453451
'units-backend': {
@@ -481,23 +479,23 @@ const configs = {
481479
nodeResolve(), // required to bundle itee-utils that cannot be integrated as standalone file (why???)=> because circular ref with itee validator package -_-'
482480
replace( {
483481
replaces: {
484-
'import { isValidSymbolicLinkPathUnits }': '//',
485-
'import { isSymbolicLinkPathUnits }': '//',
486-
'import { isValidSocketPathUnits }': '//',
487-
'import { isSocketPathUnits }': '//',
488-
'import { isValidPathUnits }': '//',
489-
'import { isValidFilePathUnits }': '//',
490-
'import { isFilePathUnits }': '//',
491-
'import { isEmptyFileUnits }': '//',
492-
'import { isValidFIFOPathUnits }': '//',
493-
'import { isFIFOPathUnits }': '//',
494-
'import { isValidDirectoryPathUnits }': '//',
495-
'import { isEmptyDirectoryUnits }': '//',
496-
'import { isDirectoryPathUnits }': '//',
482+
'import { isValidSymbolicLinkPathUnits }': '//',
483+
'import { isSymbolicLinkPathUnits }': '//',
484+
'import { isValidSocketPathUnits }': '//',
485+
'import { isSocketPathUnits }': '//',
486+
'import { isValidPathUnits }': '//',
487+
'import { isValidFilePathUnits }': '//',
488+
'import { isFilePathUnits }': '//',
489+
'import { isEmptyFileUnits }': '//',
490+
'import { isValidFIFOPathUnits }': '//',
491+
'import { isFIFOPathUnits }': '//',
492+
'import { isValidDirectoryPathUnits }': '//',
493+
'import { isEmptyDirectoryUnits }': '//',
494+
'import { isDirectoryPathUnits }': '//',
497495
'import { isValidCharacterDevicePathUnits }': '//',
498-
'import { isCharacterDevicePathUnits }': '//',
499-
'import { isValidBlockDevicePathUnits }': '//',
500-
'import { isBlockDevicePathUnits }': '//',
496+
'import { isCharacterDevicePathUnits }': '//',
497+
'import { isValidBlockDevicePathUnits }': '//',
498+
'import { isBlockDevicePathUnits }': '//',
501499

502500
'isBlockDevicePathUnits.call': '//isBlockDevicePathUnits.call',
503501
'isValidBlockDevicePathUnits.call': '//isValidBlockDevicePathUnits.call',
@@ -529,7 +527,7 @@ const configs = {
529527
name: 'Itee.Units',
530528
globals: {
531529
// 'mocha': 'Mocha',
532-
'chai': 'chai'
530+
'chai': 'chai'
533531
},
534532
file: `tests/units/builds/${ packageName }.units.esm.js`
535533
}

.tasks/configs/karma.benchs.conf.js

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)