babel-plugin-tester
babel-plugin-tester copied to clipboard
plugins from babelOptions are applied differently in fixtures vs tests
babel-plugin-testerversion: 9.0.1nodeversion: 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-resolverinbabelOptions.plugins
What happened:
-
Tests in
testspass sincebabel-plugin-module-resolveris applied before theplugin. -
Tests in
fixturesfail becausebabel-plugin-module-resolveris not applied beforepluginerror 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
yarnyarn 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.pluginsfirst - Always apply
babelOptions.pluginslast 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 :package::rocket:
:tada: This issue has been resolved in version 11.0.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket: