This repository has been archived by the owner on Mar 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix test task for IE11 / viewport dependent tests (#1022)
* Fix test task for IE11 - Downgrade Sinon, sinon@10 drops IE11 support (there is a PR to correct the site, which still says IE11 is supported). - Bundle test JavaScript in the same way as the Build Service v3, targeting es5. Previously es6+ syntax caused errors in IE11. - Correct sourcemaps. Previously sourcemap related data was incorrectly added to the page as text, pushing test DOM down, causing errors for some component tests that depend on scroll position. - Bundle and serve source javascript but do not include it. This ensures when source code changes test code is processed again. I'm unsure why this is required on top of watching the files, there may be more efficient config to trigger test rebuilds on source file changes.
- Loading branch information
Showing
4 changed files
with
75 additions
and
115 deletions.
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
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,58 @@ | ||
"use strict"; | ||
|
||
const esbuild = require('esbuild'); | ||
const babel = require('@babel/core'); | ||
|
||
/** | ||
* Creates a bundle using `esbuild` using the `entryPointPath` as the entrypoint of the bundle. | ||
* | ||
* @param {String} entryPointPath The path where the index.js resides within. | ||
* @returns {Promise<String>} The bundled JavaScript as a string | ||
*/ | ||
async function bundleJavascript(entryPointPath) { | ||
const bundle = await esbuild.build({ | ||
sourcemap: 'inline', | ||
format: 'iife', | ||
target: 'es2020', | ||
minify: false, | ||
bundle: true, | ||
write: false, | ||
splitting: false, | ||
platform: 'browser', | ||
logLevel: 'silent', | ||
entryPoints: [entryPointPath] | ||
}); | ||
|
||
const bundleString = Buffer.from(bundle.outputFiles[0].contents).toString('utf-8'); | ||
|
||
const compiledBundle = await babel.transformAsync(bundleString, { | ||
presets: [require.resolve('@babel/preset-env')], | ||
sourceMaps: 'inline' | ||
}); | ||
|
||
const bundlefinal = await esbuild.build({ | ||
sourcemap: 'inline', | ||
format: 'iife', | ||
target: 'es5', | ||
minify: false, | ||
bundle: true, | ||
write: false, | ||
splitting: false, | ||
platform: 'browser', | ||
logLevel: 'silent', | ||
stdin: { | ||
contents: compiledBundle.code | ||
} | ||
}); | ||
|
||
return Buffer.from(bundlefinal.outputFiles[0].contents).toString('utf-8'); | ||
} | ||
|
||
module.exports = { | ||
'preprocessor:javascript': ['factory', function bundleJavaScriptFactory() { | ||
return async function (content, file, done) { | ||
const bundle = await bundleJavascript(file.path); | ||
done(null, bundle); | ||
}; | ||
}] | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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