2019-12-08 02:48:30 +05:30
|
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
|
|
/* eslint-env node */
|
|
|
|
// ***********************************************************
|
|
|
|
// 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)
|
|
|
|
|
|
|
|
// export default (on, config) => {
|
|
|
|
// // `on` is used to hook into various events Cypress emits
|
|
|
|
// // `config` is the resolved Cypress config
|
|
|
|
// };
|
|
|
|
const wp = require('@cypress/webpack-preprocessor');
|
|
|
|
|
2020-05-20 21:59:48 +05:30
|
|
|
// for some reason loader can not locate babel.config. So we load it manually
|
2019-12-29 17:57:44 +05:30
|
|
|
const config = require('../../../babel.config');
|
2020-10-11 22:03:55 +05:30
|
|
|
const babelEnvName = 'browser-development';
|
2019-12-29 17:57:44 +05:30
|
|
|
|
2020-05-20 22:05:52 +05:30
|
|
|
module.exports = (on) => {
|
2020-05-24 04:38:24 +05:30
|
|
|
const options = {
|
|
|
|
webpackOptions: {
|
|
|
|
mode: 'development',
|
|
|
|
// webpack will transpile TS and JS files
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.ts', '.js', '.json'],
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.[tj]s$/,
|
|
|
|
exclude: [/node_modules/],
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
2020-10-11 22:03:55 +05:30
|
|
|
envName: babelEnvName,
|
2020-05-24 04:38:24 +05:30
|
|
|
cacheDirectory: true,
|
2020-07-07 04:16:42 +05:30
|
|
|
// We don't have the webpack's API object, so just provide necessary methods
|
|
|
|
...config({
|
2020-10-11 22:03:55 +05:30
|
|
|
env(value) {
|
|
|
|
// see @babel/core/lib/config/helpers/config-api.js
|
|
|
|
switch (typeof value) {
|
|
|
|
case 'string':
|
|
|
|
return value === babelEnvName;
|
|
|
|
case 'function':
|
|
|
|
return value(babelEnvName);
|
|
|
|
|
|
|
|
case 'undefined':
|
|
|
|
return babelEnvName;
|
|
|
|
default:
|
|
|
|
if (Array.isArray(value)) {
|
|
|
|
throw new Error('Unimplemented env() argument');
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error('Invalid env() argument');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
cache: {
|
|
|
|
using() {},
|
2020-07-07 04:16:42 +05:30
|
|
|
},
|
|
|
|
}),
|
2020-05-24 04:38:24 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2019-12-08 02:48:30 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
on('file:preprocessor', wp(options));
|
2019-12-08 02:48:30 +05:30
|
|
|
};
|