Stubbing a CJS module from an ESM
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 32/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, node.js
- Lĩnh vực
- devtools, testing-qa
Hướng nghiên cứu
Start by running examples/node-esm/test/lib/numbers-only-test.mjs and trace td.replace('is-number') before ../../lib/numbers-only.mjs is dynamically imported. Check the ESM/CJS module-loading path involved in that example; done means the fake is-number module is used and the test assertion passes.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
In the testdouble repo, I created examples/node-esm/test/lib/numbers-only-test.mjs with the following code.
import assert from 'assert'
import mocha from 'mocha'
import * as td from 'testdouble'
mocha.describe('numbers-only', function () {
mocha.it.only('goes boom', async function () {
const isNumber = td.replace('is-number');
const numbersOnly = await import('../../lib/numbers-only.mjs')
td.when(isNumber('a string')).thenReturn(true) // tee-hee, this is silly
const result = numbersOnly.default('a string')
assert.equal(result, true)
});
});
Based on what I read from the docs, I would expect this code to pass, but whenever ../../lib/numbers-only.mjs is loaded, the real is-number is resolved instead of the faked module.
Issue
the real module is being loaded instead of the fake.
Environment
-
node -v20.1.0 or 22.3.0: -
npm -v(oryarn --version) output: 10.5.2 or 10.8.1 -
npm ls testdouble(oryarn list testdouble) version: from the example
Failing Test
See above
Example Repo
See above
Runkit Notebook
- Create a Runkit notebook
- Invoke
var td = require('testdouble')at the top - Verify the behavior your issue is concerned with by clicking "Run"
- Link to the Runkit here
Code-fenced Examples
var td = require('testdouble')
// Your steps here.
- Ngôn ngữ chính
- JavaScript
- Star
- 1.4k
- Fork
- 140
- Merge trung bình
- 7 giờ 51 phút
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của testdouble/testdouble.js
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
testdouble/testdouble.js#538 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
testdouble/testdouble.js#537 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
testdouble/testdouble.js#536 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
testdouble/testdouble.js#534 ·
-
`npm-run-all` to `npm-run-all2`Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 45/100
testdouble/testdouble.js#533 ·
Tất cả issue của testdouble/testdouble.js
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
solana-foundation/solana-com#2202 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
yegor256/copyrights-action#216 ·
-
[BUG] onScroll never refreshes the window container's height after a vertical-only viewport resizeĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
juliangarnier/anime#1192 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
PedestrianDynamics/pyFDS-Evac#226 ·
Maintainer thường phản hồi trong vòng 1 ngày