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

Explicit Resource Management is not supported #4303

Closed
james-pre opened this issue May 20, 2024 · 6 comments
Closed

Explicit Resource Management is not supported #4303

james-pre opened this issue May 20, 2024 · 6 comments

Comments

@james-pre
Copy link

james-pre commented May 20, 2024

Version

^29.1.0

Steps to reproduce

  1. git clone https://github.com/zen-fs/core.git
  2. git checkout erm
  3. npm i
  4. npm test

Expected behavior

Explicit resource management should be supported[1]

Actual behavior

 FAIL  tests/...
  ● Test suite failed to run

    SyntaxError: Unexpected identifier '[*]'

      at Runtime.loadEsmModule (node_modules/jest-runtime/build/index.js:510:20)

[*] Some identifier that comes after using or await using

Debug log

ts-jest.log

Additional context

[1] Esbuild and Typescript support down-level transformation of the using and await using syntax. From what I understand, ts-jest uses or is moving to Esbuild for the transformer.

Environment

System:
    OS: Linux 5.14 Rocky Linux 9.4 (Blue Onyx)
    CPU: (16) x64 13th Gen Intel(R) Core(TM) i5-1340P
  Binaries:
    Node: 21.7.2 - ~/.nvm/versions/node/v21.7.2/bin/node
    npm: 10.5.0 - ~/.nvm/versions/node/v21.7.2/bin/npm
    pnpm: 8.15.1 - ~/.nvm/versions/node/v21.7.2/bin/pnpm
  npmPackages:
    jest: ^29.5.0 => 29.5.0
@james-pre
Copy link
Author

@kulshekhar Any updates on this?

@james-pre
Copy link
Author

@ahnpnl Any updates?

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jun 28, 2024

Not sure what is the issue with your repo though, I created a simple example here #4400 and it works (CI passed)

@james-pre
Copy link
Author

james-pre commented Jun 28, 2024

