babel-plugin-tester
babel-plugin-tester copied to clipboard
Suggestion: Fixture output file extension configuration.
babel-plugin-testerversion: ^9.1.0nodeversion: v12.16.3yarnversion: 1.19.1
folder structure (some files ommited):
ROOT
|-- package.json
|-- src
|-- __tests__
| |-- __fixtures__
| | |-- firstTest
| | | \-- code.ts
| | \-- secondTest
| | \-- code.ts
| \-- index-test.ts
\-- index.ts
content of src/__tests__/index-test.ts file:
import pluginTester from "babel-plugin-tester";
import * as path from "path";
import plugin from ".."; // my babel plugin
pluginTester({
plugin,
pluginName: "plugin",
endOfLine: "crlf",
babelOptions: {
presets: ["@babel/preset-env", "@babel/preset-typescript"],
plugins: [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-export-default-from",
"@babel/proposal-object-rest-spread",
],
},
filename: __filename,
fixtures: path.join(__dirname, '__fixtures__'),
});
What you did: run jest via 'yarn test' command ("test": "jest" in package.json)
What happened:
test run succesfully and created files __fixtures__/*/output.ts
Problem description:
output files have .ts extension because source files are written in typescript, but theyre actually transpiled javascripts, so they should have .js extension.
Suggested solution:
add option to speicfy output file extension:
fixtureOutputExt?: string | (test: string) => string where:
string: all output files use this extension(testName: string) => string: projection 'test name' to output extension:name => name === "firstTest" ? ".jsx" : ".js";
That sounds reasonable to me 👍
I'd be willing to accept a pull request for this.
create PR #73 - string version only, because config is json..
I believe #73 closes this, but feel free to reopen if this is not the case.