2021-09-20 14:56:02 +00:00
|
|
|
// The Webpack preprocessor does not include any types so it will have to be ignored.
|
|
|
|
// @ts-ignore
|
|
|
|
import webpackPreprocessor from "@cypress/webpack-batteries-included-preprocessor";
|
|
|
|
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
|
2021-12-07 11:11:22 +00:00
|
|
|
import fs from "fs";
|
2021-09-20 14:56:02 +00:00
|
|
|
import path from "path";
|
|
|
|
|
2021-01-12 17:04:52 +00:00
|
|
|
// ***********************************************************
|
|
|
|
// This example plugins/index.js can be used to load plugins
|
|
|
|
//
|
|
|
|
// You can change the location of this file or turn off loading
|
|
|
|
// the plugins file with the 'pluginsFile' configuration option.
|
|
|
|
//
|
|
|
|
// You can read more here:
|
|
|
|
// https://on.cypress.io/plugins-guide
|
|
|
|
// ***********************************************************
|
|
|
|
|
|
|
|
// This function is called when a project is opened or re-opened (e.g. due to
|
|
|
|
// the project's config changing)
|
|
|
|
|
2021-09-20 14:56:02 +00:00
|
|
|
const configurePlugins: Cypress.PluginConfig = (on) => {
|
|
|
|
const defaultOptions = webpackPreprocessor.defaultOptions.webpackOptions;
|
|
|
|
const webpackOptions = {
|
|
|
|
...defaultOptions,
|
|
|
|
context: path.resolve(__dirname, ".."),
|
|
|
|
plugins: [
|
|
|
|
new ForkTsCheckerWebpackPlugin({
|
|
|
|
async: false,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
on(
|
|
|
|
"file:preprocessor",
|
|
|
|
webpackPreprocessor({
|
|
|
|
typescript: require.resolve("typescript"),
|
|
|
|
webpackOptions,
|
|
|
|
})
|
|
|
|
);
|
2021-12-06 10:50:29 +00:00
|
|
|
on("after:spec", (spec, results) => {
|
2021-12-07 11:11:22 +00:00
|
|
|
if (!results.video) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do we have failures for any retry attempts?
|
|
|
|
const failures = results.tests.some(({ attempts }) =>
|
|
|
|
attempts.some(({ state }) => state === "failed")
|
|
|
|
);
|
|
|
|
|
|
|
|
// delete the video if the spec passed and no tests retried
|
|
|
|
if (!failures) {
|
|
|
|
fs.rmSync(results.video);
|
2021-12-06 10:50:29 +00:00
|
|
|
}
|
|
|
|
});
|
2021-09-16 10:24:21 +00:00
|
|
|
};
|
2021-09-17 13:23:34 +00:00
|
|
|
|
|
|
|
export default configurePlugins;
|