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

[Bug]: ECMAScript Modules with multi spec can not debug #12075

Closed
wszgrcy opened this issue Nov 18, 2021 · 7 comments
Closed

[Bug]: ECMAScript Modules with multi spec can not debug #12075

wszgrcy opened this issue Nov 18, 2021 · 7 comments

Comments

@wszgrcy
Copy link

wszgrcy commented Nov 18, 2021

Version

27.3.1

Steps to reproduce

npm script: {"test": "NODE_OPTIONS="--experimental-vm-modules --inspect-brk" jest"}
launch.json

    {
      "name": "test",
      "type": "node",
      "request": "launch",
      "cwd": "${workspaceRoot}",
      "runtimeExecutable": "npm",
      "runtimeArgs": ["run-script", "test"],
      "port": 9229
    },

when spec pattern match only one(not xdescribe,is one file one describe)
I can debug one spec
when spec pattern match multi will throw error and can't debug

(node:85313) UnhandledPromiseRejectionWarning: Error: You need to run with a version of node that supports ES Modules in the VM API. See https://jestjs.io/docs/ecmascript-modules
    at invariant (/Users/chen/my-project/angular-miniprogram/node_modules/jest-runtime/build/index.js:2423:11)
    at importModuleDynamically (/Users/chen/my-project/angular-miniprogram/node_modules/jest-runtime/build/index.js:1735:11)
    at importModuleDynamicallyWrapper (internal/vm/module.js:451:21)
    at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:30:14)
    at eval (eval at <anonymous> (/Users/chen/my-project/angular-miniprogram/src/builder/util/load_esm.ts:2:33), <anonymous>:3:1)
    at /Users/chen/my-project/angular-miniprogram/src/builder/util/load_esm.ts:5:4
    at Generator.next (<anonymous>)
    at /Users/chen/my-project/angular-miniprogram/src/builder/util/load_esm.ts:8:71
    at new Promise (<anonymous>)
    at Object.<anonymous>.__awaiter (/Users/chen/my-project/angular-miniprogram/src/builder/util/load_esm.ts:4:12)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:85313) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 6)
(node:85313) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

but I add --experimental-vm-modules flag and run success on one spec one describe.

Expected behavior

multi spec file also run success

Actual behavior

only match one spec can run success

Additional context

No response

Environment

System:
    OS: macOS 11.1
    CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
  Binaries:
    Node: 14.17.1 - ~/.nvm/versions/node/v14.17.1/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.13 - ~/.nvm/versions/node/v14.17.1/bin/npm
  npmPackages:
    jest: ^27.3.1 => 27.3.1
@SimenB
Copy link
Member

SimenB commented Nov 18, 2021

Sorry, I don't follow to example. Could you put together a reproduction I can pull down and run?

@wszgrcy
Copy link
Author

wszgrcy commented Nov 18, 2021

//b.spec.ts
import { angularCompilerPromise, getAngularCompiler } from "./load_esm";
describe("aaaa", () => {
  it("bbbb", async () => {
    let result = await getAngularCompiler();
    console.log(result);
    console.log("222");
  });
});
// a.spec.ts
describe("", () => {
  it("", () => {
    console.log("111");
  });
});
//load_esm.ts
export async function loadEsmModule<T>(modulePath: string): Promise<T> {
  const namespaceObject = await new Function("modulePath", `return import(modulePath);`)(modulePath);

  // If it is not ESM then the values needed will be stored in the `default` property.
  // TODO_ESM: This can be removed once `@angular/*` packages are ESM only.
  if (namespaceObject.default) {
    return namespaceObject.default;
  } else {
    return namespaceObject;
  }
}

export function getAngularCompiler() {
  return loadEsmModule<any>("@angular/compiler");
}
export const angularCompilerPromise = getAngularCompiler();
export const angularCompilerCliPromise = loadEsmModule<any>("@angular/compiler-cli");
//jest.config.ts
export default {
  clearMocks: true,
  collectCoverage: true,
  coverageDirectory: "coverage",
  coverageProvider: "v8",
  moduleFileExtensions: ["js", "ts"],
  transform: {
    "^.+\\.(t|j)s$": "ts-jest",
  },
  testRunner: "jasmine2",
};
  "scripts": {
    "test": "NODE_OPTIONS=\"--experimental-vm-modules  --inspect-brk\" jest",
  },

when delete a.spec.ts. I can debug(with inspec-brk) and run success

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Nov 18, 2022
@leokolezhuk
Copy link

Getting same issue

Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Mar 11, 2024
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 10, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants