plugins from babelOptions are applied differently in fixtures vs tests
eps1lon opened this issue ยท 3 comments
babel-plugin-tester
version: 9.0.1node
version: 14.3.0npm
(oryarn
) version: 1.22.4
Relevant code or config
import pluginTester from 'babel-plugin-tester/pure';
import * as path from 'path';
import plugin from 'babel-plugin-macros';
pluginTester({
plugin,
babelOptions: {
plugins: [
[
'babel-plugin-module-resolver',
{
alias: {
'@material-ui/utils': path.resolve(__dirname, '../src'),
},
},
],
],
},
filename: __filename,
fixtures: path.resolve(__dirname, './__fixtures__'),
tests: [
{
title: 'can throw on missing error codes',
error: /unknown: Missing error code for message 'missing'. Did you forget to run `yarn extract-errors` first?/,
code: `
import MuiError from '@material-ui/utils/MuiError.macro';
throw new MuiError('missing');`,
pluginOptions: {
muiError: {
missingError: 'throw',
},
},
},
],
});
What you did:
- use
babel-plugin-module-resolver
inbabelOptions.plugins
What happened:
-
Tests in
tests
pass sincebabel-plugin-module-resolver
is applied before theplugin
. -
Tests in
fixtures
fail becausebabel-plugin-module-resolver
is not applied beforeplugin
error message
/home/eps1lon/Development/projects/mui/fork/packages/material-ui-utils/test/__fixtures__/literal/code.js: Cannot find module '@material-ui/utils/MuiError.macro' from '/home/eps1lon/Development/projects/mui/fork/packages/material-ui-utils/test/__fixtures__/literal'
Reproduction repository:
- clone (checkout this specific commit) https://github.com/eps1lon/material-ui/tree/1ceb45f2f8ec509885fd68285f2ad90f8f1a4e44
yarn
yarn cross-env NODE_ENV=test mocha packages/material-ui-utils/test/MuiError.macro.test.js --watch
Problem description: I want to write the test that mirror actual usage. For babel macros I would need to use a different import source than what is actually used.
Suggested solution:
- Always apply
babelOptions.plugins
first - Always apply
babelOptions.plugins
last but add an option so that we can configure it (either flag "applyFirst" or custom merger function)
Hi @eps1lon ๐
I'm not 100% certain, but I think option 1 is probably best. ๐
:tada: This issue has been resolved in version 11.0.0-canary.1 :tada:
The release is available on:
Your semantic-release bot ๐ฆ๐
:tada: This issue has been resolved in version 11.0.0 :tada:
The release is available on:
Your semantic-release bot ๐ฆ๐