Closed felix9 closed 10 months ago
"what if I want to webpack some js that will end up in an iframe loaded by a test, instead of on the test page directly?"
Can you explain this in more detail?
untested example
say I have a karma.conf.js
that looks something like this:
module.exports = config => {
config.set({
frameworks: ['chai', 'mocha', 'webpack'],
plugins: ['karma-chai', 'karma-mocha', 'karma-webpack'],
files: [
{ pattern: 'test/**/*.spec.js', included: true, served: false },
{ pattern: 'src/**/*.js', included: false, served: true },
],
preprocessors: {
'test/**/*.spec.js': ['webpack'],
'src/**/*.js': ['webpack'],
}
});
}
the intent is I might have a test named iframe-echo.spec.js
that can load an iframe with some other js and talk to it:
describe("iframe echo test", () => {
it("should respond to hello", done => {
const frame = document.createElement("iframe");
function receiver(e) {
if (e.data === "child ready") {
frame.contentWindow.postMessage("say hello", "*");
} else {
assert.strictEqual(e.data, "child says hello");
window.removeEventListener("message", receiver);
document.body.removeChild(frame);
done();
}
}
window.addEventListener("message", receiver);
document.body.appendChild(f);
frame.contentDocument.write(`
<script src="/client/src/iframe-echo.js"></script>
`);
});
});
It's not clear to me how to do something like this if karma-webpack is going to be putting everything into one bundle.
As karma is now deprecated and coming up on EOL, we are no longer planning on any significant enhancements to this project and are instead going to focus on security updates, stability, and a migration path forward as karma's lifecycle comes to an end.
Thank you for supporting and using this project!
it looks to me like the latest karma-webpack assumes that all the js files will be loaded into the same page.
what if I want to webpack some js that will end up in an iframe loaded by a test, instead of on the test page directly?
basically, if I tell karma
{ included: false, served true: }
it looks to me like karma-webpack will ignore the included: false and add it to the bundle anyway.