|
| 1 | +/* eslint-disable no-unused-vars */ |
| 2 | +/* eslint-disable no-undef */ |
| 3 | +const assert = require("assert"); |
| 4 | +const nock = require("nock"); |
| 5 | +const should = require("should"); |
| 6 | +const { parseEnv, loadManifest } = require("../lib/core"); |
| 7 | +const view = require("../lib/cmd-view"); |
| 8 | +const { |
| 9 | + getWorkDir, |
| 10 | + createWorkDir, |
| 11 | + removeWorkDir, |
| 12 | + captureStream, |
| 13 | + nockUp, |
| 14 | + nockDown |
| 15 | +} = require("./utils"); |
| 16 | + |
| 17 | +describe("cmd-view.js", function() { |
| 18 | + const options = { |
| 19 | + parent: { |
| 20 | + registry: "http://example.com", |
| 21 | + upstream: false, |
| 22 | + chdir: getWorkDir("test-openupm-cli") |
| 23 | + } |
| 24 | + }; |
| 25 | + const upstreamOptions = { |
| 26 | + parent: { |
| 27 | + registry: "http://example.com", |
| 28 | + chdir: getWorkDir("test-openupm-cli") |
| 29 | + } |
| 30 | + }; |
| 31 | + describe("view", function() { |
| 32 | + let stdout; |
| 33 | + let stderr; |
| 34 | + const remotePkgInfoA = { |
| 35 | + name: "com.example.package-a", |
| 36 | + versions: { |
| 37 | + "1.0.0": { |
| 38 | + name: "com.example.package-a", |
| 39 | + displayName: "Package A", |
| 40 | + author: { |
| 41 | + name: "batman" |
| 42 | + }, |
| 43 | + version: "1.0.0", |
| 44 | + unity: "2018.4", |
| 45 | + description: "A demo package", |
| 46 | + keywords: [""], |
| 47 | + category: "Unity", |
| 48 | + dependencies: { |
| 49 | + "com.example.package-a": "^1.0.0" |
| 50 | + }, |
| 51 | + gitHead: "5c141ecfac59c389090a07540f44c8ac5d07a729", |
| 52 | + readmeFilename: "README.md", |
| 53 | + |
| 54 | + _nodeVersion: "12.13.1", |
| 55 | + _npmVersion: "6.12.1", |
| 56 | + dist: { |
| 57 | + integrity: |
| 58 | + "sha512-MAh44bur7HGyfbCXH9WKfaUNS67aRMfO0VAbLkr+jwseb1hJue/I1pKsC7PKksuBYh4oqoo9Jov1cBcvjVgjmA==", |
| 59 | + shasum: "516957cac4249f95cafab0290335def7d9703db7", |
| 60 | + tarball: |
| 61 | + "https://cdn.example.com/com.example.package-a/com.example.package-a-1.0.0.tgz" |
| 62 | + }, |
| 63 | + contributors: [] |
| 64 | + } |
| 65 | + }, |
| 66 | + time: { |
| 67 | + modified: "2019-11-28T18:51:58.123Z", |
| 68 | + created: "2019-11-28T18:51:58.123Z", |
| 69 | + "1.0.0": "2019-11-28T18:51:58.123Z" |
| 70 | + }, |
| 71 | + users: {}, |
| 72 | + "dist-tags": { |
| 73 | + latest: "1.0.0" |
| 74 | + }, |
| 75 | + _rev: "3-418f950115c32bd0", |
| 76 | + _id: "com.example.package-a", |
| 77 | + readme: "A demo package", |
| 78 | + _attachments: {} |
| 79 | + }; |
| 80 | + const remotePkgInfoUp = { |
| 81 | + name: "com.example.package-up", |
| 82 | + versions: { |
| 83 | + "1.0.0": { |
| 84 | + name: "com.example.package-up", |
| 85 | + displayName: "Package A", |
| 86 | + author: { |
| 87 | + name: "batman" |
| 88 | + }, |
| 89 | + version: "1.0.0", |
| 90 | + unity: "2018.4", |
| 91 | + description: "A demo package", |
| 92 | + keywords: [""], |
| 93 | + category: "Unity", |
| 94 | + dependencies: { |
| 95 | + "com.example.package-up": "^1.0.0" |
| 96 | + }, |
| 97 | + gitHead: "5c141ecfac59c389090a07540f44c8ac5d07a729", |
| 98 | + readmeFilename: "README.md", |
| 99 | + |
| 100 | + _nodeVersion: "12.13.1", |
| 101 | + _npmVersion: "6.12.1", |
| 102 | + dist: { |
| 103 | + integrity: |
| 104 | + "sha512-MAh44bur7HGyfbCXH9WKfaUNS67aRMfO0VAbLkr+jwseb1hJue/I1pKsC7PKksuBYh4oqoo9Jov1cBcvjVgjmA==", |
| 105 | + shasum: "516957cac4249f95cafab0290335def7d9703db7", |
| 106 | + tarball: |
| 107 | + "https://cdn.example.com/com.example.package-up/com.example.package-up-1.0.0.tgz" |
| 108 | + }, |
| 109 | + contributors: [] |
| 110 | + } |
| 111 | + }, |
| 112 | + time: { |
| 113 | + modified: "2019-11-28T18:51:58.123Z", |
| 114 | + created: "2019-11-28T18:51:58.123Z", |
| 115 | + "1.0.0": "2019-11-28T18:51:58.123Z" |
| 116 | + }, |
| 117 | + users: {}, |
| 118 | + "dist-tags": { |
| 119 | + latest: "1.0.0" |
| 120 | + }, |
| 121 | + _rev: "3-418f950115c32bd0", |
| 122 | + _id: "com.example.package-up", |
| 123 | + readme: "A demo package", |
| 124 | + _attachments: {} |
| 125 | + }; |
| 126 | + beforeEach(function() { |
| 127 | + removeWorkDir("test-openupm-cli"); |
| 128 | + createWorkDir("test-openupm-cli", { manifest: true }); |
| 129 | + nockUp(); |
| 130 | + nock("http://example.com") |
| 131 | + .get("/com.example.package-a") |
| 132 | + .reply(200, remotePkgInfoA, { "Content-Type": "application/json" }); |
| 133 | + nock("http://example.com") |
| 134 | + .get("/pkg-not-exist") |
| 135 | + .reply(404); |
| 136 | + nock("http://example.com") |
| 137 | + .get("/com.example.package-up") |
| 138 | + .reply(404); |
| 139 | + nock("https://api.bintray.com") |
| 140 | + .get("/npm/unity/unity/com.example.package-up") |
| 141 | + .reply(200, remotePkgInfoUp, { |
| 142 | + "Content-Type": "application/json" |
| 143 | + }); |
| 144 | + nock("https://api.bintray.com") |
| 145 | + .get("/npm/unity/unity/pkg-not-exist") |
| 146 | + .reply(404); |
| 147 | + stdout = captureStream(process.stdout); |
| 148 | + stderr = captureStream(process.stderr); |
| 149 | + }); |
| 150 | + afterEach(function() { |
| 151 | + removeWorkDir("test-openupm-cli"); |
| 152 | + nockDown(); |
| 153 | + stdout.unhook(); |
| 154 | + stderr.unhook(); |
| 155 | + }); |
| 156 | + it("view pkg", async function() { |
| 157 | + const retCode = await view("com.example.package-a", options); |
| 158 | + retCode.should.equal(0); |
| 159 | + stdout |
| 160 | + .captured() |
| 161 | + |
| 162 | + .should.be.ok(); |
| 163 | + }); |
| 164 | + it("view [email protected]", async function() { |
| 165 | + const retCode = await view("[email protected]", options); |
| 166 | + retCode.should.equal(1); |
| 167 | + stderr |
| 168 | + .captured() |
| 169 | + .includes("doesn't support name@version, using name instead") |
| 170 | + .should.be.ok(); |
| 171 | + }); |
| 172 | + it("view pkg-not-exist", async function() { |
| 173 | + const retCode = await view("pkg-not-exist", options); |
| 174 | + retCode.should.equal(1); |
| 175 | + stderr |
| 176 | + .captured() |
| 177 | + .includes("package not found") |
| 178 | + .should.be.ok(); |
| 179 | + }); |
| 180 | + it("view pkg from upstream", async function() { |
| 181 | + const retCode = await view("com.example.package-up", upstreamOptions); |
| 182 | + retCode.should.equal(0); |
| 183 | + stdout |
| 184 | + .captured() |
| 185 | + |
| 186 | + .should.be.ok(); |
| 187 | + }); |
| 188 | + it("view pkg-not-exist from upstream", async function() { |
| 189 | + const retCode = await view("pkg-not-exist", upstreamOptions); |
| 190 | + retCode.should.equal(1); |
| 191 | + stderr |
| 192 | + .captured() |
| 193 | + .includes("package not found") |
| 194 | + .should.be.ok(); |
| 195 | + }); |
| 196 | + }); |
| 197 | +}); |
0 commit comments