Skip to content

bump react-markdown from 8.0.7 to 9.0.0 #587

Open
@tadayosi

Description

@tadayosi

#578

This is proving a hard fix to find.

The problem:

 FAIL  src/Hawtio.test.tsx
  ● Test suite failed to run

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation

    Details:

    /home/phantomjinx/programming/js/hawtio-next/node_modules/react-markdown/index.js:11
    export {Markdown as default, defaultUrlTransform} from './lib/index.js'
    ^^^^^^

    SyntaxError: Unexpected token 'export'

      13 | } from '@patternfly/react-core'
      14 | import React from 'react'
    > 15 | import Markdown from 'react-markdown'
         | ^
      16 | import { NavLink, Navigate, Route, Routes, useLocation } from 'react-router-dom'
      17 | import help from './help.md'
      18 | import { helpRegistry } from './registry'

      at Runtime.createScriptFromCode (../../node_modules/jest/node_modules/jest-runtime/build/index.js:1505:14)
      at Object.<anonymous> (src/help/HawtioHelp.tsx:15:1)
      at Object.<anonymous> (src/ui/page/HawtioPage.tsx:3:1)
      at Object.<anonymous> (src/ui/page/index.ts:1:1)
      at Object.<anonymous> (src/Hawtio.tsx:6:1)
      at Object.<anonymous> (src/Hawtio.test.tsx:2:1)

Various attempts at solving similar issues are dotted around the interwebs. However, none of the most popular solutions or workarounds resolve the issue in our case:

  • Mock the Markdown component: attempt to do this results in the syntax of the mock being illegal. This might still be the most workable solution if only to get the syntax of the component correct;
  • Add a negative regex to jest.config.ts to not ignore react-markdown seems to be completely ignored:
  transformIgnorePatterns: [
    'node_modules/(?!@patternfly/react-icons/dist/esm/icons)/',
    'node_modules/(?!(devlop)/)',
    'node_modules/(?!(react-markdown)/)'
  ]
  • Trying in conjunction with a custom transform call, similarly causes the same error:
   transform: {
      '\\.[jt]sx?$': 'ts-jest',
     'node_modules/devlop/.+\\.(j|t)s?$': 'ts-jest',
     'node_modules/react-markdown/.+\\.(j|t)s?$': 'ts-jest'
   },

Interestingly, the devlop entry had to be added once the transform option was introduced. A similar error complaining about devlop appeared. By adding the entry to both transformIgnorePatterns and transform, the devlop error went away, only to be replaced by the react-markdown error.

Not sure where we go from here but upgrading to react-markdown and getting jest to play nicely with it is problematic. However, on the plus-side, actually compiling and starting the test app seems to work fine, with the Help markdown rendering without any trouble.

Originally posted by @phantomjinx in #578 (comment)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    dependenciesPull requests that update a dependency filehelp wantedExtra attention is needed

    Type

    No type

    Projects

    • Status

      Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions