Feature: Compatibility with 'app-root-path'
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
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, node.js
- Lĩnh vực
- testing-qa
Hướng nghiên cứu
Start by tracing testdouble's td.replace operation and its module-loading entry points, then compare that behavior with app-root-path's require function and absolute-path resolution. Done means app-root-path-style root resolution works with td.replace while preserving the mocked and passthrough behavior shown in the examples.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
When it comes to large codebases, it can be massively beneficial to grab libraries from the root resolution rather than relative path resolution ../../
There is an excellent library to assist with this for NodeJs but its not compatible with testdouble's .replace operation
https://www.npmjs.com/package/app-root-path
Would be great to see this compatibility so assist with a consistent resolution approach through projects.
As an example:
users.js
// NPM Requires
const express = require('express')
// Library Requires
const users = require('./users')
// const users = reqlib('routes/example/users')
// Module Variables
module.exports = function (app) {
var route = express.Router()
// Mount route as "/users"
app.use('/users', route)
// Add a route that allows us to get a user by their username
route.get('/:username', function (req, res) {
var user = users.getByUsername(req.params.username)
console.log(user)
if (!user) {
res.status(404).json({
status: 'not ok',
data: null
})
} else {
res.json({
status: 'ok',
data: user
})
}
})
}
users.spec.js
// NPM Requires
const supertest = require('supertest')
const express = require('express')
const td = require('testdouble')
// Library Requires
const chai = reqlib('helpers/chai-setup')
// Module Variables
describe('GET /ping', function() {
const interaction = ['Mocked', 'Passthrough']
const isMockedLoop = [true, false]
isMockedLoop.forEach(function(isMocked) {
let app, request, route, users, usersTD
beforeEach(function() {
// Create an express application object
app = express()
// Get our router module, with a stubbed out users dependency
// we stub this out so we can control the results returned by
// the users module to ensure we execute all paths in our code
if (isMocked) {
users = td.replace('./users')
usersTD = users.getByUsername
// Setup generic returns for each td function
td.when(usersTD(td.matchers.anything())).thenReturn(null)
}
route = require('./user-route')
// route = reqlib('routes/example/user-route')
// Bind our application to
route(app)
// Get a supertest instance so we can make requests
request = supertest(app)
})
it(interaction[isMockedLoop.indexOf(isMocked)] + ': should respond with a 404 and a null', function() {
if (isMocked) {
// td.when(usersTD('nodejs')).thenReturn({
// username: 'test'
// })
} else {
// Skip test until the mocked function has been coded
this.skip()
}
return request
.get('/users/nodejs')
.expect(404)
.then((res) => {
td.verify(users.getByUsername(td.matchers.anything()))
})
})
it(interaction[isMockedLoop.indexOf(isMocked)] + ': should respond with 200 and a user object', function() {
console.log(isMocked)
if (isMocked) {
td.when(usersTD('nodejs')).thenReturn({
username: 'test'
})
} else {
// Skip test until the mocked function has been coded
this.skip()
}
return request
.get('/users/nodejs')
.expect(200)
.then((res) => {
td.verify(users.getByUsername(td.matchers.anything()))
})
})
afterEach(function() {
if (isMocked) {
td.reset()
}
})
})
})
app-root-path is enabled by including a global in the root of the call chain
global.reqlib = require('app-root-path').require
when trying to use reqlib to load require td isn't called, even is absolute paths are used
- Ngôn ngữ chính
- JavaScript
- Star
- 1.4k
- Fork
- 140
- Merge trung bình
- 5 giờ 55 phút
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: 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ự
-
新讀者走讀回報,照著一篇文章實際操作Đang mởdocumentation good first issue help wanted
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 92/100
Maintainer thường phản hồi trong vòng 1 ngày
-
automated issue report
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
lirantal/discoprint#29 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
RSS feed autodiscoveryĐang mởfeature-request
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
louislam/uptime-kuma#7914 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Code Cleanup dependencies
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
ProjectSidewalk/SidewalkWebpage#5609 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
help wanted javascript
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
OWASP/cornucopia#3538 ·
Maintainer thường phản hồi trong vòng 1 ngày