-
Notifications
You must be signed in to change notification settings - Fork 8
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
test: setup a fake registry #38
Conversation
@@ -3,20 +3,80 @@ | |||
const assert = require("assert"); | |||
const process = require("process"); | |||
const execa = require("execa"); | |||
const createTestServer = require("create-test-server"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use nock instead? It should work transparently and we don't have to redefine registry
that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to use nock
, but failed, I think it's because we are using execa
, nock only override http.request
of main thread.
Any other suggestion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nock
only works in-process (some discussion about this in nock/nock#1911). I will set up a local HTTP server for the registry mocking instead which can be passed via --registry
during the tests.
|
||
function exit(err) { | ||
const testDir = tempy.directory(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think a temp dir is needed, just require
the JSON files directly and respond with them via nock
for the npm URLs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea behind this:
I was thinking, we can do test like this
test({
packageJson: {
dependencies: {
foo: '1.0.0'
}
},
response: {
'/foo': {
dist-tags: {
latest: "2.0.0"
},
}
},
expect: {
dependencies: {
foo: {
...
}
}
}
})
so we can kill test.json
, we need a place to write package.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to send another PR to do this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for helping out. I would suggest a file structure like
Then, load those files via This has the benefit that we can test against other registries like GitHub's too later. |
those json files supposed to be a temp solution, I was thinking to mock response by js object. |
Thanks and sorry for the delay. I will use this PR as a base for the upcoming refactor to |
* update devDependencies (silverwind) * readme tweaks (silverwind) * remove travis badge (silverwind) * update json example, add TODO (silverwind) * readme tweak (silverwind) * add release age, fixes #40 (silverwind) * move jest to devDependencies (silverwind) * remove find-up dependency (silverwind) * tweaks (silverwind) * add node 13 (silverwind) * refactors (silverwind) * move requires to top (silverwind) * move test.json to file again (silverwind) * increase jest testTimeout (silverwind) * update dependencies (silverwind) * inline package.json in tests (silverwind) * update .gitignore (silverwind) * remove yarn.lock (silverwind) * remove travis (silverwind) * try actions (silverwind) * add yarn.lock to make travis install yarn (silverwind) * check if travis windows does include 'make' (silverwind) * use self to update (silverwind) * require node 10, rewrite tests to jest (silverwind) * Merge pull request #38 from fisker/fake-registry (silverwind) * chore: pin dependencies (fisker) * test: setup a fake registry (fisker) * use semver.validRange (silverwind)
currently, I saved the registry response in
info
, maybe we can simplify those json files.also we can improve test by split those deps in
test.json
.fixes #37