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

Added Test option to package add #9

Merged
merged 5 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ Turn on debug logging
openupm --verbose ...
```

Add [testables](https://docs.unity3d.com/Manual/cus-tests.html) when importing

```
openupm --test ...
```

favoyang marked this conversation as resolved.
Show resolved Hide resolved
## Work with Unity official (upstream) registry

Most commands can fallback to Unity upstream registry if necessary, to make it easier to mix the official registry with a 3rd-party registry. i.e.
Expand Down
3 changes: 2 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ program
.option("-c, --chdir <path>", "change the working directory")
.option("-r, --registry <url>", "specify registry url")
.option("-v, --verbose", "output extra debugging")
.option("--no-upstream", "don't use upstream unity registry");
.option("--no-upstream", "don't use upstream unity registry")
.option("-t", "--test", "add package as testable");
favoyang marked this conversation as resolved.
Show resolved Hide resolved

program
.command("add <pkg> [otherPkgs...]")
Expand Down
8 changes: 8 additions & 0 deletions lib/cmd-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ const _add = async function(pkg) {
});
entry.scopes = Array.from(scopesSet).sort();
}
if (env.testables) {
if (!manifest.testables) {
manifest.testables = [];
}
if (manifest.testables.indexOf(name) === -1) {
manifest.testables.push(name);
}
}
// save manifest
if (dirty) {
if (!saveManifest(manifest)) return { code: 1, dirty };
Expand Down
4 changes: 4 additions & 0 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const parseEnv = function(options, { checkPath }) {
env.manifestPath = "";
env.upstream = true;
env.upstreamRegistry = "https://packages.unity.com";
env.testables = false;
favoyang marked this conversation as resolved.
Show resolved Hide resolved
// log level
const logLevel = options.parent.verbose ? "debug" : "info";
log.setLevel(logLevel);
Expand Down Expand Up @@ -63,6 +64,9 @@ const parseEnv = function(options, { checkPath }) {
log.error(`can not locate manifest.json at path ${manifestPath}`);
return false;
} else env.manifestPath = manifestPath;
if (options.parent.test) {
env.testables = true;
}
// return
return true;
};
Expand Down
35 changes: 35 additions & 0 deletions test/test-cmd-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ describe("cmd-add.js", function() {
chdir: getWorkDir("test-openupm-cli")
}
};
const testableOptions = {
parent: {
registry: "http://example.com",
upstream: false,
chdir: getWorkDir("test-openupm-cli"),
test: true
}
};
describe("add", function() {
let stdout;
let stderr;
Expand Down Expand Up @@ -151,6 +159,19 @@ describe("cmd-add.js", function() {
"com.upstream.package-up": "1.0.0"
}
};
const expectedManifestTestable = {
dependencies: {
"com.base.package-a": "1.0.0"
},
scopedRegistries: [
{
name: "example.com",
scopes: ["com.base.package-a", "com.example"],
url: "http://example.com"
}
],
testables: ["com.base.package-a"]
};
beforeEach(function() {
removeWorkDir("test-openupm-cli");
createWorkDir("test-openupm-cli", { manifest: true });
Expand Down Expand Up @@ -400,5 +421,19 @@ describe("cmd-add.js", function() {
.includes("manifest updated")
.should.be.ok();
});
it("add pkg with tests", async function() {
const retCode = await add("com.base.package-a", testableOptions);
retCode.should.equal(0);
const manifest = await loadManifest();
manifest.should.be.deepEqual(expectedManifestTestable);
stdout
.captured()
.includes("added: ")
.should.be.ok();
stdout
.captured()
.includes("manifest updated")
.should.be.ok();
});
});
});