@ahnpnl, I've updated the code and am experiencing a slightly different issue:

 FAIL  tests/port/timeout.test.ts
  ● 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:

    SyntaxError: <@zenfs/core>/src/filesystem.ts: Support for the experimental syntax 'explicitResourceManagement' isn't currently enabled (226:17):

      224 |             }
      225 |             else {
    > 226 |                 await using asyncFile = await this.openFile(path, parseFlag('r'), rootCred);
          |                 ^
      227 |                 using syncFile = this._sync.createFileSync(path, parseFlag('w'), stats.mode, stats.cred());
      228 |                 const buffer = new Uint8Array(stats.size);
      229 |                 await asyncFile.read(buffer);

    If you already added the plugin for this syntax to your config, it's possible that your config isn't being loaded.
    You can re-run Babel with the BABEL_SHOW_CONFIG_FOR environment variable to show the loaded configuration:
        npx cross-env BABEL_SHOW_CONFIG_FOR=/home/jp/src/@zenfs/core/src/filesystem.ts <your build command>
    See https://babeljs.io/docs/configuration#print-effective-configs for more info.

      at constructor (node_modules/@babel/parser/src/parse-error.ts:74:19)
      at Parser.toParseError [as raise] (node_modules/@babel/parser/src/tokenizer/index.ts:1497:19)
      at Parser.raise [as expectPlugin] (node_modules/@babel/parser/src/tokenizer/index.ts:1551:16)
      at Parser.expectPlugin [as startsAwaitUsing] (node_modules/@babel/parser/src/parser/statement.ts:349:14)
      at Parser.startsAwaitUsing [as parseStatementContent] (node_modules/@babel/parser/src/parser/statement.ts:492:45)
      at Parser.parseStatementContent [as parseStatementLike] (node_modules/@babel/parser/src/parser/statement.ts:421:17)
      at Parser.parseStatementLike [as parseStatementListItem] (node_modules/@babel/parser/src/parser/statement.ts:370:17)
      at Parser.parseStatementListItem [as parseBlockOrModuleBlockBody] (node_modules/@babel/parser/src/parser/statement.ts:1389:16)
      at Parser.parseBlockOrModuleBlockBody [as parseBlockBody] (node_modules/@babel/parser/src/parser/statement.ts:1362:10)
      at Parser.parseBlockBody [as parseBlock] (node_modules/@babel/parser/src/parser/statement.ts:1330:10)
      at Parser.parseBlock [as parseStatementContent] (node_modules/@babel/parser/src/parser/statement.ts:560:21)
      at Parser.parseStatementContent [as parseStatementLike] (node_modules/@babel/parser/src/parser/statement.ts:421:17)
      at Parser.parseStatementLike [as parseStatementOrSloppyAnnexBFunctionDeclaration] (node_modules/@babel/parser/src/parser/statement.ts:390:17)
      at Parser.parseStatementOrSloppyAnnexBFunctionDeclaration [as parseIfStatement] (node_modules/@babel/parser/src/parser/statement.ts:1042:14)
      at Parser.parseIfStatement [as parseStatementContent] (node_modules/@babel/parser/src/parser/statement.ts:480:21)
      at Parser.parseStatementContent [as parseStatementLike] (node_modules/@babel/parser/src/parser/statement.ts:421:17)
      at Parser.parseStatementLike [as parseStatementListItem] (node_modules/@babel/parser/src/parser/statement.ts:370:17)
      at Parser.parseStatementListItem [as parseBlockOrModuleBlockBody] (node_modules/@babel/parser/src/parser/statement.ts:1389:16)
      at Parser.parseBlockOrModuleBlockBody [as parseBlockBody] (node_modules/@babel/parser/src/parser/statement.ts:1362:10)
      at Parser.parseBlockBody [as parseBlock] (node_modules/@babel/parser/src/parser/statement.ts:1330:10)
      at Parser.parseBlock [as parseFunctionBody] (node_modules/@babel/parser/src/parser/expression.ts:2593:24)
      at Parser.parseFunctionBody [as parseFunctionBodyAndFinish] (node_modules/@babel/parser/src/parser/expression.ts:2562:10)
      at Parser.parseFunctionBodyAndFinish [as parseMethod] (node_modules/@babel/parser/src/parser/expression.ts:2467:31)
      at Parser.parseMethod [as pushClassMethod] (node_modules/@babel/parser/src/parser/statement.ts:2178:12)
      at Parser.pushClassMethod [as parseClassMemberWithIsStatic] (node_modules/@babel/parser/src/parser/statement.ts:1999:14)
      at Parser.parseClassMemberWithIsStatic [as parseClassMember] (node_modules/@babel/parser/src/parser/statement.ts:1873:10)
      at parseClassMember (node_modules/@babel/parser/src/parser/statement.ts:1786:14)
      at Parser.callback [as withSmartMixTopicForbiddingContext] (node_modules/@babel/parser/src/parser/expression.ts:3106:14)
      at Parser.withSmartMixTopicForbiddingContext [as parseClassBody] (node_modules/@babel/parser/src/parser/statement.ts:1758:10)
      at Parser.parseClassBody [as parseClass] (node_modules/@babel/parser/src/parser/statement.ts:1709:22)
      at Parser.parseClass [as parseStatementContent] (node_modules/@babel/parser/src/parser/statement.ts:471:21)
      at Parser.parseStatementContent [as parseStatementLike] (node_modules/@babel/parser/src/parser/statement.ts:421:17)
      at Parser.parseStatementLike [as parseStatementListItem] (node_modules/@babel/parser/src/parser/statement.ts:370:17)
      at Parser.parseStatementListItem [as parseBlockOrModuleBlockBody] (node_modules/@babel/parser/src/parser/statement.ts:1389:16)
      at Parser.parseBlockOrModuleBlockBody [as parseBlockBody] (node_modules/@babel/parser/src/parser/statement.ts:1362:10)
      at Parser.parseBlockBody [as parseBlock] (node_modules/@babel/parser/src/parser/statement.ts:1330:10)
      at Parser.parseBlock [as parseFunctionBody] (node_modules/@babel/parser/src/parser/expression.ts:2593:24)
      at Parser.parseFunctionBody [as parseFunctionBodyAndFinish] (node_modules/@babel/parser/src/parser/expression.ts:2562:10)
      at parseFunctionBodyAndFinish (node_modules/@babel/parser/src/parser/statement.ts:1630:12)
      at Parser.callback [as withSmartMixTopicForbiddingContext] (node_modules/@babel/parser/src/parser/expression.ts:3106:14)
      at Parser.withSmartMixTopicForbiddingContext [as parseFunction] (node_modules/@babel/parser/src/parser/statement.ts:1628:10)
      at Parser.parseFunction [as parseFunctionStatement] (node_modules/@babel/parser/src/parser/statement.ts:1026:17)
      at Parser.parseFunctionStatement [as parseStatementContent] (node_modules/@babel/parser/src/parser/statement.ts:464:21)
      at Parser.parseStatementContent [as parseStatementLike] (node_modules/@babel/parser/src/parser/statement.ts:421:17)
      at Parser.parseStatementLike [as parseStatementListItem] (node_modules/@babel/parser/src/parser/statement.ts:370:17)
      at Parser.parseStatementListItem (node_modules/@babel/parser/src/parser/statement.ts:2558:17)
      at Parser.parseExportDeclaration [as maybeParseExportDeclaration] (node_modules/@babel/parser/src/parser/statement.ts:2480:31)
      at Parser.maybeParseExportDeclaration [as parseExport] (node_modules/@babel/parser/src/parser/statement.ts:2364:29)
      at Parser.parseExport [as parseStatementContent] (node_modules/@babel/parser/src/parser/statement.ts:591:25)
      at Parser.parseStatementContent [as parseStatementLike] (node_modules/@babel/parser/src/parser/statement.ts:421:17)
      at Parser.parseStatementLike [as parseModuleItem] (node_modules/@babel/parser/src/parser/statement.ts:358:17)
      at Parser.parseModuleItem [as parseBlockOrModuleBlockBody] (node_modules/@babel/parser/src/parser/statement.ts:1388:16)
      at Parser.parseBlockOrModuleBlockBody [as parseBlockBody] (node_modules/@babel/parser/src/parser/statement.ts:1362:10)
      at Parser.parseBlockBody [as parseProgram] (node_modules/@babel/parser/src/parser/statement.ts:217:10)
      at Parser.parseProgram [as parseTopLevel] (node_modules/@babel/parser/src/parser/statement.ts:199:25)
      at Parser.parseTopLevel [as parse] (node_modules/@babel/parser/src/parser/index.ts:45:10)
      at parse (node_modules/@babel/parser/src/index.ts:67:38)
      at parser (node_modules/@babel/core/src/parser/index.ts:28:19)
          at parser.next (<anonymous>)
      at normalizeFile (node_modules/@babel/core/src/transformation/normalize-file.ts:50:24)
          at normalizeFile.next (<anonymous>)
      at run (node_modules/@babel/core/src/transformation/index.ts:39:36)
          at run.next (<anonymous>)
      at transform (node_modules/@babel/core/src/transform.ts:29:20)
          at transform.next (<anonymous>)
      at evaluateSync (node_modules/gensync/index.js:251:28)
      at sync (node_modules/gensync/index.js:89:14)
      at fn (node_modules/@babel/core/src/errors/rewrite-stack-trace.ts:99:14)
      at transformSync (node_modules/@babel/core/src/transform.ts:66:52)
      at ScriptTransformer._instrumentFile (node_modules/@jest/transform/build/ScriptTransformer.js:389:46)
      at ScriptTransformer._buildTransformResult (node_modules/@jest/transform/build/ScriptTransformer.js:491:33)
      at ScriptTransformer.transformSourceAsync (node_modules/@jest/transform/build/ScriptTransformer.js:608:17)
      at ScriptTransformer._transformAndBuildScriptAsync (node_modules/@jest/transform/build/ScriptTransformer.js:639:35)
      at ScriptTransformer.transformAsync (node_modules/@jest/transform/build/ScriptTransformer.js:703:14)

Could you please help me fix the problem? Thanks!

@james-pre
Copy link
Author

james-pre commented Jun 28, 2024

Also, the previous issue is still occurring. The second error occurs when collectCoverage is true.

@james-pre
Copy link
Author

I was able to get it working by changing the target in tests/tsconfig.json to ES2020/ES2021/ES2022 instead of ESNext, and by adding a polyfill for Symbol.dispose/Symbol.asyncDispose. Hopefully this issue can help anyone else who finds it. Thanks!

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