babel-plugin-tester icon indicating copy to clipboard operation
babel-plugin-tester copied to clipboard

Suggestion: Fixture output file extension configuration.

Open CzBuCHi opened this issue 5 years ago • 2 comments

  • babel-plugin-tester version: ^9.1.0
  • node version: v12.16.3
  • yarn version: 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";

CzBuCHi avatar May 22 '20 11:05 CzBuCHi

That sounds reasonable to me 👍

I'd be willing to accept a pull request for this.

kentcdodds avatar May 22 '20 18:05 kentcdodds

create PR #73 - string version only, because config is json..

CzBuCHi avatar May 25 '20 21:05 CzBuCHi

I believe #73 closes this, but feel free to reopen if this is not the case.

Xunnamius avatar Oct 02 '22 22:10 Xunnamius