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 all 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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ The package itself and all dependencies that exist in the registry will be serve

> Notice: openupm will not verify package or resolve dependencies for git, https and file protocol.

You can also add [testables](https://docs.unity3d.com/Manual/cus-tests.html) when importing:
```
openupm --test <pkg>
```

### Remove packages
```
openupm remove <pkg> [otherPkgs...]
Expand Down
1 change: 1 addition & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ program
program
.command("add <pkg> [otherPkgs...]")
.aliases(["install", "i"])
.option("-t, --test", "add package as testable")
.description(
`add package to manifest json
openupm add <pkg> [otherPkgs...]
Expand Down
12 changes: 10 additions & 2 deletions lib/cmd-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const add = async function(pkgs, options) {
if (!parseEnv(options, { checkPath: true })) return 1;
// add
const results = [];
for (const pkg of pkgs) results.push(await _add(pkg));
for (const pkg of pkgs) results.push(await _add({ pkg, testables: options.test }));
const result = {
code: results.filter(x => x.code != 0).length > 0 ? 1 : 0,
dirty: results.filter(x => x.dirty).length > 0
Expand All @@ -29,7 +29,7 @@ const add = async function(pkgs, options) {
return result.code;
};

const _add = async function(pkg) {
const _add = async function({ pkg, testables }) {
// dirty flag
let dirty = false;
// upstream flag
Expand Down Expand Up @@ -129,6 +129,14 @@ const _add = async function(pkg) {
});
entry.scopes = Array.from(scopesSet).sort();
}
if (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
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();
});
});
});