diff --git a/test/test-cmd-add.ts b/test/test-cmd-add.ts index 632517ae..425e8fee 100644 --- a/test/test-cmd-add.ts +++ b/test/test-cmd-add.ts @@ -15,6 +15,7 @@ import { removeWorkDir, } from "./utils"; import testConsole from "test-console"; +import assert from "assert"; describe("cmd-add.ts", function () { const options = { @@ -291,6 +292,7 @@ describe("cmd-add.ts", function () { const retCode = await add("com.base.package-a", options); retCode.should.equal(0); const manifest = loadManifest(); + assert(manifest !== null); manifest.should.be.deepEqual(expectedManifestA); const [stdout] = getOutputs(stdoutInspect, stderrInspect); stdout.includes("added").should.be.ok(); @@ -300,6 +302,7 @@ describe("cmd-add.ts", function () { const retCode = await add("com.base.package-a@1.0.0", options); retCode.should.equal(0); const manifest = loadManifest(); + assert(manifest !== null); manifest.should.be.deepEqual(expectedManifestA); const [stdout] = getOutputs(stdoutInspect, stderrInspect); stdout.includes("added").should.be.ok(); @@ -309,6 +312,7 @@ describe("cmd-add.ts", function () { const retCode = await add("com.base.package-a@latest", options); retCode.should.equal(0); const manifest = loadManifest(); + assert(manifest !== null); manifest.should.be.deepEqual(expectedManifestA); const [stdout] = getOutputs(stdoutInspect, stderrInspect); stdout.includes("added").should.be.ok(); @@ -320,6 +324,7 @@ describe("cmd-add.ts", function () { const retCode2 = await add("com.base.package-a@1.0.0", options); retCode2.should.equal(0); const manifest = loadManifest(); + assert(manifest !== null); manifest.should.be.deepEqual(expectedManifestA); const [stdout] = getOutputs(stdoutInspect, stderrInspect); stdout.includes("modified ").should.be.ok(); @@ -331,6 +336,7 @@ describe("cmd-add.ts", function () { const retCode2 = await add("com.base.package-a@1.0.0", options); retCode2.should.equal(0); const manifest = loadManifest(); + assert(manifest !== null); manifest.should.be.deepEqual(expectedManifestA); const [stdout] = getOutputs(stdoutInspect, stderrInspect); stdout.includes("existed ").should.be.ok(); @@ -340,6 +346,7 @@ describe("cmd-add.ts", function () { const retCode = await add("com.base.package-a@2.0.0", options); retCode.should.equal(1); const manifest = loadManifest(); + assert(manifest !== null); manifest.should.be.deepEqual(defaultManifest); const [stdout] = getOutputs(stdoutInspect, stderrInspect); stdout.includes("version 2.0.0 is not a valid choice").should.be.ok(); @@ -350,6 +357,7 @@ describe("cmd-add.ts", function () { const retCode = await add("com.base.package-a@" + gitUrl, options); retCode.should.equal(0); const manifest = loadManifest(); + assert(manifest !== null); manifest.dependencies["com.base.package-a"].should.be.equal(gitUrl); const [stdout] = getOutputs(stdoutInspect, stderrInspect); stdout.includes("added").should.be.ok(); @@ -360,6 +368,7 @@ describe("cmd-add.ts", function () { const retCode = await add("com.base.package-a@" + gitUrl, options); retCode.should.equal(0); const manifest = loadManifest(); + assert(manifest !== null); manifest.dependencies["com.base.package-a"].should.be.equal(gitUrl); const [stdout] = getOutputs(stdoutInspect, stderrInspect); stdout.includes("added").should.be.ok(); @@ -370,6 +379,7 @@ describe("cmd-add.ts", function () { const retCode = await add("com.base.package-a@" + fileUrl, options); retCode.should.equal(0); const manifest = loadManifest(); + assert(manifest !== null); manifest.dependencies["com.base.package-a"].should.be.equal(fileUrl); const [stdout] = getOutputs(stdoutInspect, stderrInspect); stdout.includes("added").should.be.ok(); @@ -379,6 +389,7 @@ describe("cmd-add.ts", function () { const retCode = await add("pkg-not-exist", options); retCode.should.equal(1); const manifest = loadManifest(); + assert(manifest !== null); manifest.should.deepEqual(defaultManifest); const [stdout] = getOutputs(stdoutInspect, stderrInspect); stdout.includes("package not found").should.be.ok(); @@ -390,6 +401,7 @@ describe("cmd-add.ts", function () { ); retCode.should.equal(0); const manifest = loadManifest(); + assert(manifest !== null); manifest.should.be.deepEqual(expectedManifestAB); const [stdout] = getOutputs(stdoutInspect, stderrInspect); stdout.includes("added com.base.package-a").should.be.ok(); @@ -400,6 +412,7 @@ describe("cmd-add.ts", function () { const retCode = await add("com.upstream.package-up", upstreamOptions); retCode.should.equal(0); const manifest = loadManifest(); + assert(manifest !== null); manifest.should.be.deepEqual(expectedManifestUpstream); const [stdout] = getOutputs(stdoutInspect, stderrInspect); stdout.includes("added com.upstream.package-up").should.be.ok(); @@ -409,6 +422,7 @@ describe("cmd-add.ts", function () { const retCode = await add("pkg-not-exist", upstreamOptions); retCode.should.equal(1); const manifest = loadManifest(); + assert(manifest !== null); manifest.should.deepEqual(defaultManifest); const [stdout] = getOutputs(stdoutInspect, stderrInspect); stdout.includes("package not found").should.be.ok(); @@ -417,6 +431,7 @@ describe("cmd-add.ts", function () { const retCode = await add("com.base.package-c@latest", upstreamOptions); retCode.should.equal(0); const manifest = loadManifest(); + assert(manifest !== null); manifest.should.be.deepEqual(expectedManifestC); const [stdout] = getOutputs(stdoutInspect, stderrInspect); stdout.includes("added").should.be.ok(); @@ -426,6 +441,7 @@ describe("cmd-add.ts", function () { const retCode = await add("com.base.package-a", testableOptions); retCode.should.equal(0); const manifest = loadManifest(); + assert(manifest !== null); manifest.should.be.deepEqual(expectedManifestTestable); const [stdout] = getOutputs(stdoutInspect, stderrInspect); stdout.includes("added").should.be.ok(); diff --git a/test/test-cmd-remove.ts b/test/test-cmd-remove.ts index e4d7248e..5a8e8ab8 100644 --- a/test/test-cmd-remove.ts +++ b/test/test-cmd-remove.ts @@ -57,9 +57,12 @@ describe("cmd-remove.ts", function () { const retCode = await remove("com.example.package-a", options); retCode.should.equal(0); const manifest = loadManifest(); + assert(manifest !== null); ( manifest.dependencies["com.example.package-a"] == undefined ).should.be.ok(); + assert(manifest.scopedRegistries !== undefined); + assert(manifest.scopedRegistries[0] !== undefined); manifest.scopedRegistries[0].scopes.should.be.deepEqual([ "com.example", "com.example.package-b", @@ -78,6 +81,7 @@ describe("cmd-remove.ts", function () { const retCode = await remove("com.example.package-a@1.0.0", options); retCode.should.equal(1); const manifest = loadManifest(); + assert(manifest !== null); manifest.should.be.deepEqual(defaultManifest); const [stdout] = getOutputs(stdoutInspect, stderrInspect); stdout.includes("please replace").should.be.ok(); @@ -110,12 +114,15 @@ describe("cmd-remove.ts", function () { ); retCode.should.equal(0); const manifest = await loadManifest(); + assert(manifest !== null); ( manifest.dependencies["com.example.package-a"] == undefined ).should.be.ok(); ( manifest.dependencies["com.example.package-b"] == undefined ).should.be.ok(); + assert(manifest.scopedRegistries !== undefined); + assert(manifest.scopedRegistries[0] !== undefined); manifest.scopedRegistries[0].scopes.should.be.deepEqual(["com.example"]); const [stdout] = getOutputs(stdoutInspect, stderrInspect); stdout.includes("removed com.example.package-a").should.be.ok(); diff --git a/test/test-core.ts b/test/test-core.ts index 02be0bd2..e85d26ee 100644 --- a/test/test-core.ts +++ b/test/test-core.ts @@ -25,6 +25,7 @@ import { removeWorkDir, } from "./utils"; import testConsole from "test-console"; +import assert from "assert"; describe("cmd-core.ts", function () { describe("parseEnv", function () { @@ -178,6 +179,7 @@ describe("cmd-core.ts", function () { { checkPath: true } ) ).should.be.ok(); + assert(env.editorVersion !== null); env.editorVersion.should.be.equal("2019.2.13f1"); }); it("region cn", async function () { @@ -233,6 +235,7 @@ describe("cmd-core.ts", function () { ) ).should.be.ok(); const manifest = loadManifest(); + assert(manifest !== null); manifest.should.be.deepEqual({ dependencies: {} }); }); it("no manifest file", async function () { @@ -267,10 +270,12 @@ describe("cmd-core.ts", function () { ) ).should.be.ok(); const manifest = loadManifest(); + assert(manifest !== null); manifest.should.be.deepEqual({ dependencies: {} }); manifest.dependencies["some-pack"] = "1.0.0"; saveManifest(manifest).should.be.ok(); const manifest2 = loadManifest(); + assert(manifest2 !== null); manifest2.should.be.deepEqual(manifest); }); }); @@ -294,6 +299,7 @@ describe("cmd-core.ts", function () { .get("/package-a") .reply(200, pkgInfoRemote, { "Content-Type": "application/json" }); const info = await fetchPackageInfo("package-a"); + assert(info !== undefined); info.should.deepEqual(pkgInfoRemote); }); it("404", async function () { @@ -312,9 +318,9 @@ describe("cmd-core.ts", function () { describe("getLatestVersion", function () { it("from dist-tags", async function () { - getLatestVersion({ "dist-tags": { latest: "1.0.0" } }).should.equal( - "1.0.0" - ); + const version = getLatestVersion({ "dist-tags": { latest: "1.0.0" } }); + assert(version !== undefined); + version.should.equal("1.0.0"); }); it("not found", async function () { ( @@ -328,17 +334,23 @@ describe("cmd-core.ts", function () { (parseEditorVersion(null) === null).should.be.ok(); }); it("test x.y", function () { - parseEditorVersion("2019.2").should.deepEqual({ major: 2019, minor: 2 }); + const version = parseEditorVersion("2019.2"); + assert(version !== null); + version.should.deepEqual({ major: 2019, minor: 2 }); }); it("test x.y.z", function () { - parseEditorVersion("2019.2.1").should.deepEqual({ + const version = parseEditorVersion("2019.2.1"); + assert(version !== null); + version.should.deepEqual({ major: 2019, minor: 2, patch: 1, }); }); it("test x.y.zan", function () { - parseEditorVersion("2019.2.1a5").should.deepEqual({ + const version = parseEditorVersion("2019.2.1a5"); + assert(version !== null); + version.should.deepEqual({ major: 2019, minor: 2, patch: 1, @@ -348,7 +360,9 @@ describe("cmd-core.ts", function () { }); }); it("test x.y.zbn", function () { - parseEditorVersion("2019.2.1b5").should.deepEqual({ + const version = parseEditorVersion("2019.2.1b5"); + assert(version !== null); + version.should.deepEqual({ major: 2019, minor: 2, patch: 1, @@ -358,7 +372,9 @@ describe("cmd-core.ts", function () { }); }); it("test x.y.zfn", function () { - parseEditorVersion("2019.2.1f5").should.deepEqual({ + const version = parseEditorVersion("2019.2.1f5"); + assert(version !== null); + version.should.deepEqual({ major: 2019, minor: 2, patch: 1, @@ -368,7 +384,9 @@ describe("cmd-core.ts", function () { }); }); it("test x.y.zcn", function () { - parseEditorVersion("2019.2.1f1c5").should.deepEqual({ + const version = parseEditorVersion("2019.2.1f1c5"); + assert(version !== null); + version.should.deepEqual({ major: 2019, minor: 2, patch: 1,