diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 74153de..c2b42b0 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -9,8 +9,8 @@ jobs: tests: strategy: matrix: - os: [ubuntu-latest, macos-latest] - deno: ["1.1.0"] + os: [ubuntu-latest, macos-latest, windows-latest] + deno: ["1.1.1"] runs-on: ${{ matrix.os }} steps: @@ -24,7 +24,7 @@ jobs: - name: Unit run: | deno cache mod.ts - deno test --allow-read --allow-run --allow-net + deno test --allow-read --allow-run --allow-write --allow-net linting: strategy: matrix: diff --git a/README.md b/README.md index c57825f..729c107 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ As dmm only needs to read and write to your `deps.ts`, as well as requiring netw *Install* ``` -$ deno install --allow-net --allow-read --allow-write https://deno.land/x/dmm@v1.1.0/mod.ts +$ deno install --allow-net --allow-read --allow-write https://deno.land/x/dmm@v1.1.1/mod.ts $ dmm ... ``` @@ -58,7 +58,7 @@ $ dmm ... If you are using this method, be sure to use the latest version of dmm in the command below ``` -$ deno run https://deno.land/x/dmm@v1.1.0/mod.ts ... +$ deno run https://deno.land/x/dmm@v1.1.1/mod.ts ... ``` In the examples below, dmm is installed and we will be using it that way to make the commands easier to read. @@ -78,10 +78,10 @@ Information on fmt - Name: fmt - Description: Cannot retrieve descriptions for std modules - - deno.land Link: https://deno.land/std@0.57.0/fmt + - deno.land Link: https://deno.land/std@0.58.0/fmt - GitHub Repository: https://github.com/denoland/deno/tree/master/std/fmt - - Import Statement: import * as fmt from "https://deno.land/std@0.57.0/fmt"; - - Latest Version: 0.57.0 + - Import Statement: import * as fmt from "https://deno.land/std@0.58.0/fmt"; + - Latest Version: 0.58.0 ``` @@ -94,7 +94,7 @@ export { Drash } from "https://deno.land/x/drash@v1.0.0/mod.ts"; // out of date import * as fs from "https://deno.land/std@0.53.0/fs/mod.ts"; // out of date -import * as colors from "https://deno.land/std@0.57.0/fmt/colors.ts"; // up to date +import * as colors from "https://deno.land/std@0.58.0/fmt/colors.ts"; // up to date export { fs, colors } ``` @@ -109,7 +109,7 @@ Now we want to check if any of our dependencies need updating, but we don't want $ dmm check ... drash can be updated from v1.0.0 to v1.0.5 -fs can be updated from 0.53.0 to 0.57.0 +fs can be updated from 0.53.0 to 0.58.0 ... ``` @@ -121,7 +121,7 @@ Lets update our dependencies as some are out of date: $ dmm update ... drash was updated from v1.0.0 to v1.0.5 -fs was updated from 0.53.0 to 0.57.0 +fs was updated from 0.53.0 to 0.58.0 ... ``` @@ -130,9 +130,9 @@ Now lets check the `deps.ts` file, and you will notice the versions have been mo ```typescript export { Drash } from "https://deno.land/x/drash@v1.0.5/mod.ts"; // was out of date -import * as fs from "https://deno.land/std@0.57.0/fs/mod.ts"; // was out of date +import * as fs from "https://deno.land/std@0.58.0/fs/mod.ts"; // was out of date -import * as colors from "https://deno.land/std@0.57.0/fmt/colors.ts"; +import * as colors from "https://deno.land/std@0.58.0/fmt/colors.ts"; export { fs, colors } ``` @@ -147,7 +147,7 @@ $ dmm --help A module manager for Deno. USAGE: - deno run --allow-read --allow-net [--allow-write] https://deno.land/x/dmm@v1.1.0/mod.ts [ARGS] [MODULES] + deno run --allow-read --allow-net [--allow-write] https://deno.land/x/dmm@v1.1.1/mod.ts [ARGS] [MODULES] dmm [ARGS] [MODULES] @@ -171,9 +171,9 @@ OPTIONS: EXAMPLE USAGE: Assume you are importing an out of date version of `fs` from `std`. - deno run --allow-net --allow-read https://deno.land/x/dmm@v1.1.0/mod.ts check fs - deno run --allow-net --allow-read --allow-write https://deno.land/x/dmm@v1.1.0/mod.ts update fs - deno run --allow-net https://deno.land/x/dmm@v1.1.0/mod.ts info http + deno run --allow-net --allow-read https://deno.land/x/dmm@v1.1.1/mod.ts check fs + deno run --allow-net --allow-read --allow-write https://deno.land/x/dmm@v1.1.1/mod.ts update fs + deno run --allow-net https://deno.land/x/dmm@v1.1.1/mod.ts info http dmm info http ``` diff --git a/src/commands/update.ts b/src/commands/update.ts index b4b1ee8..a4b0b25 100644 --- a/src/commands/update.ts +++ b/src/commands/update.ts @@ -29,10 +29,17 @@ export async function update(dependencies: string[]): Promise { if (module.importedVersion === module.latestRelease) { return; } - depsContent = depsContent.replace( - "std@" + module.importedVersion + "/" + module.name, - "std@" + module.latestRelease + "/" + module.name, - ); + if (module.std) { + depsContent = depsContent.replace( + "std@" + module.importedVersion + "/" + module.name, + "std@" + module.latestRelease + "/" + module.name, + ); + } else { + depsContent = depsContent.replace( + module.name + "@" + module.importedVersion, + module.name + "@" + module.latestRelease, + ); + } console.info( colours.green( module.name + " was updated from " + module.importedVersion + " to " + diff --git a/src/options/help.ts b/src/options/help.ts index dc0f8e1..631e74d 100644 --- a/src/options/help.ts +++ b/src/options/help.ts @@ -4,7 +4,7 @@ export const helpMessage: string = "\n" + "\n" + "USAGE:" + "\n" + - " deno run --allow-read --allow-net [--allow-write] https://deno.land/x/dmm@v1.1.0/mod.ts [ARGS] [MODULES]" + + " deno run --allow-read --allow-net [--allow-write] https://deno.land/x/dmm@v1.1.1/mod.ts [ARGS] [MODULES]" + "\n" + "\n" + " dmm [ARGS] [MODULES]" + @@ -45,11 +45,11 @@ export const helpMessage: string = "\n" + "\n" + " Assume you are importing an out of date version of `fs` from `std`." + "\n" + - " deno run --allow-net --allow-read https://deno.land/x/dmm@v1.1.0/mod.ts check fs" + + " deno run --allow-net --allow-read https://deno.land/x/dmm@v1.1.1/mod.ts check fs" + "\n" + - " deno run --allow-net --allow-read --allow-write https://deno.land/x/dmm@v1.1.0/mod.ts update fs" + + " deno run --allow-net --allow-read --allow-write https://deno.land/x/dmm@v1.1.1/mod.ts update fs" + "\n" + - " deno run --allow-net https://deno.land/x/dmm@v1.1.0/mod.ts info http" + + " deno run --allow-net https://deno.land/x/dmm@v1.1.1/mod.ts info http" + "\n" + " dmm info http" + "\n"; diff --git a/src/options/version.ts b/src/options/version.ts index 5c94f68..5dee28f 100644 --- a/src/options/version.ts +++ b/src/options/version.ts @@ -1,2 +1,2 @@ -const version = "1.1.0"; +const version = "1.1.1"; export const versionMessage = `dmm ${version}`; diff --git a/tests/help_test.ts b/tests/help_test.ts index 673d435..eb9133b 100644 --- a/tests/help_test.ts +++ b/tests/help_test.ts @@ -22,7 +22,7 @@ Deno.test({ "A module manager for Deno.\n" + "\n" + "USAGE:\n" + - " deno run --allow-read --allow-net [--allow-write] https://deno.land/x/dmm@v1.1.0/mod.ts [ARGS] [MODULES]\n" + + " deno run --allow-read --allow-net [--allow-write] https://deno.land/x/dmm@v1.1.1/mod.ts [ARGS] [MODULES]\n" + "\n" + " dmm [ARGS] [MODULES]\n" + "\n" + @@ -51,9 +51,9 @@ Deno.test({ "\n" + "EXAMPLE USAGE:\n" + " Assume you are importing an out of date version of `fs` from `std`.\n" + - " deno run --allow-net --allow-read https://deno.land/x/dmm@v1.1.0/mod.ts check fs\n" + - " deno run --allow-net --allow-read --allow-write https://deno.land/x/dmm@v1.1.0/mod.ts update fs\n" + - " deno run --allow-net https://deno.land/x/dmm@v1.1.0/mod.ts info http\n" + + " deno run --allow-net --allow-read https://deno.land/x/dmm@v1.1.1/mod.ts check fs\n" + + " deno run --allow-net --allow-read --allow-write https://deno.land/x/dmm@v1.1.1/mod.ts update fs\n" + + " deno run --allow-net https://deno.land/x/dmm@v1.1.1/mod.ts info http\n" + " dmm info http\n" + "\n", ); diff --git a/tests/out-of-date-deps/deps.ts b/tests/out-of-date-deps/deps.ts index c496ddd..9b73308 100644 --- a/tests/out-of-date-deps/deps.ts +++ b/tests/out-of-date-deps/deps.ts @@ -4,6 +4,4 @@ import * as fs from "https://deno.land/std@0.53.0/fs/mod.ts"; // out of date import * as colors from "https://deno.land/std@v0.53.0/fmt/colors.ts"; // out to date -import { Drash as drash } from "https://deno.land/x/drash@v1.0.6/mod.ts"; // up to date - export { Drash, fs, colors }; diff --git a/tests/out-of-date-deps/original_deps.ts b/tests/out-of-date-deps/original_deps.ts new file mode 100644 index 0000000..9b73308 --- /dev/null +++ b/tests/out-of-date-deps/original_deps.ts @@ -0,0 +1,7 @@ +import { Drash } from "https://deno.land/x/drash@v1.0.0/mod.ts"; // out of date + +import * as fs from "https://deno.land/std@0.53.0/fs/mod.ts"; // out of date + +import * as colors from "https://deno.land/std@v0.53.0/fmt/colors.ts"; // out to date + +export { Drash, fs, colors }; diff --git a/tests/up-to-date-deps/deps.ts b/tests/up-to-date-deps/deps.ts index b075480..80e566f 100644 --- a/tests/up-to-date-deps/deps.ts +++ b/tests/up-to-date-deps/deps.ts @@ -1,9 +1,7 @@ import { Drash } from "https://deno.land/x/drash@v1.0.6/mod.ts"; // up to date -import * as fs from "https://deno.land/std@0.58.0/fs/mod.ts"; // up to date +import * as fs from "https://deno.land/std@0.59.0/fs/mod.ts"; // up to date -import * as colors from "https://deno.land/std@0.58.0/fmt/colors.ts"; // up to date - -import { Drash as drash } from "https://deno.land/x/drash@v1.0.6/mod.ts"; // up to date +import * as colors from "https://deno.land/std@0.59.0/fmt/colors.ts"; // up to date export { Drash, fs, colors }; diff --git a/tests/up-to-date-deps/original_deps.ts b/tests/up-to-date-deps/original_deps.ts new file mode 100644 index 0000000..80e566f --- /dev/null +++ b/tests/up-to-date-deps/original_deps.ts @@ -0,0 +1,7 @@ +import { Drash } from "https://deno.land/x/drash@v1.0.6/mod.ts"; // up to date + +import * as fs from "https://deno.land/std@0.59.0/fs/mod.ts"; // up to date + +import * as colors from "https://deno.land/std@0.59.0/fmt/colors.ts"; // up to date + +export { Drash, fs, colors }; diff --git a/tests/update_test.ts b/tests/update_test.ts index 7ca11c1..a9aaa91 100644 --- a/tests/update_test.ts +++ b/tests/update_test.ts @@ -1,76 +1,506 @@ // Update a specific dep that can be updated -import { assertEquals } from "../deps.ts"; +import { assertEquals, colours } from "../deps.ts"; -// Deno.test({ -// name: 'Update | Single | Modules to Update Exist', -// async fn(): Promise { -// -// } -// }) -// -// // Update a specific dep that is already up to date -// Deno.test({ -// name: 'Update | Single | No Modules to Update', -// async fn(): Promise { -// -// } -// }) -// -// // Update many deps that can be updated -// Deno.test({ -// name: 'Update | Many | Modules to Update Exist', -// async fn(): Promise { -// -// } -// }) -// -// // Update many deps that are already up to date -// Deno.test({ -// name: 'Update | Many | No Modules to Update', -// async fn(): Promise { -// -// } -// }) -// -// Deno.test({ -// name: 'Update | All | Modules to Update Exist', -// async fn(): Promise { -// -// } -// }) -// -// Deno.test({ -// name: 'Update | All | Modules to Update Exist', -// async fn(): Promise { -// -// } -// }) -// -// Deno.test({ -// name: 'Update | Single | std', -// async (): Promise { -// -// } -// }) -// -// Deno.test({ -// name: 'Update | Single | 3rd Party', -// async fn(): Promise { +/** + * @param dir eg "out-of-date-deps" + */ +function defaultDepsBackToOriginal(dir: string): void { + const pathToOriginal = "tests/" + dir + "/original_deps.ts"; + const pathToMain = "tests/" + dir + "/deps.ts"; + const originalContent = new TextDecoder().decode( + Deno.readFileSync(pathToOriginal), + ); + Deno.writeFileSync(pathToMain, new TextEncoder().encode(originalContent)); +} + +/** + * @param dir eg "out-of-date-deps" + */ +function emptyDependencyFile(dir: string): void { + const path = "tests/" + dir + "/deps.ts"; + Deno.writeFileSync(path, new TextEncoder().encode("")); +} + +/** + * @param dir eg "out-of-date-deps" --> "tests/out-of-date-deps/deps.ts + */ +function removeDependencyFile(dir: string): void { + try { + const path = "tests/" + dir + "/deps.ts"; + Deno.removeSync(path); + } catch (err) { + } +} + +Deno.test({ + name: "Update | Single | Modules to Update Exist", + async fn(): Promise { + defaultDepsBackToOriginal("out-of-date-deps"); + const p = await Deno.run({ + cmd: [ + "deno", + "run", + "--allow-net", + "--allow-read", + "--allow-write", + "../../mod.ts", + "update", + "fs", + ], + cwd: "./tests/out-of-date-deps", + stdout: "piped", + stderr: "piped", + }); + const status = await p.status(); + const output = await p.output(); + await p.close(); + const stdout = new TextDecoder("utf-8").decode(output); + const error = await p.stderrOutput(); + const stderr = new TextDecoder("utf-8").decode(error); + assertEquals( + stdout, + "Gathering facts...\n" + + "Reading deps.ts to gather your dependencies...\n" + + "Checking if your modules can be updated...\n" + + colours.green("fs was updated from 0.53.0 to 0.59.0") + "\n", + ); + assertEquals(stderr, ""); + assertEquals(status.code, 0); + assertEquals(status.success, true); + const originalDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/original_deps.ts"), + ); + const newDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/deps.ts"), + ); + assertEquals(newDepContent !== originalDepContent, true); + assertEquals(newDepContent.indexOf("std@0.59.0/fs") !== -1, true); + defaultDepsBackToOriginal("out-of-date-deps"); + }, +}); // -// } -// }) +// Update a specific dep that is already up to date +Deno.test({ + name: "Update | Single | No Modules to Update", + async fn(): Promise { + const p = await Deno.run({ + cmd: [ + "deno", + "run", + "--allow-net", + "--allow-read", + "--allow-write", + "../../mod.ts", + "update", + "fs", + ], + cwd: "./tests/up-to-date-deps", + stdout: "piped", + stderr: "piped", + }); + const status = await p.status(); + const output = await p.output(); + await p.close(); + const stdout = new TextDecoder("utf-8").decode(output); + const error = await p.stderrOutput(); + const stderr = new TextDecoder("utf-8").decode(error); + assertEquals( + stdout, + "Gathering facts...\n" + + "Reading deps.ts to gather your dependencies...\n" + + "Checking if your modules can be updated...\n" + + colours.green("Everything is already up to date") + "\n", + ); + assertEquals(stderr, ""); + assertEquals(status.code, 0); + assertEquals(status.success, true); + const originalDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/original_deps.ts"), + ); + const newDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/deps.ts"), + ); + assertEquals(newDepContent === originalDepContent, true); + }, +}); + +// Update many deps that can be updated +Deno.test({ + name: "Update | Many | Modules to Update Exist", + async fn(): Promise { + defaultDepsBackToOriginal("out-of-date-deps"); + const p = await Deno.run({ + cmd: [ + "deno", + "run", + "--allow-net", + "--allow-read", + "--allow-write", + "../../mod.ts", + "update", + "fs", + "fmt", + ], + cwd: "./tests/out-of-date-deps", + stdout: "piped", + stderr: "piped", + }); + const status = await p.status(); + const output = await p.output(); + await p.close(); + const stdout = new TextDecoder("utf-8").decode(output); + const error = await p.stderrOutput(); + const stderr = new TextDecoder("utf-8").decode(error); + assertEquals( + stdout, + "Gathering facts...\n" + + "Reading deps.ts to gather your dependencies...\n" + + "Checking if your modules can be updated...\n" + + colours.green("fs was updated from 0.53.0 to 0.59.0") + "\n" + + colours.green("fmt was updated from v0.53.0 to v0.59.0") + "\n", + ); + assertEquals(stderr, ""); + assertEquals(status.code, 0); + assertEquals(status.success, true); + const originalDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/original_deps.ts"), + ); + const newDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/deps.ts"), + ); + assertEquals(newDepContent !== originalDepContent, true); + assertEquals(newDepContent.indexOf("std@0.59.0/fs") !== -1, true); + assertEquals(newDepContent.indexOf("std@v0.59.0/fmt") !== -1, true); + defaultDepsBackToOriginal("out-of-date-deps"); + }, +}); + +// Update many deps that are already up to date +Deno.test({ + name: "Update | Many | No Modules to Update", + async fn(): Promise { + const p = await Deno.run({ + cmd: [ + "deno", + "run", + "--allow-net", + "--allow-read", + "--allow-write", + "../../mod.ts", + "update", + "fs", + "fmt", + ], + cwd: "./tests/up-to-date-deps", + stdout: "piped", + stderr: "piped", + }); + const status = await p.status(); + const output = await p.output(); + await p.close(); + const stdout = new TextDecoder("utf-8").decode(output); + const error = await p.stderrOutput(); + const stderr = new TextDecoder("utf-8").decode(error); + assertEquals( + stdout, + "Gathering facts...\n" + + "Reading deps.ts to gather your dependencies...\n" + + "Checking if your modules can be updated...\n" + + colours.green("Everything is already up to date") + "\n", + ); + assertEquals(stderr, ""); + assertEquals(status.code, 0); + assertEquals(status.success, true); + const originalDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/original_deps.ts"), + ); + const newDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/deps.ts"), + ); + assertEquals(newDepContent === originalDepContent, true); + }, +}); + +Deno.test({ + name: "Update | All | Modules to Update Exist", + async fn(): Promise { + defaultDepsBackToOriginal("out-of-date-deps"); + const p = await Deno.run({ + cmd: [ + "deno", + "run", + "--allow-net", + "--allow-read", + "--allow-write", + "../../mod.ts", + "update", + ], + cwd: "./tests/out-of-date-deps", + stdout: "piped", + stderr: "piped", + }); + const status = await p.status(); + const output = await p.output(); + await p.close(); + const stdout = new TextDecoder("utf-8").decode(output); + const error = await p.stderrOutput(); + const stderr = new TextDecoder("utf-8").decode(error); + assertEquals( + stdout, + "Gathering facts...\n" + + "Reading deps.ts to gather your dependencies...\n" + + "Checking if your modules can be updated...\n" + + colours.green("drash was updated from v1.0.0 to v1.0.6") + "\n" + + colours.green("fs was updated from 0.53.0 to 0.59.0") + "\n" + + colours.green("fmt was updated from v0.53.0 to v0.59.0") + "\n", + ); + assertEquals(stderr, ""); + assertEquals(status.code, 0); + assertEquals(status.success, true); + const originalDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/original_deps.ts"), + ); + const newDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/deps.ts"), + ); + assertEquals(newDepContent !== originalDepContent, true); + assertEquals(newDepContent.indexOf("std@0.59.0/fs") !== -1, true); + assertEquals(newDepContent.indexOf("std@v0.59.0/fmt") !== -1, true); + assertEquals(newDepContent.indexOf("drash@v1.0.6") !== -1, true); + defaultDepsBackToOriginal("out-of-date-deps"); + }, +}); + +Deno.test({ + name: "Update | All | Modules to Update Don't Exist", + async fn(): Promise { + const p = await Deno.run({ + cmd: [ + "deno", + "run", + "--allow-net", + "--allow-read", + "--allow-write", + "../../mod.ts", + "update", + ], + cwd: "./tests/up-to-date-deps", + stdout: "piped", + stderr: "piped", + }); + const status = await p.status(); + const output = await p.output(); + await p.close(); + const stdout = new TextDecoder("utf-8").decode(output); + const error = await p.stderrOutput(); + const stderr = new TextDecoder("utf-8").decode(error); + assertEquals( + stdout, + "Gathering facts...\n" + + "Reading deps.ts to gather your dependencies...\n" + + "Checking if your modules can be updated...\n" + + colours.green("Everything is already up to date") + "\n", + ); + assertEquals(stderr, ""); + assertEquals(status.code, 0); + assertEquals(status.success, true); + const originalDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/original_deps.ts"), + ); + const newDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/deps.ts"), + ); + assertEquals(newDepContent === originalDepContent, true); + }, +}); + +Deno.test({ + name: "Update | Single | Third Party", + async fn(): Promise { + defaultDepsBackToOriginal("out-of-date-deps"); + const p = await Deno.run({ + cmd: [ + "deno", + "run", + "--allow-net", + "--allow-read", + "--allow-write", + "../../mod.ts", + "update", + "drash", + ], + cwd: "./tests/out-of-date-deps", + stdout: "piped", + stderr: "piped", + }); + const status = await p.status(); + const output = await p.output(); + await p.close(); + const stdout = new TextDecoder("utf-8").decode(output); + const error = await p.stderrOutput(); + const stderr = new TextDecoder("utf-8").decode(error); + assertEquals( + stdout, + "Gathering facts...\n" + + "Reading deps.ts to gather your dependencies...\n" + + "Checking if your modules can be updated...\n" + + colours.green("drash was updated from v1.0.0 to v1.0.6") + "\n", + ); + assertEquals(stderr, ""); + assertEquals(status.code, 0); + assertEquals(status.success, true); + const originalDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/original_deps.ts"), + ); + const newDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/deps.ts"), + ); + assertEquals(newDepContent !== originalDepContent, true); + assertEquals(newDepContent.indexOf("drash@v1.0.6") !== -1, true); + defaultDepsBackToOriginal("out-of-date-deps"); + }, +}); + +Deno.test({ + name: "Update | Modules Dont Exist in Dependencies", + async fn(): Promise { + const p = await Deno.run({ + cmd: [ + "deno", + "run", + "--allow-net", + "--allow-read", + "../../mod.ts", + "update", + "denon", + "io", + ], + cwd: "./tests/up-to-date-deps", + stdout: "piped", + stderr: "piped", + }); + const status = await p.status(); + const output = await p.output(); + await p.close(); + const stdout = new TextDecoder("utf-8").decode(output); + const error = await p.stderrOutput(); + const stderr = new TextDecoder("utf-8").decode(error); + assertEquals( + stdout, + "Gathering facts...\n" + + "Reading deps.ts to gather your dependencies...\n", + ); + assertEquals( + stderr, + colours.red("Modules specified do not exist in your dependencies.") + + "\n", + ); + assertEquals(status.code, 1); + assertEquals(status.success, false); + const originalDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/original_deps.ts"), + ); + const newDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/deps.ts"), + ); + assertEquals(newDepContent === originalDepContent, true); + }, +}); + +Deno.test({ + name: "Update | single | Keeps the `v` if it exists in the imported version", + async fn(): Promise { + defaultDepsBackToOriginal("out-of-date-deps"); + const p = await Deno.run({ + cmd: [ + "deno", + "run", + "--allow-net", + "--allow-read", + "--allow-write", + "../../mod.ts", + "update", + "fmt", + "drash", + ], + cwd: "./tests/out-of-date-deps", + stdout: "piped", + stderr: "piped", + }); + const status = await p.status(); + const output = await p.output(); + await p.close(); + const stdout = new TextDecoder("utf-8").decode(output); + const error = await p.stderrOutput(); + const stderr = new TextDecoder("utf-8").decode(error); + assertEquals( + stdout, + "Gathering facts...\n" + + "Reading deps.ts to gather your dependencies...\n" + + "Checking if your modules can be updated...\n" + + colours.green("drash was updated from v1.0.0 to v1.0.6") + "\n" + + colours.green("fmt was updated from v0.53.0 to v0.59.0") + "\n", + ); + assertEquals(stderr, ""); + assertEquals(status.code, 0); + assertEquals(status.success, true); + const originalDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/original_deps.ts"), + ); + const newDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/deps.ts"), + ); + assertEquals(newDepContent !== originalDepContent, true); + assertEquals(newDepContent.indexOf("std@v0.59.0/fmt") !== -1, true); + assertEquals(newDepContent.indexOf("drash@v1.0.6") !== -1, true); + defaultDepsBackToOriginal("out-of-date-deps"); + }, +}); -// Deno.test({ -// name: 'Update | Modules Dont Exist in Dependencies', -// async fn(): Promise { -// const p = await Deno.run({ -// cmd: ["deno", "run", "--allow-net", "--allow-read", "../../mod.ts", "update", "denon", "io"], -// cwd: "./tests/up-to-date-deps", -// stdout: "null" -// }) -// const status = await p.status() -// p.close() -// assertEquals(status.code, 1) -// assertEquals(status.success, false) -// } -// }) +Deno.test({ + name: + "Update | single | Omits a `v` if it is not present in the imported version", + async fn(): Promise { + defaultDepsBackToOriginal("out-of-date-deps"); + const p = await Deno.run({ + cmd: [ + "deno", + "run", + "--allow-net", + "--allow-read", + "--allow-write", + "../../mod.ts", + "update", + "fs", + ], + cwd: "./tests/out-of-date-deps", + stdout: "piped", + stderr: "piped", + }); + const status = await p.status(); + const output = await p.output(); + await p.close(); + const stdout = new TextDecoder("utf-8").decode(output); + const error = await p.stderrOutput(); + const stderr = new TextDecoder("utf-8").decode(error); + assertEquals( + stdout, + "Gathering facts...\n" + + "Reading deps.ts to gather your dependencies...\n" + + "Checking if your modules can be updated...\n" + + colours.green("fs was updated from 0.53.0 to 0.59.0") + "\n", + ); + assertEquals(stderr, ""); + assertEquals(status.code, 0); + assertEquals(status.success, true); + const originalDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/original_deps.ts"), + ); + const newDepContent = new TextDecoder("utf-8").decode( + Deno.readFileSync("tests/out-of-date-deps/deps.ts"), + ); + assertEquals(newDepContent !== originalDepContent, true); + assertEquals(newDepContent.indexOf("std@0.59.0/fs") !== -1, true); + defaultDepsBackToOriginal("out-of-date-deps"); + }, +});