Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing plugin metadata #186

Closed
ling1726 opened this issue Aug 22, 2023 · 3 comments
Closed

Testing plugin metadata #186

ling1726 opened this issue Aug 22, 2023 · 3 comments

Comments

@ling1726
Copy link

ling1726 commented Aug 22, 2023

It's possible to return metadata from the babel file transform result with a plugin. Is there a feature that can be used in the plugin tester to extract the metadata?

const babelFileResult = transform();
console.log('code', babelFileResult.code);
console.log('metadata, babelFileResult.metadata);

If not, would it be possible to have a feature that matches the returned metadata somehow?

This metadata can be set with a plugin and can return some useful information such as when the plugin is trying to extract some infomation from the source code while transforming it

@Xunnamius
Copy link
Collaborator

Xunnamius commented Aug 27, 2023

Interesting, and thank you for the example.

Is there any current documentation around the metadata property? The babel-core docs are seemingly incomplete in this regard (they describe { code, map, ast } as the result of transform(...)) and the only potential docs reference to metadata I can find is from the Babel 7 migration guide.

I only ask because if it's an undocumented but stable (legacy?) property, I think a matcher specifically for metadata would be appropriate. But if it's an undocumented new property, or there are a bunch of other undocumented stable properties, I'll opt for a more generic matcher instead.

I took a look at the types packages for Babel 6 versus Babel 7, and it seems like there are several undocumented stable properties I never noticed before. Perhaps a generic matcher property would suffice; something like rawOutput: (output: BabelFileResult) => void where you can bail out of the normal testing logic and make your own expect calls, e.g. expect(output.metadata).toStrictEqual({ ... }).

What do you think @ling1726?

@ling1726
Copy link
Author

Yeah returning the entire transform result would be a good idea regardless since it will let anyone test the entire stable return.

Xunnamius added a commit to Xunnamius/babel-plugin-tester that referenced this issue Mar 13, 2024
Xunnamius added a commit to Xunnamius/babel-plugin-tester that referenced this issue Mar 13, 2024
Xunnamius added a commit that referenced this issue Mar 13, 2024
## [12.0.0-canary.1](v11.0.4...v12.0.0-canary.1) (2024-03-13)

### 💥 BREAKING CHANGES 💥

* Minimum supported Node.js version is now 18.19.0

* Default exports are no longer available. See usage instructions
  for details on proper import syntax.

* Due to prettier@3 forcing downstream adoption of their
  asynchronous interface, `ResultFormatter` is no longer synchronous and can now
  return a `Promise`.

* Adoption of prettier@3 requires some versions of Node to be
  executed with the `--experimental-vm-modules` option. E.g.
  `NODE_OPTIONS="--no-warnings --experimental-vm-modules" npx jest`.

* Attempting to install babel-plugin-tester alongside jest@<30
  will cause NPM to fail with `ERESOLVE`. This is because only jest@>=30
  (jest-snapshot) supports the prettier@3 asynchronous interface.

#### ✨ Features

* Allow testing entire babel transform result via `outputRaw` ([e9d5aa1](e9d5aa1)) <sup>closes [#186](https://github.com/babel-utils/babel-plugin-tester/issues/186)</sup>
* Upgrade to prettier@3 ([3334248](3334248))

#### 🪄 Fixes

* **readme:** use proper codecov coverage badge ([1047e5c](1047e5c))

#### ⚙️ Build system

* **package:** bump minimum supported node versions to maintained ([ee6f7da](ee6f7da))
* Update core-js to 3.33 ([170248d](170248d))
* Upgrade typescript-babel toolchain to nodenext ([d0b722f](d0b722f))

#### 🧙🏿 Refactored

* **src:** deprecated default exports are no longer available ([b02d4f0](b02d4f0))
Xunnamius added a commit that referenced this issue Mar 13, 2024
## [12.0.0-canary.1](v11.0.4...v12.0.0-canary.1) (2024-03-13)

### 💥 BREAKING CHANGES 💥

* Minimum supported Node.js version is now 18.19.0

* Default exports are no longer available. See usage instructions
  for details on proper import syntax.

* Due to prettier@3 forcing downstream adoption of their
  asynchronous interface, `ResultFormatter` is no longer synchronous and can now
  return a `Promise`.

* Adoption of prettier@3 requires some versions of Node to be
  executed with the `--experimental-vm-modules` option. E.g.
  `NODE_OPTIONS="--no-warnings --experimental-vm-modules" npx jest`.

* Attempting to install babel-plugin-tester alongside jest@<30
  will cause NPM to fail with `ERESOLVE`. This is because only jest@>=30
  (jest-snapshot) supports the prettier@3 asynchronous interface.

#### ✨ Features

* Allow testing entire babel transform result via `outputRaw` ([e9d5aa1](e9d5aa1)) <sup>closes [#186](https://github.com/babel-utils/babel-plugin-tester/issues/186)</sup>
* Upgrade to prettier@3 ([3334248](3334248))

#### 🪄 Fixes

* **readme:** use proper codecov coverage badge ([1047e5c](1047e5c))

#### ⚙️ Build system

* **package:** bump minimum supported node versions to maintained ([ee6f7da](ee6f7da))
* Update core-js to 3.33 ([170248d](170248d))
* Upgrade typescript-babel toolchain to nodenext ([d0b722f](d0b722f))

#### 🧙🏿 Refactored

* **src:** deprecated default exports are no longer available ([b02d4f0](b02d4f0))
Xunnamius added a commit that referenced this issue Mar 13, 2024
## [12.0.0-canary.1](v11.0.4...v12.0.0-canary.1) (2024-03-13)

### 💥 BREAKING CHANGES 💥

* Minimum supported Node.js version is now 18.19.0

* Default exports are no longer available. See usage instructions
  for details on proper import syntax.

* Due to prettier@3 forcing downstream adoption of their
  asynchronous interface, `ResultFormatter` is no longer synchronous and can now
  return a `Promise`.

* Adoption of prettier@3 requires some versions of Node to be
  executed with the `--experimental-vm-modules` option. E.g.
  `NODE_OPTIONS="--no-warnings --experimental-vm-modules" npx jest`.

* Attempting to install babel-plugin-tester alongside jest@<30
  will cause NPM to fail with `ERESOLVE`. This is because only jest@>=30
  (jest-snapshot) supports the prettier@3 asynchronous interface.

#### ✨ Features

* Allow testing entire babel transform result via `outputRaw` ([e9d5aa1](e9d5aa1)) <sup>closes [#186](https://github.com/babel-utils/babel-plugin-tester/issues/186)</sup>
* Upgrade to prettier@3 ([3334248](3334248))

#### 🪄 Fixes

* **readme:** use proper codecov coverage badge ([1047e5c](1047e5c))

#### ⚙️ Build system

* **package:** bump minimum supported node versions to maintained ([ee6f7da](ee6f7da))
* Update core-js to 3.33 ([170248d](170248d))
* Upgrade typescript-babel toolchain to nodenext ([d0b722f](d0b722f))

#### 🧙🏿 Refactored

* **src:** deprecated default exports are no longer available ([b02d4f0](b02d4f0))
Xunnamius added a commit that referenced this issue Mar 13, 2024
## [12.0.0-canary.1](v11.0.4...v12.0.0-canary.1) (2024-03-13)

### 💥 BREAKING CHANGES 💥

* Minimum supported Node.js version is now 18.19.0

* Default exports are no longer available. See usage instructions
  for details on proper import syntax.

* Due to prettier@3 forcing downstream adoption of their
  asynchronous interface, `ResultFormatter` is no longer synchronous and can now
  return a `Promise`.

* Adoption of prettier@3 requires some versions of Node to be
  executed with the `--experimental-vm-modules` option. E.g.
  `NODE_OPTIONS="--no-warnings --experimental-vm-modules" npx jest`.

* Attempting to install babel-plugin-tester alongside jest@<30
  will cause NPM to fail with `ERESOLVE`. This is because only jest@>=30
  (jest-snapshot) supports the prettier@3 asynchronous interface.

#### ✨ Features

* Allow testing entire babel transform result via `outputRaw` ([e9d5aa1](e9d5aa1)) <sup>closes [#186](https://github.com/babel-utils/babel-plugin-tester/issues/186)</sup>
* Upgrade to prettier@3 ([3334248](3334248))

#### 🪄 Fixes

* **readme:** use proper codecov coverage badge ([1047e5c](1047e5c))

#### ⚙️ Build system

* **package:** bump minimum supported node versions to maintained ([ee6f7da](ee6f7da))
* Update core-js to 3.33 ([170248d](170248d))
* Upgrade typescript-babel toolchain to nodenext ([d0b722f](d0b722f))

#### 🧙🏿 Refactored

* **src:** deprecated default exports are no longer available ([b02d4f0](b02d4f0))
@Xunnamius
Copy link
Collaborator

🎉 This issue has been resolved in version 12.0.0-canary.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants