admin管理员组文章数量:1026989
I'm a C++ developer. I barely do any web related stuff. So please bear with me.
I'm using adonisjs. Everything is fine. I have a javascript file which works just fine. It does some numerical calculations.
I want to add unit tests to it. I've read a lot of questions like this: How to use ES6 modules in CommonJS? but have not been able to figure out what I need to do to use the file in my unit tests.
My last attempt was to use dynamic import, but I still get an error. This is the minimal code I have that reproduces the issue:
import { test } from '@japa/runner'
Test('seisUtils lib test', async ({ assert }) => {
import ('../../resources/js/libs/seisUtils.mjs').then(seisUtils => {
let signal1 = utils.ricker(100, 10, 0);
assert.isTrue(true);
});
})
result:
require() of ES Module
<directory>/resources/js/libs/seisUtils.mjs not supported.
Instead change the require of <directory>/resources/js/libs/seisUtils.mjs to a dynamic import() which is available in all CommonJS modules.
at anonymous tests/unit/first_breaks_lib_test.spec.ts:28
I tried using webpack, but then I messed up the configuration of adonis and gave up. Maybe that's the correct way to do it?
I'm a C++ developer. I barely do any web related stuff. So please bear with me.
I'm using adonisjs. Everything is fine. I have a javascript file which works just fine. It does some numerical calculations.
I want to add unit tests to it. I've read a lot of questions like this: How to use ES6 modules in CommonJS? but have not been able to figure out what I need to do to use the file in my unit tests.
My last attempt was to use dynamic import, but I still get an error. This is the minimal code I have that reproduces the issue:
import { test } from '@japa/runner'
Test('seisUtils lib test', async ({ assert }) => {
import ('../../resources/js/libs/seisUtils.mjs').then(seisUtils => {
let signal1 = utils.ricker(100, 10, 0);
assert.isTrue(true);
});
})
result:
require() of ES Module
<directory>/resources/js/libs/seisUtils.mjs not supported.
Instead change the require of <directory>/resources/js/libs/seisUtils.mjs to a dynamic import() which is available in all CommonJS modules.
at anonymous tests/unit/first_breaks_lib_test.spec.ts:28
I tried using webpack, but then I messed up the configuration of adonis and gave up. Maybe that's the correct way to do it?
本文标签: es6 moduleshow to use ES6 file in CommonJS using AdonisjsStack Overflow
版权声明:本文标题:es6 modules - how to use ES6 file in CommonJS using Adonisjs - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745659739a2161814.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论