danwang / yaml-jest

A YAML transform for jest
MIT License
17 stars 7 forks source link

Jest 28 error: process() should return TransformedSource instead of string #16

Open hvasc opened 2 years ago

hvasc commented 2 years ago

in Upgrade Guides say They must always return an object:

  process(sourceText, sourcePath, options) {
-   return `module.exports = ${JSON.stringify(path.basename(sourcePath))};`;
+   return {
+     code: `module.exports = ${JSON.stringify(path.basename(sourcePath))};`,
+   };
  }
conor909 commented 1 year ago

Jest 29

Invalid return value:
      `process()` or/and `processAsync()` method of code transformer found at
      "/Users/username/dev/project/node_modules/yaml-jest/dist/index.js"
      should return an object or a Promise resolving to an object. The object
      must have `code` property with a string of processed code.
      This error may be caused by a breaking change in Jest 28:
      https://jestjs.io/docs/28.x/upgrading-to-jest28#transformer
      Code Transformation Documentation:
      https://jestjs.io/docs/code-transformation
davetaylor commented 1 year ago

Workaround for this issue: https://github.com/sumwatshade/jest-transform-yaml/issues/19#issuecomment-1232857013 - just replace jest-transform-yaml in the example with yaml-jest.