EPICLab / synectic

Cards-based IDE for research into context-aware, heuristic problem-solving development tools.
https://epiclab.github.io/synectic/
MIT License
5 stars 0 forks source link

Top-level ESM support for Electron applications #659

Open nelsonni opened 2 years ago

nelsonni commented 2 years ago

Describe the bug Running Jest tests that make reference to the sindresorhus/dot-prop dependency causes the following error message:

❯ yarn test src/components/Stack
yarn run v1.22.17
$ jest src/components/Stack
 FAIL  src/components/Stack/Stack.spec.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:

    /Users/nelsonni/Workspace/synectic/node_modules/dot-prop/index.js:173
    export function getProperty(object, path, value) {
    ^^^^^^

    SyntaxError: Unexpected token 'export'

       5 | import * as ini from 'ini';
       6 | import parse from 'parse-git-config';
    >  7 | import { getProperty, setProperty, hasProperty, deleteProperty } from 'dot-prop';
         | ^
       8 | import getGitConfigPath from 'git-config-path';
       9 | import type { Repository, GitStatus } from '../types';
      10 | import * as io from './io';

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1728:14)
      at Object.<anonymous> (src/containers/git-porcelain.ts:7:1)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        2.159 s
Ran all test suites matching /src\/components\/Stack/i.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

This error occurs because sindresorhus/dot-prop v7.0.0 converts to a pure ESM format, which requires similar updates to all downstream projects (including Synectic).

To Reproduce Steps to reproduce the behavior:

  1. Open a terminal/command-line
  2. Navigate to the root directory of the Synectic source code
  3. Run any test that exercises a React component that uses sindresorhus/dot-prop (e.g. yarn test src/components/Stack)
  4. See error

Expected behavior Test suites should run and provide results based on the tests.

Screenshots N/A

Versions (please complete the following information):

Additional context Relevant issues/PR being tracked for resolution:

nelsonni commented 10 months ago

Per Electron Timelines, Electron 28.0.0 stable is expected to be released on 2023-Dec-5. There is a ES Modules (ESM) in Electron tutorial describing the steps required in order to take advantage of ESM once 28.0.0 is generally available.