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

cannot run es6 modules based tests #266

Open
2 tasks
BePo65 opened this issue May 5, 2021 · 3 comments
Open
2 tasks

cannot run es6 modules based tests #266

BePo65 opened this issue May 5, 2021 · 3 comments

Comments

@BePo65
Copy link

BePo65 commented May 5, 2021

Description

As my project is based on ES6 modules, my tests start with import path from 'path'; instead of const path = require('path');
and
my package.json contains a property "type": "module".

When I start vscode with activated extension 'mocha-sidebar' I get the following errors showing that the extension can only handle commonjs modules:

trying to searching for tests using these settings: 

    mocha path: d:\Projekte\github\license-downloader\node_modules\mocha\index.js
    test files location: test/**/*.spec.js
    files to ignore: **/.git/**/*,**/node_modules/**/*
    environmets: {}
    requires: []
    options:  {}


if you find anything wrong please change those default settings
____________________________________________________________________________
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: d:\Projekte\github\license-downloader\test\license-report-file.spec.js
require() of ES modules is not supported.
require() of d:\Projekte\github\license-downloader\test\license-report-file.spec.js from d:\Projekte\github\license-downloader\node_modules\mocha\lib\mocha.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.

Instead rename license-report-file.spec.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from d:\Projekte\github\license-downloader\package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1080:13)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    
    at d:\Projekte\github\license-downloader\node_modules\mocha\lib\mocha.js:436:36
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (d:\Projekte\github\license-downloader\node_modules\mocha\lib\mocha.js:433:14)

    at c:\Users\Entwicklung\.vscode\extensions\maty.vscode-mocha-sidebar-0.22.2\lib\worker\findtests.js:86:15
    at f (c:\Users\Entwicklung\.vscode\extensions\maty.vscode-mocha-sidebar-0.22.2\node_modules\once\once.js:25:25)
    at Glob.<anonymous> (c:\Users\Entwicklung\.vscode\extensions\maty.vscode-mocha-sidebar-0.22.2\node_modules\glob\glob.js:151:7)
    at Glob.emit (events.js:315:20)
    at Glob._finish (c:\Users\Entwicklung\.vscode\extensions\maty.vscode-mocha-sidebar-0.22.2\node_modules\glob\glob.js:197:8)
    at done (c:\Users\Entwicklung\.vscode\extensions\maty.vscode-mocha-sidebar-0.22.2\node_modules\glob\glob.js:182:14)
    at Glob._processGlobStar2 (c:\Users\Entwicklung\.vscode\extensions\maty.vscode-mocha-sidebar-0.22.2\node_modules\glob\glob.js:637:12)
    at c:\Users\Entwicklung\.vscode\extensions\maty.vscode-mocha-sidebar-0.22.2\node_modules\glob\glob.js:626:10
cant get tests [object Object] 

Steps to Reproduce

see text above

Expected Results

no errors when using es6 module based tests

Actual Results

see above

Settings file

no special settings

Versions

  • VScode: v1.55.2
  • Mocha SideBar: v0.22.2
  • Node Version: v14.16.1

OS version

  • Linux
  • Mac
  • [ X] Windows

Example for reproducing

I can deliver one if needed

Result of my problem analysis

The problem comes from the fact that this extension uses mocha v5.2.0.
If using e.g. mocha v8.3.2, it could call mocha.loadFilesAsync()in findtests.js line 86 instead of the old mocha.loadFiles() , as the new 'async' version can handle commonjs and es6 modules

@spigelli
Copy link

Did you find a workaround?

@BePo65
Copy link
Author

BePo65 commented Nov 18, 2021

Unluckily no. For me it looks like this great project is dead - no commits since 2019.

@jonkoops
Copy link

I can confirm this is an issue as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants