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

test: setup a fake registry #38

Merged
merged 2 commits into from
Mar 8, 2020
Merged

Conversation

fisker
Copy link
Contributor

@fisker fisker commented Dec 18, 2019

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

@@ -3,20 +3,80 @@
const assert = require("assert");
const process = require("process");
const execa = require("execa");
const createTestServer = require("create-test-server");
Copy link
Owner

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.

Copy link
Contributor Author

@fisker fisker Dec 19, 2019

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?

Copy link
Owner

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();
Copy link
Owner

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#39

@silverwind
Copy link
Owner

silverwind commented Dec 18, 2019

Thanks for helping out. I would suggest a file structure like

  • tests/registry.npmjs.org/prismjs.json
  • tests/registry.npmjs.org/styled-components.json

Then, load those files via require("./tests/registry.npmjs.org/prismjs.json") and add them to nock under the respective URLs (use "%2f" in the filename for scoped packages). Might also use fast-glob to enumerate all test/*/*.json files and load them via fs.

This has the benefit that we can test against other registries like GitHub's too later.

@fisker
Copy link
Contributor Author

fisker commented Dec 19, 2019

those json files supposed to be a temp solution, I was thinking to mock response by js object.

@silverwind silverwind merged commit 5d39d8b into silverwind:master Mar 8, 2020
@silverwind
Copy link
Owner

Thanks and sorry for the delay. I will use this PR as a base for the upcoming refactor to jest.

@fisker fisker deleted the fake-registry branch March 8, 2020 09:52
silverwind added a commit that referenced this pull request Mar 8, 2020
* 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)
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

Successfully merging this pull request may close these issues.

Add a registry mock for the tests
2 participants