Instrument client code before running tests
Despite being a bit gross to look at, this brings a few advantages:
- Tests are now closer to what actually runs, so more likely to find broken stuff.
- We can start using things that were so far Webpack-only or browser-only, like ES6 imports, loading Handlebars templates, etc.
- We open ourselves to browser testing (there is some work to do, but that would be a necessary step).
- We improve the client/server separation, by making it possible to run them independently
I do some extra steps around coverage: now we have 2 reports (client + server), so I have an extra step to combine them (the `nyc report` part). This is strictly to keep feature parity (the coverage report of this code is effectively the same as before), but in the near future, we might want to keep both reports separate, for example to continue separating client/server. Another reason would be to use something like Codecov, which I believe has the ability to have multiple reports. This is down the road though, our coverage is not good enough to make hosting them somewhere be useful (I think).
A few extras with this commit:
- Coverage summary is displayed when tests are run (this is not slowing down tests)
- Tests check for leaks (see https://mochajs.org/#--check-leaks)
- Tests now output with the `dot` reporter. This is nice as `npm test` runs in parallel, the whole output holds in a few lines instead of spanning over multiple screens.
2017-11-22 01:21:51 +00:00
|
|
|
"use strict";
|
|
|
|
|
2019-11-12 15:51:40 +00:00
|
|
|
const webpack = require("webpack");
|
2020-03-22 10:47:41 +00:00
|
|
|
const fs = require("fs");
|
2019-11-12 15:51:40 +00:00
|
|
|
const path = require("path");
|
2020-03-22 10:47:41 +00:00
|
|
|
const VueLoaderPlugin = require("vue-loader/lib/plugin");
|
Instrument client code before running tests
Despite being a bit gross to look at, this brings a few advantages:
- Tests are now closer to what actually runs, so more likely to find broken stuff.
- We can start using things that were so far Webpack-only or browser-only, like ES6 imports, loading Handlebars templates, etc.
- We open ourselves to browser testing (there is some work to do, but that would be a necessary step).
- We improve the client/server separation, by making it possible to run them independently
I do some extra steps around coverage: now we have 2 reports (client + server), so I have an extra step to combine them (the `nyc report` part). This is strictly to keep feature parity (the coverage report of this code is effectively the same as before), but in the near future, we might want to keep both reports separate, for example to continue separating client/server. Another reason would be to use something like Codecov, which I believe has the ability to have multiple reports. This is down the road though, our coverage is not good enough to make hosting them somewhere be useful (I think).
A few extras with this commit:
- Coverage summary is displayed when tests are run (this is not slowing down tests)
- Tests check for leaks (see https://mochajs.org/#--check-leaks)
- Tests now output with the `dot` reporter. This is nice as `npm test` runs in parallel, the whole output holds in a few lines instead of spanning over multiple screens.
2017-11-22 01:21:51 +00:00
|
|
|
const config = require("./webpack.config.js");
|
|
|
|
|
2020-03-22 10:47:41 +00:00
|
|
|
const testFile = path.resolve(__dirname, "test/public/testclient.js");
|
|
|
|
|
|
|
|
if (fs.existsSync(testFile)) {
|
|
|
|
fs.unlinkSync(testFile);
|
|
|
|
}
|
|
|
|
|
Instrument client code before running tests
Despite being a bit gross to look at, this brings a few advantages:
- Tests are now closer to what actually runs, so more likely to find broken stuff.
- We can start using things that were so far Webpack-only or browser-only, like ES6 imports, loading Handlebars templates, etc.
- We open ourselves to browser testing (there is some work to do, but that would be a necessary step).
- We improve the client/server separation, by making it possible to run them independently
I do some extra steps around coverage: now we have 2 reports (client + server), so I have an extra step to combine them (the `nyc report` part). This is strictly to keep feature parity (the coverage report of this code is effectively the same as before), but in the near future, we might want to keep both reports separate, for example to continue separating client/server. Another reason would be to use something like Codecov, which I believe has the ability to have multiple reports. This is down the road though, our coverage is not good enough to make hosting them somewhere be useful (I think).
A few extras with this commit:
- Coverage summary is displayed when tests are run (this is not slowing down tests)
- Tests check for leaks (see https://mochajs.org/#--check-leaks)
- Tests now output with the `dot` reporter. This is nice as `npm test` runs in parallel, the whole output holds in a few lines instead of spanning over multiple screens.
2017-11-22 01:21:51 +00:00
|
|
|
config.target = "node";
|
2018-09-04 20:18:17 +00:00
|
|
|
config.devtool = "eval";
|
2020-03-22 10:47:41 +00:00
|
|
|
config.stats = "errors-only";
|
|
|
|
config.output.path = path.resolve(__dirname, "test/public");
|
|
|
|
config.entry = {
|
|
|
|
"testclient.js": [path.resolve(__dirname, "test/client/index.js")],
|
|
|
|
};
|
Instrument client code before running tests
Despite being a bit gross to look at, this brings a few advantages:
- Tests are now closer to what actually runs, so more likely to find broken stuff.
- We can start using things that were so far Webpack-only or browser-only, like ES6 imports, loading Handlebars templates, etc.
- We open ourselves to browser testing (there is some work to do, but that would be a necessary step).
- We improve the client/server separation, by making it possible to run them independently
I do some extra steps around coverage: now we have 2 reports (client + server), so I have an extra step to combine them (the `nyc report` part). This is strictly to keep feature parity (the coverage report of this code is effectively the same as before), but in the near future, we might want to keep both reports separate, for example to continue separating client/server. Another reason would be to use something like Codecov, which I believe has the ability to have multiple reports. This is down the road though, our coverage is not good enough to make hosting them somewhere be useful (I think).
A few extras with this commit:
- Coverage summary is displayed when tests are run (this is not slowing down tests)
- Tests check for leaks (see https://mochajs.org/#--check-leaks)
- Tests now output with the `dot` reporter. This is nice as `npm test` runs in parallel, the whole output holds in a few lines instead of spanning over multiple screens.
2017-11-22 01:21:51 +00:00
|
|
|
|
2018-09-14 17:22:54 +00:00
|
|
|
// Add the istanbul plugin to babel-loader options
|
|
|
|
for (const rule of config.module.rules) {
|
|
|
|
if (rule.use.loader === "babel-loader") {
|
2019-07-17 09:33:59 +00:00
|
|
|
rule.use.options.plugins = ["istanbul"];
|
2018-09-14 17:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
Instrument client code before running tests
Despite being a bit gross to look at, this brings a few advantages:
- Tests are now closer to what actually runs, so more likely to find broken stuff.
- We can start using things that were so far Webpack-only or browser-only, like ES6 imports, loading Handlebars templates, etc.
- We open ourselves to browser testing (there is some work to do, but that would be a necessary step).
- We improve the client/server separation, by making it possible to run them independently
I do some extra steps around coverage: now we have 2 reports (client + server), so I have an extra step to combine them (the `nyc report` part). This is strictly to keep feature parity (the coverage report of this code is effectively the same as before), but in the near future, we might want to keep both reports separate, for example to continue separating client/server. Another reason would be to use something like Codecov, which I believe has the ability to have multiple reports. This is down the road though, our coverage is not good enough to make hosting them somewhere be useful (I think).
A few extras with this commit:
- Coverage summary is displayed when tests are run (this is not slowing down tests)
- Tests check for leaks (see https://mochajs.org/#--check-leaks)
- Tests now output with the `dot` reporter. This is nice as `npm test` runs in parallel, the whole output holds in a few lines instead of spanning over multiple screens.
2017-11-22 01:21:51 +00:00
|
|
|
|
2018-01-25 18:32:28 +00:00
|
|
|
// `optimization.splitChunks` is incompatible with a `target` of `node`. See:
|
|
|
|
// - https://github.com/zinserjan/mocha-webpack/issues/84
|
|
|
|
// - https://github.com/webpack/webpack/issues/6727#issuecomment-372589122
|
|
|
|
config.optimization.splitChunks = false;
|
Instrument client code before running tests
Despite being a bit gross to look at, this brings a few advantages:
- Tests are now closer to what actually runs, so more likely to find broken stuff.
- We can start using things that were so far Webpack-only or browser-only, like ES6 imports, loading Handlebars templates, etc.
- We open ourselves to browser testing (there is some work to do, but that would be a necessary step).
- We improve the client/server separation, by making it possible to run them independently
I do some extra steps around coverage: now we have 2 reports (client + server), so I have an extra step to combine them (the `nyc report` part). This is strictly to keep feature parity (the coverage report of this code is effectively the same as before), but in the near future, we might want to keep both reports separate, for example to continue separating client/server. Another reason would be to use something like Codecov, which I believe has the ability to have multiple reports. This is down the road though, our coverage is not good enough to make hosting them somewhere be useful (I think).
A few extras with this commit:
- Coverage summary is displayed when tests are run (this is not slowing down tests)
- Tests check for leaks (see https://mochajs.org/#--check-leaks)
- Tests now output with the `dot` reporter. This is nice as `npm test` runs in parallel, the whole output holds in a few lines instead of spanning over multiple screens.
2017-11-22 01:21:51 +00:00
|
|
|
|
2020-03-22 10:47:41 +00:00
|
|
|
// Disable plugins like copy files, it is not required
|
|
|
|
config.plugins = [
|
|
|
|
new VueLoaderPlugin(),
|
2019-11-12 15:51:40 +00:00
|
|
|
|
2020-03-22 10:47:41 +00:00
|
|
|
// Client tests that require Vue may end up requireing socket.io
|
2019-11-12 15:51:40 +00:00
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
|
|
|
/js(\/|\\)socket\.js/,
|
|
|
|
path.resolve(__dirname, "scripts/noop.js")
|
2020-03-22 10:47:41 +00:00
|
|
|
),
|
|
|
|
|
|
|
|
// "Fixes" Critical dependency: the request of a dependency is an expression
|
|
|
|
new webpack.ContextReplacementPlugin(/vue-server-renderer$/),
|
|
|
|
];
|
2019-11-12 15:51:40 +00:00
|
|
|
|
Instrument client code before running tests
Despite being a bit gross to look at, this brings a few advantages:
- Tests are now closer to what actually runs, so more likely to find broken stuff.
- We can start using things that were so far Webpack-only or browser-only, like ES6 imports, loading Handlebars templates, etc.
- We open ourselves to browser testing (there is some work to do, but that would be a necessary step).
- We improve the client/server separation, by making it possible to run them independently
I do some extra steps around coverage: now we have 2 reports (client + server), so I have an extra step to combine them (the `nyc report` part). This is strictly to keep feature parity (the coverage report of this code is effectively the same as before), but in the near future, we might want to keep both reports separate, for example to continue separating client/server. Another reason would be to use something like Codecov, which I believe has the ability to have multiple reports. This is down the road though, our coverage is not good enough to make hosting them somewhere be useful (I think).
A few extras with this commit:
- Coverage summary is displayed when tests are run (this is not slowing down tests)
- Tests check for leaks (see https://mochajs.org/#--check-leaks)
- Tests now output with the `dot` reporter. This is nice as `npm test` runs in parallel, the whole output holds in a few lines instead of spanning over multiple screens.
2017-11-22 01:21:51 +00:00
|
|
|
module.exports = config;
|